@objectstack/console 9.9.0 → 9.10.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/dist/assets/{AiPendingActionsPage-BI-QQNee.js → AiPendingActionsPage-BDYUc-T8.js} +1 -1
  2. package/dist/assets/{ApiConsolePage-CPV6vWpt.js → ApiConsolePage-BJB9Xho6.js} +1 -1
  3. package/dist/assets/{AppDocsIndex-D4Y3i2rM.js → AppDocsIndex-Cj0DpA3d.js} +1 -1
  4. package/dist/assets/{AppManagementPage-CLiHbNPr.js → AppManagementPage-BzjUDLx3.js} +1 -1
  5. package/dist/assets/{ApprovalsInboxPage-CAyznoRP.js → ApprovalsInboxPage-Dym3zM3t.js} +1 -1
  6. package/dist/assets/{AuditLogPage-BeEqEy4g.js → AuditLogPage-BJh3wy1L.js} +1 -1
  7. package/dist/assets/{ComponentNavView-DmALsugj.js → ComponentNavView-BFSklq8D.js} +1 -1
  8. package/dist/assets/{ConsoleFloatingChatbot-CXwRB3yg.js → ConsoleFloatingChatbot-_UeVODsx.js} +1 -1
  9. package/dist/assets/{DashboardView-BF0o0wgx.js → DashboardView-kL9_gMzd.js} +1 -1
  10. package/dist/assets/{DashboardWidgetInspector-DIMge0qc.js → DashboardWidgetInspector-BN8Yy27Q.js} +1 -1
  11. package/dist/assets/{DeveloperHubPage-DbQwi1EV.js → DeveloperHubPage-CB5nkyun.js} +1 -1
  12. package/dist/assets/{FlowRunsPage-CJDL4g0k.js → FlowRunsPage-65yB_BWO.js} +1 -1
  13. package/dist/assets/{IntegrationsPage-DU_wvj4-.js → IntegrationsPage-8M_88h2y.js} +2 -2
  14. package/dist/assets/{InterfaceListPage-DZpFSsQf.js → InterfaceListPage-CBomrdcf.js} +1 -1
  15. package/dist/assets/{ManagedByBadge-Difq_L_A.js → ManagedByBadge-Bmg77Q4v.js} +1 -1
  16. package/dist/assets/{MarketplaceAccessDenied-CXUE33gy.js → MarketplaceAccessDenied-CX0RbkOJ.js} +1 -1
  17. package/dist/assets/{MarketplaceInstalledPage-CBfcARvX.js → MarketplaceInstalledPage-BYXiUCpz.js} +1 -1
  18. package/dist/assets/{MarketplacePackagePage-BWCVUz3e.js → MarketplacePackagePage-C8yVjW5r.js} +2 -2
  19. package/dist/assets/{MarketplacePage-BT-WkhAG.js → MarketplacePage-pVW-NfrG.js} +1 -1
  20. package/dist/assets/{MetadataInspector-BRICMLXW.js → MetadataInspector-CACgSTc7.js} +1 -1
  21. package/dist/assets/{MetadataProvider-CEw2X-qL.js → MetadataProvider-Dh20h6BN.js} +1 -1
  22. package/dist/assets/{PageView-CP-3dRzz.js → PageView-D388xYQA.js} +1 -1
  23. package/dist/assets/{ProfilePage-BAtKSxuK.js → ProfilePage-SXmEEOn3.js} +1 -1
  24. package/dist/assets/{PublicFormsPage-D7D2WWL7.js → PublicFormsPage-aXes2XrW.js} +1 -1
  25. package/dist/assets/{RecordDetailView-BdQK61l2.js → RecordDetailView-DIiHv2mR.js} +1 -1
  26. package/dist/assets/{RecordFormPage-lFVOsTl0.js → RecordFormPage-C052nJig.js} +1 -1
  27. package/dist/assets/ReportDefaultInspector-CjR-PcBn.js +1 -0
  28. package/dist/assets/{ReportView-BHtzV5eK.js → ReportView-M_mx8mgW.js} +1 -1
  29. package/dist/assets/{RuntimeDraftBar-DXwH4Hvd.js → RuntimeDraftBar-DTf-DIfT.js} +1 -1
  30. package/dist/assets/{SearchResultsPage-CE_LTSSU.js → SearchResultsPage-DGuFKZit.js} +1 -1
  31. package/dist/assets/{SettingsHub-BLEC_8Ao.js → SettingsHub-eYWWi8O5.js} +1 -1
  32. package/dist/assets/{SettingsView-BEjR60F6.js → SettingsView-Cq3IKOhI.js} +1 -1
  33. package/dist/assets/{SystemHubPage-DjNBraYu.js → SystemHubPage-6FccxnKY.js} +1 -1
  34. package/dist/assets/{highlighted-body-OFNGDK62-DiT7C6XW.js → highlighted-body-OFNGDK62-CKMBhexn.js} +1 -1
  35. package/dist/assets/index-A8r_lURn.js +4 -0
  36. package/dist/assets/index-BGyrRTzt.css +2 -0
  37. package/dist/assets/{mergeServerFields-djmY7AgR.js → mergeServerFields-CMIOI8QD.js} +2 -2
  38. package/dist/assets/mermaid-GHXKKRXX-C3g3SOag.js +1 -0
  39. package/dist/assets/metadata-admin-ORqaeHUJ.js +19 -0
  40. package/dist/assets/plugin-calendar-Czocnijo.js +1 -0
  41. package/dist/assets/{plugin-charts-AMObsZz3.js → plugin-charts-dCyWH9k8.js} +1 -1
  42. package/dist/assets/{plugin-chatbot-Ch8YIyYL.js → plugin-chatbot-BpAQS7-q.js} +6 -6
  43. package/dist/assets/plugin-dashboard-CjtE0zwv.js +5 -0
  44. package/dist/assets/plugin-form-Dzz6GAZM.js +1 -0
  45. package/dist/assets/plugin-gantt-BedjcmIc.js +23 -0
  46. package/dist/assets/plugin-grid-BqmF7p-H.js +6 -0
  47. package/dist/assets/{plugin-kanban-DOsTOpJz.js → plugin-kanban-Dq0xJjXt.js} +1 -1
  48. package/dist/assets/{plugin-map-Bid9UXOR.js → plugin-map-DG62gl97.js} +1 -1
  49. package/dist/assets/{plugin-markdown-BUQOG31j.js → plugin-markdown-BL0QvMCD.js} +1 -1
  50. package/dist/assets/{plugin-report-FxG9jOvy.js → plugin-report-DckNGNq6.js} +1 -1
  51. package/dist/assets/{plugin-timeline-DDrFKEb8.js → plugin-timeline-dBrX3lS3.js} +1 -1
  52. package/dist/assets/plugin-view-DCPYomdU.js +1 -0
  53. package/dist/assets/plugins-views-B-EGcBP2.js +4 -0
  54. package/dist/assets/{resolveActionParams-C_x4GXvS.js → resolveActionParams-B_7wSkli.js} +1 -1
  55. package/dist/assets/{skeletons-B_SNEnMn.js → skeletons-BK7w4pLE.js} +1 -1
  56. package/dist/assets/src-9qM7N8MR.js +2 -0
  57. package/dist/assets/{src-DbxuLwqh.js → src-Czx03pos.js} +1 -1
  58. package/dist/assets/{types-CosU35As.js → types-C2_UYDEK.js} +1 -1
  59. package/dist/assets/{ui-components-CrPYFyEM.js → ui-components-NS_7__gn.js} +7 -7
  60. package/dist/assets/{ui-layout-DAWxaQvy.js → ui-layout-BdKOzi1L.js} +1 -1
  61. package/dist/assets/{useActionModal-DDu3wUOI.js → useActionModal-BE61500N.js} +1 -1
  62. package/dist/assets/{useReconcileOnError-Agbi2njU.js → useReconcileOnError-Cvd01WQv.js} +1 -1
  63. package/dist/assets/{utils-bipVuqQL.js → utils-29quoGQV.js} +1 -1
  64. package/dist/index.html +3 -3
  65. package/package.json +1 -1
  66. package/dist/assets/ReportDefaultInspector-GD1EQSTh.js +0 -1
  67. package/dist/assets/index-CJe1zUD0.css +0 -2
  68. package/dist/assets/index-DdQV1cqi.js +0 -4
  69. package/dist/assets/mermaid-GHXKKRXX-CK-9EMhD.js +0 -1
  70. package/dist/assets/metadata-admin-BbJpmVQm.js +0 -19
  71. package/dist/assets/plugin-calendar-DQC9zdKq.js +0 -1
  72. package/dist/assets/plugin-dashboard-C7fxXXeO.js +0 -5
  73. package/dist/assets/plugin-form-gQDKenio.js +0 -1
  74. package/dist/assets/plugin-gantt-BHmpu6VX.js +0 -23
  75. package/dist/assets/plugin-grid-boi_rkH3.js +0 -6
  76. package/dist/assets/plugin-view-DhNkNfUe.js +0 -1
  77. package/dist/assets/plugins-views-DUKPQNs8.js +0 -4
  78. package/dist/assets/src-Bzm5L_v8.js +0 -2
@@ -1,4 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css","./plugin-map-CsMXqW6n.css"])))=>i.map(i=>d[i]);
2
- import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,a as r,c as i,f as a,h as o,l as s,m as c,n as l,o as u,p as d,r as f,s as p,t as m,u as h}from"./vendor-react-DR370ovB.js";import{a as g,c as _,f as v,i as y,l as b,p as x,r as S,s as C,u as w}from"./infrastructure-CJNwTVno.js";import{B as T,T as E,V as D,at as O,et as k,ht as A,n as j,ot as ee,r as M,w as N}from"./framework-BLEk-ou3.js";import{$i as te,$n as P,$r as ne,$s as re,Ai as ie,Ar as ae,As as oe,Ba as se,Bo as ce,Co as le,Cs as F,Da as ue,Ds as de,Ea as fe,Eo as pe,Es as me,Fi as he,Fo as I,Fs as ge,Gi as _e,Ha as ve,Ia as ye,Io as be,Ir as xe,Ji as Se,Jn as Ce,Js as we,Ka as Te,La as Ee,Li as De,Lr as Oe,Ls as ke,Ma as Ae,O as je,Os as Me,Pa as Ne,Po as Pe,Pr as Fe,Ps as Ie,Qo as Le,Qr as Re,Ra as ze,Rr as Be,Sa as Ve,Si as He,Sr as Ue,Ta as We,Ts as Ge,Ui as Ke,Uo as qe,Ur as Je,Va as Ye,Vr as Xe,Wo as Ze,Xa as Qe,Xi as $e,Xn as L,Yn as R,Yo as et,Zn as z,Zo as tt,Zr as nt,_ as rt,_o as it,ao as at,as as ot,at as st,ca as ct,cs as lt,di as ut,do as dt,ea as ft,ga as pt,gs as mt,hr as B,ia as ht,ii as gt,io as _t,it as vt,ja as yt,ka as bt,lo as xt,ma as St,na as Ct,ni as wt,nn as V,nt as Tt,oa as Et,on as H,oo as Dt,pc as Ot,qn as U,ra as kt,rt as At,sc as jt,to as Mt,tt as Nt,v as Pt,vr as Ft,wa as It,y as Lt,ya as Rt,yi as zt,yr as Bt,ys as Vt,za as Ht,zr as Ut}from"./ui-components-CrPYFyEM.js";import{a as W,o as G,r as K}from"./vendor-ui-utils-rQOI1gAo.js";import{_ as Wt,a as Gt,c as Kt,d as qt,f as Jt,g as Yt,h as Xt,i as Zt,l as Qt,m as $t,n as en,o as tn,p as q,r as nn,s as rn,t as an,u as on,v as sn}from"./src-Bzm5L_v8.js";import"./data-adapter-CCidkDs3.js";import{n as cn,r as ln}from"./plugin-form-gQDKenio.js";import{l as un}from"./useReconcileOnError-Agbi2njU.js";import{t as dn}from"./useActionModal-DDu3wUOI.js";import{v as fn,x as pn,y as mn}from"./marketplaceApi-CucX7DD9.js";import"./plugins-views-DUKPQNs8.js";import{i as hn,r as gn}from"./plugin-grid-boi_rkH3.js";import"./plugin-view-DhNkNfUe.js";import{n as _n}from"./componentRegistry-ByxoJqMW.js";import{r as vn,t as yn}from"./plugin-markdown-BUQOG31j.js";var J=e(n(),1),bn=e(o(),1),Y=m(),xn={type:`object-master-detail-form`,objectName:`expense_claim`,mode:`create`,formType:`simple`,title:`New Expense Claim`,submitText:`Create Claim`,fields:[`title`,`applicant`,`department`,`reason`,`currency`,`claim_status`,`payment_status`,`remarks`],details:[{title:`Expense Lines`,childObject:`expense_line`,relationshipField:`expense_claim`,amountField:`amount`,totalField:`total_amount`,columns:[{field:`expense_date`,label:`Date`,type:`date`},{field:`category`,label:`Category`,type:`select`,options:[{label:`Travel & Transport`,value:`travel_transport`},{label:`Lodging`,value:`lodging`},{label:`Meals & Entertainment`,value:`meals_entertainment`},{label:`Office Supplies`,value:`office_supplies`},{label:`Communications`,value:`communications`},{label:`Training & Conference`,value:`training_conference`},{label:`Client / Project`,value:`client_project`},{label:`Other`,value:`other`}]},{field:`description`,label:`Description`,type:`text`},{field:`merchant_vendor`,label:`Merchant`,type:`text`},{field:`amount`,label:`Amount`,type:`currency`}]}]},Sn=()=>(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6`,children:[(0,Y.jsx)(`h1`,{className:`mb-4 text-lg font-semibold`,children:`Dev · Master-Detail Form (ADR-0001)`}),(0,Y.jsx)(T,{schema:xn})]}),Cn={type:`element:definition-list`,properties:{columns:2,items:[{term:`Status`,description:`Active`},{term:`Owner`,description:`Ada Lovelace`},{term:`Plan`,description:`Enterprise`},{term:`Renewal`,description:`2026-12-01`}]}},wn={type:`element:repeater`,properties:{object:`showcase_category`,titleField:`name`,fields:[`color`],limit:10,emptyText:`No categories`}},Tn=()=>(0,Y.jsxs)(`div`,{className:`mx-auto max-w-2xl space-y-8 p-6`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`mb-3 text-lg font-semibold`,children:`Dev · element:definition-list`}),(0,Y.jsx)(`div`,{className:`rounded-lg border p-4`,children:(0,Y.jsx)(T,{schema:Cn})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`mb-3 text-lg font-semibold`,children:`Dev · element:repeater (showcase_category)`}),(0,Y.jsx)(`div`,{className:`rounded-lg border p-4`,children:(0,Y.jsx)(T,{schema:wn})})]})]}),En={type:`element:definition-list`,properties:{columns:2,items:[{term:`Status`,description:`Active`},{term:`Owner`,description:`Ada Lovelace`},{term:`Plan`,description:`Enterprise`},{term:`Renewal`,description:`2026-12-01`}]}},Dn=()=>{let{modalHandler:e,modalElement:t}=dn();return(0,Y.jsxs)(`div`,{className:`space-y-4 p-6`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Action modal transport`}),(0,Y.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`One `,(0,Y.jsx)(`code`,{children:`onModal`}),` handler, four placements, arbitrary SchemaNode content.`]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(B,{"data-testid":`open-center`,onClick:()=>e({placement:`center`,size:`lg`,title:`Center modal`,content:En}),children:`Center`}),(0,Y.jsx)(B,{"data-testid":`open-side`,variant:`outline`,onClick:()=>e({placement:`side`,title:`Side drawer`,content:En}),children:`Side drawer`}),(0,Y.jsx)(B,{"data-testid":`open-bottom`,variant:`outline`,onClick:()=>e({placement:`bottom`,title:`Bottom sheet`,content:En}),children:`Bottom sheet`}),(0,Y.jsx)(B,{"data-testid":`open-fullscreen`,variant:`outline`,onClick:()=>e({placement:`fullscreen`,title:`Fullscreen`,content:En}),children:`Fullscreen`})]}),t]})},On=()=>{let[e,t]=J.useState([{},{}]);return(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-4 p-6`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Line-item grid with a lookup cell`}),(0,Y.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`The `,(0,Y.jsx)(`code`,{children:`Account`}),` column is a real lookup picker bound to live `,(0,Y.jsx)(`code`,{children:`showcase_account`}),`.`]}),(0,Y.jsx)(rt,{value:e,onChange:t,field:{columns:[{field:`account`,label:`Account`,type:`lookup`,reference:`showcase_account`,displayField:`name`},{field:`note`,label:`Note`,type:`text`},{field:`amount`,label:`Amount`,type:`currency`}],total_field:`amount`}}),(0,Y.jsx)(`pre`,{className:`rounded bg-muted p-3 text-xs`,"data-testid":`rows-json`,children:JSON.stringify(e)})]})},kn=(0,J.lazy)(()=>c(()=>import(`./SystemHubPage-DjNBraYu.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0,1]),import.meta.url)),An=(0,J.lazy)(()=>c(()=>import(`./AppManagementPage-CLiHbNPr.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0,1]),import.meta.url)),jn=(0,J.lazy)(()=>c(()=>import(`./ProfilePage-BAtKSxuK.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),Mn=(0,J.lazy)(()=>c(()=>import(`./ApprovalsInboxPage-CAyznoRP.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),Nn=(0,J.lazy)(()=>c(()=>import(`./AiPendingActionsPage-BI-QQNee.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),Pn=(0,J.lazy)(()=>c(()=>import(`./AuditLogPage-BeEqEy4g.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),Fn=(0,J.lazy)(()=>c(()=>import(`./SettingsHub-BLEC_8Ao.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),In=(0,J.lazy)(()=>c(()=>import(`./SettingsView-BEjR60F6.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),Ln=(0,J.lazy)(()=>c(()=>import(`./DeveloperHubPage-DbQwi1EV.js`).then(e=>({default:e.DeveloperHubPage})),__vite__mapDeps([0]),import.meta.url)),Rn=(0,J.lazy)(()=>c(()=>import(`./ApiConsolePage-CPV6vWpt.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0,1]),import.meta.url)),zn=(0,J.lazy)(()=>c(()=>import(`./FlowRunsPage-CJDL4g0k.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0,1]),import.meta.url)),Bn=(0,J.lazy)(()=>c(()=>import(`./PublicFormsPage-D7D2WWL7.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0,1]),import.meta.url)),Vn=(0,J.lazy)(()=>c(()=>import(`./IntegrationsPage-DU_wvj4-.js`).then(e=>({default:e.IntegrationsPage})),__vite__mapDeps([0]),import.meta.url)),Hn=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>Yr),void 0,import.meta.url)),Un=(0,J.lazy)(()=>c(()=>import(`./AppDocsIndex-D4Y3i2rM.js`),__vite__mapDeps([0]),import.meta.url)),Wn=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>$r),void 0,import.meta.url)),Gn=(0,J.lazy)(()=>c(()=>Promise.resolve().then(()=>ti),void 0,import.meta.url));function Kn(){let{objectName:e}=a(),t=s().pathname.replace(/\/objects(\/.*)?$/,``);return(0,Y.jsx)(r,{to:e?`${t}/component/metadata/resource/${e}?type=object`:`${t}/component/metadata/resource?type=object`,replace:!0})}function qn(){let{metadataType:e,itemName:t}=a(),n=s().pathname.replace(/\/metadata(\/.*)?$/,``),i=`${n}/component/metadata/resource`;return(0,Y.jsx)(r,{to:e?t?`${i}/${t}?type=${e}`:`${i}?type=${e}`:`${n}/component/metadata/directory`,replace:!0})}var Jn=(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(p,{path:`system`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(kn,{})})}),(0,Y.jsx)(p,{path:`system/apps`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(An,{})})}),(0,Y.jsx)(p,{path:`system/profile`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(jn,{})})}),(0,Y.jsx)(p,{path:`system/approvals`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Mn,{})})}),(0,Y.jsx)(p,{path:`system/ai-approvals`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Nn,{})})}),(0,Y.jsx)(p,{path:`system/audit-log`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Pn,{})})}),(0,Y.jsx)(p,{path:`system/settings`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Fn,{})})}),(0,Y.jsx)(p,{path:`system/settings/:namespace`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(In,{})})}),(0,Y.jsx)(p,{path:`developer`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Ln,{})})}),(0,Y.jsx)(p,{path:`developer/api-console`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Rn,{})})}),(0,Y.jsx)(p,{path:`developer/flow-runs`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(zn,{})})}),(0,Y.jsx)(p,{path:`developer/public-forms`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Bn,{})})}),(0,Y.jsx)(p,{path:`developer/integrations`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Vn,{})})}),(0,Y.jsxs)(p,{path:`docs`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Gn,{})}),children:[(0,Y.jsx)(p,{index:!0,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Un,{})})}),(0,Y.jsx)(p,{path:`:slug`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Wn,{})})}),(0,Y.jsx)(p,{path:`:slug/:name`,element:(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Hn,{})})})]}),(0,Y.jsx)(p,{path:`system/objects`,element:(0,Y.jsx)(Kn,{})}),(0,Y.jsx)(p,{path:`system/objects/:objectName`,element:(0,Y.jsx)(Kn,{})}),(0,Y.jsx)(p,{path:`system/metadata`,element:(0,Y.jsx)(qn,{})}),(0,Y.jsx)(p,{path:`system/metadata/:metadataType`,element:(0,Y.jsx)(qn,{})}),(0,Y.jsx)(p,{path:`system/metadata/:metadataType/:itemName`,element:(0,Y.jsx)(qn,{})})]});function Yn(){let e=(0,J.useMemo)(()=>Lt({baseUrl:``}),[``]);return(0,Y.jsx)(S,{endpoint:`/api/v1/auth/me/permissions`,loadingFallback:(0,Y.jsx)(q,{}),children:(0,Y.jsx)(Pt,{adapter:e,children:(0,Y.jsx)(on,{extraRoutes:Jn,extraRoutesNoApp:Jn})})})}var Xn=[`cloud_control`];function Zn(){let{apps:e,loading:t}=E();if(t)return(0,Y.jsx)(Yt,{});let n=new Set((e??[]).map(e=>e?.name).filter(Boolean));for(let e of Xn)if(n.has(e))return(0,Y.jsx)(r,{to:`/apps/${e}`,replace:!0});return(0,Y.jsx)(r,{to:`/home`,replace:!0})}var Qn=`/api/v1`;function $n(e){let t=typeof e==`string`?parseInt(e,10):e;return t===1||t===2||t===3||t===4?t:2}function er(e){if(Array.isArray(e))return e.map(e=>{if(typeof e==`string`)return{value:e,label:e};if(e&&typeof e==`object`){let t=String(e.value??e.id??``);return{value:t,label:String(e.label??e.name??t)}}return{value:String(e),label:String(e)}})}function tr(e,t){let n=e.sections??e.groups??[],r=t?.fields??{};return n.map(e=>{let t=$n(e.columns),n=[];for(let t of e.fields??[]){let e=typeof t==`string`?{field:t}:{...t},i=r[e.field]??{type:`text`};n.push({name:e.field,label:e.label??i.label??e.field,type:i.type??`text`,required:e.required??i.required??!1,readonly:e.readonly??!1,hidden:e.hidden??!1,placeholder:e.placeholder??i.placeholder,helpText:e.helpText??i.helpText,defaultValue:i.defaultValue,options:er(i.options),maxLength:i.maxLength,colSpan:e.colSpan??1})}return{label:e.label,columns:t,collapsible:!!e.collapsible,collapsed:!!e.collapsed,fields:n}})}function nr(e,t){let n={};for(let r of e){r.defaultValue!==void 0&&(n[r.name]=r.defaultValue);let e=t.get(`prefill_${r.name}`);e!==null&&(n[r.name]=e)}return n}async function rr(e,t){return fetch(`${Qn}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function ir(e){let t=await rr(`/forms/${encodeURIComponent(e)}`);if(!t.ok){let e=await t.text().catch(()=>``);throw Error(`Failed to load form (${t.status}): ${e||t.statusText}`)}let n=await t.json();return{label:n.label??n.form?.label??n.object,object:n.object,form:n.form,objectSchema:n.objectSchema}}async function ar(e){let t=await rr(`/meta/view/${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Form metadata not found: view/${e}`);let n=await t.json(),r=n?.item??n,i=r?.spec??r,a=i?.object;if(!a)throw Error(`FormView "${e}" is missing an "object" target`);let o=null;try{let e=await rr(`/meta/object/${encodeURIComponent(a)}`);if(e.ok){let t=await e.json(),n=t?.item??t,r=n?.spec??n;r?.fields&&typeof r.fields==`object`&&(o={name:r.name??a,label:r.label,fields:r.fields})}}catch{}return{label:i?.label??e,object:a,form:i,objectSchema:o}}async function or(e,t){let n=await rr(`/forms/${encodeURIComponent(e)}/submit`,{method:`POST`,body:JSON.stringify(t)});if(!n.ok){let e=await n.text().catch(()=>``);throw Error(`Submit failed (${n.status}): ${e||n.statusText}`)}return n.json().catch(()=>({}))}async function sr(e,t){let n=await rr(`/data/${encodeURIComponent(e)}`,{method:`POST`,body:JSON.stringify(t)});if(!n.ok){let e=await n.text().catch(()=>``);throw Error(`Create failed (${n.status}): ${e||n.statusText}`)}return n.json().catch(()=>({}))}var cr=`w-full rounded-md border border-input bg-background px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`;function lr({field:e,value:t,onChange:n}){let r={id:`f_${e.name}`,name:e.name,required:e.required,disabled:e.readonly,placeholder:e.placeholder,className:cr},i=t??``;switch(e.type){case`textarea`:case`paragraph`:case`long_text`:return(0,Y.jsx)(`textarea`,{...r,rows:5,maxLength:e.maxLength,value:String(i),onChange:e=>n(e.target.value)});case`number`:case`integer`:case`decimal`:case`currency`:return(0,Y.jsx)(`input`,{...r,type:`number`,value:i===``?``:Number(i),onChange:e=>n(e.target.value===``?null:Number(e.target.value))});case`email`:return(0,Y.jsx)(`input`,{...r,type:`email`,value:String(i),onChange:e=>n(e.target.value)});case`url`:return(0,Y.jsx)(`input`,{...r,type:`url`,value:String(i),onChange:e=>n(e.target.value)});case`password`:return(0,Y.jsx)(`input`,{...r,type:`password`,value:String(i),onChange:e=>n(e.target.value)});case`date`:return(0,Y.jsx)(`input`,{...r,type:`date`,value:String(i),onChange:e=>n(e.target.value)});case`time`:return(0,Y.jsx)(`input`,{...r,type:`time`,value:String(i),onChange:e=>n(e.target.value)});case`datetime`:case`timestamp`:return(0,Y.jsx)(`input`,{...r,type:`datetime-local`,value:String(i),onChange:e=>n(e.target.value)});case`boolean`:case`toggle`:case`checkbox`:return(0,Y.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-sm`,children:[(0,Y.jsx)(`input`,{id:r.id,name:r.name,type:`checkbox`,disabled:e.readonly,checked:!!i,onChange:e=>n(e.target.checked),className:`h-4 w-4 rounded border-input`}),(0,Y.jsx)(`span`,{children:e.placeholder??e.label})]});case`select`:case`picklist`:case`enum`:{let t=e.options??[];return(0,Y.jsxs)(`select`,{...r,value:String(i),onChange:e=>n(e.target.value),children:[(0,Y.jsx)(`option`,{value:``,disabled:e.required,children:e.placeholder??`— Select —`}),t.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))]})}case`radio`:return(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:(e.options??[]).map(t=>(0,Y.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,Y.jsx)(`input`,{type:`radio`,name:e.name,value:t.value,checked:String(i)===t.value,disabled:e.readonly,onChange:()=>n(t.value)}),(0,Y.jsx)(`span`,{children:t.label})]},t.value))});default:return(0,Y.jsx)(`input`,{...r,type:`text`,maxLength:e.maxLength,value:String(i),onChange:e=>n(e.target.value)})}}function ur({mode:e}){let t=a(),[n]=d(),r=(e===`public`?t.slug:t.name)??``,[i,o]=(0,J.useState)(!0),[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(null),[f,p]=(0,J.useState)({}),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(!1);(0,J.useEffect)(()=>{let t=!1;return o(!0),c(null),(e===`public`?ir(r):ar(r)).then(e=>{t||(u(e),p(nr(tr(e.form,e.objectSchema).flatMap(e=>e.fields),n)))}).catch(e=>{t||c(e?.message??String(e))}).finally(()=>{t||o(!1)}),()=>{t=!0}},[e,r,n]);let v=(0,J.useMemo)(()=>l?tr(l.form,l.objectSchema):[],[l]),y=l?.form?.submitBehavior??{kind:`thank-you`};return i?(0,Y.jsx)(`div`,{className:`flex min-h-[60vh] items-center justify-center`,children:(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Loading…`})}):s&&!l?(0,Y.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,Y.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:s})}):l?g&&y.kind===`thank-you`?(0,Y.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,Y.jsxs)(`div`,{className:`rounded-md border bg-card p-6 text-center`,children:[(0,Y.jsx)(`h2`,{className:`mb-2 text-lg font-semibold`,children:y.title??`Thanks!`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:y.message??`Your submission has been received.`})]})}):g&&y.kind===`redirect`?(0,Y.jsx)(`div`,{className:`mx-auto max-w-2xl p-6 text-center text-sm text-muted-foreground`,children:`Redirecting…`}):(0,Y.jsxs)(`div`,{className:`mx-auto max-w-2xl p-4 sm:p-6`,children:[(0,Y.jsxs)(`header`,{className:`mb-6`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold`,children:l.label}),l.form?.label&&l.form.label!==l.label&&(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:l.form.label})]}),(0,Y.jsxs)(`form`,{onSubmit:async t=>{if(t.preventDefault(),l){h(!0),c(null);try{switch(e===`public`?await or(r,f):await sr(l.object,f),K.success(`Submitted`),y.kind){case`redirect`:{let e=y.delayMs??0;setTimeout(()=>window.location.assign(y.url),e),_(!0);break}case`continue`:p(nr(v.flatMap(e=>e.fields),n));break;default:_(!0);break}}catch(e){let t=e?.message??String(e);c(t),K.error(t)}finally{h(!1)}}},className:`space-y-6`,children:[v.map((e,t)=>(0,Y.jsxs)(`section`,{className:`rounded-md border bg-card p-4 sm:p-5`,children:[e.label&&(0,Y.jsx)(`h2`,{className:`mb-3 text-sm font-medium`,children:e.label}),(0,Y.jsx)(`div`,{className:e.columns===1?`grid grid-cols-1 gap-4`:e.columns===2?`grid grid-cols-1 gap-4 sm:grid-cols-2`:e.columns===3?`grid grid-cols-1 gap-4 sm:grid-cols-3`:`grid grid-cols-1 gap-4 sm:grid-cols-4`,children:e.fields.filter(e=>!e.hidden).map(e=>(0,Y.jsxs)(`div`,{className:e.colSpan===2?`sm:col-span-2`:e.colSpan===3?`sm:col-span-3`:e.colSpan===4?`sm:col-span-4`:``,children:[(0,Y.jsxs)(`label`,{htmlFor:`f_${e.name}`,className:`mb-1 block text-xs font-medium text-foreground`,children:[e.label,e.required&&(0,Y.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`})]}),(0,Y.jsx)(lr,{field:e,value:f[e.name],onChange:t=>p(n=>({...n,[e.name]:t}))}),e.helpText&&(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:e.helpText})]},e.name))})]},t)),s&&(0,Y.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:s}),(0,Y.jsx)(`div`,{className:`flex justify-end gap-2`,children:(0,Y.jsx)(`button`,{type:`submit`,disabled:m,className:`rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow-sm hover:bg-primary/90 disabled:opacity-50`,children:m?`Submitting…`:`Submit`})})]})]}):null}function dr({enabled:e=!1,url:t=`/api/v1/dev/metadata-events`,debounceMs:n=400,reconnectDelayMs:r=2e3}){let i=(0,J.useRef)(null);return(0,J.useEffect)(()=>{if(!e||typeof window>`u`||typeof EventSource>`u`)return;let a=null,o=null,s=!1,c=e=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{try{K.info(`Metadata changed (${e}) — reloading…`,{duration:800})}catch{}setTimeout(()=>{try{window.location.reload()}catch{}},150)},n)},l=e=>{try{let t=JSON.parse(e.data);c(t?.name?`${t.metadataType??`metadata`}:${t.name}`:`metadata`)}catch{c(`change`)}},u=e=>{let t=`rebuild`;try{t=JSON.parse(e.data)?.reason??t}catch{}c(t)},d=()=>{if(!s)try{a=new EventSource(t),a.addEventListener(`metadata-change`,l),a.addEventListener(`reload`,u),a.addEventListener(`error`,()=>{s||a?.readyState===EventSource.CLOSED&&(a=null,o=setTimeout(d,r))})}catch{o=setTimeout(d,r)}};return d(),()=>{if(s=!0,o&&clearTimeout(o),i.current&&clearTimeout(i.current),a)try{a.close()}catch{}}},[e,t,n,r]),null}function fr(){let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`}.VITE_SERVER_URL??``;return e?e.replace(/\/$/,``):typeof window<`u`?window.location.origin:``}function pr(e){return typeof e.content==`string`&&e.content.trim()?e.content:Array.isArray(e.parts)?e.parts.map(e=>e.text??e.content??``).filter(Boolean).join(`
3
-
4
- `):``}function mr(){let{token:e}=a(),t=`${(0,J.useMemo)(()=>fr(),[])}/api/v1`,[n,r]=(0,J.useState)(null),[i,o]=(0,J.useState)(null),[s,c]=(0,J.useState)(!0),[l,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(``),[p,m]=(0,J.useState)(null),h=(0,J.useCallback)(async n=>{if(e){c(!0),o(null);try{let i=new URL(`${t}/share-links/${encodeURIComponent(e)}/resolve`);n&&i.searchParams.set(`password`,n);let a=await fetch(i.toString(),{headers:{Accept:`application/json`}});if(a.status===401){u(!0),o(n?`Wrong password.`:null),c(!1);return}if(a.status===404){o(`This link is invalid or no longer available.`),c(!1);return}if(a.status===410){o(`This link has expired or was revoked.`),c(!1);return}if(!a.ok){o((await a.json().catch(()=>null))?.error?.message??`Failed to load (HTTP ${a.status}).`),c(!1);return}let s=await a.json();r(`data`in s?s.data:{record:s.record,link:s.link,redactedFields:s.redactFields}),u(!1)}catch(e){o(e?.message??`Failed to load shared content.`)}finally{c(!1)}}},[t,e]);if((0,J.useEffect)(()=>{h()},[h]),(0,J.useEffect)(()=>{if(!n||n.link.object_name!==`ai_conversations`)return;let e=`${t}/share-links/${encodeURIComponent(n.link.token)}/messages`;fetch(e,{headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).then(e=>m(e?.data??[])).catch(()=>m([]))},[t,n]),s)return(0,Y.jsxs)(`div`,{className:`flex h-svh w-full items-center justify-center bg-background text-muted-foreground`,children:[(0,Y.jsx)(Ae,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading…`]});if(l)return(0,Y.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-md flex-col items-center justify-center gap-4 px-4 text-center`,children:[(0,Y.jsx)(ye,{className:`h-8 w-8 text-muted-foreground`}),(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Password required`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The owner protected this link with a password.`}),(0,Y.jsxs)(`form`,{className:`flex w-full flex-col gap-2`,onSubmit:e=>{e.preventDefault(),h(d)},children:[(0,Y.jsx)(H,{htmlFor:`share-pw`,className:`sr-only`,children:`Password`}),(0,Y.jsx)(V,{id:`share-pw`,type:`password`,value:d,onChange:e=>f(e.target.value),autoFocus:!0,placeholder:`Enter password`}),i&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive`,children:i}),(0,Y.jsx)(B,{type:`submit`,size:`sm`,children:`Continue`})]})]});if(i)return(0,Y.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-md flex-col items-center justify-center gap-3 px-4 text-center`,children:[(0,Y.jsx)(Be,{className:`h-8 w-8 text-amber-500`}),(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Can't open this link`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i})]});if(!n)return null;if(n.link.object_name===`ai_conversations`){let e=n.record;return(0,Y.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,Y.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background px-4 py-3`,children:[(0,Y.jsx)(Ve,{className:`h-5 w-5 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`h1`,{className:`truncate text-sm font-semibold`,children:e.title??`Shared conversation`}),(0,Y.jsx)(`p`,{className:`truncate text-[11px] text-muted-foreground`,children:`Read-only · Shared via ObjectStack`})]}),(0,Y.jsx)(P,{variant:`outline`,className:`text-[10px] capitalize`,children:n.link.permission})]}),(0,Y.jsxs)(`main`,{className:`flex-1 overflow-y-auto px-4 py-6`,children:[p==null&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-sm text-muted-foreground`,children:[(0,Y.jsx)(Ae,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading messages…`]}),p&&p.length===0&&(0,Y.jsx)(`p`,{className:`py-12 text-center text-sm text-muted-foreground`,children:`This conversation has no messages yet.`}),(0,Y.jsx)(`ul`,{className:`space-y-4`,children:p?.map(e=>{let t=pr(e);if(!t)return null;let n=e.role===`user`;return(0,Y.jsx)(`li`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:(0,Y.jsx)(`div`,{className:`max-w-[85%] rounded-lg px-3 py-2 text-sm leading-relaxed ${n?`bg-primary text-primary-foreground`:`bg-muted text-foreground`}`,children:n?(0,Y.jsx)(`p`,{className:`whitespace-pre-wrap`,children:t}):(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap font-sans text-sm leading-relaxed`,children:t})})},e.id)})})]}),(0,Y.jsx)(`footer`,{className:`border-t bg-muted/30 px-4 py-2 text-center text-[11px] text-muted-foreground`,children:`Powered by ObjectStack`})]})}return(0,Y.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,Y.jsx)(`header`,{className:`border-b px-4 py-3`,children:(0,Y.jsxs)(`h1`,{className:`text-sm font-semibold`,children:[`Shared `,n.link.object_name]})}),(0,Y.jsxs)(`main`,{className:`flex-1 overflow-y-auto p-4`,children:[(0,Y.jsx)(`pre`,{className:`overflow-x-auto rounded-md border bg-muted/30 p-3 text-[12px]`,children:JSON.stringify(n.record,null,2)}),n.redactedFields&&n.redactedFields.length>0&&(0,Y.jsxs)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:[`Some fields are hidden by the owner: `,n.redactedFields.join(`, `)]})]})]})}var hr=/(^```[^\n]*\n[\s\S]*?\n```[ \t]*$|^~~~[^\n]*\n[\s\S]*?\n~~~[ \t]*$)/m,gr=/(`[^`\n]+`)/,_r=/\]\((?:\.\/)?([a-z][a-z0-9_]*)\.md(#[^)\s]*)?\)/g;function vr(e){return e.split(gr).map((e,t)=>t%2==1?e:e.replace(_r,`](/docs/$1$2)`)).join(``)}function yr(e){let t=[],n=e;for(;;){let e=hr.exec(n);if(!e||e.index===void 0)return t.push(vr(n)),t.join(``);t.push(vr(n.slice(0,e.index)),e[0]),n=n.slice(e.index+e[0].length)}}function br({breadcrumb:e,children:t}){return(0,Y.jsxs)(`div`,{className:`min-h-full`,children:[(0,Y.jsx)(`header`,{className:`sticky top-0 z-10 border-b border-border bg-background/80 backdrop-blur supports-[backdrop-filter]:bg-background/60`,children:(0,Y.jsxs)(`div`,{className:`mx-auto flex max-w-3xl items-center gap-2 px-4 py-3 sm:px-6`,children:[(0,Y.jsxs)(f,{to:`/docs`,className:`flex items-center gap-2 text-sm font-semibold hover:opacity-80`,children:[(0,Y.jsx)(we,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`span`,{children:`Documentation`})]}),e?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground/60`,"aria-hidden":!0,children:`/`}),(0,Y.jsx)(`span`,{className:`truncate text-sm text-muted-foreground`,children:e})]}):null]})}),t]})}function xr({book:e,activeDoc:t,docHref:n}){return(0,Y.jsxs)(`nav`,{"aria-label":e.label??e.name,className:`text-sm`,children:[e.label?(0,Y.jsx)(`div`,{className:`mb-3 px-2 text-sm font-semibold text-foreground`,children:e.label}):null,(0,Y.jsx)(`div`,{className:`space-y-5`,children:e.groups.map(e=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 px-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:e.label}),(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:e.entries.map((e,r)=>{if(e.separator)return(0,Y.jsx)(`li`,{className:`my-1.5 border-t border-border/60`,"aria-hidden":!0},`sep-${r}`);if(e.href)return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,className:`flex items-center gap-1.5 rounded px-2 py-1 text-muted-foreground hover:bg-muted/50 hover:text-foreground`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:e.label??e.href}),(0,Y.jsx)(be,{className:`h-3 w-3 shrink-0 opacity-60`})]})},`ext-${r}`);if(!e.doc)return null;let i=e.doc===t;return(0,Y.jsx)(`li`,{children:(0,Y.jsx)(f,{to:n(e.doc),"aria-current":i?`page`:void 0,className:`block truncate rounded px-2 py-1 transition ${i?`bg-primary/10 font-medium text-foreground`:`text-muted-foreground hover:bg-muted/50 hover:text-foreground`}`,children:e.label??e.doc})},e.doc)})})]},e.key))})]})}var Sr=`uncategorized`;function Cr(e){let t=e.indexOf(`_`);return t>0?e.slice(0,t):e}function wr(e){return e.packageId??Cr(e.name)}function Tr(e){return e.packageId??Cr(e.name)}function Er(e){return e.slug??e.name}function Dr(e){let t=e.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`);return RegExp(`^${t}$`)}function Or(e,t,n){return n&&wr(e)!==n?!1:typeof t==`string`?Dr(t).test(e.name):Array.isArray(e.tags)&&e.tags.includes(t.tag)}function kr(e,t){return(e.order??0)-(t.order??0)||(e.label??e.name).localeCompare(t.label??t.name)}function Ar(e){return{doc:e.name,label:e.label,description:e.description}}function jr(e,t,n){let r=n??e.packageId,i=[...e.groups??[]].map((e,t)=>({g:e,i:t})).sort((e,t)=>(e.g.order??0)-(t.g.order??0)||e.i-t.i).map(e=>e.g),a=new Set,o=new Map(t.map(e=>[e.name,e])),s=new Map;for(let e of i){if(e.pages)continue;let n=e.package??r,i=t.filter(t=>a.has(t.name)?!1:e.include!=null&&Or(t,e.include,n)||t.group!=null&&t.group===e.key);i.sort(kr),i.forEach(e=>a.add(e.name)),s.set(e.key,i)}let c=[];for(let e of i){let n;if(e.pages){let i=e.package??r;n=[];let s=new Set(e.pages.filter(e=>typeof e==`string`&&e!==`...`&&e!==`---`));for(let r of e.pages)if(r===`---`)n.push({separator:!0});else if(r===`...`){let r=t.filter(t=>!a.has(t.name)&&!s.has(t.name)&&(e.include!=null&&Or(t,e.include,i)||t.group!=null&&t.group===e.key));r.sort(kr),r.forEach(e=>{a.add(e.name),n.push(Ar(e))})}else if(typeof r==`string`){let e=o.get(r);a.add(r),n.push(e?Ar(e):{doc:r})}else if(r.doc){let e=o.get(r.doc);a.add(r.doc),n.push({...e?Ar(e):{doc:r.doc},label:r.label??e?.label,badge:r.badge,icon:r.icon})}else r.href&&n.push({href:r.href,label:r.label,badge:r.badge,icon:r.icon})}else n=(s.get(e.key)??[]).map(Ar);c.push({key:e.key,label:e.label,entries:n})}let l=t.filter(e=>!a.has(e.name)).sort(kr);return l.length&&c.push({key:Sr,label:`Uncategorized`,entries:l.map(Ar),synthetic:!0}),{name:e.name,label:e.label,description:e.description,groups:c}}function Mr(e,t){return{name:e,label:t??e,audience:`org`,groups:[{key:`all`,label:t??`Documentation`,include:`*`,package:e}]}}function Nr(e){let t=new Set;e.packageId&&t.add(e.packageId);for(let n of e.groups??[])n.package&&t.add(n.package);return t}function Pr(e,t){let n=Nr(e);return n.size===0?t:t.filter(e=>n.has(wr(e)))}function Fr(e){return[...e].map((e,t)=>({b:e,i:t})).sort((e,t)=>(e.b.order??0)-(t.b.order??0)||(e.b.label??e.b.name).localeCompare(t.b.label??t.b.name)||e.i-t.i).map(e=>e.b)}function Ir(e,t){let n=jr(e,Pr(e,t)),r=new Set;for(let e of n.groups)if(!e.synthetic)for(let t of e.entries)t.doc&&!t.separator&&r.add(t.doc);return r.size}function Lr(e,t){return e.map(e=>({name:e.name,slug:Er(e),label:e.label??e.name,description:e.description,subtitle:e.implicit&&!e.description?e.packageId:void 0,icon:e.icon,packageId:e.packageId,docCount:Ir(e,t)}))}function Rr(e,t){let n=new Set(e.map(Tr)),r=[...new Set(t.map(wr))].filter(e=>!n.has(e)).map(e=>({...Mr(e),label:zr(e),packageId:e,implicit:!0}));return[...Fr(e),...Fr(r)]}function zr(e){let t=e.split(`.`).pop()||e;return t.charAt(0).toUpperCase()+t.slice(1)}function Br(e,t,n){let r=n.find(t=>t.name===e),i=r?wr(r):Cr(e);return Fr(t).find(e=>Tr(e)===i)??null}function Vr(e){let t=[];for(let n of e.groups)for(let e of n.entries)e.doc&&!e.separator&&t.push(e.doc);return t.find(e=>/(^|_)index$/.test(e))??t[0]}function Hr(e){if(Array.isArray(e))return e;let t=e;return Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[]}function Ur(e){return!e||typeof e.name!=`string`||!e.name?null:{name:e.name,label:e.label,description:e.description,slug:e.slug,icon:e.icon,order:typeof e.order==`number`?e.order:void 0,audience:e.audience,groups:Array.isArray(e.groups)?e.groups:[],packageId:e._packageId??e.packageId}}function Wr(e){return!e||typeof e.name!=`string`||!e.name?null:{name:e.name,label:e.label,description:e.description,order:typeof e.order==`number`?e.order:void 0,group:typeof e.group==`string`?e.group:void 0,tags:Array.isArray(e.tags)?e.tags:void 0,packageId:e._packageId??e.packageId}}function Gr(){let e=N(),[t,n]=(0,J.useState)({authoredBooks:[],docs:[],state:`loading`});(0,J.useEffect)(()=>{let t=!1;async function r(){if(!e)return;let r=e.getClient();if(!r?.meta?.getItems){n({authoredBooks:[],docs:[],state:`error`,error:`meta.getItems is not available`});return}n(e=>({...e,state:`loading`}));try{let e=await r.meta.getItems(`doc`),i=[];try{i=await r.meta.getItems(`book`)}catch{i=[]}if(t)return;let a=Hr(e).map(Wr).filter(e=>e!==null);n({authoredBooks:Hr(i).map(Ur).filter(e=>e!==null),docs:a,state:`ready`})}catch(e){if(t)return;n({authoredBooks:[],docs:[],state:`error`,error:e?.message??`Failed to load documentation`})}}return r(),()=>{t=!0}},[e]);let r=(0,J.useMemo)(()=>Rr(t.authoredBooks,t.docs),[t.authoredBooks,t.docs]);return{...t,books:r}}var Kr={authoredBooks:[],books:[],docs:[],state:`loading`},qr=(0,J.createContext)(null);function Jr(){return(0,J.useContext)(qr)??Kr}var Yr=t({default:()=>Xr});function Xr(){let{slug:e,name:t,appName:n}=a(),r=h(),i=N(),{t:o}=M(),[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(`loading`),[d,f]=(0,J.useState)(``);(0,J.useEffect)(()=>{let e=!1;async function r(){if(!(!t||!i)){u(`loading`);try{let r=await i.getClient().meta.getItem(`doc`,t,n?{packageId:n}:void 0),a=r?.item??r?.data??r;if(e)return;a&&typeof a.content==`string`?(c({name:t,label:a.label,content:a.content}),u(`ready`)):u(`missing`)}catch(t){if(e)return;(t?.status??t?.response?.status)===404||/not found/i.test(t?.message??``)?u(`missing`):(f(t?.message??`Failed to load documentation`),u(`error`))}}}return r(),()=>{e=!0}},[t,n,i]);let p=(0,J.useCallback)(e=>{document.getElementById(e)?.scrollIntoView({behavior:`smooth`,block:`start`}),window.history.replaceState(null,``,`${window.location.pathname}${window.location.search}#${e}`)},[]),m=(0,J.useCallback)(e=>{if(e.defaultPrevented||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0)return;let t=e.target.closest(`a`)?.getAttribute(`href`);t&&(t.startsWith(`/docs/`)?(e.preventDefault(),r(t)):t.startsWith(`#`)&&(e.preventDefault(),p(decodeURIComponent(t.slice(1)))))},[r,p]),g=(0,J.useCallback)((e,t)=>{e.defaultPrevented||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0||(e.preventDefault(),p(t))},[p]),_=(0,J.useMemo)(()=>vn(s?.content??``),[s?.content]),v=o(`help.onThisPage`,{defaultValue:`On this page`}),{books:y,docs:b}=Jr(),x=n?`/apps/${n}/docs`:`/docs`,S=(0,J.useMemo)(()=>{let t=y.find(t=>Er(t)===e);return t?jr(t,Pr(t,b)):null},[y,b,e]),C=(0,J.useCallback)(t=>`${x}/${e}/${t}`,[x,e]);return l===`loading`?(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-10 text-muted-foreground`,children:(0,Y.jsx)(Ae,{className:`h-5 w-5 animate-spin`,"aria-label":`Loading documentation`})}):l===`missing`?(0,Y.jsx)(br,{breadcrumb:t,children:(0,Y.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col items-center gap-3 p-10 text-center`,children:[(0,Y.jsx)(pe,{className:`h-10 w-10 text-muted-foreground`}),(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Documentation not found`}),(0,Y.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`No document named `,(0,Y.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5`,children:t}),` is installed. It may belong to a package that is not installed, or it was removed in a newer version.`]})]})}):l===`error`?(0,Y.jsx)(br,{breadcrumb:t,children:(0,Y.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col items-center gap-3 p-10 text-center`,children:[(0,Y.jsx)(Vt,{className:`h-10 w-10 text-destructive`}),(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Failed to load documentation`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:d})]})}):(0,Y.jsxs)(br,{breadcrumb:s?.label??t,children:[S?(0,Y.jsxs)(`details`,{className:`group mx-auto max-w-6xl px-4 pt-4 sm:px-6 lg:hidden`,children:[(0,Y.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 rounded-md border bg-muted/30 px-3 py-2 text-sm font-medium [&::-webkit-details-marker]:hidden`,children:[(0,Y.jsx)(It,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`truncate`,children:S.label??`Contents`}),(0,Y.jsx)(de,{className:`ml-auto h-4 w-4 text-muted-foreground transition-transform group-open:rotate-180`})]}),(0,Y.jsx)(`div`,{className:`mt-2 rounded-md border p-3`,children:(0,Y.jsx)(xr,{book:S,activeDoc:t,docHref:C})})]}):null,(0,Y.jsxs)(`div`,{className:`mx-auto flex gap-8 p-4 sm:p-6 ${S?`max-w-6xl`:`max-w-5xl`}`,children:[S?(0,Y.jsx)(`aside`,{className:`hidden w-56 shrink-0 lg:block`,children:(0,Y.jsx)(`nav`,{className:`sticky top-20 max-h-[calc(100vh-6rem)] overflow-auto pr-1`,children:(0,Y.jsx)(xr,{book:S,activeDoc:t,docHref:C})})}):null,(0,Y.jsx)(`article`,{className:`min-w-0 max-w-3xl flex-1 [&_h1]:scroll-mt-24 [&_h2]:scroll-mt-24 [&_h3]:scroll-mt-24`,onClick:m,children:(0,Y.jsx)(yn,{schema:{type:`markdown`,content:yr(s?.content??``)}})}),_.length>=3?(0,Y.jsx)(`aside`,{className:`hidden xl:block w-56 shrink-0`,children:(0,Y.jsxs)(`nav`,{"aria-label":v,className:`sticky top-20 max-h-[calc(100vh-6rem)] overflow-auto`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:v}),(0,Y.jsx)(`ul`,{className:`border-l border-border text-sm`,children:_.map(e=>(0,Y.jsx)(`li`,{style:{paddingLeft:(e.depth-2)*12},children:(0,Y.jsx)(`a`,{href:`#${e.id}`,onClick:t=>g(t,e.id),className:`-ml-px block border-l border-transparent py-0.5 pl-3 text-muted-foreground hover:border-primary hover:text-foreground`,children:e.text})},e.id))})]})}):null]})]})}function Zr(){let{books:e,docs:t,state:n,error:r}=Jr(),i=(0,J.useMemo)(()=>Lr(e,t),[e,t]);return n===`loading`?(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-10 text-muted-foreground`,children:(0,Y.jsx)(Ae,{className:`h-5 w-5 animate-spin`,"aria-label":`Loading documentation`})}):n===`error`?(0,Y.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col items-center gap-3 p-10 text-center`,children:[(0,Y.jsx)(Vt,{className:`h-10 w-10 text-destructive`}),(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Failed to load documentation`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r})]}):(0,Y.jsx)(br,{children:(0,Y.jsxs)(`div`,{className:`mx-auto max-w-4xl p-4 sm:p-6`,children:[(0,Y.jsxs)(`header`,{className:`mb-6`,children:[(0,Y.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:`Documentation`}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Books and guides from your installed packages.`})]}),i.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-16 text-center text-muted-foreground`,children:[(0,Y.jsx)(we,{className:`h-10 w-10`}),(0,Y.jsxs)(`p`,{className:`text-sm`,children:[`No documentation is installed. Packages ship docs as flat`,(0,Y.jsx)(`code`,{className:`mx-1 rounded bg-muted px-1 py-0.5`,children:`src/docs/*.md`}),`files, organised by a `,(0,Y.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5`,children:`book`}),` (ADR-0046).`]})]}):(0,Y.jsx)(`ul`,{className:`grid items-stretch gap-3 sm:grid-cols-2`,children:i.map(e=>(0,Y.jsx)(`li`,{className:`h-full`,children:(0,Y.jsxs)(f,{to:`/docs/${e.slug}`,className:`flex h-full items-start gap-3 rounded-md border border-border p-3 hover:bg-muted/50`,children:[(0,Y.jsx)(we,{className:`mt-0.5 h-5 w-5 shrink-0 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-semibold`,children:e.label}),e.description?(0,Y.jsx)(`div`,{className:`mt-0.5 line-clamp-2 text-xs text-muted-foreground`,children:e.description}):e.subtitle?(0,Y.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-muted-foreground/70`,children:e.subtitle}):null,(0,Y.jsxs)(`div`,{className:`mt-1 text-xs text-muted-foreground/80`,children:[e.docCount,` `,e.docCount===1?`article`:`articles`]})]})]})},e.name))})]})})}function Qr(){let{slug:e,appName:t}=a(),{books:n,docs:i,state:o}=Jr(),s=(0,J.useMemo)(()=>n.find(t=>Er(t)===e),[n,e]),c=(0,J.useMemo)(()=>s?Vr(jr(s,Pr(s,i))):void 0,[s,i]);return o===`loading`?(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-10 text-muted-foreground`,children:(0,Y.jsx)(Ae,{className:`h-5 w-5 animate-spin`,"aria-label":`Loading documentation`})}):s&&c?(0,Y.jsx)(r,{to:`${t?`/apps/${t}/docs`:`/docs`}/${e}/${c}`,replace:!0}):(0,Y.jsx)(br,{breadcrumb:s?s.label??e:e,children:(0,Y.jsx)(`div`,{className:`mx-auto flex max-w-3xl flex-col items-center gap-3 p-10 text-center`,children:s?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(we,{className:`h-10 w-10 text-muted-foreground`}),(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:s.label??e}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This book has no documents yet.`})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(pe,{className:`h-10 w-10 text-muted-foreground`}),(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Book not found`}),(0,Y.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`No book named `,(0,Y.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5`,children:e}),` is installed.`]})]})})})}var $r=t({default:()=>ei});function ei(){let{slug:e,appName:t}=a(),{books:n,docs:i,state:o}=Jr();if(o===`loading`)return(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-10 text-muted-foreground`,children:(0,Y.jsx)(Ae,{className:`h-5 w-5 animate-spin`,"aria-label":`Loading documentation`})});if(e&&n.some(t=>Er(t)===e))return(0,Y.jsx)(Qr,{});let s=t?`/apps/${t}/docs`:`/docs`,c=e?Br(e,n,i):null;return c&&e?(0,Y.jsx)(r,{to:`${s}/${Er(c)}/${e}`,replace:!0}):(0,Y.jsx)(br,{breadcrumb:e,children:(0,Y.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col items-center gap-3 p-10 text-center`,children:[(0,Y.jsx)(pe,{className:`h-10 w-10 text-muted-foreground`}),(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Documentation not found`}),(0,Y.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`No book or document named `,(0,Y.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5`,children:e}),` is installed.`]})]})})}var ti=t({default:()=>ni});function ni(){let e=Gr();return(0,Y.jsx)(qr.Provider,{value:e,children:(0,Y.jsx)(u,{})})}function ri(e){let t=e.split(`:`)[0].toLowerCase();return/^cloud\./.test(t)}function ii(e){let t=e.split(`:`)[0].toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t.endsWith(`.local`)}function ai(){return typeof window>`u`?null:window.location.host||null}function oi(){let e=fn();return(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 select-none`,children:[(0,Y.jsx)(`span`,{className:`inline-flex h-9 w-9 items-center justify-center rounded-xl bg-gradient-to-br from-indigo-500 to-indigo-600 text-white shadow-sm shadow-indigo-500/30`,children:(0,Y.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,Y.jsx)(`path`,{d:`M12 2 2 7l10 5 10-5-10-5Z`}),(0,Y.jsx)(`path`,{d:`m2 17 10 5 10-5`}),(0,Y.jsx)(`path`,{d:`m2 12 10 5 10-5`})]})}),(0,Y.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-foreground`,children:e})]})}function si({children:e,formWidth:t=`sm`}){let{t:n}=M(),r=t===`md`?`max-w-md`:`max-w-sm`,i=ai(),a=!!i&&!ri(i)&&!ii(i);return(0,J.useEffect)(()=>{if(typeof document>`u`||!i)return;let e=document.title;return a&&(document.title=i),()=>{document.title=e}},[i,a]),(0,Y.jsxs)(`div`,{className:`relative flex min-h-svh w-full items-center justify-center overflow-hidden bg-background p-6`,children:[(0,Y.jsxs)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 -z-10`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 opacity-[0.35] dark:opacity-[0.25] [mask-image:radial-gradient(ellipse_at_center,black,transparent_72%)] [-webkit-mask-image:radial-gradient(ellipse_at_center,black,transparent_72%)]`,style:{backgroundImage:`radial-gradient(hsl(var(--border)) 1px, transparent 1px)`,backgroundSize:`22px 22px`}}),(0,Y.jsx)(`div`,{className:`absolute left-1/2 top-1/2 h-[34rem] w-[34rem] -translate-x-1/2 -translate-y-1/2 rounded-full bg-gradient-to-br from-indigo-500/10 to-indigo-600/10 blur-3xl dark:from-indigo-500/10 dark:to-indigo-600/10`})]}),(0,Y.jsxs)(`div`,{className:Ot(`flex w-full flex-col gap-5`,r),children:[(0,Y.jsx)(oi,{}),a?(0,Y.jsx)(`div`,{className:`flex justify-center`,children:(0,Y.jsx)(`span`,{className:`rounded-full border border-border/60 bg-background/60 px-2 py-0.5 font-mono text-[10px] uppercase tracking-wide text-muted-foreground`,title:n(`auth.shell.tenantHostHint`,{defaultValue:`You are signing in to this workspace`}),children:i})}):null,e]})]})}function ci(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function li(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function ui(e){return(0,Y.jsx)(f,{to:e.href,className:e.className,children:e.children})}function di(){let{t:e}=M(),[t]=d(),n=t.get(`redirect`),{user:r,isLoading:i,organizations:a,isOrganizationsLoading:o,activeOrganization:s,switchOrganization:c,getAuthConfig:l}=v(),[u,f]=(0,J.useState)(!1),[p,m]=(0,J.useState)(!1),[h,g]=(0,J.useState)(!1);(0,J.useLayoutEffect)(()=>{i||g(!0)},[i]);let _=(0,J.useMemo)(()=>{if(typeof window>`u`)return null;let e=new URLSearchParams(window.location.search),t=e.get(`redirect_uri`);if(!e.has(`client_id`)||!t)return null;try{return new URL(t).host}catch{return null}},[]);if((0,J.useEffect)(()=>{let e=!1;return l().then(t=>{e||f(t?.emailPassword?.disableSignUp===!0)}).catch(()=>{}),()=>{e=!0}},[l]),(0,J.useEffect)(()=>{if(r){if(typeof window<`u`){let e=new URLSearchParams(window.location.search);if(e.has(`client_id`)&&e.has(`redirect_uri`)){window.location.assign(`/api/v1/auth/oauth2/authorize${window.location.search}`);return}}if(!s){if(o||p)return;if(a.length===1){m(!0),c(a[0].id).catch(()=>void 0).finally(()=>m(!1));return}if(a.length===0){window.location.assign(li(ci(n)?n:`/`));return}window.location.assign(li(`/organizations`));return}p||window.location.assign(li(ci(n)?n:`/`))}},[r,s,a,o,p,n,c]),i&&!h||r)return(0,Y.jsx)(si,{children:(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground`,children:[(0,Y.jsx)(`div`,{className:`size-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent`}),(0,Y.jsx)(`span`,{children:e(`auth.login.signingIn`,{defaultValue:`Signing you in…`})})]})});let y=n?`/register?redirect=${encodeURIComponent(n)}`:`/register`;return(0,Y.jsx)(si,{formWidth:`md`,children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[_?(0,Y.jsxs)(`div`,{role:`status`,className:`flex items-start gap-3 rounded-md border border-primary/30 bg-primary/5 px-4 py-3 text-sm text-foreground`,children:[(0,Y.jsx)(`span`,{className:`mt-0.5 inline-block size-2 shrink-0 rounded-full bg-primary`}),(0,Y.jsx)(`span`,{children:e(`auth.login.ssoHandoff`,{target:_,defaultValue:`Continue to ${_}`})})]}):null,(0,Y.jsx)(U,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,Y.jsx)(fi,{registerUrl:u?void 0:y,redirect:n})})]})})}function fi({registerUrl:e,redirect:t}){let{t:n}=M(),r=h(),i=(0,J.useRef)(``);return(0,J.useEffect)(()=>{let e=e=>{let t=e.target;t?.id===`login-email`&&(i.current=t.value)};return document.addEventListener(`input`,e,!0),()=>document.removeEventListener(`input`,e,!0)},[]),(0,Y.jsx)(b,{onError:e=>{let n=e.message||``,a=e.code,o=n.toLowerCase();if(a===`EMAIL_NOT_VERIFIED`||o.includes(`email`)&&(o.includes(`verif`)||o.includes(`not verified`))){let e=new URLSearchParams;i.current&&e.set(`email`,i.current),t&&e.set(`redirect`,t),r(`/verify-email-prompt?${e.toString()}`)}},title:n(`auth.login.title`,{defaultValue:`Sign in to your account`}),description:n(`auth.login.description`,{defaultValue:`Enter your email and password to continue`}),registerUrl:e,forgotPasswordUrl:`/forgot-password`,linkComponent:ui,errorMessages:{INVALID_EMAIL_OR_PASSWORD:n(`auth.login.errors.invalidCredentials`,{defaultValue:`Invalid email or password`}),EMAIL_NOT_VERIFIED:n(`auth.login.errors.emailNotVerified`,{defaultValue:`Please verify your email address before signing in.`})},labels:{emailLabel:n(`auth.login.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:n(`auth.login.emailPlaceholder`,{defaultValue:`name@example.com`}),passwordLabel:n(`auth.login.passwordLabel`,{defaultValue:`Password`}),passwordPlaceholder:n(`auth.login.passwordPlaceholder`,{defaultValue:`Enter your password`}),forgotPasswordText:n(`auth.login.forgotPasswordText`,{defaultValue:`Forgot password?`}),submitButton:n(`auth.login.submitButton`,{defaultValue:`Sign In`}),submittingButton:n(`auth.login.submittingButton`,{defaultValue:`Signing in…`}),noAccountText:n(`auth.login.noAccountText`,{defaultValue:`Don't have an account?`}),signUpText:n(`auth.login.signUpText`,{defaultValue:`Sign up`})}})}function pi(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function mi(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function hi(e){return(0,Y.jsx)(f,{to:e.href,className:e.className,children:e.children})}function gi(){let{t:e}=M(),t=h(),[n]=d(),r=n.get(`redirect`),{user:i,isLoading:a,organizations:o,isOrganizationsLoading:s,activeOrganization:c,switchOrganization:l,getAuthConfig:u}=v(),[f,p]=(0,J.useState)(null),[m,g]=(0,J.useState)(!1),[y,b]=(0,J.useState)(!1);if((0,J.useLayoutEffect)(()=>{a||b(!0)},[a]),(0,J.useEffect)(()=>{let e=!1;return u().then(n=>{if(e)return;let i=n?.emailPassword?.disableSignUp===!0;p(i),i&&t(`/login${r?`?redirect=${encodeURIComponent(r)}`:``}`,{replace:!0})}).catch(()=>{e||p(!1)}),()=>{e=!0}},[u,t,r]),(0,J.useEffect)(()=>{if(i){if(typeof window<`u`){let e=new URLSearchParams(window.location.search);if(e.has(`client_id`)&&e.has(`redirect_uri`)){window.location.assign(`/api/v1/auth/oauth2/authorize${window.location.search}`);return}}if(!c){if(s||m)return;if(o.length===1){g(!0),l(o[0].id).catch(()=>void 0).finally(()=>g(!1));return}if(o.length===0){window.location.assign(mi(pi(r)?r:`/`));return}window.location.assign(mi(`/organizations`));return}m||window.location.assign(mi(pi(r)?r:`/`))}},[i,c,o,s,m,r,l]),f===null||a&&!y||i)return(0,Y.jsx)(si,{children:(0,Y.jsx)(`div`,{className:`flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground`,children:(0,Y.jsx)(`div`,{className:`size-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent`})})});let x=r?`/login?redirect=${encodeURIComponent(r)}`:`/login`;return(0,Y.jsx)(si,{formWidth:`md`,children:(0,Y.jsx)(U,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,Y.jsx)(_,{title:e(`auth.register.title`,{defaultValue:`Create your account`}),description:e(`auth.register.description`,{defaultValue:`Sign up to get started`}),loginUrl:x,linkComponent:hi,errorMessages:{USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL:e(`auth.register.errors.userExists`,{defaultValue:`An account with this email already exists. Try signing in instead.`}),USER_ALREADY_EXISTS:e(`auth.register.errors.userExists`,{defaultValue:`An account with this email already exists. Try signing in instead.`})},onVerificationRequired:e=>{let n=new URLSearchParams;n.set(`email`,e),r&&n.set(`redirect`,r),t(`/verify-email-prompt?${n.toString()}`,{replace:!0})},labels:{nameLabel:e(`auth.register.nameLabel`,{defaultValue:`Name`}),namePlaceholder:e(`auth.register.namePlaceholder`,{defaultValue:`John Doe`}),emailLabel:e(`auth.register.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:e(`auth.register.emailPlaceholder`,{defaultValue:`name@example.com`}),passwordLabel:e(`auth.register.passwordLabel`,{defaultValue:`Password`}),passwordPlaceholder:e(`auth.register.passwordPlaceholder`,{defaultValue:`Create a password (min. 8 characters)`}),confirmPasswordLabel:e(`auth.register.confirmPasswordLabel`,{defaultValue:`Confirm password`}),confirmPasswordPlaceholder:e(`auth.register.confirmPasswordPlaceholder`,{defaultValue:`Confirm your password`}),passwordMismatchError:e(`auth.register.passwordMismatchError`,{defaultValue:`Passwords do not match`}),passwordTooShortError:e(`auth.register.passwordTooShortError`,{defaultValue:`Password must be at least 8 characters`}),submitButton:e(`auth.register.submitButton`,{defaultValue:`Create account`}),submittingButton:e(`auth.register.submittingButton`,{defaultValue:`Creating account…`}),hasAccountText:e(`auth.register.hasAccountText`,{defaultValue:`Already have an account?`}),signInText:e(`auth.register.signInText`,{defaultValue:`Sign in`})}})})})}function _i(e){return(0,Y.jsx)(f,{to:e.href,className:e.className,children:e.children})}function vi(){let{t:e}=M();return(0,Y.jsx)(si,{formWidth:`md`,children:(0,Y.jsx)(U,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,Y.jsx)(C,{loginUrl:`/login`,linkComponent:_i,title:e(`auth.forgotPassword.title`,{defaultValue:`Reset your password`}),description:e(`auth.forgotPassword.description`,{defaultValue:`Enter your email and we'll send you a reset link.`}),labels:{emailLabel:e(`auth.forgotPassword.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:e(`auth.forgotPassword.emailPlaceholder`,{defaultValue:`name@example.com`}),submitButton:e(`auth.forgotPassword.submitButton`,{defaultValue:`Send reset link`}),submittingButton:e(`auth.forgotPassword.submittingButton`,{defaultValue:`Sending…`}),successTitle:e(`auth.forgotPassword.successTitle`,{defaultValue:`Check your email`}),successDescription:e(`auth.forgotPassword.successDescription`,{defaultValue:`If an account exists, a reset link has been sent.`}),backToSignInText:e(`auth.forgotPassword.backToSignInText`,{defaultValue:`Back to sign in`}),rememberPasswordText:e(`auth.forgotPassword.rememberPasswordText`,{defaultValue:`Remember your password?`}),signInText:e(`auth.forgotPassword.signInText`,{defaultValue:`Sign in`})}})})})}function yi(){let{t:e}=M(),t=h(),[n]=d(),r=n.get(`token`),{resetPassword:i}=v(),[a,o]=(0,J.useState)(``),[s,c]=(0,J.useState)(``),[l,u]=(0,J.useState)(!1);return(0,Y.jsx)(si,{children:(0,Y.jsxs)(U,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(z,{className:`text-xl tracking-tight`,children:e(`auth.resetPassword.title`,{defaultValue:`Set a new password`})}),(0,Y.jsx)(R,{children:e(`auth.resetPassword.description`,{defaultValue:`Choose a password you have not used before.`})})]}),(0,Y.jsx)(Ce,{children:r?(0,Y.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),a!==s){K.error(e(`auth.resetPassword.passwordsMismatch`,{defaultValue:`Passwords do not match`}));return}if(!r){K.error(e(`auth.resetPassword.missingToken`,{defaultValue:`Reset link is missing or expired`}));return}u(!0);try{await i(r,a),K.success(e(`auth.resetPassword.success`,{defaultValue:`Password updated`})),t(`/login`)}catch(t){K.error(e(`auth.resetPassword.failed`,{defaultValue:`Reset failed`}),{description:t.message})}finally{u(!1)}},className:`flex flex-col gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(H,{htmlFor:`new-password`,children:e(`auth.resetPassword.newPassword`,{defaultValue:`New password`})}),(0,Y.jsx)(V,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:a,onChange:e=>o(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(H,{htmlFor:`confirm-password`,children:e(`auth.resetPassword.confirmPassword`,{defaultValue:`Confirm password`})}),(0,Y.jsx)(V,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:s,onChange:e=>c(e.target.value)})]}),(0,Y.jsx)(B,{type:`submit`,className:`w-full`,disabled:l,children:l?e(`auth.resetPassword.submitting`,{defaultValue:`Updating…`}):e(`auth.resetPassword.submit`,{defaultValue:`Update password`})})]}):(0,Y.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.resetPassword.invalidToken`,{defaultValue:`This reset link is invalid or has expired.`}),` `,(0,Y.jsx)(f,{to:`/forgot-password`,className:`font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.resetPassword.requestNewLink`,{defaultValue:`Request a new link`})})]})})]})})}function bi(e){return e&&e.startsWith(`/`)&&!e.startsWith(`//`)?e:`/`}function xi(){let{t:e}=M(),t=h(),[n]=d(),r=bi(n.get(`next`)),{user:i,isLoading:a,setInitialPassword:o}=v(),[s,c]=(0,J.useState)(``),[l,u]=(0,J.useState)(``),[p,m]=(0,J.useState)(!1);return(0,Y.jsx)(si,{children:(0,Y.jsxs)(U,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(z,{className:`text-xl tracking-tight`,children:e(`auth.setPassword.title`,{defaultValue:`Set a recovery password`})}),(0,Y.jsx)(R,{children:e(`auth.setPassword.description`,{defaultValue:`You signed in via single sign-on. Set a local password so you can still sign in to this environment directly if SSO ever becomes unavailable.`})})]}),(0,Y.jsx)(Ce,{children:!a&&!i?(0,Y.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.setPassword.noSession`,{defaultValue:`Your session has expired.`}),` `,(0,Y.jsx)(f,{to:`/login`,className:`font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.setPassword.backToSignIn`,{defaultValue:`Sign in again`})})]}):(0,Y.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),s!==l){K.error(e(`auth.setPassword.passwordsMismatch`,{defaultValue:`Passwords do not match`}));return}m(!0);try{await o(s),K.success(e(`auth.setPassword.success`,{defaultValue:`Local password set`})),t(r)}catch(t){K.error(e(`auth.setPassword.failed`,{defaultValue:`Could not set password`}),{description:t.message})}finally{m(!1)}},className:`flex flex-col gap-4`,children:[i?.email?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(H,{htmlFor:`set-password-email`,children:e(`auth.setPassword.email`,{defaultValue:`Email`})}),(0,Y.jsx)(V,{id:`set-password-email`,type:`email`,autoComplete:`username`,value:i.email,disabled:!0,className:`bg-muted text-muted-foreground`})]}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(H,{htmlFor:`new-password`,children:e(`auth.setPassword.newPassword`,{defaultValue:`New password`})}),(0,Y.jsx)(V,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:s,onChange:e=>c(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(H,{htmlFor:`confirm-password`,children:e(`auth.setPassword.confirmPassword`,{defaultValue:`Confirm password`})}),(0,Y.jsx)(V,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:l,onChange:e=>u(e.target.value)})]}),(0,Y.jsx)(B,{type:`submit`,className:`w-full`,disabled:p,children:p?e(`auth.setPassword.submitting`,{defaultValue:`Saving…`}):e(`auth.setPassword.submit`,{defaultValue:`Set password`})})]})})]})})}var Si=`/api/v1/auth`;function Ci(){let{t:e}=M(),[t]=d(),n=t.get(`token`),[r,i]=(0,J.useState)(`loading`),[a,o]=(0,J.useState)(``);return(0,J.useEffect)(()=>{if(!n){i(`error`),o(e(`auth.verifyEmail.missingToken`,{defaultValue:`Verification link is missing a token.`}));return}let t=!1;return(async()=>{try{let e=await fetch(`${Si}/verify-email`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({token:n})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t?.message||`Verification failed: ${e.status}`)}t||i(`success`)}catch(n){t||(i(`error`),o(n.message||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})))}})(),()=>{t=!0}},[n,e]),(0,Y.jsx)(si,{children:(0,Y.jsxs)(U,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[r===`loading`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(z,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.verifyingTitle`,{defaultValue:`Verifying…`})}),(0,Y.jsx)(R,{children:e(`auth.verifyEmail.verifyingDescription`,{defaultValue:`Hang tight while we confirm your email.`})})]}),(0,Y.jsx)(Ce,{className:`flex justify-center py-6`,children:(0,Y.jsx)(`div`,{className:`h-10 w-10 animate-spin rounded-full border-4 border-muted border-t-primary`})})]}),r===`success`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-2 flex size-12 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-500 ring-1 ring-emerald-500/30`,children:(0,Y.jsx)(mt,{className:`size-6`})}),(0,Y.jsx)(z,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.successTitle`,{defaultValue:`Email verified`})}),(0,Y.jsx)(R,{children:e(`auth.verifyEmail.successDescription`,{defaultValue:`Your email is confirmed. You can now sign in.`})})]}),(0,Y.jsx)(Ce,{className:`text-center`,children:(0,Y.jsx)(f,{to:`/login`,className:`text-sm font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.verifyEmail.signInLink`,{defaultValue:`Go to sign in`})})})]}),r===`error`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-2 flex size-12 items-center justify-center rounded-full bg-destructive/10 text-destructive ring-1 ring-destructive/30`,children:(0,Y.jsx)(lt,{className:`size-6`})}),(0,Y.jsx)(z,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.errorTitle`,{defaultValue:`Verification failed`})}),(0,Y.jsx)(R,{children:a||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})})]}),(0,Y.jsx)(Ce,{className:`text-center`,children:(0,Y.jsx)(f,{to:`/login`,className:`text-sm font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.verifyEmail.backToSignIn`,{defaultValue:`Back to sign in`})})})]})]})})}function wi(){let{t:e}=M(),t=h(),[n]=d(),r=n.get(`email`)??``,i=n.get(`redirect`)??``,{sendVerificationEmail:a}=v(),[o,s]=(0,J.useState)(!1),[c,l]=(0,J.useState)(!1);return(0,Y.jsx)(si,{children:(0,Y.jsxs)(U,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(`div`,{className:`mx-auto mb-4 flex size-16 items-center justify-center rounded-full bg-primary/10`,children:(0,Y.jsx)(bt,{className:`size-8 text-primary`})}),(0,Y.jsx)(z,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.title`,{defaultValue:`Verify your email address`})}),(0,Y.jsx)(R,{children:e(`auth.verifyEmail.description`,{defaultValue:`We sent a verification link to your email address. Please click the link to verify your account.`})})]}),(0,Y.jsx)(Ce,{children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r?(0,Y.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.verifyEmail.sentTo`,{defaultValue:`Sent to:`}),` `,(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:r})]}):null,(0,Y.jsx)(B,{onClick:async()=>{if(!r){K.error(e(`auth.verifyEmail.resendFailed`,{defaultValue:`Cannot resend verification email`}),{description:e(`auth.verifyEmail.emailMissing`,{defaultValue:`Email address is missing`})});return}s(!0);try{await a(r,i||`/`),l(!0),K.success(e(`auth.verifyEmail.resentSuccess`,{defaultValue:`Verification email sent!`}),{description:e(`auth.verifyEmail.resentDescription`,{defaultValue:`Please check your inbox and click the verification link.`})})}catch(t){K.error(e(`auth.verifyEmail.resendFailed`,{defaultValue:`Failed to resend verification email`}),{description:t.message})}finally{s(!1)}},disabled:o||c,className:`w-full`,variant:c?`outline`:`default`,children:o?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(he,{className:`mr-2 size-4 animate-spin`}),e(`auth.verifyEmail.resending`,{defaultValue:`Sending…`})]}):c?e(`auth.verifyEmail.resent`,{defaultValue:`Email sent! Check your inbox`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(he,{className:`mr-2 size-4`}),e(`auth.verifyEmail.resendButton`,{defaultValue:`Resend verification email`})]})}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,Y.jsx)(`span`,{className:`w-full border-t`})}),(0,Y.jsx)(`div`,{className:`relative flex justify-center text-xs uppercase`,children:(0,Y.jsx)(`span`,{className:`bg-card px-2 text-muted-foreground`,children:e(`auth.verifyEmail.or`,{defaultValue:`Or`})})})]}),(0,Y.jsx)(B,{onClick:()=>{t(`/login${i?`?redirect=${encodeURIComponent(i)}`:``}`)},variant:`ghost`,className:`w-full`,children:e(`auth.verifyEmail.backToLogin`,{defaultValue:`Back to login`})}),(0,Y.jsx)(`p`,{className:`text-center text-xs text-muted-foreground`,children:e(`auth.verifyEmail.checkSpam`,{defaultValue:`Didn't receive the email? Check your spam folder or contact support.`})})]})})]})})}var Ti=`/api/v1/auth`;function Ei(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function Di(){let{t:e}=M(),t=h(),{user:n,signUp:r,organizations:i,refreshOrganizations:a,updateOrganization:o,createOrganization:s,switchOrganization:c}=v(),[l,u]=(0,J.useState)(``),[d,f]=(0,J.useState)(``),[p,m]=(0,J.useState)(``),[g,_]=(0,J.useState)(``),[y,b]=(0,J.useState)(!1),[x,S]=(0,J.useState)(null);return(0,J.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await fetch(`${Ti}/bootstrap-status`,{credentials:`include`}),n=t.ok?await t.json().catch(()=>({})):{};e||S(n.hasOwner===!0)}catch{e||S(!1)}})(),()=>{e=!0}},[]),(0,J.useEffect)(()=>{x===!0&&!n&&t(`/login`,{replace:!0})},[x,n,t]),(0,J.useEffect)(()=>{n&&window.location.assign(`/`)},[n]),x===null?(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center bg-muted`,children:(0,Y.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-muted-foreground/20 border-t-primary`})}):(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center bg-muted p-6`,children:(0,Y.jsx)(`div`,{className:`flex w-full max-w-md flex-col gap-6`,children:(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(z,{children:e(`auth.setup.welcomeTitle`,{defaultValue:`Welcome to ObjectStack`})}),(0,Y.jsx)(R,{children:e(`auth.setup.description`,{defaultValue:`Create the first owner account to finish setting up this deployment.`})})]}),(0,Y.jsx)(Ce,{children:(0,Y.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),b(!0);try{await r(l,d,p);let e=g.trim();if(e)try{await a();let t=i[0],n;t?.id?(await o(t.id,{name:e,slug:Ei(e)}),n=t.id):n=(await s({name:e,slug:Ei(e)}))?.id,n&&await c(n).catch(()=>void 0)}catch(e){console.warn(`[setup] organization rename/create failed`,e)}window.location.assign(`/`)}catch(t){K.error(e(`auth.setup.failed`,{defaultValue:`Setup failed`}),{description:t.message})}finally{b(!1)}},className:`flex flex-col gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(H,{htmlFor:`name`,children:e(`auth.setup.yourName`,{defaultValue:`Your name`})}),(0,Y.jsx)(V,{id:`name`,autoComplete:`name`,required:!0,value:l,onChange:e=>u(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(H,{htmlFor:`orgName`,children:e(`auth.setup.orgName`,{defaultValue:`Organization name`})}),(0,Y.jsx)(V,{id:`orgName`,required:!0,placeholder:e(`auth.setup.orgNamePlaceholder`,{defaultValue:`Acme Inc.`}),value:g,onChange:e=>_(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(H,{htmlFor:`email`,children:e(`auth.setup.emailLabel`,{defaultValue:`Email`})}),(0,Y.jsx)(V,{id:`email`,type:`email`,placeholder:e(`auth.setup.emailPlaceholder`,{defaultValue:`name@example.com`}),autoComplete:`email`,required:!0,value:d,onChange:e=>f(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(H,{htmlFor:`password`,children:e(`auth.setup.passwordLabel`,{defaultValue:`Password`})}),(0,Y.jsx)(V,{id:`password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,placeholder:e(`auth.setup.passwordHint`,{defaultValue:`Minimum 8 characters`}),value:p,onChange:e=>m(e.target.value)})]}),(0,Y.jsx)(B,{type:`submit`,className:`mt-2 w-full`,disabled:y,children:y?e(`auth.setup.submitting`,{defaultValue:`Setting up…`}):e(`auth.setup.submit`,{defaultValue:`Create owner account`})})]})})]})})})}var Oi=`/api/v1/auth`;function ki(){let{t:e}=M(),t=h(),{user:n,isLoading:r}=v(),[i,a]=(0,J.useState)(!1),[o,s]=(0,J.useState)(null),c=typeof window<`u`?window.location.search:``,l=c.startsWith(`?`)?c.slice(1):c,u=new URLSearchParams(l),d=u.get(`client_id`)??void 0,f=u.get(`scope`)??``;(0,J.useEffect)(()=>{if(!r&&!n){let e=window.location.pathname+window.location.search;t(`/login?redirect=${encodeURIComponent(e)}`,{replace:!0})}},[n,r,t]),(0,J.useEffect)(()=>{if(!d)return;let e=!1;return fetch(`${Oi}/oauth2/applications/${encodeURIComponent(d)}/public`,{credentials:`include`}).then(async t=>{if(!t.ok)return;let n=await t.json().catch(()=>({}));e||s(n?.data??n)}).catch(()=>{}),()=>{e=!0}},[d]);let p=f.split(/\s+/).filter(Boolean),m=async t=>{a(!0);try{let n=await fetch(`${Oi}/oauth2/consent`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({accept:t,oauth_query:l})}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r?.message||`Consent failed: ${n.status}`);let i=r.redirect_uri??r.redirectURI??r.url;if(i){window.location.href=i;return}K(t?e(`oauth.consent.granted`,{defaultValue:`Access granted`}):e(`oauth.consent.denied`,{defaultValue:`Access denied`}),{description:e(`oauth.consent.noRedirect`,{defaultValue:`No redirect URL returned by the server.`})})}catch(t){K.error(e(`oauth.consent.failed`,{defaultValue:`Consent failed`}),{description:t.message})}finally{a(!1)}},g=o?.name??o?.client_name??d??e(`oauth.consent.unknownApp`,{defaultValue:`an application`});return(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full flex-1 items-center justify-center bg-background px-4`,children:(0,Y.jsxs)(U,{className:`w-full max-w-md`,children:[(0,Y.jsxs)(L,{className:`items-center text-center`,children:[(0,Y.jsx)(`div`,{className:`mb-3 rounded-full border bg-muted p-3`,children:o?.icon||o?.logo_uri?(0,Y.jsx)(`img`,{src:o.icon||o.logo_uri,alt:``,className:`h-8 w-8 rounded`,onError:e=>{e.currentTarget.style.display=`none`}}):(0,Y.jsx)(Te,{className:`h-7 w-7 text-muted-foreground`})}),(0,Y.jsx)(z,{className:`text-xl`,children:e(`oauth.consent.title`,{appName:g,defaultValue:`${g} wants to access your account`})}),(0,Y.jsx)(R,{children:e(`oauth.consent.request`,{appName:g,suffix:n?.email?` (${n.email})`:``,defaultValue:`${g} is requesting permission${n?.email?` for ${n.email}`:``}.`})})]}),(0,Y.jsxs)(Ce,{className:`space-y-4`,children:[p.length>0&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:e(`oauth.consent.willAllow`,{defaultValue:`This app will be able to:`})}),(0,Y.jsx)(`ul`,{className:`space-y-1.5 rounded-md border bg-muted/40 p-3 text-sm`,children:p.map(t=>(0,Y.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Me,{className:`mt-0.5 h-4 w-4 text-green-600 dark:text-green-400`}),(0,Y.jsx)(`span`,{children:Ai(t,e)})]},t))})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-2`,children:[(0,Y.jsxs)(B,{variant:`outline`,onClick:()=>m(!1),disabled:i,children:[(0,Y.jsx)(Ue,{className:`mr-2 h-4 w-4`}),e(`oauth.consent.deny`,{defaultValue:`Deny`})]}),(0,Y.jsxs)(B,{onClick:()=>m(!0),disabled:i,children:[(0,Y.jsx)(Me,{className:`mr-2 h-4 w-4`}),i?e(`oauth.consent.submitting`,{defaultValue:`Authorizing…`}):e(`oauth.consent.authorize`,{defaultValue:`Authorize`})]})]}),(0,Y.jsx)(`p`,{className:`pt-2 text-center text-xs text-muted-foreground`,children:e(`oauth.consent.footer`,{defaultValue:`You can revoke access at any time from your account settings.`})})]})]})})}function Ai(e,t){switch(e){case`openid`:return t(`oauth.consent.scope.openid`,{defaultValue:`Confirm your identity`});case`profile`:return t(`oauth.consent.scope.profile`,{defaultValue:`Read your basic profile (name, picture)`});case`email`:return t(`oauth.consent.scope.email`,{defaultValue:`Read your email address`});case`offline_access`:return t(`oauth.consent.scope.offlineAccess`,{defaultValue:`Stay signed in (refresh access)`});default:return e}}var ji=`/api/v1/auth`;function Mi({children:e}){return(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full flex-col items-center justify-center gap-6 bg-muted p-6 md:p-10`,children:(0,Y.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col gap-6`,children:[(0,Y.jsxs)(`a`,{href:`#`,className:`flex items-center gap-2 self-center font-medium`,children:[(0,Y.jsx)(`div`,{className:`flex size-6 items-center justify-center rounded-md bg-primary text-primary-foreground`,children:(0,Y.jsx)(dt,{className:`size-4`})}),`ObjectStack`]}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-6`,children:e})]})})}function Ni(){let{t:e}=M(),t=s(),[n]=d(),i=n.get(`user_code`)??n.get(`code`)??``,a=n.get(`runtime_name`)??``,o=n.get(`runtime_version`)??``,{user:c,isLoading:l}=v(),u=h(),[f,p]=(0,J.useState)(!1),[m,g]=(0,J.useState)(!1),[_,y]=(0,J.useState)(!1),[b,x]=(0,J.useState)(!1),[S,C]=(0,J.useState)(``);if(!i)return(0,Y.jsx)(Mi,{children:(0,Y.jsx)(U,{children:(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(z,{children:e(`auth.device.invalidTitle`,{defaultValue:`Invalid device link`})}),(0,Y.jsx)(R,{children:e(`auth.device.invalidDescription`,{defaultValue:`No device code was provided in the URL.`})})]})})});if(l)return(0,Y.jsx)(Mi,{children:(0,Y.jsx)(U,{children:(0,Y.jsx)(L,{className:`text-center`,children:(0,Y.jsx)(R,{children:e(`auth.device.loading`,{defaultValue:`Loading…`})})})})});if(!c)return(0,Y.jsx)(r,{to:`/login?redirect=${encodeURIComponent(`/auth/device${t.search}`)}`,replace:!0});if(_)return(0,Y.jsx)(Mi,{children:(0,Y.jsx)(U,{children:(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(mt,{className:`mx-auto mb-2 h-10 w-10 text-green-500`}),(0,Y.jsx)(z,{children:e(`auth.device.approvedTitle`,{defaultValue:`Device authorized`})}),(0,Y.jsx)(R,{children:e(`auth.device.approvedDescription`,{defaultValue:`You can return to the device — it should sign in shortly.`})})]})})});if(b)return(0,Y.jsx)(Mi,{children:(0,Y.jsx)(U,{children:(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(z,{children:e(`auth.device.deniedTitle`,{defaultValue:`Access denied`})}),(0,Y.jsx)(R,{children:e(`auth.device.deniedDescription`,{defaultValue:`The device will not be granted access.`})})]})})});let w=async()=>{await fetch(`${ji}/device?user_code=${encodeURIComponent(i)}`,{credentials:`include`}).catch(()=>{})};return(0,Y.jsx)(Mi,{children:(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(z,{children:e(`auth.device.title`,{defaultValue:`Authorize new device`})}),(0,Y.jsx)(R,{children:e(`auth.device.subtitle`,{email:c.email,defaultValue:`Approve this device to sign in as ${c.email}.`})})]}),(0,Y.jsxs)(Ce,{className:`space-y-4`,children:[a?(0,Y.jsxs)(`div`,{className:`rounded-md border bg-background px-4 py-3 text-center`,children:[(0,Y.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e(`auth.device.requesterLabel`,{defaultValue:`Connection request from`})}),(0,Y.jsx)(`p`,{className:`font-medium`,children:a}),o?(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`objectos `,o]}):null]}):null,(0,Y.jsxs)(`div`,{className:`rounded-md border bg-background px-4 py-3 text-center`,children:[(0,Y.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e(`auth.device.userCodeLabel`,{defaultValue:`Device code`})}),(0,Y.jsx)(`p`,{className:`font-mono text-lg font-semibold tracking-widest`,children:i})]}),(0,Y.jsx)(`p`,{className:`text-center text-xs text-muted-foreground`,children:e(`auth.device.approveWarning`,{defaultValue:`Only approve if you started this connection yourself a moment ago. Once approved, this runtime can access your organization's private packages.`})}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-center text-sm text-muted-foreground`,children:e(`auth.device.loggedInAs`,{email:c.email,defaultValue:`Signed in as ${c.email}`})}),S&&(0,Y.jsx)(`p`,{className:`text-center text-sm text-destructive`,children:S}),(0,Y.jsx)(B,{onClick:async()=>{C(``),p(!0);try{await w();let t=await fetch(`${ji}/device/approve`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({userCode:i})});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n?.message??n?.error?.message??e(`auth.device.approveFailed`,{defaultValue:`Approval failed`}))}y(!0),K.success(e(`auth.device.approveSuccess`,{defaultValue:`Device authorized`}),{description:e(`auth.device.approveSuccessDescription`,{defaultValue:`You can close this window.`})})}catch(t){C(t?.message??e(`auth.device.approveFailed`,{defaultValue:`Approval failed`}))}finally{p(!1)}},className:`w-full`,disabled:f||m,children:f?e(`auth.device.approving`,{defaultValue:`Approving…`}):e(`auth.device.approve`,{defaultValue:`Approve device`})}),(0,Y.jsx)(B,{onClick:async()=>{C(``),g(!0);try{await w(),await fetch(`${ji}/device/deny`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({userCode:i})}),x(!0)}catch(t){C(t?.message??e(`auth.device.denyFailed`,{defaultValue:`Failed to deny request`}))}finally{g(!1)}},variant:`outline`,className:`w-full`,disabled:f||m,children:m?e(`auth.device.denying`,{defaultValue:`Denying…`}):e(`auth.device.deny`,{defaultValue:`Deny request`})}),(0,Y.jsx)(`div`,{className:`text-center`,children:(0,Y.jsx)(`button`,{type:`button`,className:`text-sm text-muted-foreground underline-offset-4 hover:underline`,onClick:()=>u(`/`),children:e(`auth.device.cancel`,{defaultValue:`Cancel`})})})]})]})]})})}function Pi(){let{t:e}=M(),{invitationId:t}=a(),n=h(),{user:r,isLoading:i,acceptInvitation:o,rejectInvitation:s,refreshOrganizations:c}=v(),[l,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(!1);return(0,J.useEffect)(()=>{if(!i&&!r&&t){let e=`/accept-invitation/${t}`;n(`/login?redirect=${encodeURIComponent(e)}`,{replace:!0})}},[i,r,t,n]),t?(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full flex-col items-center justify-center gap-6 bg-muted p-6 md:p-10`,children:(0,Y.jsx)(`div`,{className:`flex w-full max-w-sm flex-col gap-6`,children:(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(z,{className:`text-xl`,children:e(`acceptInvitation.title`,{defaultValue:`Accept organization invitation`})}),(0,Y.jsx)(R,{children:e(`acceptInvitation.description`,{defaultValue:`You've been invited to join an organization.`})})]}),(0,Y.jsxs)(Ce,{className:`flex flex-col gap-3`,children:[(0,Y.jsx)(B,{className:`w-full`,onClick:async()=>{u(!0);try{await o(t),await c().catch(()=>void 0),K.success(e(`acceptInvitation.accepted`,{defaultValue:`Invitation accepted`})),n(`/organizations`)}catch(t){K.error(e(`acceptInvitation.acceptFailed`,{defaultValue:`Could not accept`}),{description:t.message})}finally{u(!1)}},disabled:l||d,children:l?e(`acceptInvitation.accepting`,{defaultValue:`Accepting…`}):e(`acceptInvitation.accept`,{defaultValue:`Accept invitation`})}),(0,Y.jsx)(B,{variant:`outline`,className:`w-full`,onClick:async()=>{f(!0);try{await s(t),K.success(e(`acceptInvitation.declined`,{defaultValue:`Invitation declined`})),n(`/organizations`)}catch(t){K.error(e(`acceptInvitation.declineFailed`,{defaultValue:`Could not decline`}),{description:t.message})}finally{f(!1)}},disabled:l||d,children:d?e(`acceptInvitation.declining`,{defaultValue:`Declining…`}):e(`acceptInvitation.decline`,{defaultValue:`Decline`})})]})]})})}):(0,Y.jsx)(`div`,{className:`flex min-h-svh w-full flex-col items-center justify-center bg-muted p-6`,children:(0,Y.jsx)(U,{className:`w-full max-w-sm`,children:(0,Y.jsxs)(L,{className:`text-center`,children:[(0,Y.jsx)(z,{className:`text-xl`,children:e(`acceptInvitation.invalidTitle`,{defaultValue:`Invalid invitation link`})}),(0,Y.jsx)(R,{children:e(`acceptInvitation.invalidDescription`,{defaultValue:`The invitation id is missing from the URL.`})})]})})})}var Fi=`/api/v1/auth`;function Ii(){try{if(typeof document>`u`)return`/`;let e=document.querySelector(`base`)?.getAttribute(`href`);return e&&new URL(e,window.location.origin).pathname.replace(/\/$/,``)||`/`}catch{return`/`}}var Li=Ii();function Ri(){let e=s(),t=e.pathname+e.search;return(0,Y.jsx)(r,{to:`/login${t&&t!==`/`?`?redirect=${encodeURIComponent(t)}`:``}`,replace:!0})}function X({children:e,requireOrganization:t=!0}){return(0,Y.jsx)(w,{fallback:(0,Y.jsx)(Ri,{}),loadingFallback:(0,Y.jsx)(Yt,{}),children:(0,Y.jsx)($t,{children:t?(0,Y.jsx)(Wt,{children:e}):e})})}function zi(){let{user:e}=v();return(0,Y.jsx)(Qt,{userId:e?.id,children:(0,Y.jsx)(Kt,{})})}function Bi(){return(0,Y.jsxs)(x,{authUrl:Fi,children:[(0,Y.jsx)(Jt,{position:`bottom-right`}),(0,Y.jsx)(dr,{}),(0,Y.jsx)(l,{basename:Li,children:(0,Y.jsx)(Xt,{children:(0,Y.jsxs)(i,{children:[(0,Y.jsx)(p,{path:`/login`,element:(0,Y.jsx)(di,{})}),(0,Y.jsx)(p,{path:`/register`,element:(0,Y.jsx)(gi,{})}),(0,Y.jsx)(p,{path:`/forgot-password`,element:(0,Y.jsx)(vi,{})}),(0,Y.jsx)(p,{path:`/reset-password`,element:(0,Y.jsx)(yi,{})}),(0,Y.jsx)(p,{path:`/set-password`,element:(0,Y.jsx)(xi,{})}),(0,Y.jsx)(p,{path:`/verify-email`,element:(0,Y.jsx)(Ci,{})}),(0,Y.jsx)(p,{path:`/verify-email-prompt`,element:(0,Y.jsx)(wi,{})}),(0,Y.jsx)(p,{path:`/setup`,element:(0,Y.jsx)(Di,{})}),(0,Y.jsx)(p,{path:`/oauth/consent`,element:(0,Y.jsx)(ki,{})}),(0,Y.jsx)(p,{path:`/auth/device`,element:(0,Y.jsx)(Ni,{})}),(0,Y.jsx)(p,{path:`/accept-invitation/:invitationId`,element:(0,Y.jsx)(Pi,{})}),(0,Y.jsx)(p,{path:`/f/:slug`,element:(0,Y.jsx)(ur,{mode:`public`})}),(0,Y.jsx)(p,{path:`/s/:token`,element:(0,Y.jsx)(mr,{})}),(0,Y.jsx)(p,{path:`/forms/:name`,element:(0,Y.jsx)(X,{children:(0,Y.jsx)(ur,{mode:`internal`})})}),(0,Y.jsxs)(p,{path:`/docs`,element:(0,Y.jsx)(X,{children:(0,Y.jsx)(ni,{})}),children:[(0,Y.jsx)(p,{index:!0,element:(0,Y.jsx)(Zr,{})}),(0,Y.jsx)(p,{path:`:slug`,element:(0,Y.jsx)(ei,{})}),(0,Y.jsx)(p,{path:`:slug/:name`,element:(0,Y.jsx)(Xr,{})})]}),(0,Y.jsx)(p,{path:`/home`,element:(0,Y.jsx)(X,{children:(0,Y.jsx)(zi,{})})}),(0,Y.jsx)(p,{path:`/dev/master-detail`,element:(0,Y.jsx)(X,{children:(0,Y.jsx)(Sn,{})})}),(0,Y.jsx)(p,{path:`/dev/lists`,element:(0,Y.jsx)(X,{children:(0,Y.jsx)(Tn,{})})}),(0,Y.jsx)(p,{path:`/dev/modal`,element:(0,Y.jsx)(X,{children:(0,Y.jsx)(Dn,{})})}),(0,Y.jsx)(p,{path:`/dev/lookup`,element:(0,Y.jsx)(X,{children:(0,Y.jsx)(On,{})})}),(0,Y.jsx)(p,{path:`/organizations`,element:(0,Y.jsx)(X,{requireOrganization:!1,children:(0,Y.jsx)(rn,{children:(0,Y.jsx)(tn,{})})})}),(0,Y.jsxs)(p,{path:`/organizations/:slug`,element:(0,Y.jsx)(X,{requireOrganization:!1,children:(0,Y.jsx)(Gt,{})}),children:[(0,Y.jsx)(p,{index:!0,element:(0,Y.jsx)(r,{to:`members`,replace:!0})}),(0,Y.jsx)(p,{path:`members`,element:(0,Y.jsx)(Zt,{})}),(0,Y.jsx)(p,{path:`invitations`,element:(0,Y.jsx)(nn,{})}),(0,Y.jsx)(p,{path:`settings`,element:(0,Y.jsx)(en,{})})]}),(0,Y.jsx)(p,{path:`/system/*`,element:(0,Y.jsx)(sn,{})}),(0,Y.jsx)(p,{path:`/ai`,element:(0,Y.jsx)(X,{children:(0,Y.jsx)(an,{})})}),(0,Y.jsx)(p,{path:`/ai/:conversationId`,element:(0,Y.jsx)(X,{children:(0,Y.jsx)(an,{})})}),(0,Y.jsx)(p,{path:`/apps/:appName/*`,element:(0,Y.jsx)(X,{children:(0,Y.jsx)(Yn,{})})}),(0,Y.jsx)(p,{path:`/`,element:(0,Y.jsx)($t,{children:(0,Y.jsx)(Zn,{})})}),(0,Y.jsx)(p,{path:`*`,element:(0,Y.jsx)(r,{to:`/`,replace:!0})})]})})})]})}async function Vi(e){try{let t=await fetch(`/api/v1/i18n/translations/${e}`);if(!t.ok)return console.warn(`[i18n] Failed to load translations for '${e}': HTTP ${t.status}`),{};let n=await t.json(),r;return r=n?.data?.translations&&typeof n.data.translations==`object`?n.data.translations:n,y(r)?g(r):r}catch(t){return console.warn(`[i18n] Failed to load translations for '${e}':`,t),{}}}var Hi=`auth-session-token`,Ui=`auth-active-organization-id`;async function Wi(e){if(typeof window>`u`)return;let t=null;try{t=localStorage.getItem(Hi)}catch{return}if(t)try{let n=await fetch(`${e}/get-session`,{method:`GET`,credentials:`omit`,headers:{Authorization:`Bearer ${t}`,Accept:`application/json`}});if(n.ok){let e=await n.json().catch(()=>null);if(e?.user??e?.data?.user??null)return}localStorage.removeItem(Hi),localStorage.removeItem(Ui)}catch{}}function Gi(e,t){let n=Array.isArray(e.fields)?e.fields:Object.values(e.fields||{});return{id:e.name||`obj_${t}`,name:e.name||``,label:typeof e.label==`object`?e.label.defaultValue||e.label.key||``:e.label||e.name||``,pluralLabel:e.pluralLabel||e.plural_label||void 0,description:typeof e.description==`object`?e.description.defaultValue:e.description||void 0,icon:e.icon||void 0,group:e.name?.startsWith(`sys_`)?`System Objects`:`Custom Objects`,sortOrder:t,isSystem:e.name?.startsWith(`sys_`)||!1,enabled:e.enabled!==!1,fieldCount:n.length,relationships:Array.isArray(e.relationships)?e.relationships.map(e=>({relatedObject:e.object||e.relatedObject||``,type:e.type||`one-to-many`,label:e.label||e.name||void 0,foreignKey:e.foreign_key||e.foreignKey||void 0})):void 0}}function Ki(e,t){return{id:e.name||`fld_${t}`,name:e.name||``,label:typeof e.label==`object`?e.label.defaultValue||e.label.key||``:e.label||e.name||``,type:e.type||`text`,group:e.group||void 0,sortOrder:t,description:e.description||e.help||void 0,required:e.required||!1,unique:e.unique||!1,readonly:e.readonly||!1,hidden:e.hidden||!1,defaultValue:e.defaultValue||e.default_value||void 0,placeholder:e.placeholder||void 0,options:Array.isArray(e.options)?e.options.map(e=>typeof e==`string`?{label:e,value:e}:{label:e.label||e.value,value:e.value,color:e.color}):void 0,isSystem:e.readonly===!0&&(e.name===`id`||e.name===`createdAt`||e.name===`updatedAt`),externalId:e.externalId||!1,trackHistory:e.trackHistory||e.track_history||!1,indexed:e.indexed||!1,referenceTo:e.reference_to||e.referenceTo||void 0,formula:e.formula||void 0}}function qi(e){let{objects:t}=E(),n=(0,J.useMemo)(()=>(t||[]).find(t=>t.name===e),[t,e]);return{object:(0,J.useMemo)(()=>n?Gi(n,0):null,[n]),fields:(0,J.useMemo)(()=>n?(Array.isArray(n.fields)?n.fields:Object.values(n.fields||{})).map(Ki):[],[n]),metadataObject:n}}function Ji({label:e,value:t,onSave:n,multiline:r=!1,disabled:i=!1,placeholder:a}){let[o,s]=(0,J.useState)(!1),[c,l]=(0,J.useState)(t),[u,d]=(0,J.useState)(!1),f=(0,J.useRef)(null),p=()=>{l(t),s(!0),setTimeout(()=>f.current?.focus(),0)},m=(0,J.useCallback)(async()=>{if(c===t){s(!1);return}d(!0);try{await n(c),s(!1)}catch{}finally{d(!1)}},[c,t,n]),h=()=>{l(t),s(!1)},g=e=>{e.key===`Enter`&&!r&&(e.preventDefault(),m()),e.key===`Escape`&&h()};return(0,Y.jsxs)(`div`,{className:`space-y-1.5 group`,children:[(0,Y.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:e}),(0,Y.jsx)(`dd`,{children:o?(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[r?(0,Y.jsx)(Nt,{ref:f,value:c,onChange:e=>l(e.target.value),onKeyDown:g,placeholder:a,rows:3,className:`text-sm flex-1 min-w-0`,disabled:u}):(0,Y.jsx)(V,{ref:f,value:c,onChange:e=>l(e.target.value),onKeyDown:g,placeholder:a,className:`text-sm h-7 flex-1 min-w-0`,disabled:u}),(0,Y.jsx)(`button`,{onClick:()=>void m(),disabled:u,className:`mt-0.5 p-1 rounded text-green-600 hover:bg-green-50 disabled:opacity-50 shrink-0`,"aria-label":`Save`,children:u?(0,Y.jsx)(Ae,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Me,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{onClick:h,disabled:u,className:`mt-0.5 p-1 rounded text-muted-foreground hover:bg-accent shrink-0`,"aria-label":`Cancel`,children:(0,Y.jsx)(Ue,{className:`h-3.5 w-3.5`})})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 min-h-7`,children:[(0,Y.jsx)(`span`,{className:`text-sm flex-1 min-w-0 truncate`,children:t||(0,Y.jsx)(`span`,{className:`text-muted-foreground italic`,children:a||`—`})}),!i&&(0,Y.jsx)(`button`,{onClick:p,className:`p-1 rounded text-muted-foreground opacity-0 group-hover:opacity-100 hover:bg-accent transition-opacity shrink-0`,"aria-label":`Edit ${e}`,children:(0,Y.jsx)($e,{className:`h-3 w-3`})})]})})]})}function Yi({schema:e}){let t=e.objectName,{object:n,fields:r,metadataObject:i}=qi(t),{refresh:a}=E(),o=un(),s=(0,J.useCallback)(async(e,n)=>{if(!o||!i)return;let r={...i,[e]:n};try{await o.saveMetadataItem(`object`,t,r),await a(),K.success(`${e===`label`?`Display name`:`Field`} updated`)}catch(e){throw K.error(e?.message||`Failed to save`),e}},[o,i,t,a]);if(!n)return null;let c=n.isSystem;return(0,Y.jsxs)(`div`,{className:`space-y-6`,"data-testid":`object-properties`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`基本信息`}),(0,Y.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-5`,children:[(0,Y.jsx)(Ji,{label:`显示名称`,value:n.label,onSave:e=>s(`label`,e),placeholder:`输入显示名称`,disabled:c}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`API 名称`}),(0,Y.jsx)(`dd`,{className:`text-sm font-mono bg-muted/50 rounded px-2 py-1 inline-block`,children:n.name})]}),(0,Y.jsx)(Ji,{label:`复数名称`,value:n.pluralLabel||``,onSave:e=>s(`pluralLabel`,e),placeholder:`例如:客户们`,disabled:c}),(0,Y.jsx)(Ji,{label:`分组`,value:n.group||``,onSave:e=>s(`group`,e),placeholder:`对象分组`,disabled:c}),(0,Y.jsx)(`div`,{className:`sm:col-span-2`,children:(0,Y.jsx)(Ji,{label:`描述`,value:n.description||``,onSave:e=>s(`description`,e),multiline:!0,placeholder:`输入对象描述`,disabled:c})})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`配置`}),(0,Y.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`状态`}),(0,Y.jsx)(`dd`,{children:(0,Y.jsx)(P,{variant:n.enabled===!1?`secondary`:`default`,className:`font-normal`,children:n.enabled===!1?`已禁用`:`已启用`})})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`字段数量`}),(0,Y.jsxs)(`dd`,{className:`text-sm font-medium`,children:[n.fieldCount??r.length,` 个字段`]})]}),c&&(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`类型`}),(0,Y.jsx)(`dd`,{children:(0,Y.jsx)(P,{variant:`secondary`,className:`font-normal`,children:`系统对象`})})]})]})]})]})}var Xi=[{label:`一对多`,value:`one-to-many`},{label:`多对多`,value:`many-to-many`},{label:`一对一`,value:`one-to-one`},{label:`多对一`,value:`many-to-one`}];function Zi({schema:e}){let t=e.objectName,{object:n,metadataObject:r}=qi(t),{refresh:i}=E(),a=un(),[o,s]=(0,J.useState)(!1),[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``}),f=(0,J.useCallback)(async()=>{if(!a||!r||!u.relatedObject.trim())return;let e={relatedObject:u.relatedObject.trim(),type:u.type,label:u.label.trim()||void 0,foreignKey:u.foreignKey.trim()||void 0},n={...r,relationships:[...Array.isArray(r.relationships)?r.relationships:[],e]};l(!0);try{await a.saveMetadataItem(`object`,t,n),await i(),K.success(`关联关系已添加`),s(!1),d({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``})}catch(e){K.error(e?.message||`保存失败`)}finally{l(!1)}},[a,r,n,u,t,i]),p=(0,J.useCallback)(async e=>{if(!a||!r)return;let n=Array.isArray(r.relationships)?[...r.relationships]:[];n.splice(e,1);let o={...r,relationships:n};l(!0);try{await a.saveMetadataItem(`object`,t,o),await i(),K.success(`关联关系已删除`)}catch(e){K.error(e?.message||`删除失败`)}finally{l(!1)}},[a,r,t,i]);if(!n)return null;let m=n.relationships&&n.relationships.length>0;return(0,Y.jsx)(`div`,{className:`space-y-4`,"data-testid":`relationships-section`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`关联关系`}),!n.isSystem&&(0,Y.jsxs)(B,{size:`sm`,variant:`outline`,onClick:()=>s(e=>!e),className:`h-7 text-xs`,children:[(0,Y.jsx)(Ke,{className:`h-3 w-3 mr-1`}),`添加关联`]})]}),o&&(0,Y.jsxs)(`div`,{className:`mb-4 p-4 border rounded-lg bg-muted/30 space-y-3`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium`,children:`新建关联关系`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联对象 *`}),(0,Y.jsx)(V,{value:u.relatedObject,onChange:e=>d(t=>({...t,relatedObject:e.target.value})),placeholder:`例如:account`,className:`h-7 text-xs`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联类型`}),(0,Y.jsx)(`select`,{value:u.type,onChange:e=>d(t=>({...t,type:e.target.value})),className:`w-full h-7 text-xs rounded-md border border-input bg-background px-2`,children:Xi.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`显示名称`}),(0,Y.jsx)(V,{value:u.label,onChange:e=>d(t=>({...t,label:e.target.value})),placeholder:`可选`,className:`h-7 text-xs`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`外键字段`}),(0,Y.jsx)(V,{value:u.foreignKey,onChange:e=>d(t=>({...t,foreignKey:e.target.value})),placeholder:`例如:account_id`,className:`h-7 text-xs`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 justify-end`,children:[(0,Y.jsx)(B,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>s(!1),disabled:c,children:`取消`}),(0,Y.jsxs)(B,{size:`sm`,className:`h-7 text-xs`,onClick:()=>void f(),disabled:c||!u.relatedObject.trim(),children:[c?(0,Y.jsx)(Ae,{className:`h-3 w-3 animate-spin mr-1`}):null,`保存`]})]})]}),m?(0,Y.jsx)(`div`,{className:`space-y-2`,children:n.relationships?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors group`,children:[(0,Y.jsx)(P,{variant:`outline`,className:`text-xs shrink-0 mt-0.5`,children:Xi.find(t=>t.value===e.type)?.label||e.type}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.relatedObject}),e.label&&e.label!==e.relatedObject&&(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`关联对象: `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.relatedObject})]}),e.foreignKey&&(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`外键: `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.foreignKey})]})]}),!n.isSystem&&(0,Y.jsx)(`button`,{onClick:()=>void p(t),disabled:c,className:`p-1 rounded text-muted-foreground opacity-0 group-hover:opacity-100 hover:text-destructive hover:bg-destructive/10 transition-all shrink-0`,"aria-label":`删除关联`,children:(0,Y.jsx)(Xe,{className:`h-3.5 w-3.5`})})]},t))}):!o&&(0,Y.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,Y.jsx)(ye,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`暂无关联关系。`}),!n.isSystem&&(0,Y.jsxs)(B,{size:`sm`,variant:`outline`,className:`mt-3 h-7 text-xs`,onClick:()=>s(!0),children:[(0,Y.jsx)(Ke,{className:`h-3 w-3 mr-1`}),`添加关联`]})]})]})})}function Qi({schema:e}){let t=e.objectName,{fields:n}=qi(t),r=(0,J.useMemo)(()=>n.filter(e=>e.unique||e.name===`id`||e.externalId),[n]);return(0,Y.jsx)(`div`,{className:`space-y-4`,"data-testid":`keys-section`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`唯一键`}),r.length>0?(0,Y.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors`,children:[(0,Y.jsx)(P,{variant:e.name===`id`?`default`:`outline`,className:`text-xs shrink-0 mt-0.5`,children:e.name===`id`?`主键`:e.externalId?`外部 ID`:`唯一`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.name}),(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`类型: `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.type})]})]})]},e.name))}):(0,Y.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,Y.jsx)(Te,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`未找到唯一键或主键。`})]})]})})}function $i(e){return(0,Y.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-experience-section`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据体验`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`配置用户与此对象数据的交互方式`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,Y.jsxs)(`div`,{className:`rounded-lg border p-5 text-center hover:bg-accent/30 transition-colors cursor-pointer`,"data-testid":`data-experience-forms`,children:[(0,Y.jsx)(ft,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,Y.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`表单`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`设计数据录入表单`})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border p-5 text-center hover:bg-accent/30 transition-colors cursor-pointer`,"data-testid":`data-experience-views`,children:[(0,Y.jsx)(se,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,Y.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`视图`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`配置列表和详情视图`})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border p-5 text-center hover:bg-accent/30 transition-colors cursor-pointer`,"data-testid":`data-experience-dashboards`,children:[(0,Y.jsx)(ge,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,Y.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`仪表盘`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`构建可视化仪表盘`})]})]})]})})}function ea({schema:e}){let t=e.objectName,{object:n}=qi(t);return(0,Y.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-preview-section`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据预览`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`查看此对象的示例记录`}),(0,Y.jsxs)(`div`,{className:`rounded-lg border border-dashed p-12 text-center`,children:[(0,Y.jsx)(nt,{className:`h-12 w-12 mx-auto mb-4 text-muted-foreground opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium mb-1`,children:`示例数据`}),(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`“`,n?.label||t,`” 的实时数据预览将在此处显示`]})]})]})})}function ta(e){return e||(typeof window<`u`&&window.sessionStorage?window.sessionStorage:null)}function na(e,t={}){let{maxHistory:n=50,persistKey:r,storage:i}=t,a=ta(i),o=(()=>{if(!r||!a)return null;try{let e=a.getItem(r);if(!e)return null;let t=JSON.parse(e);if(t&&t.v===1&&Array.isArray(t.past)&&Array.isArray(t.future))return t}catch{}return null})(),[s,c]=(0,J.useState)(o?.current??e),l=(0,J.useRef)(o?.past??[]),u=(0,J.useRef)(o?.future??[]),[,d]=(0,J.useState)(0),f=(0,J.useCallback)(()=>d(e=>e+1),[]);(0,J.useEffect)(()=>{if(!(!r||!a))try{let e={v:1,past:l.current,current:s,future:u.current};a.setItem(r,JSON.stringify(e))}catch{}},[s,r,a]);let p=(0,J.useCallback)(e=>{c(t=>(l.current=[...l.current.slice(-(n-1)),t],u.current=[],e)),f()},[n,f]),m=(0,J.useCallback)(()=>{l.current.length!==0&&(c(e=>{let t=[...l.current],n=t.pop();return l.current=t,u.current=[e,...u.current],n}),f())},[f]),h=(0,J.useCallback)(()=>{u.current.length!==0&&(c(e=>{let t=[...u.current],n=t.shift();return u.current=t,l.current=[...l.current,e],n}),f())},[f]),g=(0,J.useCallback)(e=>{l.current=[],u.current=[],c(e),f()},[f]),_=(0,J.useCallback)(()=>{if(!(!r||!a))try{a.removeItem(r)}catch{}},[r,a]),v=(0,J.useCallback)(e=>{let t=l.current.length+1+u.current.length;e<0||e>=t||e!==l.current.length&&(c(t=>{let n=[...l.current,t,...u.current],r=n[e];return l.current=n.slice(0,e),u.current=n.slice(e+1),r}),f())},[f]);return{current:s,canUndo:l.current.length>0,canRedo:u.current.length>0,undoCount:l.current.length,redoCount:u.current.length,timeline:[...l.current,s,...u.current],currentIndex:l.current.length,push:p,undo:m,redo:h,reset:g,jumpTo:v,clearPersisted:_}}function ra(){let[e,t]=(0,J.useState)(!1),[n,r]=(0,J.useState)(``),[i,a]=(0,J.useState)(``),o=(0,J.useRef)(null);return{isOpen:e,title:n,message:i,confirm:(0,J.useCallback)((e,n)=>(r(e),a(n),t(!0),new Promise(e=>{o.current=e})),[]),onConfirm:(0,J.useCallback)(()=>{t(!1),o.current?.(!0),o.current=null},[]),onCancel:(0,J.useCallback)(()=>{t(!1),o.current?.(!1),o.current=null},[])}}function ia(){let[e,t]=(0,J.useState)(new Set);return{selectedIds:e,toggle:(0,J.useCallback)((e,n=!1)=>{t(t=>{let r=new Set(n?t:[]);return t.has(e)&&n?r.delete(e):r.add(e),r})},[]),selectOne:(0,J.useCallback)(e=>{t(new Set([e]))},[]),selectMany:(0,J.useCallback)(e=>{t(new Set(e))},[]),clearSelection:(0,J.useCallback)(()=>{t(new Set)},[]),isSelected:(0,J.useCallback)(t=>e.has(t),[e]),count:e.size}}function aa(){let[e,t]=(0,J.useState)(null);return{clipboard:e,copy:(0,J.useCallback)(e=>{t(structuredClone(e))},[]),paste:(0,J.useCallback)(()=>e?structuredClone(e):null,[e]),hasContent:e!==null}}function oa(e={}){let{minZoom:t=.25,maxZoom:n=3,zoomStep:r=.1,initialZoom:i=1}=e,[a,o]=(0,J.useState)(i),[s,c]=(0,J.useState)({x:0,y:0}),l=(0,J.useRef)(!1),u=(0,J.useRef)({x:0,y:0}),d=(0,J.useCallback)(e=>Math.min(n,Math.max(t,+e.toFixed(2))),[t,n]);return{zoom:a,panOffset:s,zoomIn:(0,J.useCallback)(()=>o(e=>d(e+r)),[d,r]),zoomOut:(0,J.useCallback)(()=>o(e=>d(e-r)),[d,r]),resetZoom:(0,J.useCallback)(()=>{o(1),c({x:0,y:0})},[]),setZoom:(0,J.useCallback)(e=>o(d(e)),[d]),handleWheel:(0,J.useCallback)(e=>{if(e.ctrlKey||e.metaKey){e.preventDefault();let t=e.deltaY>0?-r:r;o(e=>d(e+t))}},[d,r]),startPan:(0,J.useCallback)(e=>{if(e.button===1||e.button===0&&e.altKey){e.preventDefault(),l.current=!0,u.current={x:e.clientX,y:e.clientY};let t=e=>{if(!l.current)return;let t=e.clientX-u.current.x,n=e.clientY-u.current.y;u.current={x:e.clientX,y:e.clientY},c(e=>({x:e.x+t,y:e.y+n}))},n=()=>{l.current=!1,document.removeEventListener(`mousemove`,t),document.removeEventListener(`mouseup`,n)};document.addEventListener(`mousemove`,t),document.addEventListener(`mouseup`,n)}},[]),transformStyle:{transform:`translate(${s.x}px, ${s.y}px) scale(${a})`,transformOrigin:`0 0`}}}function sa(...e){return W(G(e))}function ca({isOpen:e,title:t,message:n,confirmLabel:r=`Delete`,cancelLabel:i=`Cancel`,destructive:a=!0,onConfirm:o,onCancel:s}){let c=(0,J.useRef)(null);return(0,J.useEffect)(()=>{let t=c.current;t&&(e&&!t.open?t.showModal():!e&&t.open&&t.close())},[e]),e?(0,Y.jsx)(`dialog`,{ref:c,className:`fixed inset-0 z-50 m-auto rounded-lg border bg-background p-0 shadow-lg backdrop:bg-black/50`,onClose:s,"aria-labelledby":`confirm-title`,"aria-describedby":`confirm-message`,children:(0,Y.jsxs)(`div`,{className:`w-80 p-6`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[a&&(0,Y.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-destructive/10`,children:(0,Y.jsx)(Be,{className:`h-5 w-5 text-destructive`})}),(0,Y.jsx)(`h2`,{id:`confirm-title`,className:`text-lg font-semibold`,children:t})]}),(0,Y.jsx)(`p`,{id:`confirm-message`,className:`text-sm text-muted-foreground mb-6`,children:n}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Y.jsx)(`button`,{onClick:s,className:`px-4 py-2 text-sm rounded-md border hover:bg-accent`,children:i}),(0,Y.jsx)(`button`,{onClick:o,className:sa(`px-4 py-2 text-sm rounded-md font-medium`,a?`bg-destructive text-destructive-foreground hover:bg-destructive/90`:`bg-primary text-primary-foreground hover:bg-primary/90`),autoFocus:!0,children:r})]})]})}):null}function la(...e){return W(G(e))}function ua({title:e=`Properties`,fields:t,onChange:n,className:r}){let[i,a]=(0,J.useState)(new Set),o=(0,J.useCallback)(e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=t.reduce((e,t)=>{let n=t.group??`General`;return e[n]||(e[n]=[]),e[n].push(t),e},{});return(0,Y.jsxs)(`div`,{className:la(`flex flex-col`,r),role:`region`,"aria-label":e,children:[(0,Y.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:e}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[Object.entries(s).map(([e,t])=>(0,Y.jsxs)(`div`,{className:`border-b last:border-b-0`,children:[(0,Y.jsxs)(`button`,{onClick:()=>o(e),className:`w-full flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50`,children:[i.has(e)?(0,Y.jsx)(Ge,{className:`h-3 w-3`}):(0,Y.jsx)(de,{className:`h-3 w-3`}),e]}),!i.has(e)&&(0,Y.jsx)(`div`,{className:`px-3 pb-2 space-y-2`,children:t.map(e=>(0,Y.jsx)(da,{field:e,onChange:n},e.name))})]},e)),t.length===0&&(0,Y.jsx)(`div`,{className:`p-3 text-xs text-muted-foreground text-center`,children:`Select an element to edit its properties`})]})]})}function da({field:e,onChange:t}){let n=n=>{t(e.name,n)};return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:e.label}),e.type===`text`&&(0,Y.jsx)(`input`,{type:`text`,value:String(e.value??``),onChange:e=>n(e.target.value),className:`w-full px-2 py-1 text-xs border rounded bg-background`}),e.type===`number`&&(0,Y.jsx)(`input`,{type:`number`,value:Number(e.value??0),onChange:e=>n(Number(e.target.value)),className:`w-full px-2 py-1 text-xs border rounded bg-background`}),e.type===`boolean`&&(0,Y.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:!!e.value,onChange:e=>n(e.target.checked),className:`rounded`}),(0,Y.jsx)(`span`,{className:`text-xs`,children:e.value?`Yes`:`No`})]}),e.type===`select`&&(0,Y.jsx)(`select`,{value:String(e.value??``),onChange:e=>n(e.target.value),className:`w-full px-2 py-1 text-xs border rounded bg-background`,children:e.options?.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))}),e.type===`color`&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`color`,value:String(e.value??`#000000`),onChange:e=>n(e.target.value),className:`h-6 w-6 rounded border cursor-pointer`}),(0,Y.jsx)(`span`,{className:`text-xs font-mono`,children:String(e.value??`#000000`)})]}),e.type===`textarea`&&(0,Y.jsx)(`textarea`,{value:String(e.value??``),onChange:e=>n(e.target.value),className:`w-full px-2 py-1 text-xs border rounded bg-background resize-y`,rows:3}),e.description&&(0,Y.jsx)(`p`,{className:`text-[0.65rem] text-muted-foreground/70`,children:e.description})]})}function fa(...e){return W(G(e))}function pa({items:e,canvasWidth:t,canvasHeight:n,position:r=`bottom-right`,size:i=150,className:a}){let o=Math.min(i/t,i/n),s=t*o,c=n*o;return(0,Y.jsx)(`div`,{className:fa(`absolute border rounded bg-background/90 shadow-sm overflow-hidden`,{"top-left":`top-2 left-2`,"top-right":`top-2 right-2`,"bottom-left":`bottom-2 left-2`,"bottom-right":`bottom-2 right-2`}[r],a),role:`img`,"aria-label":`Canvas minimap`,children:(0,Y.jsxs)(`svg`,{width:s,height:c,viewBox:`0 0 ${t} ${n}`,children:[(0,Y.jsx)(`rect`,{width:t,height:n,fill:`hsl(var(--muted))`,opacity:`0.3`}),e.map(e=>(0,Y.jsx)(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,fill:e.selected?`hsl(var(--primary))`:e.color??`hsl(var(--foreground) / 0.3)`,rx:`2`},e.id))]})})}var ma=(0,J.createContext)(null);ma.displayName=`CollaborationContext`;function ha(){return(0,J.useContext)(ma)}function Z(...e){return W(G(e))}function ga({canvas:e={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:t=[],palette:n=_a,showComponentTree:r=!0,undoRedo:i=!0,propertyEditor:a=!0,readOnly:o=!1,showMinimap:s=!1,onChange:c,className:l}){let u=na(t),d=u.current,f=(0,J.useCallback)(e=>{u.push(e),c?.(e)},[u,c]),p=oa({initialZoom:e.zoom??1}),{zoom:m}=p,h=ia(),g=(0,J.useMemo)(()=>{let e=Array.from(h.selectedIds);return e.length>0?e[0]:null},[h.selectedIds]),_=(0,J.useMemo)(()=>d.find(e=>e.id===g),[d,g]),v=aa(),y=ra(),b=ha(),x=(0,J.useCallback)(e=>{b&&b.sendOperation({...e,userId:b.currentUserId??``})},[b]),[S,C]=(0,J.useState)(!0),[w,T]=(0,J.useState)(!0),[E,D]=(0,J.useState)(s),O=(0,J.useRef)(null),k=(0,J.useRef)(null),A=(0,J.useCallback)(t=>!e.snapToGrid||!e.gridSize?t:Math.round(t/e.gridSize)*e.gridSize,[e.snapToGrid,e.gridSize]),j=(0,J.useCallback)((e,t)=>{if(o)return;let r=n.flatMap(e=>e.items).find(t=>t.type===e),i=r?.defaultSize,a={id:`comp-${Date.now()}`,type:e,label:t,position:{x:100,y:100,width:i?.width??200,height:i?.height??100},props:r?.defaultProps??{}};f([...d,a]),h.selectOne(a.id),x({type:`insert`,elementId:a.id,data:{component:a}})},[d,o,n,f,h,x]),ee=(0,J.useCallback)(e=>{o||(f(d.filter(t=>t.id!==e)),h.isSelected(e)&&h.clearSelection(),x({type:`delete`,elementId:e,data:{}}))},[d,o,f,h,x]),M=(0,J.useCallback)(async()=>{if(o||h.count===0||!await y.confirm(`Delete components`,`Are you sure you want to delete ${h.count} component${h.count>1?`s`:``}?`))return;let e=h.selectedIds;f(d.filter(t=>!e.has(t.id))),h.clearSelection(),e.forEach(e=>{x({type:`delete`,elementId:e,data:{}})})},[o,h,y,d,f,x]),N=(0,J.useCallback)((e,t)=>{o||!g||(f(d.map(n=>n.id===g?e===`label`?{...n,label:String(t)}:e===`x`?{...n,position:{...n.position,x:Number(t)}}:e===`y`?{...n,position:{...n.position,y:Number(t)}}:e===`width`?{...n,position:{...n.position,width:Number(t)}}:e===`height`?{...n,position:{...n.position,height:Number(t)}}:{...n,props:{...n.props,[e]:t}}:n)),x({type:`update`,elementId:g,data:{[e]:t}}))},[o,g,d,f,x]),te=(0,J.useCallback)(()=>{let e=h.selectedIds;if(e.size===0)return;let t=d.filter(t=>e.has(t.id));v.copy(t)},[h,d,v]),P=(0,J.useCallback)(()=>{if(o)return;let e=v.paste();if(!e||e.length===0)return;let t=0,n=e.map(e=>({...e,id:`comp-${Date.now()}-${++t}-${Math.random().toString(36).slice(2,7)}`,position:{...e.position,x:e.position.x+20,y:e.position.y+20}}));f([...d,...n]),h.selectMany(n.map(e=>e.id)),n.forEach(e=>{x({type:`insert`,elementId:e.id,data:{component:e}})})},[o,v,d,f,h,x]),ne=(0,J.useCallback)((e,t)=>{o||(O.current={id:t.id,startX:e.clientX,startY:e.clientY},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.id))},[o]),re=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),ie=(0,J.useCallback)(e=>{e.preventDefault();let t=O.current;if(!t||o)return;let n=(e.clientX-t.startX)/m,r=(e.clientY-t.startY)/m;f(d.map(e=>e.id===t.id?{...e,position:{...e.position,x:A(e.position.x+n),y:A(e.position.y+r)}}:e)),x({type:`move`,elementId:t.id,data:{}}),O.current=null},[o,m,d,f,A,x]),ae=(0,J.useMemo)(()=>_?[{name:`label`,label:`Label`,type:`text`,value:_.label??``,group:`General`},{name:`x`,label:`X`,type:`number`,value:_.position.x,group:`Position`},{name:`y`,label:`Y`,type:`number`,value:_.position.y,group:`Position`},{name:`width`,label:`Width`,type:`number`,value:_.position.width,group:`Size`},{name:`height`,label:`Height`,type:`number`,value:_.position.height,group:`Size`}]:[],[_]),oe=(0,J.useMemo)(()=>d.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:typeof e.position.width==`number`?e.position.width:100,height:typeof e.position.height==`number`?e.position.height:50,selected:h.isSelected(e.id)})),[d,h]);return(0,J.useEffect)(()=>{let e=k.current;if(!e)return;let t=e=>{let t=[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.target.tagName),n=e.ctrlKey||e.metaKey;if((e.key===`Delete`||e.key===`Backspace`)&&h.count>0&&!t){e.preventDefault(),M();return}if(e.key===`Escape`){h.clearSelection();return}if(!t){if(n&&e.key===`z`&&!e.shiftKey&&i&&!o){e.preventDefault(),u.undo();return}if(n&&(e.key===`z`&&e.shiftKey||e.key===`y`)&&i&&!o){e.preventDefault(),u.redo();return}if(n&&e.key===`c`){e.preventDefault(),te();return}if(n&&e.key===`v`&&!o){e.preventDefault(),P();return}if(n&&e.key===`a`){e.preventDefault(),h.selectMany(d.map(e=>e.id));return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[h,M,i,o,u,te,P,d]),(0,Y.jsxs)(`div`,{ref:k,tabIndex:0,className:Z(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,l),children:[!o&&(0,Y.jsx)(`div`,{className:Z(`border-r bg-muted/30 flex flex-col transition-[width] duration-200`,S?`w-60`:`w-0 overflow-hidden`),role:`region`,"aria-label":`Component palette`,children:S&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:`Components`}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:n.map(e=>(0,Y.jsxs)(`div`,{className:`mb-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground px-2 py-1 uppercase`,children:e.label}),e.items.map(e=>(0,Y.jsxs)(`button`,{onClick:()=>j(e.type,e.label),className:`w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-accent text-left`,children:[(0,Y.jsx)(Ke,{className:`h-3 w-3`}),e.label]},e.type))]},e.name))})]})}),(0,Y.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Designer toolbar`,children:[!o&&(0,Y.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:S?`Collapse palette`:`Expand palette`,"aria-label":S?`Collapse palette`:`Expand palette`,onClick:()=>C(e=>!e),children:(0,Y.jsx)(Et,{className:Z(`h-4 w-4`,!S&&`rotate-180`)})}),i&&!o&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,Y.jsx)(`button`,{className:Z(`p-1.5 rounded hover:bg-accent`,!u.canUndo&&`opacity-40 pointer-events-none`),title:`Undo (Ctrl+Z)`,"aria-label":`Undo`,disabled:!u.canUndo,onClick:()=>u.undo(),children:(0,Y.jsx)(xe,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:Z(`p-1.5 rounded hover:bg-accent`,!u.canRedo&&`opacity-40 pointer-events-none`),title:`Redo (Ctrl+Shift+Z)`,"aria-label":`Redo`,disabled:!u.canRedo,onClick:()=>u.redo(),children:(0,Y.jsx)(De,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{className:Z(`p-1.5 rounded hover:bg-accent`,h.count===0&&`opacity-40 pointer-events-none`),title:`Copy (Ctrl+C)`,"aria-label":`Copy`,disabled:h.count===0,onClick:te,children:(0,Y.jsx)(et,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:Z(`p-1.5 rounded hover:bg-accent`,!v.hasContent&&`opacity-40 pointer-events-none`),title:`Paste (Ctrl+V)`,"aria-label":`Paste`,disabled:!v.hasContent,onClick:P,children:(0,Y.jsx)(ot,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Y.jsx)(`button`,{className:Z(`p-1.5 rounded hover:bg-accent`,h.count===0&&`opacity-40 pointer-events-none`),title:`Delete selected`,"aria-label":`Delete selected`,disabled:h.count===0,onClick:M,children:(0,Y.jsx)(Xe,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:`Preview`,"aria-label":`Preview`,children:(0,Y.jsx)(Pe,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:Z(`p-1.5 rounded hover:bg-accent`,E&&`bg-accent`),title:`Toggle minimap`,"aria-label":`Toggle minimap`,onClick:()=>D(e=>!e),children:(0,Y.jsx)(fe,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom out`,onClick:p.zoomOut,children:(0,Y.jsx)(Rt,{className:`h-3 w-3`})}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground w-10 text-center`,children:[Math.round(m*100),`%`]}),(0,Y.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom in`,onClick:p.zoomIn,children:(0,Y.jsx)(Ke,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Reset zoom`,onClick:p.resetZoom,children:(0,Y.jsx)(We,{className:`h-3 w-3`})})]}),r&&(0,Y.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:w?`Collapse panel`:`Expand panel`,"aria-label":w?`Collapse panel`:`Expand panel`,onClick:()=>T(e=>!e),children:(0,Y.jsx)(kt,{className:Z(`h-4 w-4`,!w&&`rotate-180`)})})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto bg-muted/10 p-4 relative`,role:`region`,"aria-label":`Design canvas`,onWheel:p.handleWheel,onMouseDown:p.startPan,onDragOver:re,onDrop:ie,children:(0,Y.jsxs)(`div`,{className:`relative bg-background border rounded shadow-sm mx-auto`,style:{width:e.width*m,height:e.height*m,transform:`translate(${p.panOffset.x}px, ${p.panOffset.y}px)`,backgroundImage:e.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:e.showGrid&&e.gridSize?`${e.gridSize*m}px ${e.gridSize*m}px`:void 0},children:[d.map(e=>{let t=h.isSelected(e.id);return(0,Y.jsxs)(`div`,{draggable:!o,onDragStart:t=>ne(t,e),className:Z(`absolute border rounded cursor-move select-none transition-shadow`,t?`border-primary ring-2 ring-primary/20 shadow-md`:`border-border hover:border-primary/50`),style:{left:e.position.x*m,top:e.position.y*m,width:typeof e.position.width==`number`?e.position.width*m:e.position.width,height:typeof e.position.height==`number`?e.position.height*m:e.position.height},onClick:t=>h.toggle(e.id,t.shiftKey),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 bg-muted/50 text-xs border-b`,children:[(0,Y.jsx)(_t,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.label??e.type}),!o&&(0,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ee(e.id)},className:`ml-auto p-0.5 rounded hover:bg-destructive/10`,"aria-label":`Delete ${e.label??e.type}`,children:(0,Y.jsx)(Xe,{className:`h-3 w-3 text-destructive`})})]}),(0,Y.jsx)(`div`,{className:`p-2 text-xs text-muted-foreground`,children:e.type})]},e.id)}),E&&(0,Y.jsx)(pa,{items:oe,canvasWidth:e.width,canvasHeight:e.height})]})})]}),r&&(0,Y.jsx)(`div`,{className:Z(`border-l bg-muted/30 flex flex-col transition-[width] duration-200`,w?`w-60`:`w-0 overflow-hidden`),role:`region`,"aria-label":`Component tree`,children:w&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`p-3 border-b font-medium text-sm flex items-center gap-2`,children:[(0,Y.jsx)(Ye,{className:`h-4 w-4`}),`Component Tree`]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:d.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground text-center py-4`,children:`No components added yet. Click a component in the palette to add it to the canvas.`}):d.map(e=>(0,Y.jsx)(`button`,{onClick:t=>h.toggle(e.id,t.shiftKey),className:Z(`w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded text-left`,h.isSelected(e.id)?`bg-accent`:`hover:bg-accent/50`),children:(0,Y.jsx)(`span`,{className:`truncate`,children:e.label??e.type})},e.id))}),a&&_?(0,Y.jsx)(`div`,{className:`border-t`,children:(0,Y.jsx)(ua,{title:`Properties – ${_.label??_.type}`,fields:ae,onChange:N})}):_&&(0,Y.jsxs)(`div`,{className:`border-t p-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium mb-2`,children:`Properties`}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground space-y-1`,children:[(0,Y.jsxs)(`div`,{children:[`Type: `,_.type]}),(0,Y.jsxs)(`div`,{children:[`ID: `,_.id]}),(0,Y.jsxs)(`div`,{children:[`Position: `,_.position.x,`,`,` `,_.position.y]}),(0,Y.jsxs)(`div`,{children:[`Size: `,_.position.width,` ×`,` `,_.position.height]})]})]})]})}),(0,Y.jsx)(ca,{isOpen:y.isOpen,title:y.title,message:y.message,onConfirm:y.onConfirm,onCancel:y.onCancel})]})}var _a=[{name:`layout`,label:`Layout`,items:[{type:`container`,label:`Container`,defaultSize:{width:400,height:300}},{type:`flex`,label:`Flex`,defaultSize:{width:400,height:200}},{type:`grid`,label:`Grid`,defaultSize:{width:400,height:300}},{type:`card`,label:`Card`,defaultSize:{width:300,height:200}},{type:`tabs`,label:`Tabs`,defaultSize:{width:400,height:300}}]},{name:`form`,label:`Form`,items:[{type:`input`,label:`Input`,defaultSize:{width:300,height:60}},{type:`textarea`,label:`Textarea`,defaultSize:{width:300,height:120}},{type:`select`,label:`Select`,defaultSize:{width:300,height:60}},{type:`checkbox`,label:`Checkbox`,defaultSize:{width:200,height:40}},{type:`button`,label:`Button`,defaultSize:{width:120,height:40}}]},{name:`data`,label:`Data`,items:[{type:`table`,label:`Table`,defaultSize:{width:600,height:400}},{type:`chart`,label:`Chart`,defaultSize:{width:400,height:300}},{type:`list`,label:`List`,defaultSize:{width:300,height:400}},{type:`statistic`,label:`Statistic`,defaultSize:{width:200,height:100}}]}];function va(e,t={}){return na(e,t)}function ya(...e){return W(G(e))}var ba=[`text`,`number`,`boolean`,`date`,`datetime`,`uuid`,`email`,`url`,`phone`,`json`,`integer`,`float`,`decimal`,`currency`,`percent`,`textarea`,`select`,`multiselect`,`lookup`,`attachment`,`formula`,`autonumber`];function xa(e,t=4,n=280,r=250,i=50,a=50){return e.map((e,o)=>({...e,position:{x:i+o%t*n,y:a+Math.floor(o/t)*r}}))}function Sa({entities:e=[],relationships:t=[],canvas:n={width:1200,height:800,showGrid:!0},showRelationshipLabels:r=!0,readOnly:i=!1,onEntitiesChange:a,onRelationshipsChange:o,className:s}){let c=(0,J.useRef)(null),l=va({entities:e,relationships:t},{maxHistory:50}),{entities:u,relationships:d}=l.current,f=(0,J.useCallback)(e=>{l.push(e),a?.(e.entities),o?.(e.relationships)},[l,a,o]),p=ra(),m=ia(),h=m.count>0?Array.from(m.selectedIds)[0]:null,g=aa(),_=oa({minZoom:.25,maxZoom:3,zoomStep:.1}),v=ha(),[y,b]=(0,J.useState)(!0),[x,S]=(0,J.useState)(!0),[C,w]=(0,J.useState)(null),[T,E]=(0,J.useState)(``),[D,O]=(0,J.useState)(null),[k,A]=(0,J.useState)(``),j=(0,J.useRef)(null),ee=(0,J.useCallback)(()=>{if(i)return;let e=l.current,t={id:`entity-${Date.now()}`,name:`new_entity_${e.entities.length+1}`,label:`New Entity ${e.entities.length+1}`,fields:[{name:`id`,type:`uuid`,primaryKey:!0,required:!0},{name:`created_at`,type:`datetime`,required:!0},{name:`updated_at`,type:`datetime`,required:!0}],position:{x:50+e.entities.length%4*280,y:50+Math.floor(e.entities.length/4)*250}};f({entities:[...e.entities,t],relationships:e.relationships}),m.selectOne(t.id),v?.sendOperation({type:`insert`,userId:v?.currentUserId??``,elementId:t.id,data:{name:t.name,label:t.label}})},[i,l,f,m,v]),M=(0,J.useCallback)(async e=>{if(i)return;let t=u.find(t=>t.id===e);if(!await p.confirm(`Delete Entity`,`Are you sure you want to delete "${t?.label??e}"? This action cannot be undone.`))return;let n=l.current;f({entities:n.entities.filter(t=>t.id!==e),relationships:n.relationships.filter(t=>t.sourceEntity!==e&&t.targetEntity!==e)}),m.isSelected(e)&&m.clearSelection(),v?.sendOperation({type:`delete`,userId:v?.currentUserId??``,elementId:e,data:{}})},[i,u,p,l,f,m,v]),N=(0,J.useCallback)(async()=>{if(i||m.count===0)return;let e=Array.from(m.selectedIds);if(!await p.confirm(`Delete Entities`,`Are you sure you want to delete ${e.length} selected entity(s)? This action cannot be undone.`))return;let t=l.current,n=new Set(e);f({entities:t.entities.filter(e=>!n.has(e.id)),relationships:t.relationships.filter(e=>!n.has(e.sourceEntity)&&!n.has(e.targetEntity))}),m.clearSelection()},[i,m,p,l,f]),te=(0,J.useCallback)(()=>{if(i)return;let e=l.current;f({entities:xa(e.entities),relationships:e.relationships})},[i,l,f]),P=(0,J.useCallback)(()=>{let e=u.filter(e=>m.isSelected(e.id));e.length>0&&g.copy(e)},[u,m,g]),ne=(0,J.useCallback)(()=>{if(i)return;let e=g.paste();if(!e||e.length===0)return;let t=l.current,n=e.map((e,t)=>({...e,id:`entity-${Date.now()}-${t}`,name:`${e.name}_copy`,label:`${e.label} (Copy)`,position:{x:e.position.x+30,y:e.position.y+30}}));f({entities:[...t.entities,...n],relationships:t.relationships}),m.selectMany(n.map(e=>e.id))},[i,g,l,f,m]),re=(0,J.useCallback)(e=>{if(i)return;let t=l.current;f({entities:t.entities.map(t=>{if(t.id!==e)return t;let n={name:`field_${t.fields.length+1}`,type:`text`,required:!1};return{...t,fields:[...t.fields,n]}}),relationships:t.relationships})},[i,l,f]),oe=(0,J.useCallback)((e,t,n)=>{i||(w({entityId:e,fieldIndex:t}),E(n))},[i]),se=(0,J.useCallback)(()=>{if(!C)return;let e=T.trim();if(e===``){w(null);return}let t=l.current;f({entities:t.entities.map(t=>{if(t.id!==C.entityId)return t;let n=t.fields.map((t,n)=>n===C.fieldIndex?{...t,name:e}:t);return{...t,fields:n}}),relationships:t.relationships}),w(null)},[C,T,l,f]),ce=(0,J.useCallback)(()=>{w(null)},[]),le=(0,J.useCallback)((e,t)=>{i||(O(e),A(t))},[i]),F=(0,J.useCallback)(()=>{if(!D)return;let e=k.trim();if(e===``){O(null);return}let t=l.current;f({entities:t.entities.map(t=>t.id===D?{...t,label:e}:t),relationships:t.relationships}),O(null)},[D,k,l,f]),ue=(0,J.useCallback)(()=>{O(null)},[]),fe=(0,J.useCallback)((e,t,n)=>{if(i)return;let r=l.current;f({entities:r.entities.map(r=>{if(r.id!==e)return r;let i=r.fields.map((e,r)=>r===t?{...e,type:n}:e);return{...r,fields:i}}),relationships:r.relationships})},[i,l,f]),pe=(0,J.useCallback)((e,t)=>{if(i||!u.find(e=>e.id===t))return;let n=e.target.getBoundingClientRect();j.current={entityId:t,offsetX:e.clientX-n.left,offsetY:e.clientY-n.top},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},[i,u]),me=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),he=(0,J.useCallback)(e=>{if(e.preventDefault(),!j.current)return;let t=e.currentTarget.getBoundingClientRect(),n=_.zoom,r=(e.clientX-t.left-_.panOffset.x)/n-j.current.offsetX,i=(e.clientY-t.top-_.panOffset.y)/n-j.current.offsetY,a=l.current;f({entities:a.entities.map(e=>e.id===j.current.entityId?{...e,position:{x:Math.max(0,Math.round(r)),y:Math.max(0,Math.round(i))}}:e),relationships:a.relationships}),j.current=null},[_.zoom,_.panOffset,l,f]),I=h?u.find(e=>e.id===h):null,ge=I?[{name:`name`,label:`Name`,type:`text`,value:I.name,group:`General`},{name:`label`,label:`Label`,type:`text`,value:I.label,group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:I.description??``,group:`General`},{name:`color`,label:`Color`,type:`color`,value:I.color??`#3b82f6`,group:`Appearance`},{name:`position.x`,label:`X Position`,type:`number`,value:I.position.x,group:`Position`},{name:`position.y`,label:`Y Position`,type:`number`,value:I.position.y,group:`Position`}]:[],_e=(0,J.useCallback)((e,t)=>{if(!h)return;let n=l.current;f({entities:n.entities.map(n=>n.id===h?e===`position.x`?{...n,position:{...n.position,x:Number(t)}}:e===`position.y`?{...n,position:{...n.position,y:Number(t)}}:{...n,[e]:t}:n),relationships:n.relationships})},[h,l,f]);(0,J.useEffect)(()=>{let e=c.current;if(!e)return;let t=e=>{let t=e.target.tagName;if(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`)return;let n=e.ctrlKey||e.metaKey;n&&e.key===`z`?(e.preventDefault(),l.undo()):n&&(e.key===`y`||e.shiftKey&&e.key===`Z`)?(e.preventDefault(),l.redo()):n&&e.key===`c`?(e.preventDefault(),P()):n&&e.key===`v`?(e.preventDefault(),ne()):(e.key===`Delete`||e.key===`Backspace`)&&m.count>0?(e.preventDefault(),N()):e.key===`Escape`&&(m.clearSelection(),w(null),O(null))};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[l,P,ne,N,m]);let ve=u.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:240,height:40+e.fields.length*24,color:e.color,selected:m.isSelected(e.id)}));return(0,Y.jsxs)(`div`,{ref:c,tabIndex:0,className:ya(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,s),children:[(0,Y.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{role:`toolbar`,"aria-label":`Designer toolbar`,className:`flex items-center gap-2 p-2 border-b bg-muted/20 flex-wrap`,children:[(0,Y.jsx)(Ze,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`font-medium text-sm`,children:`Data Model Designer`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 ml-2 border-l pl-2`,children:[(0,Y.jsx)(`button`,{onClick:()=>l.undo(),disabled:!l.canUndo,"aria-label":`Undo`,title:`Undo (Ctrl+Z)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Y.jsx)(xe,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{onClick:()=>l.redo(),disabled:!l.canRedo,"aria-label":`Redo`,title:`Redo (Ctrl+Y)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Y.jsx)(De,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,Y.jsx)(`button`,{onClick:_.zoomOut,"aria-label":`Zoom Out`,title:`Zoom Out`,className:`p-1 rounded hover:bg-accent`,children:(0,Y.jsx)(Ft,{className:`h-3.5 w-3.5`})}),(0,Y.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-center`,children:[Math.round(_.zoom*100),`%`]}),(0,Y.jsx)(`button`,{onClick:_.zoomIn,"aria-label":`Zoom In`,title:`Zoom In`,className:`p-1 rounded hover:bg-accent`,children:(0,Y.jsx)(Bt,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{onClick:_.resetZoom,"aria-label":`Reset Zoom`,title:`Reset Zoom`,className:`p-1 rounded hover:bg-accent`,children:(0,Y.jsx)(ie,{className:`h-3 w-3`})})]}),!i&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,Y.jsx)(`button`,{onClick:P,disabled:m.count===0,"aria-label":`Copy`,title:`Copy (Ctrl+C)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Y.jsx)(et,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{onClick:ne,disabled:!g.hasContent,"aria-label":`Paste`,title:`Paste (Ctrl+V)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Y.jsx)(ot,{className:`h-3.5 w-3.5`})})]}),!i&&(0,Y.jsxs)(`button`,{onClick:te,"aria-label":`Auto Layout`,title:`Auto Layout`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded border hover:bg-accent`,children:[(0,Y.jsx)(at,{className:`h-3 w-3`}),` Auto Layout`]}),(0,Y.jsx)(`div`,{className:`flex-1`}),v?.isConnected&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,Y.jsx)(ae,{className:`h-3 w-3`}),(0,Y.jsxs)(`span`,{children:[v.users.length,` user`,v.users.length===1?``:`s`]})]}),m.count>1&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[m.count,` selected`]}),!i&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`button`,{onClick:ee,"aria-label":`Add Entity`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90`,children:[(0,Y.jsx)(Ke,{className:`h-3 w-3`}),` Add Entity`]}),(0,Y.jsxs)(`button`,{"aria-label":`Add Relationship`,title:`Add Relationship (coming soon)`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded bg-secondary text-secondary-foreground hover:bg-secondary/80`,children:[(0,Y.jsx)(ye,{className:`h-3 w-3`}),` Add Relationship`]})]})]}),(0,Y.jsxs)(`div`,{role:`region`,"aria-label":`Canvas`,className:`flex-1 overflow-auto bg-muted/10 p-4 relative`,onWheel:_.handleWheel,onMouseDown:_.startPan,onDragOver:me,onDrop:he,children:[(0,Y.jsxs)(`div`,{className:`relative`,style:{width:n.width,minHeight:n.height,..._.transformStyle,backgroundImage:n.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:n.showGrid?`20px 20px`:void 0},children:[(0,Y.jsx)(`svg`,{className:`absolute inset-0 pointer-events-none`,width:n.width,height:n.height,children:d.map(e=>{let t=u.find(t=>t.id===e.sourceEntity),n=u.find(t=>t.id===e.targetEntity);return!t||!n?null:(0,Y.jsxs)(`g`,{children:[(0,Y.jsx)(`line`,{x1:t.position.x+120,y1:t.position.y+50,x2:n.position.x+120,y2:n.position.y+50,stroke:`hsl(var(--primary))`,strokeWidth:`2`,strokeDasharray:e.type===`many-to-many`?`5,5`:void 0}),r&&e.label&&(0,Y.jsx)(`text`,{x:(t.position.x+n.position.x)/2+120,y:(t.position.y+n.position.y)/2+50-8,textAnchor:`middle`,className:`text-xs fill-muted-foreground`,children:e.label})]},e.id)})}),u.length===0&&(0,Y.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-muted-foreground text-sm`,children:`No entities in the model. Click 'Add Entity' to create your first entity.`}),u.map(e=>(0,Y.jsxs)(`div`,{role:`group`,"aria-label":e.label,draggable:!i,onDragStart:t=>pe(t,e.id),className:ya(`absolute rounded-lg border-2 bg-background shadow-sm w-60 select-none cursor-grab active:cursor-grabbing`,m.isSelected(e.id)?`border-primary ring-2 ring-primary/20`:`border-border hover:border-primary/50`),style:{left:e.position.x,top:e.position.y},onClick:t=>m.toggle(e.id,t.shiftKey),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-t-lg font-medium text-sm`,style:{backgroundColor:e.color??`hsl(var(--primary) / 0.1)`},children:[(0,Y.jsx)(Ze,{className:`h-3.5 w-3.5`}),D===e.id?(0,Y.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),onBlur:F,onKeyDown:e=>{e.key===`Enter`&&F(),e.key===`Escape`&&ue()},className:`text-sm font-medium px-1 py-0 border rounded bg-background w-32 focus:outline-none focus:ring-1 focus:ring-primary`,autoFocus:!0,onClick:e=>e.stopPropagation(),"data-testid":`entity-label-input-${e.id}`}):(0,Y.jsx)(`span`,{className:`truncate cursor-text`,onDoubleClick:t=>{t.stopPropagation(),le(e.id,e.label)},title:`Double-click to edit label`,"data-testid":`entity-label-${e.id}`,children:e.label}),!i&&(0,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),M(e.id)},"aria-label":`Delete ${e.label}`,className:`ml-auto p-0.5 rounded hover:bg-destructive/20`,children:(0,Y.jsx)(Xe,{className:`h-3 w-3 text-destructive`})})]}),(0,Y.jsx)(`div`,{className:`px-3 py-1 divide-y`,children:e.fields.map((t,n)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 py-1 text-xs`,children:[C&&C.entityId===e.id&&C.fieldIndex===n?(0,Y.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),onBlur:se,onKeyDown:e=>{e.key===`Enter`&&se(),e.key===`Escape`&&ce()},className:`font-mono text-xs px-1 py-0 border rounded bg-background w-24 focus:outline-none focus:ring-1 focus:ring-primary`,autoFocus:!0,onClick:e=>e.stopPropagation()}):(0,Y.jsxs)(`span`,{className:ya(`font-mono cursor-text`,t.primaryKey&&`font-bold text-primary`),onClick:r=>{r.stopPropagation(),oe(e.id,n,t.name)},title:`Click to edit field name`,children:[t.primaryKey&&(0,Y.jsx)(`span`,{className:`text-[0.65rem] font-semibold text-primary mr-0.5`,children:`PK`}),t.name]}),i?(0,Y.jsx)(`span`,{className:`text-muted-foreground ml-auto`,children:t.type}):(0,Y.jsx)(`select`,{value:t.type,onChange:t=>{t.stopPropagation(),fe(e.id,n,t.target.value)},onClick:e=>e.stopPropagation(),className:`text-xs text-muted-foreground ml-auto bg-transparent border-none focus:ring-1 focus:ring-primary rounded cursor-pointer p-0`,"data-testid":`field-type-${e.id}-${n}`,children:ba.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))}),t.required&&(0,Y.jsx)(`span`,{className:`text-destructive`,children:`*`})]},`${t.name}-${n}`))}),!i&&(0,Y.jsx)(`div`,{className:`px-3 py-1 border-t`,children:(0,Y.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),re(e.id)},"aria-label":`Add field to ${e.label}`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground w-full py-0.5`,children:[(0,Y.jsx)(Ke,{className:`h-3 w-3`}),` Add Field`]})})]},e.id))]}),x&&u.length>0&&(0,Y.jsx)(pa,{items:ve,canvasWidth:n.width,canvasHeight:n.height,position:`bottom-right`,size:150})]})]}),(0,Y.jsxs)(`div`,{className:`w-64 border-l flex flex-col bg-background shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,Y.jsxs)(`button`,{onClick:()=>b(e=>!e),className:`flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50 border-b`,"aria-expanded":y,"aria-controls":`property-editor-panel`,children:[y?(0,Y.jsx)(de,{className:`h-3 w-3`}):(0,Y.jsx)(Ge,{className:`h-3 w-3`}),`Properties`]}),y&&(0,Y.jsx)(`div`,{id:`property-editor-panel`,className:`flex-1 overflow-y-auto`,children:(0,Y.jsx)(ua,{title:I?I.label:`Properties`,fields:ge,onChange:_e})})]}),(0,Y.jsx)(`div`,{className:`border-t`,children:(0,Y.jsxs)(`button`,{onClick:()=>S(e=>!e),className:`flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50 w-full`,"aria-expanded":x,children:[x?(0,Y.jsx)(de,{className:`h-3 w-3`}):(0,Y.jsx)(Ge,{className:`h-3 w-3`}),`Minimap`]})})]}),(0,Y.jsx)(ca,{isOpen:p.isOpen,title:p.title,message:p.message,onConfirm:p.onConfirm,onCancel:p.onCancel,destructive:!0})]})}function Ca(...e){return W(G(e))}var wa=120,Ta=50;function Ea(e,t){if(e.length===0)return e;let n=new Map,r=new Map;for(let t of e)n.set(t.id,0),r.set(t.id,[]);for(let e of t)n.set(e.target,(n.get(e.target)??0)+1),r.get(e.source)?.push(e.target);let i=[],a=new Set,o=e.filter(e=>(n.get(e.id)??0)===0).map(e=>e.id);for(o.length===0&&(o=[e[0].id]);o.length>0;){i.push(o);for(let e of o)a.add(e);let e=new Set;for(let t of o)for(let n of r.get(t)??[])a.has(n)||e.add(n);o=Array.from(e)}let s=e.filter(e=>!a.has(e.id)).map(e=>e.id);s.length>0&&i.push(s);let c=new Map;for(let e=0;e<i.length;e++){let t=i[e];for(let n=0;n<t.length;n++)c.set(t[n],{x:80+e*200,y:80+n*100})}return e.map(e=>({...e,position:c.get(e.id)??e.position}))}function Da({processName:e=`New Process`,nodes:t=[],edges:n=[],lanes:r,canvas:i={width:1400,height:800,showGrid:!0},showMinimap:a=!0,showToolbar:o=!0,readOnly:s=!1,onNodesChange:c,onEdgesChange:l,className:u}){let d=na({nodes:t,edges:n},{maxHistory:50}),f=d.current.nodes,p=d.current.edges,m=(0,J.useCallback)((e,t)=>{d.push({nodes:e,edges:t}),c?.(e),l?.(t)},[d,c,l]),h=ra(),g=ia(),_=aa(),v=oa({initialZoom:1}),y=ha(),[b,x]=(0,J.useState)(null),[S,C]=(0,J.useState)(!1),[w,T]=(0,J.useState)(null),[E,D]=(0,J.useState)(null),[O,k]=(0,J.useState)(!0),[A,j]=(0,J.useState)(null),[ee,M]=(0,J.useState)({x:0,y:0}),N=(0,J.useRef)(null),P=(0,J.useRef)(c),ne=(0,J.useRef)(l);P.current=c,ne.current=l,(0,J.useEffect)(()=>{P.current?.(f),ne.current?.(p)},[d.current]);let re=(0,J.useCallback)((e,t)=>{if(s)return;let n={id:`node-${Date.now()}`,type:e,label:t,position:{x:200+f.length*160,y:200}};m([...f,n],p),x(n.id),g.selectOne(n.id),y?.sendOperation({type:`insert`,elementId:n.id,data:{label:t},userId:y.currentUserId??``})},[f,p,s,m,g,y]),ae=(0,J.useCallback)(async e=>{if(s)return;let t=f.find(t=>t.id===e);await h.confirm(`Delete Node`,`Are you sure you want to delete "${t?.label??e}"? This will also remove all connected edges.`)&&(m(f.filter(t=>t.id!==e),p.filter(t=>t.source!==e&&t.target!==e)),b===e&&x(null),g.clearSelection(),y?.sendOperation({type:`delete`,elementId:e,data:{},userId:y.currentUserId??``}))},[f,p,b,s,m,h,g,y]),oe=(0,J.useCallback)(async()=>{if(s||g.count===0||!await h.confirm(`Delete Selected Nodes`,`Are you sure you want to delete ${g.count} selected node(s) and their connected edges?`))return;let e=g.selectedIds;m(f.filter(t=>!e.has(t.id)),p.filter(t=>!e.has(t.source)&&!e.has(t.target))),x(null),g.clearSelection()},[f,p,s,m,h,g]),se=(0,J.useCallback)(()=>{let e=g.count>0?g.selectedIds:b?new Set([b]):new Set;if(e.size===0)return;let t=f.filter(t=>e.has(t.id));_.copy(t)},[f,b,g,_]),ce=(0,J.useCallback)(()=>{if(s)return;let e=_.paste();if(!e||e.length===0)return;let t=e.map(e=>({...e,id:`node-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,position:{x:e.position.x+40,y:e.position.y+40}}));m([...f,...t],p),g.selectMany(t.map(e=>e.id)),x(t[0].id)},[s,f,p,_,m,g]),le=(0,J.useCallback)(()=>{C(e=>e?(T(null),!1):!0)},[]),F=(0,J.useCallback)(e=>{if(!S)return!1;if(!w)return T(e),!0;if(w===e)return!0;let t={id:`edge-${Date.now()}`,source:w,target:e};return m(f,[...p,t]),T(null),C(!1),y?.sendOperation({type:`insert`,elementId:t.id,data:{source:w,target:e},userId:y.currentUserId??``}),!0},[S,w,f,p,m,y]),ue=(0,J.useCallback)(()=>{s||f.length===0||m(Ea(f,p),p)},[f,p,s,m]),de=(0,J.useCallback)((e,t)=>{if(s||!f.find(e=>e.id===t))return;j(t);let n=e.target.getBoundingClientRect();M({x:e.clientX-n.left,y:e.clientY-n.top}),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},[s,f]),fe=(0,J.useCallback)(e=>{if(e.preventDefault(),s||!A)return;let t=e.currentTarget.getBoundingClientRect(),n=v.zoom,r=(e.clientX-t.left-v.panOffset.x)/n-ee.x,i=(e.clientY-t.top-v.panOffset.y)/n-ee.y,a=Math.max(0,Math.round(r/20)*20),o=Math.max(0,Math.round(i/20)*20);m(f.map(e=>e.id===A?{...e,position:{x:a,y:o}}:e),p),j(null)},[s,A,ee,f,p,v.zoom,v.panOffset,m]),pe=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),me=(0,J.useMemo)(()=>f.find(e=>e.id===b)??null,[f,b]),he=(0,J.useMemo)(()=>me?[{name:`label`,label:`Name`,type:`text`,value:me.label,group:`General`},{name:`type`,label:`Type`,type:`select`,value:me.type,options:[{label:`Start Event`,value:`start-event`},{label:`End Event`,value:`end-event`},{label:`User Task`,value:`user-task`},{label:`Service Task`,value:`service-task`},{label:`Script Task`,value:`script-task`},{label:`Exclusive Gateway`,value:`exclusive-gateway`},{label:`Parallel Gateway`,value:`parallel-gateway`},{label:`Inclusive Gateway`,value:`inclusive-gateway`}],group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:me.description??``,group:`General`}]:[],[me]),I=(0,J.useCallback)((e,t)=>{s||!b||m(f.map(n=>n.id===b?{...n,[e]:t}:n),p)},[s,b,f,p,m]),ge=e=>{switch(e){case`start-event`:return`rounded-full bg-green-100 border-green-500 text-green-700`;case`end-event`:return`rounded-full bg-red-100 border-red-500 text-red-700`;case`exclusive-gateway`:case`parallel-gateway`:case`inclusive-gateway`:case`event-based-gateway`:return`rotate-45 bg-yellow-100 border-yellow-500 text-yellow-700`;case`user-task`:return`rounded bg-blue-100 border-blue-500 text-blue-700`;case`service-task`:case`script-task`:return`rounded bg-purple-100 border-purple-500 text-purple-700`;default:return`rounded bg-gray-100 border-gray-500 text-gray-700`}},ve=(0,J.useMemo)(()=>f.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:wa,height:Ta,selected:g.isSelected(e.id)||e.id===b})),[f,g,b]);(0,J.useEffect)(()=>{let e=N.current;if(!e)return;let t=e=>{let t=e.target?.tagName;if(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`)return;let n=e.ctrlKey||e.metaKey;if(n&&e.key===`z`&&!e.shiftKey){e.preventDefault(),d.undo();return}if(n&&e.key===`y`||n&&e.key===`z`&&e.shiftKey){e.preventDefault(),d.redo();return}if(n&&e.key===`c`){e.preventDefault(),se();return}if(n&&e.key===`v`){e.preventDefault(),ce();return}if(e.key===`Delete`||e.key===`Backspace`){g.count>0?(e.preventDefault(),oe()):b&&(e.preventDefault(),ae(b));return}if(e.key===`Escape`){S?(C(!1),T(null)):(x(null),g.clearSelection());return}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[b,S,g,d,se,ce,ae,oe]);let ye=(0,J.useCallback)(e=>{e.target===e.currentTarget&&(x(null),g.clearSelection(),S&&(C(!1),T(null)))},[S,g]);return(0,Y.jsxs)(`div`,{ref:N,tabIndex:0,className:Ca(`flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Y.jsx)(ca,{isOpen:h.isOpen,title:h.title,message:h.message,onConfirm:h.onConfirm,onCancel:h.onCancel,destructive:!0}),o&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Process toolbar`,children:[(0,Y.jsx)(xt,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`font-medium text-sm`,"aria-label":`Process name`,children:e}),y?.isConnected&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),y.users.length,` user`,y.users.length===1?``:`s`]}),(0,Y.jsx)(`div`,{className:`flex-1`}),!s&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>d.undo(),disabled:!d.canUndo,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Undo (Ctrl+Z)`,"aria-label":`Undo`,children:(0,Y.jsx)(xe,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>d.redo(),disabled:!d.canRedo,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Redo (Ctrl+Y)`,"aria-label":`Redo`,children:(0,Y.jsx)(De,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsx)(`button`,{onClick:se,disabled:g.count===0&&!b,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Copy (Ctrl+C)`,"aria-label":`Copy`,children:(0,Y.jsx)(et,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:ce,disabled:!_.hasContent,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Paste (Ctrl+V)`,"aria-label":`Paste`,children:(0,Y.jsx)(ot,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsxs)(`button`,{onClick:le,className:Ca(`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,S&&`bg-primary text-primary-foreground`),title:`Connect nodes`,"aria-label":`Connect nodes`,"aria-pressed":S,children:[(0,Y.jsx)(Ee,{className:`h-3 w-3`}),` Connect`]}),(0,Y.jsxs)(`button`,{onClick:ue,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Auto layout`,"aria-label":`Auto layout`,children:[(0,Y.jsx)(te,{className:`h-3 w-3`}),` Layout`]}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsx)(`button`,{onClick:v.zoomIn,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Zoom in`,"aria-label":`Zoom in`,children:(0,Y.jsx)(Bt,{className:`h-3 w-3`})}),(0,Y.jsxs)(`span`,{className:`text-xs tabular-nums min-w-[3ch] text-center`,"aria-label":`Zoom level`,children:[Math.round(v.zoom*100),`%`]}),(0,Y.jsx)(`button`,{onClick:v.zoomOut,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Zoom out`,"aria-label":`Zoom out`,children:(0,Y.jsx)(Ft,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:v.resetZoom,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Reset zoom`,"aria-label":`Reset zoom`,children:(0,Y.jsx)(ie,{className:`h-3 w-3`})}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsxs)(`button`,{onClick:()=>re(`start-event`,`Start`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Start Event`,"aria-label":`Add Start Event`,children:[(0,Y.jsx)(_e,{className:`h-3 w-3 text-green-600`}),` Start`]}),(0,Y.jsxs)(`button`,{onClick:()=>re(`user-task`,`User Task`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add User Task`,"aria-label":`Add User Task`,children:[(0,Y.jsx)(gt,{className:`h-3 w-3 text-blue-600`}),` Task`]}),(0,Y.jsxs)(`button`,{onClick:()=>re(`exclusive-gateway`,`Decision`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Gateway`,"aria-label":`Add Gateway`,children:[(0,Y.jsx)(qe,{className:`h-3 w-3 text-yellow-600`}),` Gateway`]}),(0,Y.jsxs)(`button`,{onClick:()=>re(`end-event`,`End`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add End Event`,"aria-label":`Add End Event`,children:[(0,Y.jsx)(gt,{className:`h-3 w-3 text-red-600`}),` End`]}),(0,Y.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Y.jsx)(`button`,{onClick:()=>k(e=>!e),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:O?`Hide properties`:`Show properties`,"aria-label":O?`Hide property panel`:`Show property panel`,"aria-expanded":O,children:O?(0,Y.jsx)(kt,{className:`h-3 w-3`}):(0,Y.jsx)(Ct,{className:`h-3 w-3`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto bg-muted/10 p-4`,role:`region`,"aria-label":`Process canvas`,onWheel:v.handleWheel,onMouseDown:v.startPan,children:(0,Y.jsxs)(`div`,{className:`relative`,style:{...v.transformStyle,width:i.width,minHeight:i.height,backgroundImage:i.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:i.showGrid?`20px 20px`:void 0},onClick:ye,onDrop:fe,onDragOver:pe,children:[(0,Y.jsxs)(`svg`,{className:`absolute inset-0 pointer-events-none`,width:i.width,height:i.height,children:[(0,Y.jsx)(`defs`,{children:(0,Y.jsx)(`marker`,{id:`arrowhead`,markerWidth:`10`,markerHeight:`7`,refX:`10`,refY:`3.5`,orient:`auto`,children:(0,Y.jsx)(`polygon`,{points:`0 0, 10 3.5, 0 7`,fill:`hsl(var(--foreground))`})})}),p.map(e=>{let t=f.find(t=>t.id===e.source),n=f.find(t=>t.id===e.target);if(!t||!n)return null;t.position.x+wa/2;let r=t.position.y+Ta/2;n.position.x+wa/2;let i=n.position.y+Ta/2,a=t.position.x+wa,o=r,s=n.position.x,c=i;return(0,Y.jsxs)(`g`,{children:[(0,Y.jsx)(`path`,{d:`M ${a} ${o} Q ${(a+s)/2} ${o}, ${(a+s)/2} ${(o+c)/2} T ${s} ${c}`,fill:`none`,stroke:`hsl(var(--foreground) / 0.5)`,strokeWidth:`2`,markerEnd:`url(#arrowhead)`}),e.label&&(0,Y.jsx)(`text`,{x:(a+s)/2,y:(o+c)/2-8,textAnchor:`middle`,className:`text-[10px] fill-muted-foreground`,children:e.label})]},e.id)})]}),f.length===0&&(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full min-h-[200px] text-muted-foreground text-sm`,children:`No nodes in the process. Use the toolbar buttons to add start events, tasks, gateways, and end events.`}),f.map(e=>{let t=g.isSelected(e.id)||b===e.id,n=w===e.id,r=E===e.id,i=S||r;return(0,Y.jsxs)(`div`,{className:`absolute select-none`,style:{left:e.position.x,top:e.position.y},role:`group`,"aria-label":e.label,draggable:!s&&!S,onDragStart:t=>de(t,e.id),onMouseEnter:()=>D(e.id),onMouseLeave:()=>D(null),onClick:t=>{F(e.id)||(t.shiftKey?g.toggle(e.id,!0):(x(e.id),g.selectOne(e.id)))},children:[(0,Y.jsx)(`div`,{className:Ca(`flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow`,ge(e.type),t&&`ring-2 ring-primary shadow-md`,n&&`ring-2 ring-blue-400 shadow-lg`,S&&!n&&`cursor-crosshair`),children:(0,Y.jsx)(`span`,{className:Ca(`text-xs font-medium`,(e.type===`exclusive-gateway`||e.type===`parallel-gateway`||e.type===`inclusive-gateway`||e.type===`event-based-gateway`)&&`-rotate-45`),children:e.label})}),i&&!s&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{left:-6,top:Ta/2-6},title:`Input port`,onClick:t=>{t.stopPropagation(),F(e.id)}}),(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{right:-6,top:Ta/2-6},title:`Output port`,onClick:t=>{t.stopPropagation(),S?F(e.id):(C(!0),T(e.id))}}),(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:wa/2-6,top:-6},title:`Port`,onClick:t=>{t.stopPropagation(),F(e.id)}}),(0,Y.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:wa/2-6,bottom:-6},title:`Port`,onClick:t=>{t.stopPropagation(),F(e.id)}})]}),!s&&t&&!S&&(0,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ae(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":`Delete node`,children:(0,Y.jsx)(Xe,{className:`h-3 w-3`})})]},e.id)}),a&&f.length>0&&(0,Y.jsx)(pa,{items:ve,canvasWidth:i.width??1400,canvasHeight:i.height??800,position:`bottom-right`})]})}),O&&!s&&(0,Y.jsx)(`div`,{className:`w-64 border-l bg-background overflow-y-auto shrink-0`,role:`complementary`,"aria-label":`Property panel`,children:(0,Y.jsx)(ua,{title:me?`Properties: ${me.label}`:`Properties`,fields:he,onChange:I})})]})]})}function Oa(...e){return W(G(e))}var Q={untitledReport:`Untitled Report`,reportCanvas:`Report canvas`,properties:`Properties`,propertiesPanel:`Properties panel`,designerToolbar:`Report designer toolbar`,selectElementPrompt:`Select an element to edit its properties`,addElementsPrompt:`Add elements using the buttons above`,addText:`Add Text`,addField:`Add Field`,addImage:`Add Image`,addChart:`Add Chart`,addTable:`Add Table`,undo:`Undo`,undoShortcut:`Undo (Ctrl+Z)`,redo:`Redo`,redoShortcut:`Redo (Ctrl+Shift+Z)`,copy:`Copy`,copyShortcut:`Copy (Ctrl+C)`,paste:`Paste`,pasteShortcut:`Paste (Ctrl+V)`,deleteSelected:`Delete selected`,deleteElement:`Delete element`,deleteElementsTitle:`Delete elements`,deleteElementMessage:e=>`Are you sure you want to delete ${e} element${e>1?`s`:``}?`,collapsePanel:`Collapse panel`,expandPanel:`Expand panel`,collaborationConnected:`Connected`,sectionHeader:`Report Header`,sectionPageHeader:`Page Header`,sectionGroupHeader:`Group Header`,sectionDetail:`Detail`,sectionGroupFooter:`Group Footer`,sectionPageFooter:`Page Footer`,sectionFooter:`Report Footer`,elementText:`Text`,elementImage:`🖼 Image`,elementChart:`📊 Chart`,elementTable:`📋 Table`,propLabel:`Label`,propX:`X`,propY:`Y`,propWidth:`Width`,propHeight:`Height`,propText:`Text`,propField:`Field`,groupPosition:`Position`,groupSize:`Size`,groupContent:`Content`,groupGeneral:`General`},ka={A4:{width:595,height:842},A3:{width:842,height:1191},Letter:{width:612,height:792},Legal:{width:612,height:1008},Tabloid:{width:792,height:1224}},Aa=[{type:`header`,height:80,elements:[]},{type:`detail`,height:400,elements:[],repeat:!0},{type:`footer`,height:60,elements:[]}];function ja({reportName:e=Q.untitledReport,objectName:t,pageSize:n=`A4`,orientation:r=`portrait`,margins:i={top:40,right:40,bottom:40,left:40},sections:a=[],showToolbar:o=!0,showPropertyPanel:s=!0,readOnly:c=!1,onSectionsChange:l,className:u}){let d=na(a.length>0?a:Aa),f=d.current,p=(0,J.useCallback)(e=>{d.push(e),l?.(e)},[d,l]),m=ia(),h=(0,J.useMemo)(()=>{let e=Array.from(m.selectedIds);return e.length>0?e[0]:null},[m.selectedIds]),g=aa(),_=ra(),v=ha(),y=(0,J.useCallback)(e=>{v&&v.sendOperation({...e,userId:v.currentUserId??``})},[v]),[b,x]=(0,J.useState)(!0),S=(0,J.useRef)(null),C=(0,J.useRef)(null),w=ka[n],T=r===`landscape`?w.height:w.width,E=r===`landscape`?w.width:w.height,D=e=>{switch(e){case`header`:return Q.sectionHeader;case`page-header`:return Q.sectionPageHeader;case`group-header`:return Q.sectionGroupHeader;case`detail`:return Q.sectionDetail;case`group-footer`:return Q.sectionGroupFooter;case`page-footer`:return Q.sectionPageFooter;case`footer`:return Q.sectionFooter;default:return e}},O=(0,J.useMemo)(()=>h?f.flatMap(e=>e.elements).find(e=>e.id===h):null,[h,f]),k=(0,J.useCallback)((e,t)=>{if(c)return;let n={id:`elem-${Date.now()}`,type:t,position:{x:i.left,y:10,width:200,height:30},properties:{text:t===`text`?`New Text`:void 0,field:t===`field`?`field_name`:void 0}};p(f.map((t,r)=>r===e?{...t,elements:[...t.elements,n]}:t)),m.selectOne(n.id),y({type:`insert`,elementId:n.id,data:{element:n}})},[f,i.left,c,p,m,y]),A=(0,J.useCallback)(e=>{c||(p(f.map(t=>({...t,elements:t.elements.filter(t=>t.id!==e)}))),m.isSelected(e)&&m.clearSelection(),y({type:`delete`,elementId:e,data:{}}))},[f,c,p,m,y]),j=(0,J.useCallback)(async()=>{if(c||m.count===0||!await _.confirm(Q.deleteElementsTitle,Q.deleteElementMessage(m.count)))return;let e=m.selectedIds;p(f.map(t=>({...t,elements:t.elements.filter(t=>!e.has(t.id))}))),m.clearSelection(),e.forEach(e=>{y({type:`delete`,elementId:e,data:{}})})},[c,m,_,f,p,y]),ee=(0,J.useCallback)((e,t)=>{c||!h||(p(f.map(n=>({...n,elements:n.elements.map(n=>n.id===h?e===`x`?{...n,position:{...n.position,x:Number(t)}}:e===`y`?{...n,position:{...n.position,y:Number(t)}}:e===`width`?{...n,position:{...n.position,width:Number(t)}}:e===`height`?{...n,position:{...n.position,height:Number(t)}}:{...n,properties:{...n.properties,[e]:t}}:n)}))),y({type:`update`,elementId:h,data:{[e]:t}}))},[c,h,f,p,y]),M=(0,J.useCallback)(()=>{let e=m.selectedIds;if(e.size===0)return;let t=f.flatMap(e=>e.elements).filter(t=>e.has(t.id));g.copy(t)},[m,f,g]),N=(0,J.useCallback)(()=>{if(c)return;let e=g.paste();if(!e||e.length===0)return;let t=0,n=e.map(e=>({...e,id:`elem-${Date.now()}-${++t}-${Math.random().toString(36).slice(2,7)}`,position:{...e.position,x:e.position.x+20,y:e.position.y+20}})),r=f.findIndex(e=>e.type===`detail`),i=r>=0?r:0;p(f.map((e,t)=>t===i?{...e,elements:[...e.elements,...n]}:e)),m.selectMany(n.map(e=>e.id)),n.forEach(e=>{y({type:`insert`,elementId:e.id,data:{element:e}})})},[c,g,f,p,m,y]),te=(0,J.useCallback)((e,t,n)=>{c||(S.current={id:t.id,sectionIndex:n,startX:e.clientX,startY:e.clientY},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.id))},[c]),P=(0,J.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),ne=(0,J.useCallback)((e,t)=>{e.preventDefault();let n=S.current;if(!n||c)return;let r=e.clientX-n.startX,i=e.clientY-n.startY;if(n.sectionIndex===t)p(f.map((e,a)=>a===t?{...e,elements:e.elements.map(e=>e.id===n.id?{...e,position:{...e.position,x:Math.max(0,e.position.x+r),y:Math.max(0,(typeof e.position.y==`number`?e.position.y:0)+i)}}:e)}:e));else{let e=null,i=f.map((t,i)=>{if(i!==n.sectionIndex)return t;let a=t.elements.find(e=>e.id===n.id);return a&&(e={...a,position:{...a.position,x:Math.max(0,a.position.x+r),y:10}}),{...t,elements:t.elements.filter(e=>e.id!==n.id)}});e&&p(i.map((n,r)=>r===t?{...n,elements:[...n.elements,e]}:n))}y({type:`move`,elementId:n.id,data:{}}),S.current=null},[c,f,p,y]),re=(0,J.useMemo)(()=>{if(!O)return[];let e=[{name:`x`,label:Q.propX,type:`number`,value:O.position.x,group:Q.groupPosition},{name:`y`,label:Q.propY,type:`number`,value:O.position.y,group:Q.groupPosition},{name:`width`,label:Q.propWidth,type:`number`,value:O.position.width,group:Q.groupSize},{name:`height`,label:Q.propHeight,type:`number`,value:O.position.height,group:Q.groupSize}];return O.type===`text`&&e.push({name:`text`,label:Q.propText,type:`text`,value:O.properties.text??``,group:Q.groupContent}),O.type===`field`&&e.push({name:`field`,label:Q.propField,type:`text`,value:O.properties.field??``,group:Q.groupContent}),e},[O]);return(0,J.useEffect)(()=>{let e=C.current;if(!e)return;let t=e=>{let t=[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.target.tagName),n=e.ctrlKey||e.metaKey;if((e.key===`Delete`||e.key===`Backspace`)&&m.count>0&&!t){e.preventDefault(),j();return}if(e.key===`Escape`){m.clearSelection();return}if(!t){if(n&&e.key===`z`&&!e.shiftKey&&!c){e.preventDefault(),d.undo();return}if(n&&(e.key===`z`&&e.shiftKey||e.key===`y`)&&!c){e.preventDefault(),d.redo();return}if(n&&e.key===`c`){e.preventDefault(),M();return}if(n&&e.key===`v`&&!c){e.preventDefault(),N();return}if(n&&e.key===`a`){e.preventDefault();let t=f.flatMap(e=>e.elements).map(e=>e.id);m.selectMany(t);return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[m,j,c,d,M,N,f]),(0,Y.jsxs)(`div`,{ref:C,tabIndex:0,className:Oa(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Y.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[o&&(0,Y.jsxs)(`div`,{role:`toolbar`,"aria-label":Q.designerToolbar,className:`flex items-center gap-2 p-2 border-b bg-muted/20`,children:[(0,Y.jsx)(le,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`font-medium text-sm`,children:e}),t&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,t,`)`]}),!c&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,Y.jsx)(`button`,{className:Oa(`p-1.5 rounded hover:bg-accent`,!d.canUndo&&`opacity-40 pointer-events-none`),title:Q.undoShortcut,"aria-label":Q.undo,disabled:!d.canUndo,onClick:()=>d.undo(),children:(0,Y.jsx)(xe,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:Oa(`p-1.5 rounded hover:bg-accent`,!d.canRedo&&`opacity-40 pointer-events-none`),title:Q.redoShortcut,"aria-label":Q.redo,disabled:!d.canRedo,onClick:()=>d.redo(),children:(0,Y.jsx)(De,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{className:Oa(`p-1.5 rounded hover:bg-accent`,m.count===0&&`opacity-40 pointer-events-none`),title:Q.copyShortcut,"aria-label":Q.copy,disabled:m.count===0,onClick:M,children:(0,Y.jsx)(et,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{className:Oa(`p-1.5 rounded hover:bg-accent`,!g.hasContent&&`opacity-40 pointer-events-none`),title:Q.pasteShortcut,"aria-label":Q.paste,disabled:!g.hasContent,onClick:N,children:(0,Y.jsx)(ot,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Y.jsx)(`button`,{className:Oa(`p-1.5 rounded hover:bg-accent`,m.count===0&&`opacity-40 pointer-events-none`),title:Q.deleteSelected,"aria-label":Q.deleteSelected,disabled:m.count===0,onClick:j,children:(0,Y.jsx)(Xe,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`flex-1`}),v?.isConnected&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),Q.collaborationConnected,v.users.length>1&&` (${v.users.length})`]}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[n,` `,r]}),s&&(0,Y.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:b?Q.collapsePanel:Q.expandPanel,"aria-label":b?Q.collapsePanel:Q.expandPanel,onClick:()=>x(e=>!e),children:(0,Y.jsx)(kt,{className:Oa(`h-4 w-4`,!b&&`rotate-180`)})})]}),(0,Y.jsx)(`div`,{role:`region`,"aria-label":Q.reportCanvas,className:`flex-1 overflow-auto bg-muted/10 p-4 flex justify-center`,children:(0,Y.jsx)(`div`,{className:`bg-white shadow-lg border`,style:{width:T,minHeight:E},children:f.map((e,t)=>(0,Y.jsxs)(`div`,{className:`relative border-b border-dashed border-gray-300`,style:{minHeight:e.height},onDragOver:P,onDrop:e=>ne(e,t),children:[(0,Y.jsxs)(`div`,{className:`absolute left-0 top-0 px-2 py-0.5 bg-muted text-xs text-muted-foreground border-r border-b rounded-br`,children:[D(e.type),e.repeat&&` ↻`]}),!c&&(0,Y.jsxs)(`div`,{className:`absolute right-1 top-0 flex items-center gap-0.5`,children:[(0,Y.jsx)(`button`,{onClick:()=>k(t,`text`),className:`p-0.5 rounded hover:bg-accent`,title:Q.addText,"aria-label":Q.addText,children:(0,Y.jsx)(Oe,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>k(t,`field`),className:`p-0.5 rounded hover:bg-accent`,title:Q.addField,"aria-label":Q.addField,children:(0,Y.jsx)(Ke,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>k(t,`image`),className:`p-0.5 rounded hover:bg-accent`,title:Q.addImage,"aria-label":Q.addImage,children:(0,Y.jsx)(Qe,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>k(t,`chart`),className:`p-0.5 rounded hover:bg-accent`,title:Q.addChart,"aria-label":Q.addChart,children:(0,Y.jsx)(ge,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{onClick:()=>k(t,`table`),className:`p-0.5 rounded hover:bg-accent`,title:Q.addTable,"aria-label":Q.addTable,children:(0,Y.jsx)(Re,{className:`h-3 w-3`})})]}),(0,Y.jsxs)(`div`,{className:`relative`,style:{minHeight:e.height,paddingTop:24},children:[e.elements.length===0&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground text-center pt-4`,children:Q.addElementsPrompt}),e.elements.map(e=>{let n=m.isSelected(e.id);return(0,Y.jsxs)(`div`,{draggable:!c,onDragStart:n=>te(n,e,t),className:Oa(`absolute border rounded px-2 py-1 text-xs cursor-pointer`,n?`border-primary ring-1 ring-primary/30 bg-primary/5`:`border-dashed border-gray-400 hover:border-primary/50`),style:{left:e.position.x,top:(typeof e.position.y==`number`?e.position.y:0)+24,width:e.position.width,height:e.position.height},onClick:t=>m.toggle(e.id,t.shiftKey),children:[(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.type===`text`&&(e.properties.text??Q.elementText),e.type===`field`&&`{${e.properties.field??`field`}}`,e.type===`image`&&Q.elementImage,e.type===`chart`&&Q.elementChart,e.type===`table`&&Q.elementTable]}),!c&&n&&(0,Y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),A(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":Q.deleteElement,children:(0,Y.jsx)(Xe,{className:`h-2.5 w-2.5`})})]},e.id)})]})]},`${e.type}-${t}`))})})]}),s&&(0,Y.jsx)(`div`,{role:`region`,"aria-label":Q.propertiesPanel,className:Oa(`border-l bg-muted/30 flex flex-col transition-[width] duration-200`,b?`w-56`:`w-0 overflow-hidden`),children:b&&(h&&O?(0,Y.jsx)(ua,{title:`${Q.properties} – ${O.type}`,fields:re,onChange:ee}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:Q.properties}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground text-center py-4`,children:Q.selectElementPrompt})})]}))}),(0,Y.jsx)(ca,{isOpen:_.isOpen,title:_.title,message:_.message,onConfirm:_.onConfirm,onCancel:_.onCancel})]})}var Ma={"appDesigner.basicInfo":`Basic Info`,"appDesigner.objects":`Objects`,"appDesigner.navigation":`Navigation`,"appDesigner.branding":`Branding`,"appDesigner.stepBasicDesc":`Name, title, and layout`,"appDesigner.stepObjectsDesc":`Select business objects`,"appDesigner.stepNavigationDesc":`Build navigation tree`,"appDesigner.stepBrandingDesc":`Logo, colors, and favicon`,"appDesigner.appName":`App Name`,"appDesigner.appTitle":`Title`,"appDesigner.appDescription":`Description`,"appDesigner.appIcon":`Icon`,"appDesigner.template":`Template`,"appDesigner.layout":`Layout`,"appDesigner.layoutSidebar":`Sidebar`,"appDesigner.layoutHeader":`Header`,"appDesigner.layoutEmpty":`Empty`,"appDesigner.snakeCaseHint":`Must be snake_case (e.g. my_app)`,"appDesigner.searchObjects":`Search objects…`,"appDesigner.selectAll":`Select All`,"appDesigner.deselectAll":`Deselect All`,"appDesigner.noObjectsFound":`No objects found.`,"appDesigner.addGroup":`Add Group`,"appDesigner.addUrl":`Add URL`,"appDesigner.addSeparator":`Add Separator`,"appDesigner.noNavItemsHint":`No navigation items yet. Select objects in the previous step or add items manually.`,"appDesigner.separatorLabel":`— Separator —`,"appDesigner.newGroup":`New Group`,"appDesigner.newLink":`New Link`,"appDesigner.logoUrl":`Logo URL`,"appDesigner.primaryColor":`Primary Color`,"appDesigner.faviconUrl":`Favicon URL`,"appDesigner.preview":`Preview`,"common.cancel":`Cancel`,"common.back":`Back`,"common.next":`Next`,"common.close":`Close`,"appDesigner.complete":`Complete`,"appDesigner.saveDraft":`Save Draft`,"appDesigner.cancelConfirmTitle":`Discard changes?`,"appDesigner.cancelConfirmMessage":`You have unsaved changes. Are you sure you want to cancel?`,"appDesigner.confirmDiscard":`Discard`,"appDesigner.keepEditing":`Keep Editing`,"appDesigner.navNoItems":`No navigation items. Click buttons above to add items.`,"appDesigner.navNoPreviewItems":`No items`,"appDesigner.navLivePreview":`Live Preview`,"appDesigner.navCollapseGroup":`Collapse group`,"appDesigner.navExpandGroup":`Expand group`,"appDesigner.navAddChild":`Add child`,"appDesigner.navMoveUp":`Move up`,"appDesigner.navMoveDown":`Move down`,"appDesigner.navRemove":`Remove`,"appDesigner.navObjectPage":`Object Page`,"appDesigner.navDashboard":`Dashboard`,"appDesigner.navPage":`Page`,"appDesigner.navReport":`Report`,"appDesigner.navGroup":`Group`,"appDesigner.navUrl":`URL`,"appDesigner.navSeparator":`Separator`,"appDesigner.navTypeObject":`Object`,"appDesigner.navTypeDashboard":`Dashboard`,"appDesigner.navTypePage":`Page`,"appDesigner.navTypeReport":`Report`,"appDesigner.navTypeUrl":`URL`,"appDesigner.navTypeGroup":`Group`,"appDesigner.navTypeSeparator":`Separator`,"appDesigner.navTypeAction":`Action`,"appDesigner.navEditIcon":`Edit icon`,"appDesigner.navToggleVisible":`Toggle visibility`,"appDesigner.navHidden":`Hidden`,"appDesigner.navExportSchema":`Export JSON`,"appDesigner.navImportSchema":`Import JSON`,"appDesigner.navExportSuccess":`Navigation schema exported`,"appDesigner.navImportSuccess":`Navigation schema imported`,"appDesigner.navImportError":`Invalid navigation JSON`,"appDesigner.navIconPlaceholder":`Icon name (e.g. Users)`,"appDesigner.dashboardEditor":`Dashboard Editor`,"appDesigner.noWidgets":`No widgets. Click a button above to add one.`,"appDesigner.widgetLayoutSize":`Layout Size`,"appDesigner.widgetWidth":`Width`,"appDesigner.widgetHeight":`Height`,"appDesigner.dashboardPreview":`Dashboard Preview`,"appDesigner.noWidgetsPreview":`No widgets to preview`,"appDesigner.pageCanvasEditor":`Page Canvas Editor`,"appDesigner.emptyPage":`Empty page. Click a button above to add a component.`,"appDesigner.pagePreview":`Page Preview`,"appDesigner.noComponentsPreview":`No components to preview`,"appDesigner.modePage":`Page`,"appDesigner.modeDashboard":`Dashboard`,"appDesigner.undo":`Undo`,"appDesigner.redo":`Redo`,"appDesigner.brandingEditor":`Branding Editor`,"appDesigner.brandingExport":`Export JSON`,"appDesigner.brandingImport":`Import JSON`,"appDesigner.brandingPreview":`Preview`,"appDesigner.brandingSampleButton":`Sample Button`,"appDesigner.brandingSampleText":`This is how your brand theme will look.`,"appDesigner.colorPalette":`Color Palette`,"appDesigner.fontFamily":`Font Family`,"appDesigner.fontDefault":`Default (System)`,"appDesigner.modeLight":`Light`,"appDesigner.modeDark":`Dark`,"appDesigner.mobilePreview":`Mobile Preview`,"appDesigner.objectManager.title":`Object Manager`,"appDesigner.objectManager.addObject":`New Object`,"appDesigner.objectManager.searchPlaceholder":`Search objects…`,"appDesigner.objectManager.noObjects":`No objects found.`,"appDesigner.objectManager.objectName":`API Name`,"appDesigner.objectManager.objectLabel":`Label`,"appDesigner.objectManager.pluralLabel":`Plural Label`,"appDesigner.objectManager.icon":`Icon`,"appDesigner.objectManager.selectIcon":`Select icon…`,"appDesigner.objectManager.group":`Group`,"appDesigner.objectManager.noGroup":`No Group`,"appDesigner.objectManager.sortOrder":`Sort Order`,"appDesigner.objectManager.enabled":`Enabled`,"appDesigner.objectManager.relationships":`Relationships`,"appDesigner.objectManager.systemBadge":`System`,"appDesigner.objectManager.fieldCount":`{{count}} fields`,"appDesigner.objectManager.ungrouped":`Ungrouped`,"appDesigner.objectManager.deleteConfirmTitle":`Delete Object?`,"appDesigner.objectManager.deleteConfirmMessage":`This will permanently delete the object and all its fields. This action cannot be undone.`,"appDesigner.fieldDesigner.title":`Field Designer`,"appDesigner.fieldDesigner.addField":`New Field`,"appDesigner.fieldDesigner.searchPlaceholder":`Search fields…`,"appDesigner.fieldDesigner.allTypes":`All Types`,"appDesigner.fieldDesigner.noFields":`No fields found.`,"appDesigner.fieldDesigner.fieldName":`API Name`,"appDesigner.fieldDesigner.fieldLabel":`Label`,"appDesigner.fieldDesigner.fieldType":`Type`,"appDesigner.fieldDesigner.fieldGroup":`Group`,"appDesigner.fieldDesigner.description":`Description`,"appDesigner.fieldDesigner.required":`Required`,"appDesigner.fieldDesigner.unique":`Unique`,"appDesigner.fieldDesigner.readOnly":`Read Only`,"appDesigner.fieldDesigner.hidden":`Hidden`,"appDesigner.fieldDesigner.indexed":`Indexed`,"appDesigner.fieldDesigner.externalId":`External ID`,"appDesigner.fieldDesigner.trackHistory":`Track History`,"appDesigner.fieldDesigner.defaultValue":`Default Value`,"appDesigner.fieldDesigner.placeholder":`Placeholder`,"appDesigner.fieldDesigner.referenceTo":`Reference To`,"appDesigner.fieldDesigner.formula":`Formula`,"appDesigner.fieldDesigner.options":`Options`,"appDesigner.fieldDesigner.addOption":`Add Option`,"appDesigner.fieldDesigner.validationRules":`Validation Rules`,"appDesigner.fieldDesigner.addRule":`Add Rule`,"appDesigner.fieldDesigner.systemBadge":`System`,"appDesigner.fieldDesigner.ungrouped":`General`,"appDesigner.fieldDesigner.deleteConfirmTitle":`Delete Field?`,"appDesigner.fieldDesigner.deleteConfirmMessage":`This will permanently delete the field. Existing data in this field will be lost.`,"appDesigner.fieldDesigner.basicSection":`Basic`,"appDesigner.fieldDesigner.typeSpecificSection":`Type Settings`,"appDesigner.fieldDesigner.advancedSection":`Advanced`,"appDesigner.fieldDesigner.typeCategory.text":`Text`,"appDesigner.fieldDesigner.typeCategory.number":`Number`,"appDesigner.fieldDesigner.typeCategory.date":`Date & Time`,"appDesigner.fieldDesigner.typeCategory.choice":`Choice`,"appDesigner.fieldDesigner.typeCategory.relation":`Relation`,"appDesigner.fieldDesigner.typeCategory.advanced":`Advanced`,"common.edit":`Edit`};function Na(e){return(t,n)=>{let r=e[t]||t;if(n)for(let[e,t]of Object.entries(n))r=r.replace(`{{${e}}}`,String(t));return r}}function Pa(){try{let e=M();return e.t(`appDesigner.basicInfo`)===`appDesigner.basicInfo`?{t:Na(Ma)}:{t:e.t}}catch{return{t:Na(Ma)}}}function Fa(...e){return W(G(e))}var Ia={name:``,title:``,description:``,icon:``,template:``,layout:`sidebar`,objects:[],navigation:[],branding:{logo:``,primaryColor:`#3b82f6`,favicon:``}};function La(e){return e.filter(e=>e.selected).map(e=>({id:e.name,type:`object`,label:e.label,icon:e.icon,objectName:e.name}))}var Ra=0;function za(e){return Ra+=1,`${e}_${Date.now()}_${Ra}`}function Ba({steps:e,currentIndex:t,onStepClick:n}){return(0,Y.jsx)(`nav`,{className:`flex items-center justify-center gap-0 px-4 py-6`,children:e.map((e,r)=>{let i=r<t,a=r===t;return(0,Y.jsxs)(J.Fragment,{children:[r>0&&(0,Y.jsx)(`div`,{className:Fa(`h-0.5 w-12 sm:w-20`,i?`bg-blue-500`:`bg-gray-200`)}),(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`wizard-step-${e.id}`,onClick:()=>n(r),className:Fa(`flex flex-col items-center gap-1 outline-none focus-visible:ring-2 focus-visible:ring-blue-400 rounded-lg px-2 py-1`,a&&`cursor-default`,!a&&`cursor-pointer`),children:[(0,Y.jsx)(`div`,{className:Fa(`flex h-8 w-8 items-center justify-center rounded-full text-sm font-semibold transition-colors`,i&&`bg-blue-500 text-white`,a&&`bg-blue-600 text-white ring-2 ring-blue-300`,!i&&!a&&`bg-gray-200 text-gray-500`),children:i?(0,Y.jsx)(Me,{className:`h-4 w-4`}):r+1}),(0,Y.jsx)(`span`,{className:Fa(`text-xs font-medium`,a?`text-blue-600`:`text-gray-500`),children:e.label})]})]},e.id)})})}function Va({draft:e,templates:t,readOnly:n,onChange:r,t:i}){let a=e.name.length>0&&!O(e.name);return(0,Y.jsxs)(`div`,{"data-testid":`wizard-step-basic-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`label`,{htmlFor:`app-name`,className:`block text-sm font-medium text-gray-700`,children:[i(`appDesigner.appName`),` `,(0,Y.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,Y.jsx)(`input`,{id:`app-name`,"data-testid":`app-name-input`,type:`text`,value:e.name,onChange:e=>r({name:e.target.value}),placeholder:`my_app`,disabled:n,className:Fa(`block w-full rounded-md border px-3 py-2 text-sm shadow-sm outline-none transition-colors`,`focus:border-blue-500 focus:ring-1 focus:ring-blue-500`,`disabled:cursor-not-allowed disabled:bg-gray-50`,a?`border-red-400`:`border-gray-300`)}),a&&(0,Y.jsx)(`p`,{className:`text-xs text-red-500`,children:i(`appDesigner.snakeCaseHint`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`label`,{htmlFor:`app-title`,className:`block text-sm font-medium text-gray-700`,children:[i(`appDesigner.appTitle`),` `,(0,Y.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,Y.jsx)(`input`,{id:`app-title`,"data-testid":`app-title-input`,type:`text`,value:e.title,onChange:e=>r({title:e.target.value}),placeholder:`My Application`,disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`app-description`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.appDescription`)}),(0,Y.jsx)(`textarea`,{id:`app-description`,"data-testid":`app-description-input`,value:e.description??``,onChange:e=>r({description:e.target.value}),rows:3,disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50 resize-none`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`app-icon`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.appIcon`)}),(0,Y.jsx)(`input`,{id:`app-icon`,type:`text`,value:e.icon??``,onChange:e=>r({icon:e.target.value}),placeholder:`LayoutDashboard`,disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]}),t.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`app-template`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.template`)}),(0,Y.jsxs)(`select`,{id:`app-template`,value:e.template??``,onChange:e=>r({template:e.target.value}),disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`,children:[(0,Y.jsx)(`option`,{value:``,children:`None`}),t.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]}),(0,Y.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Y.jsx)(`legend`,{className:`text-sm font-medium text-gray-700`,children:i(`appDesigner.layout`)}),(0,Y.jsx)(`div`,{className:`flex gap-3`,children:[{value:`sidebar`,labelKey:`appDesigner.layoutSidebar`,Icon:ht},{value:`header`,labelKey:`appDesigner.layoutHeader`,Icon:te},{value:`empty`,labelKey:`appDesigner.layoutEmpty`,Icon:ze}].map(({value:t,labelKey:a,Icon:o})=>(0,Y.jsxs)(`label`,{"data-testid":`app-layout-${t}`,className:Fa(`flex flex-1 cursor-pointer flex-col items-center gap-1.5 rounded-lg border-2 p-3 transition-colors`,e.layout===t?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`,n&&`pointer-events-none opacity-60`),children:[(0,Y.jsx)(o,{className:`h-5 w-5 text-gray-600`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium text-gray-700`,children:i(a)}),(0,Y.jsx)(`input`,{type:`radio`,name:`layout`,value:t,checked:e.layout===t,onChange:()=>r({layout:t}),disabled:n,className:`sr-only`})]},t))})]})]})}function Ha({objects:e,readOnly:t,onToggle:n,onToggleAll:r,search:i,onSearchChange:a,t:o}){let s=(0,J.useMemo)(()=>{if(!i)return e;let t=i.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.label.toLowerCase().includes(t))},[e,i]),c=e.length>0&&e.every(e=>e.selected);return e.every(e=>!e.selected),(0,Y.jsxs)(`div`,{"data-testid":`wizard-step-objects-content`,className:`mx-auto max-w-2xl space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(He,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.jsx)(`input`,{"data-testid":`object-search`,type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:o(`appDesigner.searchObjects`),className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500`})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>r(!c),disabled:t,className:`rounded-md border border-gray-300 px-3 py-2 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:o(c?`appDesigner.deselectAll`:`appDesigner.selectAll`)})]}),s.length===0?(0,Y.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:o(`appDesigner.noObjectsFound`)}):(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:s.map(e=>(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`object-card-${e.name}`,disabled:t,onClick:()=>n(e.name),className:Fa(`flex flex-col items-start gap-1 rounded-lg border-2 p-3 text-left transition-colors`,e.selected?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`,t&&`pointer-events-none opacity-60`),children:[(0,Y.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.label}),(0,Y.jsx)(`div`,{className:Fa(`flex h-5 w-5 items-center justify-center rounded border transition-colors`,e.selected?`border-blue-500 bg-blue-500 text-white`:`border-gray-300`),children:e.selected&&(0,Y.jsx)(Me,{className:`h-3 w-3`})})]}),(0,Y.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.name}),e.icon&&(0,Y.jsx)(`span`,{className:`text-xs text-gray-400`,children:e.icon})]},e.name))})]})}var Ua={object:`bg-green-100 text-green-700`,group:`bg-purple-100 text-purple-700`,url:`bg-sky-100 text-sky-700`,separator:`bg-gray-100 text-gray-600`,dashboard:`bg-amber-100 text-amber-700`,page:`bg-teal-100 text-teal-700`,report:`bg-rose-100 text-rose-700`,action:`bg-orange-100 text-orange-700`};function Wa({items:e,readOnly:t,onAdd:n,onRemove:r,onReorder:i,t:a}){return(0,Y.jsxs)(`div`,{"data-testid":`wizard-step-navigation-content`,className:`mx-auto max-w-lg space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`add-group-btn`,onClick:()=>n(`group`),disabled:t,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Y.jsx)(it,{className:`h-3.5 w-3.5`}),a(`appDesigner.addGroup`)]}),(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`add-url-btn`,onClick:()=>n(`url`),disabled:t,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Y.jsx)(Ee,{className:`h-3.5 w-3.5`}),a(`appDesigner.addUrl`)]}),(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`add-separator-btn`,onClick:()=>n(`separator`),disabled:t,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Y.jsx)(Rt,{className:`h-3.5 w-3.5`}),a(`appDesigner.addSeparator`)]})]}),e.length===0?(0,Y.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:a(`appDesigner.noNavItemsHint`)}):(0,Y.jsx)(`ul`,{className:`space-y-1.5`,children:e.map((n,o)=>(0,Y.jsxs)(`li`,{"data-testid":`nav-item-${n.id}`,className:`flex items-center gap-2 rounded-md border border-gray-200 bg-white px-3 py-2`,children:[n.icon&&(0,Y.jsx)(`span`,{className:`text-xs text-gray-400`,children:n.icon}),(0,Y.jsx)(`span`,{className:`flex-1 truncate text-sm text-gray-800`,children:n.type===`separator`?a(`appDesigner.separatorLabel`):D(n.label)}),(0,Y.jsx)(`span`,{className:Fa(`rounded-full px-2 py-0.5 text-[10px] font-medium`,Ua[n.type]??`bg-gray-100 text-gray-600`),children:n.type}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>i(n.id,`up`),disabled:t||o===0,className:`rounded p-0.5 text-gray-400 transition-colors hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move up`,children:(0,Y.jsx)(F,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>i(n.id,`down`),disabled:t||o===e.length-1,className:`rounded p-0.5 text-gray-400 transition-colors hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move down`,children:(0,Y.jsx)(de,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>r(n.id),disabled:t,className:`rounded p-0.5 text-gray-400 transition-colors hover:text-red-500 disabled:opacity-30`,"aria-label":`Remove`,children:(0,Y.jsx)(Xe,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function Ga({branding:e,title:t,readOnly:n,onChange:r,t:i}){return(0,Y.jsxs)(`div`,{"data-testid":`wizard-step-branding-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`branding-logo`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.logoUrl`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Qe,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.jsx)(`input`,{id:`branding-logo`,"data-testid":`branding-logo-input`,type:`text`,value:e.logo??``,onChange:e=>r({logo:e.target.value}),placeholder:`https://example.com/logo.svg`,disabled:n,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`branding-color`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.primaryColor`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(ct,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.jsx)(`input`,{id:`branding-color`,"data-testid":`branding-color-input`,type:`text`,value:e.primaryColor??`#3b82f6`,onChange:e=>r({primaryColor:e.target.value}),placeholder:`#3b82f6`,disabled:n,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`branding-favicon`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.faviconUrl`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Dt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.jsx)(`input`,{id:`branding-favicon`,"data-testid":`branding-favicon-input`,type:`text`,value:e.favicon??``,onChange:e=>r({favicon:e.target.value}),placeholder:`https://example.com/favicon.ico`,disabled:n,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`span`,{className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.preview`)}),(0,Y.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.logo?(0,Y.jsx)(`img`,{src:e.logo,alt:`App logo`,className:`h-8 w-8 rounded object-contain`}):(0,Y.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-gray-100 text-xs text-gray-400`,children:`Logo`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-gray-800`,children:t||i(`appDesigner.appTitle`)})]}),(0,Y.jsxs)(`div`,{className:`mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:e.primaryColor||`#3b82f6`}}),(0,Y.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.primaryColor||`#3b82f6`})]}),e.favicon&&(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,Y.jsx)(`img`,{src:e.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,Y.jsx)(`span`,{className:`text-xs text-gray-500`,children:`Favicon`})]})]})]})]})}function Ka({availableObjects:e=[],templates:t=[],initialDraft:n,onComplete:r,onCancel:i,onSaveDraft:a,readOnly:o=!1,className:s}){let{t:c}=Pa(),l=ra(),[u,d]=(0,J.useState)(0),[f,p]=(0,J.useState)(``),[m,h]=(0,J.useState)(()=>({...Ia,objects:e.map(e=>({...e})),...n})),g=(0,J.useMemo)(()=>[{id:`basic`,label:c(`appDesigner.basicInfo`),description:c(`appDesigner.stepBasicDesc`),icon:`Settings`},{id:`objects`,label:c(`appDesigner.objects`),description:c(`appDesigner.stepObjectsDesc`),icon:`Database`},{id:`navigation`,label:c(`appDesigner.navigation`),description:c(`appDesigner.stepNavigationDesc`),icon:`Menu`},{id:`branding`,label:c(`appDesigner.branding`),description:c(`appDesigner.stepBrandingDesc`),icon:`Palette`}],[c]),_=u===0,v=u===g.length-1,y=(0,J.useMemo)(()=>m.name.length>0&&O(m.name)&&m.title.trim().length>0,[m.name,m.title]),b=(0,J.useMemo)(()=>u===0?y:!0,[u,y]),x=(0,J.useCallback)(e=>{h(t=>({...t,...e}))},[]),S=(0,J.useCallback)(e=>{h(t=>({...t,branding:{...t.branding,...e}}))},[]),C=(0,J.useCallback)(e=>{h(t=>({...t,objects:t.objects.map(t=>t.name===e?{...t,selected:!t.selected}:t)}))},[]),w=(0,J.useCallback)(e=>{h(t=>({...t,objects:t.objects.map(t=>({...t,selected:e}))}))},[]),T=(0,J.useCallback)(e=>{let t={id:za(e),type:e,label:e===`separator`?``:e===`group`?`New Group`:`New Link`,...e===`group`?{children:[]}:{},...e===`url`?{url:``}:{}};h(e=>({...e,navigation:[...e.navigation,t]}))},[]),E=(0,J.useCallback)(e=>{h(t=>({...t,navigation:t.navigation.filter(t=>t.id!==e)}))},[]),D=(0,J.useCallback)((e,t)=>{h(n=>{let r=[...n.navigation],i=r.findIndex(t=>t.id===e);if(i<0)return n;let a=t===`up`?i-1:i+1;return a<0||a>=r.length?n:([r[i],r[a]]=[r[a],r[i]],{...n,navigation:r})})},[]),k=(0,J.useCallback)(()=>{v||(u===1&&h(e=>({...e,navigation:La(e.objects)})),d(e=>e+1))},[u,v]),A=(0,J.useCallback)(()=>{_||d(e=>e-1)},[_]),j=(0,J.useCallback)(()=>{r?.(m)},[m,r]),ee=(0,J.useCallback)(async()=>{(m.name.length>0||m.title.length>0)&&i?await l.confirm(c(`appDesigner.cancelConfirmTitle`),c(`appDesigner.cancelConfirmMessage`))&&i():i?.()},[m.name,m.title,i,l,c]),M=(0,J.useCallback)(()=>{a?.(m)},[m,a]),N=(0,J.useCallback)(e=>{e<=u?d(e):e===u+1&&b&&(u===1&&e===2&&h(e=>({...e,navigation:La(e.objects)})),d(e))},[u,b]);return(0,Y.jsxs)(`div`,{className:Fa(`flex h-full flex-col rounded-xl border border-gray-200 bg-white shadow-sm`,s),children:[l.isOpen&&(0,Y.jsx)(`div`,{"data-testid":`cancel-confirm-dialog`,className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,role:`dialog`,"aria-modal":`true`,children:(0,Y.jsxs)(`div`,{className:`mx-4 w-full max-w-sm rounded-lg bg-white p-6 shadow-xl`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-gray-900`,children:l.title}),(0,Y.jsx)(`button`,{type:`button`,onClick:l.onCancel,className:`rounded p-1 text-gray-400 hover:text-gray-600`,"aria-label":c(`common.close`),children:(0,Y.jsx)(Ue,{className:`h-4 w-4`})})]}),(0,Y.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:l.message}),(0,Y.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,"data-testid":`cancel-confirm-keep`,onClick:l.onCancel,className:`rounded-md border border-gray-300 px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50`,children:c(`appDesigner.keepEditing`)}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`cancel-confirm-discard`,onClick:l.onConfirm,className:`rounded-md bg-red-600 px-3 py-1.5 text-sm font-medium text-white transition-colors hover:bg-red-700`,children:c(`appDesigner.confirmDiscard`)})]})]})}),(0,Y.jsx)(`div`,{className:`border-b border-gray-100`,children:(0,Y.jsx)(Ba,{steps:g,currentIndex:u,onStepClick:N})}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[u===0&&(0,Y.jsx)(Va,{draft:m,templates:t,readOnly:o,onChange:x,t:c}),u===1&&(0,Y.jsx)(Ha,{objects:m.objects,readOnly:o,onToggle:C,onToggleAll:w,search:f,onSearchChange:p,t:c}),u===2&&(0,Y.jsx)(Wa,{items:m.navigation,readOnly:o,onAdd:T,onRemove:E,onReorder:D,t:c}),u===3&&(0,Y.jsx)(Ga,{branding:m.branding,title:m.title,readOnly:o,onChange:S,t:c})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-100 px-6 py-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,"data-testid":`wizard-cancel`,onClick:ee,disabled:o,className:`rounded-md px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50`,children:c(`common.cancel`)}),a&&(0,Y.jsx)(`button`,{type:`button`,"data-testid":`wizard-save-draft`,onClick:M,disabled:o,className:`rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:c(`appDesigner.saveDraft`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!_&&(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`wizard-back`,onClick:A,disabled:o,className:`inline-flex items-center gap-1 rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Y.jsx)(me,{className:`h-4 w-4`}),c(`common.back`)]}),v?(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`wizard-complete`,onClick:j,disabled:o||!b,className:`inline-flex items-center gap-1 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Y.jsx)(Me,{className:`h-4 w-4`}),c(`appDesigner.complete`)]}):(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`wizard-next`,onClick:k,disabled:o||!b,className:`inline-flex items-center gap-1 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50`,children:[c(`common.next`),(0,Y.jsx)(Ge,{className:`h-4 w-4`})]})]})]})]})}function qa(...e){return W(G(e))}var Ja=0;function Ya(e){return Ja+=1,`${e}_${Date.now()}_${Ja}`}var Xa={object:{labelKey:`appDesigner.navTypeObject`,color:`bg-green-100 text-green-700`,Icon:Ze},dashboard:{labelKey:`appDesigner.navTypeDashboard`,color:`bg-amber-100 text-amber-700`,Icon:ve},page:{labelKey:`appDesigner.navTypePage`,color:`bg-teal-100 text-teal-700`,Icon:le},report:{labelKey:`appDesigner.navTypeReport`,color:`bg-rose-100 text-rose-700`,Icon:ge},url:{labelKey:`appDesigner.navTypeUrl`,color:`bg-sky-100 text-sky-700`,Icon:Ee},group:{labelKey:`appDesigner.navTypeGroup`,color:`bg-purple-100 text-purple-700`,Icon:it},separator:{labelKey:`appDesigner.navTypeSeparator`,color:`bg-gray-100 text-gray-600`,Icon:Rt},action:{labelKey:`appDesigner.navTypeAction`,color:`bg-orange-100 text-orange-700`,Icon:St}},Za=[{type:`object`,labelKey:`appDesigner.navObjectPage`},{type:`dashboard`,labelKey:`appDesigner.navDashboard`},{type:`page`,labelKey:`appDesigner.navPage`},{type:`report`,labelKey:`appDesigner.navReport`},{type:`group`,labelKey:`appDesigner.navGroup`},{type:`url`,labelKey:`appDesigner.navUrl`},{type:`separator`,labelKey:`appDesigner.navSeparator`}];function Qa({item:e,depth:t,index:n,total:r,readOnly:i,onRemove:a,onMoveUp:o,onMoveDown:s,onToggleExpand:c,onUpdateLabel:l,onUpdateIcon:u,onToggleVisible:d,onAddChild:f,expandedIds:p,t:m}){let[h,g]=(0,J.useState)(!1),[_,v]=(0,J.useState)(D(e.label)??``),[y,b]=(0,J.useState)(!1),[x,S]=(0,J.useState)(e.icon||``),C=Xa[e.type];e.type===`group`&&e.children&&e.children.length;let w=p.has(e.id),T=e.visible===!1,E=()=>{_.trim()?l(e.id,_.trim()):v(D(e.label)??``),g(!1)},O=()=>{u(e.id,x.trim()),b(!1)};return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`li`,{"data-testid":`nav-designer-item-${e.id}`,className:qa(`flex items-center gap-2 rounded-md border border-gray-200 bg-white px-2 py-1.5 transition-colors hover:bg-gray-50`,T&&`opacity-50`),style:{marginLeft:t*20},children:[(0,Y.jsx)(_t,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-gray-300`}),e.type===`group`?(0,Y.jsx)(`button`,{type:`button`,onClick:()=>c(e.id),className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,"aria-label":m(w?`appDesigner.navCollapseGroup`:`appDesigner.navExpandGroup`),children:w?(0,Y.jsx)(de,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Ge,{className:`h-3.5 w-3.5`})}):(0,Y.jsx)(`span`,{className:`w-5`}),y&&!i?(0,Y.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),onBlur:O,onKeyDown:t=>{t.key===`Enter`&&O(),t.key===`Escape`&&(S(e.icon||``),b(!1))},autoFocus:!0,placeholder:m(`appDesigner.navIconPlaceholder`),"data-testid":`nav-designer-icon-input-${e.id}`,className:`w-24 rounded border border-blue-300 px-1 py-0.5 text-xs outline-none focus:ring-1 focus:ring-blue-400`}):(0,Y.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,Y.jsx)(C.Icon,{className:`h-3.5 w-3.5 shrink-0 text-gray-500`}),!i&&e.type!==`separator`&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{S(e.icon||``),b(!0)},className:`rounded p-0.5 text-gray-300 hover:text-blue-500`,"aria-label":m(`appDesigner.navEditIcon`),"data-testid":`nav-designer-edit-icon-${e.id}`,children:(0,Y.jsx)($e,{className:`h-2.5 w-2.5`})})]}),e.type===`separator`?(0,Y.jsx)(`span`,{className:`flex-1 text-xs italic text-gray-400`,children:m(`appDesigner.separatorLabel`)}):h&&!i?(0,Y.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),onBlur:E,onKeyDown:t=>{t.key===`Enter`&&E(),t.key===`Escape`&&(v(D(e.label)??``),g(!1))},autoFocus:!0,className:`flex-1 rounded border border-blue-300 px-1.5 py-0.5 text-sm outline-none focus:ring-1 focus:ring-blue-400`}):(0,Y.jsx)(`span`,{className:qa(`flex-1 truncate text-sm text-gray-800`,!i&&`cursor-text`),onDoubleClick:()=>{!i&&e.type!==`separator`&&(v(D(e.label)??``),g(!0))},children:D(e.label)}),(0,Y.jsx)(`span`,{className:qa(`rounded-full px-2 py-0.5 text-[10px] font-medium`,C.color),children:m(C.labelKey)}),T&&(0,Y.jsx)(`span`,{className:`rounded-full bg-gray-200 px-1.5 py-0.5 text-[10px] font-medium text-gray-500`,"data-testid":`nav-designer-hidden-badge-${e.id}`,children:m(`appDesigner.navHidden`)}),!i&&e.type!==`separator`&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>d(e.id),className:`rounded p-0.5 text-gray-400 hover:text-gray-700`,"aria-label":m(`appDesigner.navToggleVisible`),"data-testid":`nav-designer-toggle-visible-${e.id}`,children:T?(0,Y.jsx)(I,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Pe,{className:`h-3.5 w-3.5`})}),e.type===`group`&&!i&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>f(e.id,`page`),className:`rounded p-0.5 text-gray-400 hover:text-blue-500`,"aria-label":m(`appDesigner.navAddChild`),"data-testid":`nav-designer-add-child-${e.id}`,children:(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(e.id),disabled:i||n===0,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":m(`appDesigner.navMoveUp`),children:(0,Y.jsx)(F,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>s(e.id),disabled:i||n===r-1,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":m(`appDesigner.navMoveDown`),children:(0,Y.jsx)(de,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(e.id),disabled:i,className:`rounded p-0.5 text-gray-400 hover:text-red-500 disabled:opacity-30`,"aria-label":m(`appDesigner.navRemove`),"data-testid":`nav-designer-remove-${e.id}`,children:(0,Y.jsx)(Xe,{className:`h-3.5 w-3.5`})})]}),e.type===`group`&&w&&e.children&&(0,Y.jsx)(Y.Fragment,{children:e.children.map((n,r)=>(0,Y.jsx)(Qa,{item:n,depth:t+1,index:r,total:e.children.length,readOnly:i,onRemove:a,onMoveUp:o,onMoveDown:s,onToggleExpand:c,onUpdateLabel:l,onUpdateIcon:u,onToggleVisible:d,onAddChild:f,expandedIds:p,t:m},n.id))})]})}function $a({items:e,t}){return(0,Y.jsxs)(`div`,{"data-testid":`nav-designer-preview`,className:`w-56 shrink-0 rounded-lg border border-gray-200 bg-gray-50 p-3`,children:[(0,Y.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase text-gray-500`,children:t(`appDesigner.navLivePreview`)}),e.length===0?(0,Y.jsx)(`p`,{className:`text-xs text-gray-400`,children:t(`appDesigner.navNoPreviewItems`)}):(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:e.map(e=>(0,Y.jsx)(eo,{item:e,depth:0},e.id))})]})}function eo({item:e,depth:t}){let n=Xa[e.type];return e.type===`separator`?(0,Y.jsx)(`li`,{className:`my-1 border-t border-gray-200`,style:{marginLeft:t*12}}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`li`,{className:`flex items-center gap-1.5 rounded px-2 py-1 text-xs text-gray-700 hover:bg-gray-100`,style:{marginLeft:t*12},children:[(0,Y.jsx)(n.Icon,{className:`h-3 w-3 text-gray-400`}),(0,Y.jsx)(`span`,{className:`truncate`,children:D(e.label)})]}),e.type===`group`&&e.children?.map(e=>(0,Y.jsx)(eo,{item:e,depth:t+1},e.id))]})}function to({items:e,onChange:t,readOnly:n=!1,showPreview:r=!0,className:i,onExport:a,onImport:o}){let{t:s}=Pa(),c=(0,J.useRef)(null),[l,u]=(0,J.useState)(()=>new Set(e.filter(e=>e.type===`group`).map(e=>e.id))),d=(0,J.useCallback)(n=>{function r(e){return e.filter(e=>e.id!==n).map(e=>e.children?{...e,children:r(e.children)}:e)}t(r(e))},[e,t]),f=(0,J.useCallback)((n,r)=>{function i(e){let t=e.findIndex(e=>e.id===n);if(t>=0){let n=r===`up`?t-1:t+1;if(n>=0&&n<e.length){let r=[...e];return[r[t],r[n]]=[r[n],r[t]],r}return e}return e.map(e=>e.children?{...e,children:i(e.children)}:e)}t(i(e))},[e,t]),p=(0,J.useCallback)((n,r)=>{function i(e){return e.map(e=>e.id===n?{...e,label:r}:e.children?{...e,children:i(e.children)}:e)}t(i(e))},[e,t]),m=(0,J.useCallback)((n,r)=>{function i(e){return e.map(e=>e.id===n?{...e,icon:r||void 0}:e.children?{...e,children:i(e.children)}:e)}t(i(e))},[e,t]),h=(0,J.useCallback)(n=>{function r(e){return e.map(e=>e.id===n?{...e,visible:e.visible===!1}:e.children?{...e,children:r(e.children)}:e)}t(r(e))},[e,t]),g=(0,J.useCallback)((n,r)=>{let i={id:Ya(r),type:r,label:r===`separator`?``:`New ${s(Xa[r].labelKey)}`,...r===`group`?{children:[]}:{},...r===`url`?{url:``}:{}};function a(e){return e.map(e=>e.id===n&&e.type===`group`?{...e,children:[...e.children||[],i]}:e.children?{...e,children:a(e.children)}:e)}t(a(e)),u(e=>new Set(e).add(n))},[e,t]),_=(0,J.useCallback)(n=>{let r={id:Ya(n),type:n,label:n===`separator`?``:`New ${s(Xa[n].labelKey)}`,...n===`group`?{children:[]}:{},...n===`url`?{url:``}:{}};t([...e,r])},[e,t,s]),v=(0,J.useCallback)(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),y=(0,J.useCallback)(()=>{if(a)a(e);else{let t=JSON.stringify(e,null,2),n=new Blob([t],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`navigation-schema.json`,i.click(),URL.revokeObjectURL(r)}},[e,a]),b=(0,J.useCallback)(e=>{let n=e.target.files?.[0];if(!n)return;let r=new FileReader;r.onload=e=>{try{let n=JSON.parse(e.target?.result);Array.isArray(n)&&(o?o(n):t(n))}catch{}},r.readAsText(n),c.current&&(c.current.value=``)},[t,o]);return(0,Y.jsxs)(`div`,{"data-testid":`navigation-designer`,className:qa(`flex flex-col gap-4 sm:flex-row`,i),children:[(0,Y.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[Za.map(({type:e,labelKey:t})=>{let{Icon:r,color:i}=Xa[e];return(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-add-${e}`,onClick:()=>_(e),disabled:n,className:qa(`inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`),children:[(0,Y.jsx)(Ke,{className:`h-3 w-3`}),s(t)]},e)}),(0,Y.jsx)(`span`,{className:`mx-1 hidden h-4 w-px bg-gray-200 sm:block`}),(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-export`,onClick:y,className:`inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50`,children:[(0,Y.jsx)(ce,{className:`h-3 w-3`}),s(`appDesigner.navExportSchema`)]}),(0,Y.jsxs)(`label`,{"data-testid":`nav-designer-import`,className:qa(`inline-flex cursor-pointer items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50`,n&&`cursor-not-allowed opacity-50`),children:[(0,Y.jsx)(Fe,{className:`h-3 w-3`}),s(`appDesigner.navImportSchema`),(0,Y.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,className:`hidden`,onChange:b,disabled:n,"data-testid":`nav-designer-import-input`})]})]}),e.length===0?(0,Y.jsx)(`div`,{className:`py-8 text-center text-sm text-gray-400`,children:s(`appDesigner.navNoItems`)}):(0,Y.jsx)(`ul`,{className:`space-y-1`,"data-testid":`nav-designer-tree`,children:e.map((t,r)=>(0,Y.jsx)(Qa,{item:t,depth:0,index:r,total:e.length,readOnly:n,onRemove:d,onMoveUp:e=>f(e,`up`),onMoveDown:e=>f(e,`down`),onToggleExpand:v,onUpdateLabel:p,onUpdateIcon:m,onToggleVisible:h,onAddChild:g,expandedIds:l,t:s},t.id))})]}),r&&(0,Y.jsx)($a,{items:e,t:s})]})}function no(...e){return W(G(e))}var ro=[{type:`metric`,label:`KPI Metric`,Icon:Ut},{type:`bar`,label:`Bar Chart`,Icon:ge},{type:`line`,label:`Line Chart`,Icon:Ie},{type:`pie`,label:`Pie Chart`,Icon:oe},{type:`table`,label:`Table`,Icon:Re},{type:`grid`,label:`Grid`,Icon:Ht}],io=0;function ao(){return io+=1,`widget_${Date.now()}_${io}`}function oo({widget:e,index:t,total:n,selected:r,readOnly:i,onSelect:a,onRemove:o,onMoveUp:s,onMoveDown:c}){let l=e.type||`metric`,u=ro.find(e=>e.type===l)||ro[0];return(0,Y.jsxs)(`div`,{"data-testid":`dashboard-widget-${e.id}`,onClick:a,className:no(`group cursor-pointer rounded-lg border-2 p-3 transition-colors`,r?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(_t,{className:`h-4 w-4 text-gray-300`}),(0,Y.jsx)(u.Icon,{className:`h-4 w-4 text-gray-500`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.title||`Widget ${t+1}`})]}),!i&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:t===0,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move up`,children:(0,Y.jsx)(F,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:t===n-1,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move down`,children:(0,Y.jsx)(de,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},className:`rounded p-0.5 text-gray-400 hover:text-red-500`,"aria-label":`Remove widget`,"data-testid":`dashboard-widget-remove-${e.id}`,children:(0,Y.jsx)(Xe,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`rounded-full bg-gray-100 px-2 py-0.5 text-[10px] font-medium text-gray-600`,children:u.label}),e.object&&(0,Y.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:e.object})]})]})}function so({widget:e,readOnly:t,onChange:n,onClose:r}){let{t:i}=Pa();return(0,Y.jsxs)(`div`,{"data-testid":`widget-property-panel`,className:`shrink-0 space-y-4 rounded-lg border border-gray-200 bg-white p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-semibold text-gray-800`,children:i(`appDesigner.widgetProperties`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:r,className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,"aria-label":`Close`,children:(0,Y.jsx)(Ue,{className:`h-4 w-4`})})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-title`,className:`text-xs font-medium text-gray-600`,children:`Title`}),(0,Y.jsx)(`input`,{id:`widget-title`,"data-testid":`widget-prop-title`,type:`text`,value:e.title??``,onChange:e=>n({title:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-type`,className:`text-xs font-medium text-gray-600`,children:`Type`}),(0,Y.jsx)(`select`,{id:`widget-type`,"data-testid":`widget-prop-type`,value:e.type??`metric`,onChange:e=>n({type:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`,children:ro.map(e=>(0,Y.jsx)(`option`,{value:e.type,children:e.label},e.type))})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-object`,className:`text-xs font-medium text-gray-600`,children:`Data Source (Object)`}),(0,Y.jsx)(`input`,{id:`widget-object`,"data-testid":`widget-prop-object`,type:`text`,value:e.object??``,onChange:e=>n({object:e.target.value}),disabled:t,placeholder:`e.g. orders`,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-value-field`,className:`text-xs font-medium text-gray-600`,children:`Value Field`}),(0,Y.jsx)(`input`,{id:`widget-value-field`,"data-testid":`widget-prop-value-field`,type:`text`,value:e.valueField??``,onChange:e=>n({valueField:e.target.value}),disabled:t,placeholder:`e.g. amount`,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-aggregate`,className:`text-xs font-medium text-gray-600`,children:`Aggregate`}),(0,Y.jsxs)(`select`,{id:`widget-aggregate`,"data-testid":`widget-prop-aggregate`,value:e.aggregate??`count`,onChange:e=>n({aggregate:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`,children:[(0,Y.jsx)(`option`,{value:`count`,children:`Count`}),(0,Y.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,Y.jsx)(`option`,{value:`avg`,children:`Average`}),(0,Y.jsx)(`option`,{value:`min`,children:`Min`}),(0,Y.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-color`,className:`text-xs font-medium text-gray-600`,children:`Color Variant`}),(0,Y.jsxs)(`select`,{id:`widget-color`,"data-testid":`widget-prop-color`,value:e.colorVariant??`default`,onChange:e=>n({colorVariant:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`,children:[(0,Y.jsx)(`option`,{value:`default`,children:`Default`}),(0,Y.jsx)(`option`,{value:`blue`,children:`Blue`}),(0,Y.jsx)(`option`,{value:`teal`,children:`Teal`}),(0,Y.jsx)(`option`,{value:`orange`,children:`Orange`}),(0,Y.jsx)(`option`,{value:`purple`,children:`Purple`}),(0,Y.jsx)(`option`,{value:`success`,children:`Success`}),(0,Y.jsx)(`option`,{value:`warning`,children:`Warning`}),(0,Y.jsx)(`option`,{value:`danger`,children:`Danger`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{className:`text-xs font-medium text-gray-600`,children:i(`appDesigner.widgetLayoutSize`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-width`,className:`text-[10px] text-gray-400`,children:i(`appDesigner.widgetWidth`)}),(0,Y.jsx)(`input`,{id:`widget-width`,"data-testid":`widget-prop-width`,type:`number`,min:1,value:e.layout?.w??1,onChange:t=>n({layout:{...e.layout,w:Number(t.target.value)||1}}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2 py-1 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`widget-height`,className:`text-[10px] text-gray-400`,children:i(`appDesigner.widgetHeight`)}),(0,Y.jsx)(`input`,{id:`widget-height`,"data-testid":`widget-prop-height`,type:`number`,min:1,value:e.layout?.h??1,onChange:t=>n({layout:{...e.layout,h:Number(t.target.value)||1}}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2 py-1 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]})]})]})]})}function co({schema:e}){let{t}=Pa(),n=e.widgets||[];return(0,Y.jsxs)(`div`,{"data-testid":`dashboard-preview`,className:`rounded-lg border border-gray-200 bg-gray-50 p-4`,children:[(0,Y.jsx)(`h4`,{className:`mb-3 text-sm font-semibold text-gray-700`,children:e.title||t(`appDesigner.dashboardPreview`)}),n.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-gray-400`,children:t(`appDesigner.noWidgetsPreview`)}):(0,Y.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(${e.columns??2}, 1fr)`},children:n.map(e=>{let t=ro.find(t=>t.type===(e.type||`metric`))||ro[0];return(0,Y.jsxs)(`div`,{className:`rounded-md border border-gray-200 bg-white p-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(t.Icon,{className:`h-3 w-3 text-gray-400`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium text-gray-600`,children:e.title||`Untitled`})]}),(0,Y.jsx)(`div`,{className:`mt-1 text-[10px] text-gray-400`,children:t.label})]},e.id)})})]})}function lo({schema:e,onChange:t,readOnly:n=!1,className:r,onExport:i,onImport:a,selectedWidgetId:o,onWidgetSelect:s}){let{t:c}=Pa(),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(!1),p=(0,J.useRef)(null),m=(0,J.useRef)(null),h=o!==void 0,g=h?o:l,_=(0,J.useCallback)(e=>{s&&s(e),h||u(e)},[h,s,u]),{current:v,canUndo:y,canRedo:b,push:x,undo:S,redo:C}=na(e),w=(0,J.useCallback)(e=>{x(e),t(e)},[x,t]),T=v.widgets||[],E=T.find(e=>e.id===g),D=(0,J.useCallback)(e=>{let t=ao(),n={id:t,title:``,type:e,layout:{x:0,y:T.length,w:v.columns??2,h:1}};w({...v,widgets:[...T,n]}),_(t)},[v,T,w,_]),O=(0,J.useCallback)(e=>{w({...v,widgets:T.filter(t=>t.id!==e)}),g===e&&_(null)},[v,T,g,w,_]),k=(0,J.useCallback)((e,t)=>{let n=T.findIndex(t=>t.id===e);if(n<0)return;let r=t===`up`?n-1:n+1;if(r<0||r>=T.length)return;let i=[...T];[i[n],i[r]]=[i[r],i[n]],w({...v,widgets:i})},[v,T,w]),A=(0,J.useCallback)(e=>{g&&w({...v,widgets:T.map(t=>t.id===g?{...t,...e}:t)})},[v,T,g,w]);(0,J.useEffect)(()=>{let e=p.current;if(!e)return;let t=e=>{if(!n){if((e.ctrlKey||e.metaKey)&&e.key===`z`&&!e.shiftKey){e.preventDefault(),S();return}if((e.ctrlKey||e.metaKey)&&(e.key===`y`||e.key===`z`&&e.shiftKey)){e.preventDefault(),C();return}if((e.key===`Delete`||e.key===`Backspace`)&&g){let t=e.target;if(t.tagName===`INPUT`||t.tagName===`SELECT`||t.tagName===`TEXTAREA`)return;e.preventDefault(),O(g)}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[n,S,C,g,O]);let j=(0,J.useCallback)(()=>{i&&i(v)},[v,i]),ee=(0,J.useCallback)(()=>{m.current?.click()},[]),M=(0,J.useCallback)(e=>{let t=e.target.files?.[0];if(!t)return;let n=new FileReader;n.onload=()=>{try{let e=JSON.parse(n.result);e&&e.type===`dashboard`&&(w(e),a?.(e))}catch{}},n.readAsText(t),e.target.value=``},[w,a]);return(0,Y.jsxs)(`div`,{ref:p,tabIndex:0,"data-testid":`dashboard-editor`,className:no(`flex flex-col gap-4 outline-none`,r),children:[(0,Y.jsx)(`input`,{ref:m,type:`file`,accept:`.json`,className:`hidden`,"data-testid":`dashboard-import-input`,onChange:M}),E&&!d&&(0,Y.jsx)(so,{widget:E,readOnly:n,onChange:A,onClose:()=>_(null)}),(0,Y.jsxs)(`div`,{className:`flex-1 space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`text-sm font-medium text-gray-700`,children:[c(`appDesigner.addWidget`),`:`]}),ro.map(({type:e,label:t,Icon:r})=>(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>D(e),disabled:n||d,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Y.jsx)(r,{className:`h-3.5 w-3.5`}),t]},e))]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!n&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-undo`,onClick:S,disabled:!y,className:`rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":c(`appDesigner.undo`),children:(0,Y.jsx)(xe,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-redo`,onClick:C,disabled:!b,className:`rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":c(`appDesigner.redo`),children:(0,Y.jsx)(De,{className:`h-4 w-4`})})]}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-export`,onClick:j,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navExportSchema`),children:(0,Y.jsx)(ce,{className:`h-4 w-4`})}),!n&&(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-import`,onClick:ee,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navImportSchema`),children:(0,Y.jsx)(Fe,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dashboard-preview-toggle`,onClick:()=>f(e=>!e),className:no(`rounded p-1.5 transition-colors`,d?`bg-blue-100 text-blue-600`:`text-gray-400 hover:text-gray-700`),"aria-label":c(d?`appDesigner.modeEdit`:`appDesigner.preview`),children:d?(0,Y.jsx)(I,{className:`h-4 w-4`}):(0,Y.jsx)(Pe,{className:`h-4 w-4`})})]})]}),d?(0,Y.jsx)(co,{schema:v}):T.length===0?(0,Y.jsx)(`div`,{className:`flex h-48 items-center justify-center rounded-lg border-2 border-dashed border-gray-200 text-sm text-gray-400`,children:c(`appDesigner.noWidgets`)}):(0,Y.jsx)(`div`,{className:`grid gap-3`,style:{gridTemplateColumns:`repeat(${v.columns??2}, 1fr)`},children:T.map((e,t)=>(0,Y.jsx)(oo,{widget:e,index:t,total:T.length,selected:e.id===g,readOnly:n,onSelect:()=>_(e.id??null),onRemove:()=>O(e.id),onMoveUp:()=>k(e.id,`up`),onMoveDown:()=>k(e.id,`down`)},e.id))})]})]})}function $(...e){return W(G(e))}var uo=[{hex:`#3b82f6`,name:`Blue`},{hex:`#6366f1`,name:`Indigo`},{hex:`#8b5cf6`,name:`Violet`},{hex:`#a855f7`,name:`Purple`},{hex:`#ec4899`,name:`Pink`},{hex:`#ef4444`,name:`Red`},{hex:`#f97316`,name:`Orange`},{hex:`#f59e0b`,name:`Amber`},{hex:`#eab308`,name:`Yellow`},{hex:`#22c55e`,name:`Green`},{hex:`#14b8a6`,name:`Teal`},{hex:`#06b6d4`,name:`Cyan`},{hex:`#0ea5e9`,name:`Sky`},{hex:`#64748b`,name:`Slate`},{hex:`#1e293b`,name:`Dark`},{hex:`#0f172a`,name:`Navy`}],fo=[`Inter`,`Roboto`,`Open Sans`,`Lato`,`Montserrat`,`Poppins`,`Source Sans Pro`,`Noto Sans`,`system-ui`];function po({branding:e,onChange:t,appTitle:n=`My App`,readOnly:r=!1,className:i,onExport:a,onImport:o}){let{t:s}=Pa(),[c,l]=(0,J.useState)(`light`),{current:u,push:d,canUndo:f,canRedo:p,undo:m,redo:h}=na(e),g=(0,J.useRef)(!0);(0,J.useEffect)(()=>{if(g.current){g.current=!1;return}t(u)},[u]);let _=(0,J.useCallback)(e=>{let n={...u,...e};g.current=!0,d(n),t(n)},[u,d,t]),v=(0,J.useCallback)(()=>{if(a){a(u);return}let e=new Blob([JSON.stringify(u,null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`branding.json`,n.click(),URL.revokeObjectURL(t)},[u,a]),y=(0,J.useCallback)(()=>{if(o){o(u);return}let e=document.createElement(`input`);e.type=`file`,e.accept=`.json`,e.onchange=e=>{let n=e.target.files?.[0];if(!n)return;let r=new FileReader;r.onload=e=>{try{let n=JSON.parse(e.target?.result);if(typeof n==`object`&&n){let e={...u,...n};d(e),t(e)}}catch{}},r.readAsText(n)},e.click()},[u,d,t,o]),b=(0,J.useCallback)(e=>{r||((e.ctrlKey||e.metaKey)&&e.key===`z`&&(e.preventDefault(),e.shiftKey?h():m()),(e.ctrlKey||e.metaKey)&&e.key===`y`&&(e.preventDefault(),h()))},[r,m,h]),x=u.primaryColor||`#3b82f6`,S=c===`dark`;return(0,Y.jsxs)(`div`,{"data-testid":`branding-editor`,className:$(`flex flex-col gap-4 sm:gap-6`,i),onKeyDown:b,tabIndex:0,children:[(0,Y.jsxs)(`div`,{"data-testid":`branding-editor-toolbar`,className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-gray-800 mr-auto`,children:s(`appDesigner.brandingEditor`)}),(0,Y.jsxs)(`button`,{"data-testid":`branding-undo`,type:`button`,onClick:m,disabled:!f||r,className:$(`inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors`,f&&!r?`border-gray-300 bg-white text-gray-700 hover:bg-gray-50`:`border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed`),title:s(`appDesigner.undo`),children:[(0,Y.jsx)(xe,{className:`h-3.5 w-3.5`}),s(`appDesigner.undo`)]}),(0,Y.jsxs)(`button`,{"data-testid":`branding-redo`,type:`button`,onClick:h,disabled:!p||r,className:$(`inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors`,p&&!r?`border-gray-300 bg-white text-gray-700 hover:bg-gray-50`:`border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed`),title:s(`appDesigner.redo`),children:[(0,Y.jsx)(De,{className:`h-3.5 w-3.5`}),s(`appDesigner.redo`)]}),(0,Y.jsxs)(`button`,{"data-testid":`branding-export`,type:`button`,onClick:v,className:`inline-flex items-center gap-1 rounded-md border border-gray-300 bg-white px-2.5 py-1.5 text-xs font-medium text-gray-700 shadow-sm transition-colors hover:bg-gray-50`,title:s(`appDesigner.brandingExport`),children:[(0,Y.jsx)(ce,{className:`h-3.5 w-3.5`}),s(`appDesigner.brandingExport`)]}),(0,Y.jsxs)(`button`,{"data-testid":`branding-import`,type:`button`,onClick:y,disabled:r,className:$(`inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors`,r?`border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed`:`border-gray-300 bg-white text-gray-700 hover:bg-gray-50`),title:s(`appDesigner.brandingImport`),children:[(0,Y.jsx)(Fe,{className:`h-3.5 w-3.5`}),s(`appDesigner.brandingImport`)]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:gap-6`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`be-logo`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.logoUrl`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Qe,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.jsx)(`input`,{id:`be-logo`,"data-testid":`branding-logo-input`,type:`text`,value:u.logo??``,onChange:e=>_({logo:e.target.value}),placeholder:`https://example.com/logo.svg`,disabled:r,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`be-color`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.primaryColor`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(ct,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.jsx)(`input`,{id:`be-color`,"data-testid":`branding-color-input`,type:`text`,value:u.primaryColor??`#3b82f6`,onChange:e=>_({primaryColor:e.target.value}),placeholder:`#3b82f6`,disabled:r,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]}),(0,Y.jsx)(`input`,{"data-testid":`branding-color-picker`,type:`color`,value:x,onChange:e=>_({primaryColor:e.target.value}),disabled:r,className:`h-9 w-9 cursor-pointer rounded-md border border-gray-300 p-0.5 disabled:cursor-not-allowed`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-gray-500`,children:s(`appDesigner.colorPalette`)}),(0,Y.jsx)(`div`,{"data-testid":`branding-color-palette`,className:`flex flex-wrap gap-1.5`,children:uo.map(e=>(0,Y.jsx)(`button`,{"data-testid":`branding-swatch-${e.hex.slice(1)}`,type:`button`,onClick:()=>!r&&_({primaryColor:e.hex}),disabled:r,className:$(`h-6 w-6 rounded-full border-2 transition-transform hover:scale-110 disabled:cursor-not-allowed`,x===e.hex?`border-gray-800 ring-2 ring-offset-1 ring-gray-400`:`border-transparent`),style:{backgroundColor:e.hex},title:e.name},e.hex))})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`be-favicon`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.faviconUrl`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Dt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.jsx)(`input`,{id:`be-favicon`,"data-testid":`branding-favicon-input`,type:`text`,value:u.favicon??``,onChange:e=>_({favicon:e.target.value}),placeholder:`https://example.com/favicon.ico`,disabled:r,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{htmlFor:`be-font`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.fontFamily`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Oe,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Y.jsxs)(`select`,{id:`be-font`,"data-testid":`branding-font-select`,value:u.fontFamily??``,onChange:e=>_({fontFamily:e.target.value||void 0}),disabled:r,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50 appearance-none`,children:[(0,Y.jsx)(`option`,{value:``,children:s(`appDesigner.fontDefault`)}),fo.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium text-gray-700`,children:s(`appDesigner.brandingPreview`)}),(0,Y.jsxs)(`div`,{"data-testid":`branding-mode-toggle`,className:`flex rounded-md border border-gray-300 overflow-hidden`,children:[(0,Y.jsxs)(`button`,{"data-testid":`branding-mode-light`,type:`button`,onClick:()=>l(`light`),className:$(`inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium transition-colors`,c===`light`?`bg-blue-50 text-blue-700`:`bg-white text-gray-600 hover:bg-gray-50`),children:[(0,Y.jsx)(ne,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeLight`)]}),(0,Y.jsxs)(`button`,{"data-testid":`branding-mode-dark`,type:`button`,onClick:()=>l(`dark`),className:$(`inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium transition-colors`,c===`dark`?`bg-gray-800 text-gray-100`:`bg-white text-gray-600 hover:bg-gray-50`),children:[(0,Y.jsx)(pt,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeDark`)]})]})]}),(0,Y.jsxs)(`div`,{"data-testid":`branding-preview`,className:$(`rounded-lg border p-4 transition-colors`,S?`border-gray-700 bg-gray-900 text-gray-100`:`border-gray-200 bg-white text-gray-800`),style:{fontFamily:u.fontFamily||`inherit`},children:[(0,Y.jsx)(`div`,{className:`rounded-md p-3 mb-3`,style:{backgroundColor:x},children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[u.logo?(0,Y.jsx)(`img`,{src:u.logo,alt:`Logo`,className:`h-8 w-8 rounded object-contain bg-white/20`}):(0,Y.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-white/20 text-xs text-white`,children:`Logo`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:n})]})}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:x}}),(0,Y.jsx)(`span`,{className:$(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:x})]}),(0,Y.jsx)(`button`,{type:`button`,className:`rounded-md px-3 py-1.5 text-xs font-medium text-white transition-colors`,style:{backgroundColor:x},tabIndex:-1,children:s(`appDesigner.brandingSampleButton`)}),(0,Y.jsx)(`p`,{className:$(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:s(`appDesigner.brandingSampleText`)}),u.favicon&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`img`,{src:u.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,Y.jsx)(`span`,{className:$(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:`Favicon`})]}),u.fontFamily&&(0,Y.jsxs)(`div`,{className:$(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:[s(`appDesigner.fontFamily`),`: `,u.fontFamily]})]})]}),(0,Y.jsxs)(`div`,{"data-testid":`branding-preview-mobile`,className:$(`mx-auto w-48 rounded-xl border-2 p-2 transition-colors`,S?`border-gray-700 bg-gray-900`:`border-gray-300 bg-white`),style:{fontFamily:u.fontFamily||`inherit`},children:[(0,Y.jsx)(`div`,{className:`text-center text-[10px] font-medium text-gray-400 mb-1`,children:s(`appDesigner.mobilePreview`)}),(0,Y.jsx)(`div`,{className:`rounded-md p-2 mb-1`,style:{backgroundColor:x},children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[u.logo?(0,Y.jsx)(`img`,{src:u.logo,alt:`Logo`,className:`h-4 w-4 rounded object-contain bg-white/20`}):(0,Y.jsx)(`div`,{className:`flex h-4 w-4 items-center justify-center rounded bg-white/20 text-[6px] text-white`,children:`L`}),(0,Y.jsx)(`span`,{className:`text-[9px] font-semibold text-white truncate`,children:n})]})}),(0,Y.jsxs)(`div`,{className:`space-y-1 px-1`,children:[(0,Y.jsx)(`div`,{className:$(`h-2 w-3/4 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Y.jsx)(`div`,{className:$(`h-2 w-1/2 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Y.jsx)(`div`,{className:$(`h-2 w-2/3 rounded`,S?`bg-gray-700`:`bg-gray-200`)})]})]})]})]})]})}function mo(...e){return W(G(e))}var ho=[`Custom Objects`,`System Objects`,`Integration`,`Analytics`],go=[`Box`,`Database`,`Users`,`FileText`,`Settings`,`ShoppingCart`,`Calendar`,`Mail`,`Briefcase`,`Building`,`Globe`,`Heart`,`Star`,`Tag`,`Bookmark`,`Folder`,`Archive`,`Package`,`Truck`,`CreditCard`];function _o({objects:e,onObjectsChange:t,onSelectObject:n,showSystemObjects:r=!0,readOnly:i=!1,className:a}){let{t:o}=Pa(),s=ra(),[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)(null),f=(0,J.useMemo)(()=>r?e:e.filter(e=>!e.isSystem),[e,r]),p=(0,J.useMemo)(()=>new k({items:f}),[f]),m=(0,J.useMemo)(()=>[{field:`name`,label:o(`appDesigner.objectManager.objectName`),width:160},{field:`label`,label:o(`appDesigner.objectManager.objectLabel`),width:160},{field:`group`,label:o(`appDesigner.objectManager.group`),width:130},{field:`fieldCount`,label:`Fields`,width:80},{field:`enabled`,label:o(`appDesigner.objectManager.enabled`),width:80}],[o]),h=(0,J.useMemo)(()=>({type:`object-grid`,objectName:`object_definition`,columns:m,searchableFields:[`name`,`label`,`description`],showSearch:!0,operations:i?void 0:{create:!0,update:!0,delete:!0}}),[m,i]),g=(0,J.useCallback)(t=>{let r=e.find(e=>e.name===t.name);r&&n?.(r)},[e,n]),_=(0,J.useCallback)(t=>{let n=e.find(e=>e.name===t.name);n&&(d(n),l(!0))},[e]),v=(0,J.useCallback)(async n=>{let r=e.find(e=>e.name===n.name);!r||r.isSystem||await s.confirm(o(`appDesigner.objectManager.deleteConfirmTitle`),o(`appDesigner.objectManager.deleteConfirmMessage`))&&t?.(e.filter(e=>e.id!==r.id))},[e,t,s,o]),y=(0,J.useCallback)(()=>{d(null),l(!0)},[]),b=(0,J.useCallback)(n=>{if(u){let r={...u,name:String(n.name||u.name),label:String(n.label||u.label),pluralLabel:n.pluralLabel?String(n.pluralLabel):void 0,description:n.description?String(n.description):void 0,icon:n.icon?String(n.icon):void 0,group:n.group?String(n.group):void 0,sortOrder:typeof n.sortOrder==`number`?n.sortOrder:void 0,enabled:n.enabled!==!1};t?.(e.map(e=>e.id===u.id?r:e))}else{let r={id:`obj_${Date.now()}`,name:String(n.name||`new_object_${e.length+1}`),label:String(n.label||`New Object ${e.length+1}`),pluralLabel:n.pluralLabel?String(n.pluralLabel):void 0,description:n.description?String(n.description):void 0,icon:n.icon?String(n.icon):void 0,group:n.group?String(n.group):void 0,sortOrder:typeof n.sortOrder==`number`?n.sortOrder:void 0,isSystem:!1,enabled:n.enabled!==!1,fieldCount:0};t?.([...e,r])}l(!1),d(null)},[u,e,t]),x=(0,J.useCallback)(e=>{e||(l(!1),d(null))},[]),S=(0,J.useMemo)(()=>({type:`object-form`,formType:`modal`,objectName:`object_definition`,mode:u?`edit`:`create`,title:u?`${o(`common.edit`)} — ${u.label}`:o(`appDesigner.objectManager.addObject`),open:c,onOpenChange:x,modalSize:`lg`,customFields:[{name:`name`,label:o(`appDesigner.objectManager.objectName`),type:`text`,required:!0,placeholder:`api_name`,disabled:i||(u?.isSystem??!1)},{name:`label`,label:o(`appDesigner.objectManager.objectLabel`),type:`text`,required:!0,placeholder:`Display Name`,disabled:i},{name:`pluralLabel`,label:o(`appDesigner.objectManager.pluralLabel`),type:`text`,placeholder:`Display Names`,disabled:i},{name:`description`,label:o(`appDesigner.appDescription`),type:`textarea`,disabled:i},{name:`icon`,label:o(`appDesigner.objectManager.icon`),type:`select`,options:go.map(e=>({label:e,value:e})),disabled:i},{name:`group`,label:o(`appDesigner.objectManager.group`),type:`select`,options:ho.map(e=>({label:e,value:e})),disabled:i},{name:`sortOrder`,label:o(`appDesigner.objectManager.sortOrder`),type:`number`,disabled:i},{name:`enabled`,label:o(`appDesigner.objectManager.enabled`),type:`boolean`,disabled:i}],initialValues:u?{name:u.name,label:u.label,pluralLabel:u.pluralLabel||``,description:u.description||``,icon:u.icon||``,group:u.group||``,sortOrder:u.sortOrder??0,enabled:u.enabled!==!1}:{enabled:!0},onSuccess:b,onCancel:()=>x(!1),readOnly:i}),[u,c,x,b,i,o]);return(0,Y.jsxs)(`div`,{"data-testid":`object-manager`,className:mo(`w-full space-y-3`,a),children:[(0,Y.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ze,{className:`h-4 w-4 text-primary`}),(0,Y.jsx)(`h2`,{className:`text-sm font-semibold`,children:o(`appDesigner.objectManager.title`)}),(0,Y.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:f.length})]})}),(0,Y.jsx)(gn,{schema:h,dataSource:p,onRowClick:g,onEdit:i?void 0:_,onDelete:i?void 0:v,onAddRecord:i?void 0:y}),c&&(0,Y.jsx)(cn,{schema:S}),(0,Y.jsx)(ca,{isOpen:s.isOpen,title:s.title,message:s.message,confirmLabel:o(`common.delete`),cancelLabel:o(`common.cancel`),onConfirm:s.onConfirm,onCancel:s.onCancel,destructive:!0})]})}function vo(...e){return W(G(e))}var yo={text:{label:`Text`,Icon:Oe},textarea:{label:`Text Area`,Icon:le},number:{label:`Number`,Icon:Mt},boolean:{label:`Checkbox`,Icon:Je},date:{label:`Date`,Icon:ke},datetime:{label:`Date/Time`,Icon:ke},time:{label:`Time`,Icon:ke},select:{label:`Picklist`,Icon:Ne},email:{label:`Email`,Icon:re},phone:{label:`Phone`,Icon:Se},url:{label:`URL`,Icon:Dt},password:{label:`Password`,Icon:yt},currency:{label:`Currency`,Icon:Mt},percent:{label:`Percent`,Icon:Mt},lookup:{label:`Lookup`,Icon:ye},formula:{label:`Formula`,Icon:Le},autonumber:{label:`Auto Number`,Icon:Mt},file:{label:`File`,Icon:le},image:{label:`Image`,Icon:Qe},markdown:{label:`Markdown`,Icon:le},html:{label:`Rich Text`,Icon:le},color:{label:`Color`,Icon:ct},code:{label:`Code`,Icon:Le},location:{label:`Location`,Icon:ue},address:{label:`Address`,Icon:ue},rating:{label:`Rating`,Icon:wt},slider:{label:`Slider`,Icon:ut}},bo={text:[`text`,`textarea`,`email`,`phone`,`url`,`password`,`markdown`,`html`],number:[`number`,`currency`,`percent`,`autonumber`,`rating`,`slider`],date:[`date`,`datetime`,`time`],choice:[`boolean`,`select`],relation:[`lookup`],advanced:[`formula`,`file`,`image`,`color`,`code`,`location`,`address`]},xo=[`text`,`number`,`date`,`choice`,`relation`,`advanced`];function So({objectName:e,fields:t,onFieldsChange:n,readOnly:r=!1,className:i}){let{t:a}=Pa(),o=ra(),[s,c]=(0,J.useState)(!1),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(``),p=(0,J.useMemo)(()=>d?t.filter(e=>e.type===d):t,[t,d]),m=(0,J.useMemo)(()=>new k({items:p}),[p]),h=(0,J.useMemo)(()=>[{field:`name`,label:a(`appDesigner.fieldDesigner.fieldName`),width:140},{field:`label`,label:a(`appDesigner.fieldDesigner.fieldLabel`),width:160},{field:`type`,label:a(`appDesigner.fieldDesigner.fieldType`),width:100},{field:`required`,label:a(`appDesigner.fieldDesigner.required`),width:80},{field:`unique`,label:a(`appDesigner.fieldDesigner.unique`),width:80},{field:`group`,label:a(`appDesigner.fieldDesigner.fieldGroup`),width:120}],[a]),g=(0,J.useMemo)(()=>({type:`object-grid`,objectName:`field_definition`,columns:h,searchableFields:[`name`,`label`,`description`],showSearch:!0,operations:r?void 0:{create:!0,update:!0,delete:!0}}),[h,r]),_=(0,J.useCallback)(e=>{let n=t.find(t=>t.name===e.name);n&&(u(n),c(!0))},[t]),v=(0,J.useCallback)(async e=>{let r=t.find(t=>t.name===e.name);!r||r.isSystem||await o.confirm(a(`appDesigner.fieldDesigner.deleteConfirmTitle`),a(`appDesigner.fieldDesigner.deleteConfirmMessage`))&&n?.(t.filter(e=>e.id!==r.id))},[t,n,o,a]),y=(0,J.useCallback)(()=>{u(null),c(!0)},[]),b=(0,J.useCallback)(e=>{if(l){let r={...l,name:String(e.name||l.name),label:String(e.label||l.label),type:e.type||l.type,group:e.group?String(e.group):void 0,description:e.description?String(e.description):void 0,required:e.required===!0,unique:e.unique===!0,readonly:e.readonly===!0,hidden:e.hidden===!0,indexed:e.indexed===!0,externalId:e.externalId===!0,trackHistory:e.trackHistory===!0,defaultValue:e.defaultValue?String(e.defaultValue):void 0,placeholder:e.placeholder?String(e.placeholder):void 0,referenceTo:e.referenceTo?String(e.referenceTo):void 0,formula:e.formula?String(e.formula):void 0};n?.(t.map(e=>e.id===l.id?r:e))}else{let r={id:`fld_${Date.now()}`,name:String(e.name||`new_field_${t.length+1}`),label:String(e.label||`New Field ${t.length+1}`),type:e.type||`text`,group:e.group?String(e.group):void 0,description:e.description?String(e.description):void 0,required:e.required===!0,unique:e.unique===!0,readonly:e.readonly===!0,hidden:e.hidden===!0,indexed:e.indexed===!0,externalId:e.externalId===!0,trackHistory:e.trackHistory===!0,defaultValue:e.defaultValue?String(e.defaultValue):void 0,placeholder:e.placeholder?String(e.placeholder):void 0,referenceTo:e.referenceTo?String(e.referenceTo):void 0,formula:e.formula?String(e.formula):void 0,isSystem:!1};n?.([...t,r])}c(!1),u(null)},[l,t,n]),x=(0,J.useCallback)(e=>{e||(c(!1),u(null))},[]),S=(0,J.useMemo)(()=>xo.map(e=>({category:e,label:a(`appDesigner.fieldDesigner.typeCategory.${e}`),options:bo[e].map(e=>({label:yo[e].label,value:e}))})),[a]),C=(0,J.useMemo)(()=>S.flatMap(e=>e.options),[S]),w=(0,J.useMemo)(()=>({type:`object-form`,formType:`drawer`,objectName:`field_definition`,mode:l?`edit`:`create`,title:l?`${a(`common.edit`)} — ${l.label}`:a(`appDesigner.fieldDesigner.addField`),open:s,onOpenChange:x,drawerSide:`right`,drawerWidth:`480px`,sections:[{name:`basic`,label:a(`appDesigner.fieldDesigner.basicSection`),fields:[{name:`name`,label:a(`appDesigner.fieldDesigner.fieldName`),type:`text`,required:!0,placeholder:`api_name`,disabled:r||(l?.isSystem??!1)},{name:`label`,label:a(`appDesigner.fieldDesigner.fieldLabel`),type:`text`,required:!0,placeholder:`Display Label`,disabled:r},{name:`type`,label:a(`appDesigner.fieldDesigner.fieldType`),type:`select`,required:!0,options:C,disabled:r||(l?.isSystem??!1)},{name:`required`,label:a(`appDesigner.fieldDesigner.required`),type:`boolean`,disabled:r},{name:`unique`,label:a(`appDesigner.fieldDesigner.unique`),type:`boolean`,disabled:r},{name:`description`,label:a(`appDesigner.fieldDesigner.description`),type:`textarea`,disabled:r}]},{name:`typeSpecific`,label:a(`appDesigner.fieldDesigner.typeSpecificSection`),fields:[{name:`referenceTo`,label:a(`appDesigner.fieldDesigner.referenceTo`),type:`text`,placeholder:`Referenced object`,disabled:r,condition:{field:`type`,equals:`lookup`}},{name:`formula`,label:a(`appDesigner.fieldDesigner.formula`),type:`textarea`,placeholder:`e.g. price * quantity`,disabled:r,condition:{field:`type`,equals:`formula`}},{name:`defaultValue`,label:a(`appDesigner.fieldDesigner.defaultValue`),type:`text`,placeholder:`Default value`,disabled:r},{name:`placeholder`,label:a(`appDesigner.fieldDesigner.placeholder`),type:`text`,placeholder:`Placeholder text`,disabled:r},{name:`group`,label:a(`appDesigner.fieldDesigner.fieldGroup`),type:`text`,placeholder:`Field Group`,disabled:r}]},{name:`advanced`,label:a(`appDesigner.fieldDesigner.advancedSection`),collapsible:!0,collapsed:!0,fields:[{name:`indexed`,label:a(`appDesigner.fieldDesigner.indexed`),type:`boolean`,disabled:r},{name:`externalId`,label:a(`appDesigner.fieldDesigner.externalId`),type:`boolean`,disabled:r},{name:`trackHistory`,label:a(`appDesigner.fieldDesigner.trackHistory`),type:`boolean`,disabled:r},{name:`readonly`,label:a(`appDesigner.fieldDesigner.readOnly`),type:`boolean`,disabled:r},{name:`hidden`,label:a(`appDesigner.fieldDesigner.hidden`),type:`boolean`,disabled:r}]}],initialValues:l?{name:l.name,label:l.label,type:l.type,group:l.group||``,description:l.description||``,required:l.required||!1,unique:l.unique||!1,readonly:l.readonly||!1,hidden:l.hidden||!1,indexed:l.indexed||!1,externalId:l.externalId||!1,trackHistory:l.trackHistory||!1,defaultValue:l.defaultValue==null?``:String(l.defaultValue),placeholder:l.placeholder||``,referenceTo:l.referenceTo||``,formula:l.formula||``}:{type:`text`,required:!1,unique:!1},onSuccess:b,onCancel:()=>x(!1),readOnly:r}),[l,s,x,b,C,r,a]);return(0,Y.jsxs)(`div`,{"data-testid":`field-designer`,className:vo(`w-full space-y-3`,i),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(tt,{className:`h-4 w-4 text-primary`}),(0,Y.jsx)(`h2`,{className:`text-sm font-semibold`,children:a(`appDesigner.fieldDesigner.title`)}),e&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`— `,e]}),(0,Y.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:p.length})]}),(0,Y.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),"data-testid":`field-designer-type-filter`,className:`rounded-md border border-input bg-background px-2 py-1 text-xs outline-none transition-colors focus:border-primary focus:ring-1 focus:ring-primary`,children:[(0,Y.jsx)(`option`,{value:``,children:a(`appDesigner.fieldDesigner.allTypes`)}),S.map(e=>(0,Y.jsx)(`optgroup`,{label:e.label,children:e.options.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))},e.category))]})]}),(0,Y.jsx)(gn,{schema:g,dataSource:m,onEdit:r?void 0:_,onDelete:r?void 0:v,onAddRecord:r?void 0:y}),s&&(0,Y.jsx)(ln,{schema:w}),(0,Y.jsx)(ca,{isOpen:o.isOpen,title:o.title,message:o.message,confirmLabel:a(`common.delete`),cancelLabel:a(`common.cancel`),onConfirm:o.onConfirm,onCancel:o.onCancel,destructive:!0})]})}var Co=`objectui-app-wizard-draft`;function wo(){let e=h(),{appName:t}=a(),{objects:n,refresh:r}=E(),i=N(),o=(n||[]).map(e=>({name:e.name,label:e.label||e.name,icon:e.icon,selected:!1})),s=(0,J.useCallback)(()=>{try{let e=localStorage.getItem(Co);if(e)return JSON.parse(e)}catch{}},[]),c=(0,J.useCallback)(async t=>{try{let n=ee(t),a=i?.getClient();a&&await a.meta.saveItem(`app`,t.name,n),localStorage.removeItem(Co),K.success(`Application "${t.title}" created successfully`),await r?.(),e(`/apps/${t.name}`)}catch(e){K.error(e?.message||`Failed to create application`)}},[e,r,i]),l=(0,J.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),u=(0,J.useCallback)(e=>{try{localStorage.setItem(Co,JSON.stringify(e)),K.info(`Draft saved`)}catch{}},[]);return(0,Y.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4`,"data-testid":`create-app-page`,children:(0,Y.jsx)(Ka,{availableObjects:o,initialDraft:s(),onComplete:c,onCancel:l,onSaveDraft:u})})}function To(){let e=h(),{appName:t,editAppName:n}=a(),{apps:r,objects:i,refresh:o}=E(),s=N(),c=n||t,l=r.find(e=>e.name===c),u=(i||[]).map(e=>({name:e.name,label:e.label||e.name,icon:e.icon,selected:l?.navigation?.some(t=>t.type===`object`&&t.objectName===e.name)??!1})),d=(0,J.useMemo)(()=>{if(l)return{name:l.name,title:l.title||l.label||``,description:l.description||``,icon:l.icon||``,layout:l.layout||`sidebar`,navigation:l.navigation||[],branding:{logo:l.branding?.logo||l.logo||``,primaryColor:l.branding?.primaryColor||`#3b82f6`,favicon:l.branding?.favicon||l.favicon||``}}},[l]),f=(0,J.useCallback)(async t=>{try{let n=ee(t),r={...l,...n},i=s?.getClient();i&&await i.meta.saveItem(`app`,t.name,r),K.success(`Application "${t.title}" updated successfully`),await o?.(),e(`/apps/${t.name}`)}catch(e){K.error(e?.message||`Failed to update application`)}},[e,o,s,l]),p=(0,J.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),m=(0,J.useCallback)(e=>{try{localStorage.setItem(`objectui-edit-draft-${c}`,JSON.stringify(e)),K.info(`Draft saved`)}catch{}},[c]);return l?(0,Y.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4`,"data-testid":`edit-app-page`,children:(0,Y.jsx)(Ka,{availableObjects:u,initialDraft:d,onComplete:f,onCancel:p,onSaveDraft:m})}):(0,Y.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4 text-center`,"data-testid":`edit-app-not-found`,children:(0,Y.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Application "`,c,`" not found.`]})})}function Eo(){let e=h(),{dashboardName:t}=a(),n=N(),{dashboards:r,refresh:i}=E(),o=r?.find(e=>e.name===t),[s,c]=(0,J.useState)(()=>o||{type:`dashboard`,name:t??``,title:t??``,columns:2,widgets:[]}),l=(0,J.useRef)(s);l.current=s;let u=(0,J.useCallback)(async e=>{try{if(n)return await n.update(`sys_dashboard`,t,e),i().catch(()=>{}),!0}catch{}return!1},[n,t,i]),d=(0,J.useCallback)(async e=>{c(e),await u(e)},[u]);(0,J.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`s`&&(e.preventDefault(),u(l.current).then(e=>{e&&K.success(`Dashboard saved`)}))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u]);let f=(0,J.useCallback)(e=>{let n=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t||`dashboard`}.json`,i.click(),URL.revokeObjectURL(r),K.success(`Dashboard schema exported`)},[t]),p=(0,J.useCallback)(e=>{K.success(`Dashboard schema imported`),d(e)},[d]);return o?(0,Y.jsxs)(`div`,{className:`h-full flex flex-col`,"data-testid":`dashboard-design-page`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-4 py-3 sm:px-6`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>e(-1),className:`rounded p-1.5 text-muted-foreground hover:text-foreground`,"aria-label":`Go back`,"data-testid":`dashboard-design-back`,children:(0,Y.jsx)(jt,{className:`h-4 w-4`})}),(0,Y.jsxs)(`h1`,{className:`text-lg font-semibold tracking-tight truncate`,children:[`Edit Dashboard: `,o.label||o.title||t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,Y.jsx)(lo,{schema:s,onChange:d,onExport:f,onImport:p})})]}):(0,Y.jsxs)(`div`,{className:`h-full flex items-center justify-center text-muted-foreground`,children:[`Dashboard "`,t,`" not found`]})}var Do=t({AppCreationWizard:()=>Ka,BrandingEditor:()=>po,CreateAppPage:()=>wo,DashboardDesignPage:()=>Eo,DashboardEditor:()=>lo,DataModelDesigner:()=>Sa,EditAppPage:()=>To,FieldDesigner:()=>So,NavigationDesigner:()=>to,ObjectManager:()=>_o,PageDesigner:()=>ga,ProcessDesigner:()=>Da,ReportDesigner:()=>ja});A.register(`page-designer`,ga,{namespace:`plugin-designer`,label:`Page Designer`,category:`Designer`,inputs:[{name:`canvas`,type:`code`,label:`Canvas Configuration`},{name:`components`,type:`code`,label:`Components`},{name:`showComponentTree`,type:`boolean`,label:`Show Component Tree`,defaultValue:!0},{name:`undoRedo`,type:`boolean`,label:`Undo/Redo`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),A.register(`data-model-designer`,Sa,{namespace:`plugin-designer`,label:`Data Model Designer`,category:`Designer`,inputs:[{name:`entities`,type:`code`,label:`Entities`},{name:`relationships`,type:`code`,label:`Relationships`},{name:`autoLayout`,type:`boolean`,label:`Auto Layout`,defaultValue:!1},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),A.register(`process-designer`,Da,{namespace:`plugin-designer`,label:`Process Designer (BPMN)`,category:`Designer`,inputs:[{name:`processName`,type:`string`,label:`Process Name`},{name:`nodes`,type:`code`,label:`Nodes`},{name:`edges`,type:`code`,label:`Edges`},{name:`showMinimap`,type:`boolean`,label:`Show Minimap`,defaultValue:!1},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),A.register(`report-designer`,ja,{namespace:`plugin-designer`,label:`Report Designer`,category:`Designer`,inputs:[{name:`reportName`,type:`string`,label:`Report Name`},{name:`objectName`,type:`string`,label:`Data Source Object`},{name:`sections`,type:`code`,label:`Sections`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`,defaultValue:!0},{name:`showPropertyPanel`,type:`boolean`,label:`Show Property Panel`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),A.register(`app-creation-wizard`,Ka,{namespace:`plugin-designer`,label:`App Creation Wizard`,category:`Designer`,inputs:[{name:`availableObjects`,type:`code`,label:`Available Objects`},{name:`templates`,type:`code`,label:`Templates`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),A.register(`navigation-designer`,to,{namespace:`plugin-designer`,label:`Navigation Designer`,category:`Designer`,inputs:[{name:`items`,type:`code`,label:`Navigation Items`},{name:`showPreview`,type:`boolean`,label:`Show Preview`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),A.register(`dashboard-editor`,lo,{namespace:`plugin-designer`,label:`Dashboard Editor`,category:`Designer`,inputs:[{name:`schema`,type:`code`,label:`Dashboard Schema`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),A.register(`branding-editor`,po,{namespace:`plugin-designer`,label:`Branding Editor`,category:`Designer`,inputs:[{name:`branding`,type:`code`,label:`Branding Config`},{name:`appTitle`,type:`string`,label:`App Title`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),A.register(`object-manager`,_o,{namespace:`plugin-designer`,label:`Object Manager`,category:`Designer`,inputs:[{name:`objects`,type:`code`,label:`Object Definitions`},{name:`showSystemObjects`,type:`boolean`,label:`Show System Objects`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),A.register(`field-designer`,So,{namespace:`plugin-designer`,label:`Field Designer`,category:`Designer`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`},{name:`fields`,type:`code`,label:`Field Definitions`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]});function Oo(e,t){return{name:e.name,label:e.label,pluralLabel:e.pluralLabel,description:e.description,icon:e.icon,group:e.group,sortOrder:e.sortOrder,enabled:e.enabled,fields:t,relationships:e.relationships}}function ko(e){return{name:e.name,label:e.label,type:e.type,group:e.group,description:e.description,required:e.required,unique:e.unique,readonly:e.readonly,hidden:e.hidden,defaultValue:e.defaultValue,placeholder:e.placeholder,options:e.options,externalId:e.externalId,trackHistory:e.trackHistory,indexed:e.indexed,referenceTo:e.referenceTo,formula:e.formula,sortOrder:e.sortOrder}}var Ao=class{adapter;constructor(e){this.adapter=e}async getItems(e){let t=await this.adapter.getClient().meta.getItems(e);return t&&typeof t==`object`&&`items`in t&&Array.isArray(t.items)?t.items:[]}async saveMetadataItem(e,t,n){await this.adapter.getClient().meta.saveItem(e,t,n),this.adapter.invalidateCache(`${e}:${t}`)}async deleteMetadataItem(e,t){await this.adapter.getClient().meta.saveItem(e,t,{name:t,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`${e}:${t}`)}async saveObject(e,t){let n=this.adapter.getClient(),r=Oo(e,t);await n.meta.saveItem(`object`,e.name,r),this.adapter.invalidateCache(`object:${e.name}`)}async deleteObject(e){await this.adapter.getClient().meta.saveItem(`object`,e,{name:e,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`object:${e}`)}async saveFields(e,t){let n=this.adapter.getClient(),r={};try{let t=await n.meta.getItem(`object`,e);r=t?.item??t??{}}catch{}let i={...r,name:e,fields:t.map(ko)};await n.meta.saveItem(`object`,e,i),this.adapter.invalidateCache(`object:${e}`)}static diffObjects(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,object:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,object:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,object:t}}return null}static diffFields(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,field:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,field:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,field:t}}return null}};function jo({schema:e}){let t=e.objectName,{objects:n,refresh:r}=E(),i=un(),a=(0,J.useMemo)(()=>(n||[]).find(e=>e.name===t),[n,t]),o=(0,J.useMemo)(()=>a?(Array.isArray(a.fields)?a.fields:Object.values(a.fields||{})).map(Ki):[],[a]),[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(!1),d=s??o,f=(0,J.useRef)(d),p=(0,J.useCallback)(async e=>{let n=f.current;if(c(e),f.current=e,!i){K.error(`Service unavailable — changes saved locally only`);return}let a=Ao.diffFields(n,e),o=a?a.type===`create`?`Field "${a.field.label||a.field.name}" created`:a.type===`update`?`Field "${a.field.label||a.field.name}" updated`:`Field "${a.field.label||a.field.name}" deleted`:`Field configuration updated`;u(!0);try{await i.saveFields(t,e),await r(),K.success(o)}catch(e){c(n),f.current=n,K.error(e?.message||`Failed to save field changes`)}finally{u(!1)}},[i,t,r]);return(0,Y.jsxs)(`div`,{className:`space-y-3`,"data-testid":`field-management-section`,children:[l&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`field-saving-indicator`,children:[(0,Y.jsx)(Ae,{className:`h-4 w-4 animate-spin`}),`Saving field changes…`]}),d.some(e=>e.isSystem)&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground bg-muted/50 rounded-md px-3 py-2`,"data-testid":`system-field-hint`,children:[(0,Y.jsx)(Vt,{className:`h-3.5 w-3.5 shrink-0`}),`System fields (e.g. id, createdAt, updatedAt) are read-only and cannot be edited or deleted.`]}),(0,Y.jsx)(So,{objectName:t,fields:d,onFieldsChange:p})]})}function Mo({schema:e}){let t=e.objectName,[n,r]=(0,J.useState)(`details`),i={type:`object-properties`,id:`${t}-properties`,objectName:t},a={type:`object-field-designer`,id:`${t}-field-designer`,objectName:t},o={type:`object-relationships`,id:`${t}-relationships`,objectName:t},s={type:`object-keys`,id:`${t}-keys`,objectName:t},c={type:`object-data-experience`,id:`${t}-data-experience`,objectName:t},l={type:`object-data-preview`,id:`${t}-data-preview`,objectName:t};return(0,Y.jsx)(`div`,{className:`w-full`,"data-testid":`object-detail-tabs`,children:(0,Y.jsxs)(Tt,{value:n,onValueChange:r,className:`w-full`,children:[(0,Y.jsxs)(vt,{className:`w-full justify-start border-b rounded-none bg-transparent p-0 h-auto`,children:[(0,Y.jsxs)(st,{value:`details`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,Y.jsx)(zt,{className:`h-4 w-4 mr-2`}),`详情`]}),(0,Y.jsxs)(st,{value:`fields`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,Y.jsx)(tt,{className:`h-4 w-4 mr-2`}),`字段`]}),(0,Y.jsxs)(st,{value:`relationships`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,Y.jsx)(ye,{className:`h-4 w-4 mr-2`}),`关联关系`]}),(0,Y.jsxs)(st,{value:`data`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,Y.jsx)(nt,{className:`h-4 w-4 mr-2`}),`数据`]})]}),(0,Y.jsx)(At,{value:`details`,className:`mt-6`,children:(0,Y.jsx)(`div`,{className:`space-y-6`,children:(0,Y.jsx)(T,{schema:i})})}),(0,Y.jsx)(At,{value:`fields`,className:`mt-6`,children:(0,Y.jsx)(`div`,{className:`space-y-6`,children:(0,Y.jsx)(T,{schema:a})})}),(0,Y.jsx)(At,{value:`relationships`,className:`mt-6`,children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(T,{schema:o}),(0,Y.jsx)(T,{schema:s})]})}),(0,Y.jsx)(At,{value:`data`,className:`mt-6`,children:(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(T,{schema:l}),(0,Y.jsx)(T,{schema:c})]})})]})})}var No={namespace:`console`,category:`system`};A.register(`object-detail-tabs`,Mo,{...No,label:`Object Detail Tabs`,icon:`LayoutDashboard`}),A.register(`object-properties`,Yi,{...No,label:`Object Properties`,icon:`Settings2`}),A.register(`object-relationships`,Zi,{...No,label:`Object Relationships`,icon:`Link2`}),A.register(`object-keys`,Qi,{...No,label:`Object Keys`,icon:`KeyRound`}),A.register(`object-data-experience`,$i,{...No,label:`Data Experience`,icon:`LayoutList`}),A.register(`object-data-preview`,ea,{...No,label:`Data Preview`,icon:`Table`}),A.register(`object-field-designer`,jo,{...No,label:`Field Designer`,icon:`Columns`});var Po=(0,J.lazy)(()=>c(()=>import(`./ApiConsolePage-CPV6vWpt.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0,1]),import.meta.url)),Fo=(0,J.lazy)(()=>c(()=>import(`./FlowRunsPage-CJDL4g0k.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0,1]),import.meta.url)),Io=(0,J.lazy)(()=>c(()=>import(`./PublicFormsPage-D7D2WWL7.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0,1]),import.meta.url));function Lo({label:e}){return(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}_n({ref:`developer:api-console`,label:`API Console`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Lo,{label:`API console`}),children:(0,Y.jsx)(Po,{...e})})}),_n({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Lo,{label:`flow runs`}),children:(0,Y.jsx)(Fo,{...e})})}),_n({ref:`developer:public-forms`,label:`Public Forms`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(Lo,{label:`public forms`}),children:(0,Y.jsx)(Io,{...e})})});var Ro=(0,J.lazy)(()=>c(()=>import(`./ProfilePage-BAtKSxuK.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url));function zo({label:e}){return(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}_n({ref:`account:profile_card`,label:`My Profile`,source:`@objectstack/console`,component:e=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(zo,{label:`profile`}),children:(0,Y.jsx)(Ro,{...e})})});var Bo=`/api/v1/auth`;qt(),A.registerLazy(`object-map`,()=>c(()=>import(`./plugin-map-Bid9UXOR.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),A.registerLazy(`map`,()=>c(()=>import(`./plugin-map-Bid9UXOR.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`dashboard`,`metric`,`metric-card`,`object-metric`,`pivot`,`object-pivot`,`dashboard-grid`,`object-data-table`])A.registerLazy(e,()=>c(()=>import(`./plugin-dashboard-C7fxXXeO.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});A.registerLazy(`chart`,()=>c(()=>import(`./plugin-charts-AMObsZz3.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});for(let e of[`object-chart`,`bar-chart`,`pie-chart`,`donut-chart`,`radar-chart`,`scatter-chart`,`line-chart`,`area-chart`,`advanced-chart`,`chart:bar`])A.registerLazy(e,()=>c(()=>import(`./plugin-charts-AMObsZz3.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});A.registerLazy(`object-gantt`,()=>c(()=>import(`./plugin-gantt-BHmpu6VX.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),A.registerLazy(`gantt`,()=>c(()=>import(`./plugin-gantt-BHmpu6VX.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),A.registerLazy(`markdown`,()=>c(()=>import(`./plugin-markdown-BUQOG31j.js`).then(e=>e.n),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),A.registerLazy(`object-timeline`,()=>c(()=>import(`./plugin-timeline-DDrFKEb8.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),A.registerLazy(`timeline`,()=>c(()=>import(`./plugin-timeline-DDrFKEb8.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),A.registerLazy(`object-calendar`,()=>c(()=>import(`./plugin-calendar-DQC9zdKq.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),A.registerLazy(`calendar`,()=>c(()=>import(`./plugin-calendar-DQC9zdKq.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),A.registerLazy(`calendar-view`,()=>c(()=>import(`./plugin-calendar-DQC9zdKq.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),A.registerLazy(`object-kanban`,()=>c(()=>import(`./plugin-kanban-DOsTOpJz.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),A.registerLazy(`kanban`,()=>c(()=>import(`./plugin-kanban-DOsTOpJz.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`kanban-ui`,`kanban-enhanced`])A.registerLazy(e,()=>c(()=>import(`./plugin-kanban-DOsTOpJz.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`});A.registerLazy(`report`,()=>c(()=>import(`./plugin-report-FxG9jOvy.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});for(let e of[`report-viewer`,`spec-report`])A.registerLazy(e,()=>c(()=>import(`./plugin-report-FxG9jOvy.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});je();var Vo=``.replace(/\/+$/,``);Promise.all([pn(Vo),Wi(Bo)]).finally(()=>{bn.createRoot(document.getElementById(`root`)).render((0,Y.jsx)(J.StrictMode,{children:(0,Y.jsx)(hn,{pwa:{enabled:!0,name:fn(),shortName:mn()},children:(0,Y.jsx)(j,{loadLanguage:Vi,children:(0,Y.jsx)(Bi,{})})})}))});export{br as a,Tr as i,Jr as n,Lr as r,Do as t};