@object-ui/console 3.0.1 → 3.0.3

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 (127) hide show
  1. package/dist/assets/{AuditLogPage-BQW_Xbnm.js → AuditLogPage-CyY7VZJW.js} +1 -1
  2. package/dist/assets/AuditLogPage-CyY7VZJW.js.br +0 -0
  3. package/dist/assets/AuditLogPage-CyY7VZJW.js.gz +0 -0
  4. package/dist/assets/DashboardView-DSh9LYBb.js +1 -0
  5. package/dist/assets/DashboardView-DSh9LYBb.js.br +0 -0
  6. package/dist/assets/DashboardView-DSh9LYBb.js.gz +0 -0
  7. package/dist/assets/{ForgotPasswordPage-zr9S5vrE.js → ForgotPasswordPage-DUfjj-wh.js} +1 -1
  8. package/dist/assets/{KanbanEnhanced-BlGp--J7.js → KanbanEnhanced-ZOndyXyg.js} +1 -1
  9. package/dist/assets/KanbanEnhanced-ZOndyXyg.js.br +0 -0
  10. package/dist/assets/KanbanEnhanced-ZOndyXyg.js.gz +0 -0
  11. package/dist/assets/{KanbanImpl-B5wWMXrJ.js → KanbanImpl-BsMtStI7.js} +1 -1
  12. package/dist/assets/KanbanImpl-BsMtStI7.js.br +0 -0
  13. package/dist/assets/KanbanImpl-BsMtStI7.js.gz +0 -0
  14. package/dist/assets/{LoginPage-H688gsah.js → LoginPage-2CoFvwsL.js} +1 -1
  15. package/dist/assets/{OrgManagementPage-x3qIkxHL.js → OrgManagementPage-BJt5Iiun.js} +1 -1
  16. package/dist/assets/OrgManagementPage-BJt5Iiun.js.br +0 -0
  17. package/dist/assets/OrgManagementPage-BJt5Iiun.js.gz +0 -0
  18. package/dist/assets/PageView-bHvRhycc.js +1 -0
  19. package/dist/assets/PageView-bHvRhycc.js.br +0 -0
  20. package/dist/assets/PageView-bHvRhycc.js.gz +0 -0
  21. package/dist/assets/{ProfilePage-DjAiGvFb.js → ProfilePage-MVUfKMrp.js} +1 -1
  22. package/dist/assets/ProfilePage-MVUfKMrp.js.br +0 -0
  23. package/dist/assets/ProfilePage-MVUfKMrp.js.gz +0 -0
  24. package/dist/assets/{RecordDetailView-Bfu7541n.js → RecordDetailView-Sm8_iQw_.js} +1 -1
  25. package/dist/assets/RecordDetailView-Sm8_iQw_.js.br +0 -0
  26. package/dist/assets/RecordDetailView-Sm8_iQw_.js.gz +0 -0
  27. package/dist/assets/{RegisterPage-CR91Lc7x.js → RegisterPage-B9itUVYp.js} +1 -1
  28. package/dist/assets/ReportView-B0D9jx4v.js +1 -0
  29. package/dist/assets/ReportView-B0D9jx4v.js.br +0 -0
  30. package/dist/assets/ReportView-B0D9jx4v.js.gz +0 -0
  31. package/dist/assets/{RoleManagementPage-DnWuzxKJ.js → RoleManagementPage-BRqaeF_L.js} +1 -1
  32. package/dist/assets/RoleManagementPage-BRqaeF_L.js.br +0 -0
  33. package/dist/assets/RoleManagementPage-BRqaeF_L.js.gz +0 -0
  34. package/dist/assets/SearchResultsPage-wlC0eLLr.js +1 -0
  35. package/dist/assets/SearchResultsPage-wlC0eLLr.js.br +0 -0
  36. package/dist/assets/SearchResultsPage-wlC0eLLr.js.gz +0 -0
  37. package/dist/assets/{UserManagementPage-o0_K0dzR.js → UserManagementPage-DOH6ql6-.js} +1 -1
  38. package/dist/assets/UserManagementPage-DOH6ql6-.js.br +0 -0
  39. package/dist/assets/UserManagementPage-DOH6ql6-.js.gz +0 -0
  40. package/dist/assets/{ViewDesignerPage-BbwrZa9D.js → ViewDesignerPage-TCaXYb43.js} +1 -1
  41. package/dist/assets/ViewDesignerPage-TCaXYb43.js.br +0 -0
  42. package/dist/assets/{ViewDesignerPage-BbwrZa9D.js.gz → ViewDesignerPage-TCaXYb43.js.gz} +0 -0
  43. package/dist/assets/{data-adapter-Cn800k4a.js → data-adapter-D15yh-pb.js} +1 -1
  44. package/dist/assets/data-adapter-D15yh-pb.js.br +0 -0
  45. package/dist/assets/data-adapter-D15yh-pb.js.gz +0 -0
  46. package/dist/assets/index-RAPqkKVL.js +9 -0
  47. package/dist/assets/index-RAPqkKVL.js.br +0 -0
  48. package/dist/assets/index-RAPqkKVL.js.gz +0 -0
  49. package/dist/assets/{infrastructure-aS2LF8OZ.js → infrastructure-Di0WqY4l.js} +1 -1
  50. package/dist/assets/infrastructure-Di0WqY4l.js.br +0 -0
  51. package/dist/assets/infrastructure-Di0WqY4l.js.gz +0 -0
  52. package/dist/assets/{plugins-core-CcBSZCjG.js → plugins-core-Cv2TPt86.js} +2 -2
  53. package/dist/assets/plugins-core-Cv2TPt86.js.br +0 -0
  54. package/dist/assets/plugins-core-Cv2TPt86.js.gz +0 -0
  55. package/dist/assets/plugins-views-divN-xXs.js +60 -0
  56. package/dist/assets/plugins-views-divN-xXs.js.br +0 -0
  57. package/dist/assets/plugins-views-divN-xXs.js.gz +0 -0
  58. package/dist/assets/{ui-components-DVonQS7H.js → ui-components-CseD2Dpn.js} +1 -1
  59. package/dist/assets/ui-components-CseD2Dpn.js.br +0 -0
  60. package/dist/assets/ui-components-CseD2Dpn.js.gz +0 -0
  61. package/dist/assets/{ui-layout-BENIRxAF.js → ui-layout-CF_1bNSv.js} +1 -1
  62. package/dist/assets/ui-layout-CF_1bNSv.js.br +0 -0
  63. package/dist/assets/ui-layout-CF_1bNSv.js.gz +0 -0
  64. package/dist/assets/vendor-objectstack-Bifvxvds.js +1 -0
  65. package/dist/assets/vendor-objectstack-Bifvxvds.js.br +0 -0
  66. package/dist/assets/vendor-objectstack-Bifvxvds.js.gz +0 -0
  67. package/dist/assets/{vendor-zod-Dpl-cylz.js → vendor-zod-UZPqlszj.js} +4 -4
  68. package/dist/assets/vendor-zod-UZPqlszj.js.br +0 -0
  69. package/dist/assets/vendor-zod-UZPqlszj.js.gz +0 -0
  70. package/dist/index.html +24 -24
  71. package/dist/index.html.br +0 -0
  72. package/dist/index.html.gz +0 -0
  73. package/dist/stats.html +1 -1
  74. package/package.json +46 -41
  75. package/plugin.d.ts +44 -0
  76. package/plugin.js +62 -0
  77. package/plugin.ts +9 -118
  78. package/dist/assets/AuditLogPage-BQW_Xbnm.js.br +0 -0
  79. package/dist/assets/AuditLogPage-BQW_Xbnm.js.gz +0 -0
  80. package/dist/assets/DashboardView-Dt-4VhH6.js +0 -1
  81. package/dist/assets/DashboardView-Dt-4VhH6.js.br +0 -0
  82. package/dist/assets/DashboardView-Dt-4VhH6.js.gz +0 -0
  83. package/dist/assets/KanbanEnhanced-BlGp--J7.js.br +0 -0
  84. package/dist/assets/KanbanEnhanced-BlGp--J7.js.gz +0 -0
  85. package/dist/assets/KanbanImpl-B5wWMXrJ.js.br +0 -0
  86. package/dist/assets/KanbanImpl-B5wWMXrJ.js.gz +0 -0
  87. package/dist/assets/OrgManagementPage-x3qIkxHL.js.br +0 -0
  88. package/dist/assets/OrgManagementPage-x3qIkxHL.js.gz +0 -0
  89. package/dist/assets/PageView-BRN1h8QD.js +0 -1
  90. package/dist/assets/PageView-BRN1h8QD.js.br +0 -0
  91. package/dist/assets/PageView-BRN1h8QD.js.gz +0 -0
  92. package/dist/assets/ProfilePage-DjAiGvFb.js.br +0 -0
  93. package/dist/assets/ProfilePage-DjAiGvFb.js.gz +0 -0
  94. package/dist/assets/RecordDetailView-Bfu7541n.js.br +0 -0
  95. package/dist/assets/RecordDetailView-Bfu7541n.js.gz +0 -0
  96. package/dist/assets/ReportView-CwWsv2yl.js +0 -1
  97. package/dist/assets/ReportView-CwWsv2yl.js.br +0 -0
  98. package/dist/assets/ReportView-CwWsv2yl.js.gz +0 -0
  99. package/dist/assets/RoleManagementPage-DnWuzxKJ.js.br +0 -0
  100. package/dist/assets/RoleManagementPage-DnWuzxKJ.js.gz +0 -0
  101. package/dist/assets/SearchResultsPage-DBpjAlh2.js +0 -1
  102. package/dist/assets/SearchResultsPage-DBpjAlh2.js.br +0 -0
  103. package/dist/assets/SearchResultsPage-DBpjAlh2.js.gz +0 -0
  104. package/dist/assets/UserManagementPage-o0_K0dzR.js.br +0 -0
  105. package/dist/assets/UserManagementPage-o0_K0dzR.js.gz +0 -0
  106. package/dist/assets/ViewDesignerPage-BbwrZa9D.js.br +0 -0
  107. package/dist/assets/data-adapter-Cn800k4a.js.br +0 -0
  108. package/dist/assets/data-adapter-Cn800k4a.js.gz +0 -0
  109. package/dist/assets/index-BjEGJcpx.js +0 -56
  110. package/dist/assets/index-BjEGJcpx.js.br +0 -0
  111. package/dist/assets/index-BjEGJcpx.js.gz +0 -0
  112. package/dist/assets/infrastructure-aS2LF8OZ.js.br +0 -0
  113. package/dist/assets/infrastructure-aS2LF8OZ.js.gz +0 -0
  114. package/dist/assets/plugins-core-CcBSZCjG.js.br +0 -0
  115. package/dist/assets/plugins-core-CcBSZCjG.js.gz +0 -0
  116. package/dist/assets/plugins-views-DQwkCaaO.js +0 -60
  117. package/dist/assets/plugins-views-DQwkCaaO.js.br +0 -0
  118. package/dist/assets/plugins-views-DQwkCaaO.js.gz +0 -0
  119. package/dist/assets/ui-components-DVonQS7H.js.br +0 -0
  120. package/dist/assets/ui-components-DVonQS7H.js.gz +0 -0
  121. package/dist/assets/ui-layout-BENIRxAF.js.br +0 -0
  122. package/dist/assets/ui-layout-BENIRxAF.js.gz +0 -0
  123. package/dist/assets/vendor-objectstack-DqojdwYW.js +0 -37
  124. package/dist/assets/vendor-objectstack-DqojdwYW.js.br +0 -0
  125. package/dist/assets/vendor-objectstack-DqojdwYW.js.gz +0 -0
  126. package/dist/assets/vendor-zod-Dpl-cylz.js.br +0 -0
  127. package/dist/assets/vendor-zod-Dpl-cylz.js.gz +0 -0
@@ -1 +1 @@
1
- import{r as l,i as it,h as ot,j as Ae}from"./vendor-react-Dy_xkBQQ.js";import{C as we}from"./framework-mHWN965c.js";import{d as ue,c as pe,b as dt}from"./vendor-ui-utils-h6yAcIi9.js";import{aQ as ct,aR as je,aS as Ne,aT as Ce,aU as ke,aV as ut,ar as pt,ap as ce,aW as mt,aX as xt,aY as Be,aj as ht,ak as bt,aZ as gt,a_ as qe,a$ as ft,b0 as _e,b1 as yt,b2 as vt,b3 as Je,b4 as wt,aq as de,b5 as jt,b6 as Nt,b7 as Ct,b8 as kt,b9 as Ue,an as St,ba as He,bb as Qe,bc as et,bd as tt,be as Dt,bf as Tt,bg as Ft,bh as Re,bi as Ge,bj as It,bk as Pt,bl as Et,bm as $t,bn as Ve,bo as Ot,bp as zt,bq as At,br as Mt,bs as Rt,bt as Gt}from"./vendor-icons-CQ8b-fGy.js";var Xe={exports:{}},ye={},Ke;function Ut(){if(Ke)return ye;Ke=1;var o=Symbol.for("react.transitional.element"),A=Symbol.for("react.fragment");function F(C,b,$){var f=null;if($!==void 0&&(f=""+$),b.key!==void 0&&(f=""+b.key),"key"in b){$={};for(var g in b)g!=="key"&&($[g]=b[g])}else $=b;return b=$.ref,{$$typeof:o,type:C,key:f,ref:b!==void 0?b:null,props:$}}return ye.Fragment=A,ye.jsx=F,ye.jsxs=F,ye}var Ye;function Lt(){return Ye||(Ye=1,Xe.exports=Ut()),Xe.exports}var e=Lt();function Se(o,A={}){const{maxHistory:F=50}=A,[C,b]=l.useState(o),$=l.useRef([]),f=l.useRef([]),g=l.useCallback(c=>{b(d=>($.current=[...$.current.slice(-(F-1)),d],f.current=[],c))},[F]),v=l.useCallback(()=>{$.current.length!==0&&b(c=>{const d=[...$.current],j=d.pop();return $.current=d,f.current=[c,...f.current],j})},[]),s=l.useCallback(()=>{f.current.length!==0&&b(c=>{const d=[...f.current],j=d.shift();return f.current=d,$.current=[...$.current,c],j})},[]),y=l.useCallback(c=>{$.current=[],f.current=[],b(c)},[]);return{current:C,canUndo:$.current.length>0,canRedo:f.current.length>0,undoCount:$.current.length,redoCount:f.current.length,push:g,undo:v,redo:s,reset:y}}function De(){const[o,A]=l.useState(!1),[F,C]=l.useState(""),[b,$]=l.useState(""),f=l.useRef(null),g=l.useCallback((y,c)=>(C(y),$(c),A(!0),new Promise(d=>{f.current=d})),[]),v=l.useCallback(()=>{A(!1),f.current?.(!0),f.current=null},[]),s=l.useCallback(()=>{A(!1),f.current?.(!1),f.current=null},[]);return{isOpen:o,title:F,message:b,confirm:g,onConfirm:v,onCancel:s}}function $e(){const[o,A]=l.useState(new Set),F=l.useCallback((g,v=!1)=>{A(s=>{const y=new Set(v?s:[]);return s.has(g)&&v?y.delete(g):y.add(g),y})},[]),C=l.useCallback(g=>{A(new Set([g]))},[]),b=l.useCallback(g=>{A(new Set(g))},[]),$=l.useCallback(()=>{A(new Set)},[]),f=l.useCallback(g=>o.has(g),[o]);return{selectedIds:o,toggle:F,selectOne:C,selectMany:b,clearSelection:$,isSelected:f,count:o.size}}function Te(){const[o,A]=l.useState(null),F=l.useCallback(b=>{A(structuredClone(b))},[]),C=l.useCallback(()=>o?structuredClone(o):null,[o]);return{clipboard:o,copy:F,paste:C,hasContent:o!==null}}function Le(o={}){const{minZoom:A=.25,maxZoom:F=3,zoomStep:C=.1,initialZoom:b=1}=o,[$,f]=l.useState(b),[g,v]=l.useState({x:0,y:0}),s=l.useRef(!1),y=l.useRef({x:0,y:0}),c=l.useCallback(k=>Math.min(F,Math.max(A,+k.toFixed(2))),[A,F]),d=l.useCallback(()=>f(k=>c(k+C)),[c,C]),j=l.useCallback(()=>f(k=>c(k-C)),[c,C]),p=l.useCallback(()=>{f(1),v({x:0,y:0})},[]),x=l.useCallback(k=>f(c(k)),[c]),I=l.useCallback(k=>{if(k.ctrlKey||k.metaKey){k.preventDefault();const E=k.deltaY>0?-C:C;f(N=>c(N+E))}},[c,C]),P=l.useCallback(k=>{if(k.button===1||k.button===0&&k.altKey){k.preventDefault(),s.current=!0,y.current={x:k.clientX,y:k.clientY};const E=L=>{if(!s.current)return;const H=L.clientX-y.current.x,G=L.clientY-y.current.y;y.current={x:L.clientX,y:L.clientY},v(Z=>({x:Z.x+H,y:Z.y+G}))},N=()=>{s.current=!1,document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",N)};document.addEventListener("mousemove",E),document.addEventListener("mouseup",N)}},[]),O={transform:`translate(${g.x}px, ${g.y}px) scale(${$})`,transformOrigin:"0 0"};return{zoom:$,panOffset:g,zoomIn:d,zoomOut:j,resetZoom:p,setZoom:x,handleWheel:I,startPan:P,transformStyle:O}}function Zt(...o){return ue(pe(o))}function Fe({isOpen:o,title:A,message:F,confirmLabel:C="Delete",cancelLabel:b="Cancel",destructive:$=!0,onConfirm:f,onCancel:g}){const v=l.useRef(null);return l.useEffect(()=>{const s=v.current;s&&(o&&!s.open?s.showModal():!o&&s.open&&s.close())},[o]),o?e.jsx("dialog",{ref:v,className:"fixed inset-0 z-50 m-auto rounded-lg border bg-background p-0 shadow-lg backdrop:bg-black/50",onClose:g,"aria-labelledby":"confirm-title","aria-describedby":"confirm-message",children:e.jsxs("div",{className:"w-80 p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[$&&e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-destructive/10",children:e.jsx(jt,{className:"h-5 w-5 text-destructive"})}),e.jsx("h2",{id:"confirm-title",className:"text-lg font-semibold",children:A})]}),e.jsx("p",{id:"confirm-message",className:"text-sm text-muted-foreground mb-6",children:F}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:g,className:"px-4 py-2 text-sm rounded-md border hover:bg-accent",children:b}),e.jsx("button",{onClick:f,className:Zt("px-4 py-2 text-sm rounded-md font-medium",$?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"),autoFocus:!0,children:C})]})]})}):null}function Ht(...o){return ue(pe(o))}function Oe({title:o="Properties",fields:A,onChange:F,className:C}){const[b,$]=l.useState(new Set),f=l.useCallback(v=>{$(s=>{const y=new Set(s);return y.has(v)?y.delete(v):y.add(v),y})},[]),g=A.reduce((v,s)=>{const y=s.group??"General";return v[y]||(v[y]=[]),v[y].push(s),v},{});return e.jsxs("div",{className:Ht("flex flex-col",C),role:"region","aria-label":o,children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:o}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[Object.entries(g).map(([v,s])=>e.jsxs("div",{className:"border-b last:border-b-0",children:[e.jsxs("button",{onClick:()=>f(v),className:"w-full flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50",children:[b.has(v)?e.jsx(Ge,{className:"h-3 w-3"}):e.jsx(Re,{className:"h-3 w-3"}),v]}),!b.has(v)&&e.jsx("div",{className:"px-3 pb-2 space-y-2",children:s.map(y=>e.jsx(Vt,{field:y,onChange:F},y.name))})]},v)),A.length===0&&e.jsx("div",{className:"p-3 text-xs text-muted-foreground text-center",children:"Select an element to edit its properties"})]})]})}function Vt({field:o,onChange:A}){const F=C=>{A(o.name,C)};return e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:o.label}),o.type==="text"&&e.jsx("input",{type:"text",value:String(o.value??""),onChange:C=>F(C.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background"}),o.type==="number"&&e.jsx("input",{type:"number",value:Number(o.value??0),onChange:C=>F(Number(C.target.value)),className:"w-full px-2 py-1 text-xs border rounded bg-background"}),o.type==="boolean"&&e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:!!o.value,onChange:C=>F(C.target.checked),className:"rounded"}),e.jsx("span",{className:"text-xs",children:o.value?"Yes":"No"})]}),o.type==="select"&&e.jsx("select",{value:String(o.value??""),onChange:C=>F(C.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background",children:o.options?.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))}),o.type==="color"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:String(o.value??"#000000"),onChange:C=>F(C.target.value),className:"h-6 w-6 rounded border cursor-pointer"}),e.jsx("span",{className:"text-xs font-mono",children:String(o.value??"#000000")})]}),o.type==="textarea"&&e.jsx("textarea",{value:String(o.value??""),onChange:C=>F(C.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background resize-y",rows:3}),o.description&&e.jsx("p",{className:"text-[0.65rem] text-muted-foreground/70",children:o.description})]})}function Xt(...o){return ue(pe(o))}function Ze({items:o,canvasWidth:A,canvasHeight:F,position:C="bottom-right",size:b=150,className:$}){const f=Math.min(b/A,b/F),g=A*f,v=F*f,s={"top-left":"top-2 left-2","top-right":"top-2 right-2","bottom-left":"bottom-2 left-2","bottom-right":"bottom-2 right-2"};return e.jsx("div",{className:Xt("absolute border rounded bg-background/90 shadow-sm overflow-hidden",s[C],$),role:"img","aria-label":"Canvas minimap",children:e.jsxs("svg",{width:g,height:v,viewBox:`0 0 ${A} ${F}`,children:[e.jsx("rect",{width:A,height:F,fill:"hsl(var(--muted))",opacity:"0.3"}),o.map(y=>e.jsx("rect",{x:y.x,y:y.y,width:y.width,height:y.height,fill:y.selected?"hsl(var(--primary))":y.color??"hsl(var(--foreground) / 0.3)",rx:"2"},y.id))]})})}const at=l.createContext(null);at.displayName="CollaborationContext";function Ie(){return l.useContext(at)}function te(...o){return ue(pe(o))}function Kt({canvas:o={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:A=[],palette:F=Yt,showComponentTree:C=!0,undoRedo:b=!0,propertyEditor:$=!0,readOnly:f=!1,showMinimap:g=!1,onChange:v,className:s}){const y=Se(A),c=y.current,d=l.useCallback(n=>{y.push(n),v?.(n)},[y,v]),j=Le({initialZoom:o.zoom??1}),{zoom:p}=j,x=$e(),I=l.useMemo(()=>{const n=Array.from(x.selectedIds);return n.length>0?n[0]:null},[x.selectedIds]),P=l.useMemo(()=>c.find(n=>n.id===I),[c,I]),O=Te(),k=De(),E=Ie(),N=l.useCallback(n=>{E&&E.sendOperation({...n,userId:E.currentUserId??""})},[E]),[L,H]=l.useState(!0),[G,Z]=l.useState(!0),[Q,Y]=l.useState(g),V=l.useRef(null),q=l.useRef(null),J=l.useCallback(n=>!o.snapToGrid||!o.gridSize?n:Math.round(n/o.gridSize)*o.gridSize,[o.snapToGrid,o.gridSize]),ae=l.useCallback((n,a)=>{if(f)return;const r=F.flatMap(T=>T.items).find(T=>T.type===n),t=r?.defaultSize,i={id:`comp-${Date.now()}`,type:n,label:a,position:{x:100,y:100,width:t?.width??200,height:t?.height??100},props:r?.defaultProps??{}},h=[...c,i];d(h),x.selectOne(i.id),N({type:"insert",elementId:i.id,data:{component:i}})},[c,f,F,d,x,N]),ee=l.useCallback(n=>{if(f)return;const a=c.filter(r=>r.id!==n);d(a),x.isSelected(n)&&x.clearSelection(),N({type:"delete",elementId:n,data:{}})},[c,f,d,x,N]),B=l.useCallback(async()=>{if(f||x.count===0||!await k.confirm("Delete components",`Are you sure you want to delete ${x.count} component${x.count>1?"s":""}?`))return;const n=x.selectedIds,a=c.filter(r=>!n.has(r.id));d(a),x.clearSelection(),n.forEach(r=>{N({type:"delete",elementId:r,data:{}})})},[f,x,k,c,d,N]),le=l.useCallback((n,a)=>{if(f||!I)return;const r=c.map(t=>t.id!==I?t:n==="label"?{...t,label:String(a)}:n==="x"?{...t,position:{...t.position,x:Number(a)}}:n==="y"?{...t,position:{...t.position,y:Number(a)}}:n==="width"?{...t,position:{...t.position,width:Number(a)}}:n==="height"?{...t,position:{...t.position,height:Number(a)}}:{...t,props:{...t.props,[n]:a}});d(r),N({type:"update",elementId:I,data:{[n]:a}})},[f,I,c,d,N]),se=l.useCallback(()=>{const n=x.selectedIds;if(n.size===0)return;const a=c.filter(r=>n.has(r.id));O.copy(a)},[x,c,O]),_=l.useCallback(()=>{if(f)return;const n=O.paste();if(!n||n.length===0)return;let a=0;const r=n.map(i=>({...i,id:`comp-${Date.now()}-${++a}-${Math.random().toString(36).slice(2,7)}`,position:{...i.position,x:i.position.x+20,y:i.position.y+20}})),t=[...c,...r];d(t),x.selectMany(r.map(i=>i.id)),r.forEach(i=>{N({type:"insert",elementId:i.id,data:{component:i}})})},[f,O,c,d,x,N]),ne=l.useCallback((n,a)=>{f||(V.current={id:a.id,startX:n.clientX,startY:n.clientY},n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("text/plain",a.id))},[f]),re=l.useCallback(n=>{n.preventDefault(),n.dataTransfer.dropEffect="move"},[]),w=l.useCallback(n=>{n.preventDefault();const a=V.current;if(!a||f)return;const r=(n.clientX-a.startX)/p,t=(n.clientY-a.startY)/p,i=c.map(h=>h.id!==a.id?h:{...h,position:{...h.position,x:J(h.position.x+r),y:J(h.position.y+t)}});d(i),N({type:"move",elementId:a.id,data:{}}),V.current=null},[f,p,c,d,J,N]),M=l.useMemo(()=>P?[{name:"label",label:"Label",type:"text",value:P.label??"",group:"General"},{name:"x",label:"X",type:"number",value:P.position.x,group:"Position"},{name:"y",label:"Y",type:"number",value:P.position.y,group:"Position"},{name:"width",label:"Width",type:"number",value:P.position.width,group:"Size"},{name:"height",label:"Height",type:"number",value:P.position.height,group:"Size"}]:[],[P]),m=l.useMemo(()=>c.map(n=>({id:n.id,x:n.position.x,y:n.position.y,width:typeof n.position.width=="number"?n.position.width:100,height:typeof n.position.height=="number"?n.position.height:50,selected:x.isSelected(n.id)})),[c,x]);return l.useEffect(()=>{const n=q.current;if(!n)return;const a=r=>{const t=["INPUT","TEXTAREA","SELECT"].includes(r.target.tagName),i=r.ctrlKey||r.metaKey;if((r.key==="Delete"||r.key==="Backspace")&&x.count>0&&!t){r.preventDefault(),B();return}if(r.key==="Escape"){x.clearSelection();return}if(!t){if(i&&r.key==="z"&&!r.shiftKey&&b&&!f){r.preventDefault(),y.undo();return}if(i&&(r.key==="z"&&r.shiftKey||r.key==="y")&&b&&!f){r.preventDefault(),y.redo();return}if(i&&r.key==="c"){r.preventDefault(),se();return}if(i&&r.key==="v"&&!f){r.preventDefault(),_();return}if(i&&r.key==="a"){r.preventDefault(),x.selectMany(c.map(h=>h.id));return}}};return n.addEventListener("keydown",a),()=>n.removeEventListener("keydown",a)},[x,B,b,f,y,se,_,c]),e.jsxs("div",{ref:q,tabIndex:0,className:te("flex h-full w-full border rounded-lg overflow-hidden bg-background",s),children:[!f&&e.jsx("div",{className:te("border-r bg-muted/30 flex flex-col transition-[width] duration-200",L?"w-60":"w-0 overflow-hidden"),role:"region","aria-label":"Component palette",children:L&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:"Components"}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:F.map(n=>e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground px-2 py-1 uppercase",children:n.label}),n.items.map(a=>e.jsxs("button",{onClick:()=>ae(a.type,a.label),className:"w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-accent text-left",children:[e.jsx(ce,{className:"h-3 w-3"}),a.label]},a.type))]},n.name))})]})}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 border-b bg-muted/20",role:"toolbar","aria-label":"Designer toolbar",children:[!f&&e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:L?"Collapse palette":"Expand palette","aria-label":L?"Collapse palette":"Expand palette",onClick:()=>H(n=>!n),children:e.jsx(Nt,{className:te("h-4 w-4",!L&&"rotate-180")})}),b&&!f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-5 bg-border mx-1"}),e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",!y.canUndo&&"opacity-40 pointer-events-none"),title:"Undo (Ctrl+Z)","aria-label":"Undo",disabled:!y.canUndo,onClick:()=>y.undo(),children:e.jsx(je,{className:"h-4 w-4"})}),e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",!y.canRedo&&"opacity-40 pointer-events-none"),title:"Redo (Ctrl+Shift+Z)","aria-label":"Redo",disabled:!y.canRedo,onClick:()=>y.redo(),children:e.jsx(Ne,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!f&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",x.count===0&&"opacity-40 pointer-events-none"),title:"Copy (Ctrl+C)","aria-label":"Copy",disabled:x.count===0,onClick:se,children:e.jsx(Ce,{className:"h-4 w-4"})}),e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",!O.hasContent&&"opacity-40 pointer-events-none"),title:"Paste (Ctrl+V)","aria-label":"Paste",disabled:!O.hasContent,onClick:_,children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!f&&e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",x.count===0&&"opacity-40 pointer-events-none"),title:"Delete selected","aria-label":"Delete selected",disabled:x.count===0,onClick:B,children:e.jsx(de,{className:"h-4 w-4"})}),e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:"Preview","aria-label":"Preview",children:e.jsx(Je,{className:"h-4 w-4"})}),e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",Q&&"bg-accent"),title:"Toggle minimap","aria-label":"Toggle minimap",onClick:()=>Y(n=>!n),children:e.jsx(qe,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{className:"p-1 rounded hover:bg-accent text-xs","aria-label":"Zoom out",onClick:j.zoomOut,children:e.jsx(Ct,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-xs text-muted-foreground w-10 text-center",children:[Math.round(p*100),"%"]}),e.jsx("button",{className:"p-1 rounded hover:bg-accent text-xs","aria-label":"Zoom in",onClick:j.zoomIn,children:e.jsx(ce,{className:"h-3 w-3"})}),e.jsx("button",{className:"p-1 rounded hover:bg-accent text-xs","aria-label":"Reset zoom",onClick:j.resetZoom,children:e.jsx(kt,{className:"h-3 w-3"})})]}),C&&e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:G?"Collapse panel":"Expand panel","aria-label":G?"Collapse panel":"Expand panel",onClick:()=>Z(n=>!n),children:e.jsx(Ue,{className:te("h-4 w-4",!G&&"rotate-180")})})]}),e.jsx("div",{className:"flex-1 overflow-auto bg-muted/10 p-4 relative",role:"region","aria-label":"Design canvas",onWheel:j.handleWheel,onMouseDown:j.startPan,onDragOver:re,onDrop:w,children:e.jsxs("div",{className:"relative bg-background border rounded shadow-sm mx-auto",style:{width:o.width*p,height:o.height*p,transform:`translate(${j.panOffset.x}px, ${j.panOffset.y}px)`,backgroundImage:o.showGrid?"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)":void 0,backgroundSize:o.showGrid&&o.gridSize?`${o.gridSize*p}px ${o.gridSize*p}px`:void 0},children:[c.map(n=>{const a=x.isSelected(n.id);return e.jsxs("div",{draggable:!f,onDragStart:r=>ne(r,n),className:te("absolute border rounded cursor-move select-none transition-shadow",a?"border-primary ring-2 ring-primary/20 shadow-md":"border-border hover:border-primary/50"),style:{left:n.position.x*p,top:n.position.y*p,width:typeof n.position.width=="number"?n.position.width*p:n.position.width,height:typeof n.position.height=="number"?n.position.height*p:n.position.height},onClick:r=>x.toggle(n.id,r.shiftKey),children:[e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted/50 text-xs border-b",children:[e.jsx(_e,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:n.label??n.type}),!f&&e.jsx("button",{onClick:r=>{r.stopPropagation(),ee(n.id)},className:"ml-auto p-0.5 rounded hover:bg-destructive/10","aria-label":`Delete ${n.label??n.type}`,children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]}),e.jsx("div",{className:"p-2 text-xs text-muted-foreground",children:n.type})]},n.id)}),Q&&e.jsx(Ze,{items:m,canvasWidth:o.width,canvasHeight:o.height})]})})]}),C&&e.jsx("div",{className:te("border-l bg-muted/30 flex flex-col transition-[width] duration-200",G?"w-60":"w-0 overflow-hidden"),role:"region","aria-label":"Component tree",children:G&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-3 border-b font-medium text-sm flex items-center gap-2",children:[e.jsx(St,{className:"h-4 w-4"}),"Component Tree"]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:c.length===0?e.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."}):c.map(n=>e.jsx("button",{onClick:a=>x.toggle(n.id,a.shiftKey),className:te("w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded text-left",x.isSelected(n.id)?"bg-accent":"hover:bg-accent/50"),children:e.jsx("span",{className:"truncate",children:n.label??n.type})},n.id))}),$&&P?e.jsx("div",{className:"border-t",children:e.jsx(Oe,{title:`Properties – ${P.label??P.type}`,fields:M,onChange:le})}):P&&e.jsxs("div",{className:"border-t p-3",children:[e.jsx("div",{className:"text-xs font-medium mb-2",children:"Properties"}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsxs("div",{children:["Type: ",P.type]}),e.jsxs("div",{children:["ID: ",P.id]}),e.jsxs("div",{children:["Position: ",P.position.x,","," ",P.position.y]}),e.jsxs("div",{children:["Size: ",P.position.width," ×"," ",P.position.height]})]})]})]})}),e.jsx(Fe,{isOpen:k.isOpen,title:k.title,message:k.message,onConfirm:k.onConfirm,onCancel:k.onCancel})]})}const Yt=[{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 Me(...o){return ue(pe(o))}function Wt(o,A=4,F=280,C=250,b=50,$=50){return o.map((f,g)=>({...f,position:{x:b+g%A*F,y:$+Math.floor(g/A)*C}}))}function Bt({entities:o=[],relationships:A=[],canvas:F={width:1200,height:800,showGrid:!0},showRelationshipLabels:C=!0,readOnly:b=!1,onEntitiesChange:$,onRelationshipsChange:f,className:g}){const v=l.useRef(null),s=Se({entities:o,relationships:A},{maxHistory:50}),{entities:y,relationships:c}=s.current,d=l.useCallback(t=>{s.push(t),$?.(t.entities),f?.(t.relationships)},[s,$,f]),j=De(),p=$e(),x=p.count>0?Array.from(p.selectedIds)[0]:null,I=Te(),P=Le({minZoom:.25,maxZoom:3,zoomStep:.1}),O=Ie(),[k,E]=l.useState(!0),[N,L]=l.useState(!0),[H,G]=l.useState(null),[Z,Q]=l.useState(""),Y=l.useRef(null),V=l.useCallback(()=>{if(b)return;const t=s.current,i={id:`entity-${Date.now()}`,name:`new_entity_${t.entities.length+1}`,label:`New Entity ${t.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+t.entities.length%4*280,y:50+Math.floor(t.entities.length/4)*250}},h={entities:[...t.entities,i],relationships:t.relationships};d(h),p.selectOne(i.id),O?.sendOperation({type:"insert",userId:O?.currentUserId??"",elementId:i.id,data:{name:i.name,label:i.label}})},[b,s,d,p,O]),q=l.useCallback(async t=>{if(b)return;const i=y.find(R=>R.id===t);if(!await j.confirm("Delete Entity",`Are you sure you want to delete "${i?.label??t}"? This action cannot be undone.`))return;const h=s.current,T={entities:h.entities.filter(R=>R.id!==t),relationships:h.relationships.filter(R=>R.sourceEntity!==t&&R.targetEntity!==t)};d(T),p.isSelected(t)&&p.clearSelection(),O?.sendOperation({type:"delete",userId:O?.currentUserId??"",elementId:t,data:{}})},[b,y,j,s,d,p,O]),J=l.useCallback(async()=>{if(b||p.count===0)return;const t=Array.from(p.selectedIds);if(!await j.confirm("Delete Entities",`Are you sure you want to delete ${t.length} selected entity(s)? This action cannot be undone.`))return;const i=s.current,h=new Set(t),T={entities:i.entities.filter(R=>!h.has(R.id)),relationships:i.relationships.filter(R=>!h.has(R.sourceEntity)&&!h.has(R.targetEntity))};d(T),p.clearSelection()},[b,p,j,s,d]),ae=l.useCallback(()=>{if(b)return;const t=s.current,i={entities:Wt(t.entities),relationships:t.relationships};d(i)},[b,s,d]),ee=l.useCallback(()=>{const t=y.filter(i=>p.isSelected(i.id));t.length>0&&I.copy(t)},[y,p,I]),B=l.useCallback(()=>{if(b)return;const t=I.paste();if(!t||t.length===0)return;const i=s.current,h=t.map((R,ie)=>({...R,id:`entity-${Date.now()}-${ie}`,name:`${R.name}_copy`,label:`${R.label} (Copy)`,position:{x:R.position.x+30,y:R.position.y+30}})),T={entities:[...i.entities,...h],relationships:i.relationships};d(T),p.selectMany(h.map(R=>R.id))},[b,I,s,d,p]),le=l.useCallback(t=>{if(b)return;const i=s.current,h={entities:i.entities.map(T=>{if(T.id!==t)return T;const R={name:`field_${T.fields.length+1}`,type:"text",required:!1};return{...T,fields:[...T.fields,R]}}),relationships:i.relationships};d(h)},[b,s,d]),se=l.useCallback((t,i,h)=>{b||(G({entityId:t,fieldIndex:i}),Q(h))},[b]),_=l.useCallback(()=>{if(!H)return;const t=Z.trim();if(t===""){G(null);return}const i=s.current,h={entities:i.entities.map(T=>{if(T.id!==H.entityId)return T;const R=T.fields.map((ie,ge)=>ge===H.fieldIndex?{...ie,name:t}:ie);return{...T,fields:R}}),relationships:i.relationships};d(h),G(null)},[H,Z,s,d]),ne=l.useCallback(()=>{G(null)},[]),re=l.useCallback((t,i)=>{if(b||!y.find(T=>T.id===i))return;const h=t.target.getBoundingClientRect();Y.current={entityId:i,offsetX:t.clientX-h.left,offsetY:t.clientY-h.top},t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",i)},[b,y]),w=l.useCallback(t=>{t.preventDefault(),t.dataTransfer.dropEffect="move"},[]),M=l.useCallback(t=>{if(t.preventDefault(),!Y.current)return;const i=t.currentTarget.getBoundingClientRect(),h=P.zoom,T=(t.clientX-i.left-P.panOffset.x)/h-Y.current.offsetX,R=(t.clientY-i.top-P.panOffset.y)/h-Y.current.offsetY,ie=s.current,ge={entities:ie.entities.map(fe=>fe.id===Y.current.entityId?{...fe,position:{x:Math.max(0,Math.round(T)),y:Math.max(0,Math.round(R))}}:fe),relationships:ie.relationships};d(ge),Y.current=null},[P.zoom,P.panOffset,s,d]),m=x?y.find(t=>t.id===x):null,n=m?[{name:"name",label:"Name",type:"text",value:m.name,group:"General"},{name:"label",label:"Label",type:"text",value:m.label,group:"General"},{name:"description",label:"Description",type:"textarea",value:m.description??"",group:"General"},{name:"color",label:"Color",type:"color",value:m.color??"#3b82f6",group:"Appearance"},{name:"position.x",label:"X Position",type:"number",value:m.position.x,group:"Position"},{name:"position.y",label:"Y Position",type:"number",value:m.position.y,group:"Position"}]:[],a=l.useCallback((t,i)=>{if(!x)return;const h=s.current,T={entities:h.entities.map(R=>R.id!==x?R:t==="position.x"?{...R,position:{...R.position,x:Number(i)}}:t==="position.y"?{...R,position:{...R.position,y:Number(i)}}:{...R,[t]:i}),relationships:h.relationships};d(T)},[x,s,d]);l.useEffect(()=>{const t=v.current;if(!t)return;const i=h=>{const T=h.target.tagName;if(T==="INPUT"||T==="TEXTAREA"||T==="SELECT")return;const R=h.ctrlKey||h.metaKey;R&&h.key==="z"?(h.preventDefault(),s.undo()):R&&(h.key==="y"||h.shiftKey&&h.key==="Z")?(h.preventDefault(),s.redo()):R&&h.key==="c"?(h.preventDefault(),ee()):R&&h.key==="v"?(h.preventDefault(),B()):(h.key==="Delete"||h.key==="Backspace")&&p.count>0?(h.preventDefault(),J()):h.key==="Escape"&&(p.clearSelection(),G(null))};return t.addEventListener("keydown",i),()=>t.removeEventListener("keydown",i)},[s,ee,B,J,p]);const r=y.map(t=>({id:t.id,x:t.position.x,y:t.position.y,width:240,height:40+t.fields.length*24,color:t.color,selected:p.isSelected(t.id)}));return e.jsxs("div",{ref:v,tabIndex:0,className:Me("flex h-full w-full border rounded-lg overflow-hidden bg-background",g),children:[e.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[e.jsxs("div",{role:"toolbar","aria-label":"Designer toolbar",className:"flex items-center gap-2 p-2 border-b bg-muted/20 flex-wrap",children:[e.jsx(He,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-sm",children:"Data Model Designer"}),e.jsxs("div",{className:"flex items-center gap-1 ml-2 border-l pl-2",children:[e.jsx("button",{onClick:()=>s.undo(),disabled:!s.canUndo,"aria-label":"Undo",title:"Undo (Ctrl+Z)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(je,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>s.redo(),disabled:!s.canRedo,"aria-label":"Redo",title:"Redo (Ctrl+Y)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-1 border-l pl-2",children:[e.jsx("button",{onClick:P.zoomOut,"aria-label":"Zoom Out",title:"Zoom Out",className:"p-1 rounded hover:bg-accent",children:e.jsx(Qe,{className:"h-3.5 w-3.5"})}),e.jsxs("span",{className:"text-xs tabular-nums w-10 text-center",children:[Math.round(P.zoom*100),"%"]}),e.jsx("button",{onClick:P.zoomIn,"aria-label":"Zoom In",title:"Zoom In",className:"p-1 rounded hover:bg-accent",children:e.jsx(et,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:P.resetZoom,"aria-label":"Reset Zoom",title:"Reset Zoom",className:"p-1 rounded hover:bg-accent",children:e.jsx(tt,{className:"h-3 w-3"})})]}),!b&&e.jsxs("div",{className:"flex items-center gap-1 border-l pl-2",children:[e.jsx("button",{onClick:ee,disabled:p.count===0,"aria-label":"Copy",title:"Copy (Ctrl+C)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(Ce,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:B,disabled:!I.hasContent,"aria-label":"Paste",title:"Paste (Ctrl+V)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(ke,{className:"h-3.5 w-3.5"})})]}),!b&&e.jsxs("button",{onClick:ae,"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:[e.jsx(Dt,{className:"h-3 w-3"})," Auto Layout"]}),e.jsx("div",{className:"flex-1"}),O?.isConnected&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",role:"status","aria-label":"Collaboration active",children:[e.jsx(Tt,{className:"h-3 w-3"}),e.jsxs("span",{children:[O.users.length," user",O.users.length!==1?"s":""]})]}),p.count>1&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[p.count," selected"]}),!b&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:V,"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:[e.jsx(ce,{className:"h-3 w-3"})," Add Entity"]}),e.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:[e.jsx(Ft,{className:"h-3 w-3"})," Add Relationship"]})]})]}),e.jsxs("div",{role:"region","aria-label":"Canvas",className:"flex-1 overflow-auto bg-muted/10 p-4 relative",onWheel:P.handleWheel,onMouseDown:P.startPan,onDragOver:w,onDrop:M,children:[e.jsxs("div",{className:"relative",style:{width:F.width,minHeight:F.height,...P.transformStyle,backgroundImage:F.showGrid?"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)":void 0,backgroundSize:F.showGrid?"20px 20px":void 0},children:[e.jsx("svg",{className:"absolute inset-0 pointer-events-none",width:F.width,height:F.height,children:c.map(t=>{const i=y.find(T=>T.id===t.sourceEntity),h=y.find(T=>T.id===t.targetEntity);return!i||!h?null:e.jsxs("g",{children:[e.jsx("line",{x1:i.position.x+120,y1:i.position.y+50,x2:h.position.x+120,y2:h.position.y+50,stroke:"hsl(var(--primary))",strokeWidth:"2",strokeDasharray:t.type==="many-to-many"?"5,5":void 0}),C&&t.label&&e.jsx("text",{x:(i.position.x+h.position.x)/2+120,y:(i.position.y+h.position.y)/2+50-8,textAnchor:"middle",className:"text-xs fill-muted-foreground",children:t.label})]},t.id)})}),y.length===0&&e.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."}),y.map(t=>e.jsxs("div",{role:"group","aria-label":t.label,draggable:!b,onDragStart:i=>re(i,t.id),className:Me("absolute rounded-lg border-2 bg-background shadow-sm w-60 select-none cursor-grab active:cursor-grabbing",p.isSelected(t.id)?"border-primary ring-2 ring-primary/20":"border-border hover:border-primary/50"),style:{left:t.position.x,top:t.position.y},onClick:i=>p.toggle(t.id,i.shiftKey),children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-t-lg font-medium text-sm",style:{backgroundColor:t.color??"hsl(var(--primary) / 0.1)"},children:[e.jsx(He,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"truncate",children:t.label}),!b&&e.jsx("button",{onClick:i=>{i.stopPropagation(),q(t.id)},"aria-label":`Delete ${t.label}`,className:"ml-auto p-0.5 rounded hover:bg-destructive/20",children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]}),e.jsx("div",{className:"px-3 py-1 divide-y",children:t.fields.map((i,h)=>e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs",children:[H&&H.entityId===t.id&&H.fieldIndex===h?e.jsx("input",{type:"text",value:Z,onChange:T=>Q(T.target.value),onBlur:_,onKeyDown:T=>{T.key==="Enter"&&_(),T.key==="Escape"&&ne()},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:T=>T.stopPropagation()}):e.jsxs("span",{className:Me("font-mono cursor-text",i.primaryKey&&"font-bold text-primary"),onClick:T=>{T.stopPropagation(),se(t.id,h,i.name)},title:"Click to edit field name",children:[i.primaryKey&&e.jsx("span",{className:"text-[0.65rem] font-semibold text-primary mr-0.5",children:"PK"}),i.name]}),e.jsx("span",{className:"text-muted-foreground ml-auto",children:i.type}),i.required&&e.jsx("span",{className:"text-destructive",children:"*"})]},`${i.name}-${h}`))}),!b&&e.jsx("div",{className:"px-3 py-1 border-t",children:e.jsxs("button",{onClick:i=>{i.stopPropagation(),le(t.id)},"aria-label":`Add field to ${t.label}`,className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground w-full py-0.5",children:[e.jsx(ce,{className:"h-3 w-3"})," Add Field"]})})]},t.id))]}),N&&y.length>0&&e.jsx(Ze,{items:r,canvasWidth:F.width,canvasHeight:F.height,position:"bottom-right",size:150})]})]}),e.jsxs("div",{className:"w-64 border-l flex flex-col bg-background shrink-0",children:[e.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[e.jsxs("button",{onClick:()=>E(t=>!t),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":k,"aria-controls":"property-editor-panel",children:[k?e.jsx(Re,{className:"h-3 w-3"}):e.jsx(Ge,{className:"h-3 w-3"}),"Properties"]}),k&&e.jsx("div",{id:"property-editor-panel",className:"flex-1 overflow-y-auto",children:e.jsx(Oe,{title:m?m.label:"Properties",fields:n,onChange:a})})]}),e.jsx("div",{className:"border-t",children:e.jsxs("button",{onClick:()=>L(t=>!t),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":N,children:[N?e.jsx(Re,{className:"h-3 w-3"}):e.jsx(Ge,{className:"h-3 w-3"}),"Minimap"]})})]}),e.jsx(Fe,{isOpen:j.isOpen,title:j.title,message:j.message,onConfirm:j.onConfirm,onCancel:j.onCancel,destructive:!0})]})}function Pe(...o){return ue(pe(o))}const be=120,ve=50;function qt(o,A){if(o.length===0)return o;const F=200,C=100,b=new Map,$=new Map;for(const c of o)b.set(c.id,0),$.set(c.id,[]);for(const c of A)b.set(c.target,(b.get(c.target)??0)+1),$.get(c.source)?.push(c.target);const f=[],g=new Set;let v=o.filter(c=>(b.get(c.id)??0)===0).map(c=>c.id);for(v.length===0&&(v=[o[0].id]);v.length>0;){f.push(v);for(const d of v)g.add(d);const c=new Set;for(const d of v)for(const j of $.get(d)??[])g.has(j)||c.add(j);v=Array.from(c)}const s=o.filter(c=>!g.has(c.id)).map(c=>c.id);s.length>0&&f.push(s);const y=new Map;for(let c=0;c<f.length;c++){const d=f[c];for(let j=0;j<d.length;j++)y.set(d[j],{x:80+c*F,y:80+j*C})}return o.map(c=>({...c,position:y.get(c.id)??c.position}))}function _t({processName:o="New Process",nodes:A=[],edges:F=[],lanes:C,canvas:b={width:1400,height:800,showGrid:!0},showMinimap:$=!0,showToolbar:f=!0,readOnly:g=!1,onNodesChange:v,onEdgesChange:s,className:y}){const c=Se({nodes:A,edges:F},{maxHistory:50}),d=c.current.nodes,j=c.current.edges,p=l.useCallback((u,U)=>{c.push({nodes:u,edges:U}),v?.(u),s?.(U)},[c,v,s]),x=De(),I=$e(),P=Te(),O=Le({initialZoom:1}),k=Ie(),[E,N]=l.useState(null),[L,H]=l.useState(!1),[G,Z]=l.useState(null),[Q,Y]=l.useState(null),[V,q]=l.useState(!0),[J,ae]=l.useState(null),[ee,B]=l.useState({x:0,y:0}),le=l.useRef(null),se=l.useRef(v),_=l.useRef(s);se.current=v,_.current=s,l.useEffect(()=>{se.current?.(d),_.current?.(j)},[c.current]);const ne=l.useCallback((u,U)=>{if(g)return;const z={id:`node-${Date.now()}`,type:u,label:U,position:{x:200+d.length*160,y:200}},X=[...d,z];p(X,j),N(z.id),I.selectOne(z.id),k?.sendOperation({type:"insert",elementId:z.id,data:{label:U},userId:k.currentUserId??""})},[d,j,g,p,I,k]),re=l.useCallback(async u=>{if(g)return;const U=d.find(K=>K.id===u);if(!await x.confirm("Delete Node",`Are you sure you want to delete "${U?.label??u}"? This will also remove all connected edges.`))return;const z=d.filter(K=>K.id!==u),X=j.filter(K=>K.source!==u&&K.target!==u);p(z,X),E===u&&N(null),I.clearSelection(),k?.sendOperation({type:"delete",elementId:u,data:{},userId:k.currentUserId??""})},[d,j,E,g,p,x,I,k]),w=l.useCallback(async()=>{if(g||I.count===0||!await x.confirm("Delete Selected Nodes",`Are you sure you want to delete ${I.count} selected node(s) and their connected edges?`))return;const u=I.selectedIds,U=d.filter(X=>!u.has(X.id)),z=j.filter(X=>!u.has(X.source)&&!u.has(X.target));p(U,z),N(null),I.clearSelection()},[d,j,g,p,x,I]),M=l.useCallback(()=>{const u=I.count>0?I.selectedIds:E?new Set([E]):new Set;if(u.size===0)return;const U=d.filter(z=>u.has(z.id));P.copy(U)},[d,E,I,P]),m=l.useCallback(()=>{if(g)return;const u=P.paste();if(!u||u.length===0)return;const U=40,z=u.map(K=>({...K,id:`node-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,position:{x:K.position.x+U,y:K.position.y+U}})),X=[...d,...z];p(X,j),I.selectMany(z.map(K=>K.id)),N(z[0].id)},[g,d,j,P,p,I]),n=l.useCallback(()=>{H(u=>u?(Z(null),!1):!0)},[]),a=l.useCallback(u=>{if(!L)return!1;if(!G)return Z(u),!0;if(G===u)return!0;const U={id:`edge-${Date.now()}`,source:G,target:u},z=[...j,U];return p(d,z),Z(null),H(!1),k?.sendOperation({type:"insert",elementId:U.id,data:{source:G,target:u},userId:k.currentUserId??""}),!0},[L,G,d,j,p,k]),r=l.useCallback(()=>{if(g||d.length===0)return;const u=qt(d,j);p(u,j)},[d,j,g,p]),t=l.useCallback((u,U)=>{if(g||!d.find(X=>X.id===U))return;ae(U);const z=u.target.getBoundingClientRect();B({x:u.clientX-z.left,y:u.clientY-z.top}),u.dataTransfer.effectAllowed="move",u.dataTransfer.setData("text/plain",U)},[g,d]),i=l.useCallback(u=>{if(u.preventDefault(),g||!J)return;const U=u.currentTarget.getBoundingClientRect(),z=O.zoom,X=(u.clientX-U.left-O.panOffset.x)/z-ee.x,K=(u.clientY-U.top-O.panOffset.y)/z-ee.y,W=Math.max(0,Math.round(X/20)*20),xe=Math.max(0,Math.round(K/20)*20),he=d.map(me=>me.id===J?{...me,position:{x:W,y:xe}}:me);p(he,j),ae(null)},[g,J,ee,d,j,O.zoom,O.panOffset,p]),h=l.useCallback(u=>{u.preventDefault(),u.dataTransfer.dropEffect="move"},[]),T=l.useMemo(()=>d.find(u=>u.id===E)??null,[d,E]),R=l.useMemo(()=>T?[{name:"label",label:"Name",type:"text",value:T.label,group:"General"},{name:"type",label:"Type",type:"select",value:T.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:T.description??"",group:"General"}]:[],[T]),ie=l.useCallback((u,U)=>{if(g||!E)return;const z=d.map(X=>X.id===E?{...X,[u]:U}:X);p(z,j)},[g,E,d,j,p]),ge=u=>{switch(u){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"}},fe=l.useMemo(()=>d.map(u=>({id:u.id,x:u.position.x,y:u.position.y,width:be,height:ve,selected:I.isSelected(u.id)||u.id===E})),[d,I,E]);l.useEffect(()=>{const u=le.current;if(!u)return;const U=z=>{const X=z.target?.tagName;if(X==="INPUT"||X==="TEXTAREA"||X==="SELECT")return;const K=z.ctrlKey||z.metaKey;if(K&&z.key==="z"&&!z.shiftKey){z.preventDefault(),c.undo();return}if(K&&z.key==="y"||K&&z.key==="z"&&z.shiftKey){z.preventDefault(),c.redo();return}if(K&&z.key==="c"){z.preventDefault(),M();return}if(K&&z.key==="v"){z.preventDefault(),m();return}if(z.key==="Delete"||z.key==="Backspace"){I.count>0?(z.preventDefault(),w()):E&&(z.preventDefault(),re(E));return}if(z.key==="Escape"){L?(H(!1),Z(null)):(N(null),I.clearSelection());return}};return u.addEventListener("keydown",U),()=>u.removeEventListener("keydown",U)},[E,L,I,c,M,m,re,w]);const st=l.useCallback(u=>{u.target===u.currentTarget&&(N(null),I.clearSelection(),L&&(H(!1),Z(null)))},[L,I]);return e.jsxs("div",{ref:le,tabIndex:0,className:Pe("flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background",y),children:[e.jsx(Fe,{isOpen:x.isOpen,title:x.title,message:x.message,onConfirm:x.onConfirm,onCancel:x.onCancel,destructive:!0}),f&&e.jsxs("div",{className:"flex items-center gap-2 p-2 border-b bg-muted/20",role:"toolbar","aria-label":"Process toolbar",children:[e.jsx(It,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-sm","aria-label":"Process name",children:o}),k?.isConnected&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",role:"status","aria-label":"Collaboration active",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-green-500"}),k.users.length," user",k.users.length!==1?"s":""]}),e.jsx("div",{className:"flex-1"}),!g&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>c.undo(),disabled:!c.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:e.jsx(je,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>c.redo(),disabled:!c.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:e.jsx(Ne,{className:"h-3 w-3"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsx("button",{onClick:M,disabled:I.count===0&&!E,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:e.jsx(Ce,{className:"h-3 w-3"})}),e.jsx("button",{onClick:m,disabled:!P.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:e.jsx(ke,{className:"h-3 w-3"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsxs("button",{onClick:n,className:Pe("flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",L&&"bg-primary text-primary-foreground"),title:"Connect nodes","aria-label":"Connect nodes","aria-pressed":L,children:[e.jsx(Pt,{className:"h-3 w-3"})," Connect"]}),e.jsxs("button",{onClick:r,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Auto layout","aria-label":"Auto layout",children:[e.jsx(Et,{className:"h-3 w-3"})," Layout"]}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsx("button",{onClick:O.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:e.jsx(et,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-xs tabular-nums min-w-[3ch] text-center","aria-label":"Zoom level",children:[Math.round(O.zoom*100),"%"]}),e.jsx("button",{onClick:O.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:e.jsx(Qe,{className:"h-3 w-3"})}),e.jsx("button",{onClick:O.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:e.jsx(tt,{className:"h-3 w-3"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsxs("button",{onClick:()=>ne("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:[e.jsx($t,{className:"h-3 w-3 text-green-600"})," Start"]}),e.jsxs("button",{onClick:()=>ne("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:[e.jsx(Ve,{className:"h-3 w-3 text-blue-600"})," Task"]}),e.jsxs("button",{onClick:()=>ne("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:[e.jsx(Ot,{className:"h-3 w-3 text-yellow-600"})," Gateway"]}),e.jsxs("button",{onClick:()=>ne("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:[e.jsx(Ve,{className:"h-3 w-3 text-red-600"})," End"]}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsx("button",{onClick:()=>q(u=>!u),className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:V?"Hide properties":"Show properties","aria-label":V?"Hide property panel":"Show property panel","aria-expanded":V,children:V?e.jsx(Ue,{className:"h-3 w-3"}):e.jsx(zt,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsx("div",{className:"flex-1 overflow-auto bg-muted/10 p-4",role:"region","aria-label":"Process canvas",onWheel:O.handleWheel,onMouseDown:O.startPan,children:e.jsxs("div",{className:"relative",style:{...O.transformStyle,width:b.width,minHeight:b.height,backgroundImage:b.showGrid?"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)":void 0,backgroundSize:b.showGrid?"20px 20px":void 0},onClick:st,onDrop:i,onDragOver:h,children:[e.jsxs("svg",{className:"absolute inset-0 pointer-events-none",width:b.width,height:b.height,children:[e.jsx("defs",{children:e.jsx("marker",{id:"arrowhead",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:e.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"hsl(var(--foreground))"})})}),j.map(u=>{const U=d.find(ze=>ze.id===u.source),z=d.find(ze=>ze.id===u.target);if(!U||!z)return null;U.position.x+be/2;const X=U.position.y+ve/2;z.position.x+be/2;const K=z.position.y+ve/2,W=U.position.x+be,xe=X,he=z.position.x,me=K,nt=(W+he)/2,rt=`M ${W} ${xe} Q ${nt} ${xe}, ${(W+he)/2} ${(xe+me)/2} T ${he} ${me}`;return e.jsxs("g",{children:[e.jsx("path",{d:rt,fill:"none",stroke:"hsl(var(--foreground) / 0.5)",strokeWidth:"2",markerEnd:"url(#arrowhead)"}),u.label&&e.jsx("text",{x:(W+he)/2,y:(xe+me)/2-8,textAnchor:"middle",className:"text-[10px] fill-muted-foreground",children:u.label})]},u.id)})]}),d.length===0&&e.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."}),d.map(u=>{const U=I.isSelected(u.id)||E===u.id,z=G===u.id,X=Q===u.id,K=L||X;return e.jsxs("div",{className:"absolute select-none",style:{left:u.position.x,top:u.position.y},role:"group","aria-label":u.label,draggable:!g&&!L,onDragStart:W=>t(W,u.id),onMouseEnter:()=>Y(u.id),onMouseLeave:()=>Y(null),onClick:W=>{a(u.id)||(W.shiftKey?I.toggle(u.id,!0):(N(u.id),I.selectOne(u.id)))},children:[e.jsx("div",{className:Pe("flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow",ge(u.type),U&&"ring-2 ring-primary shadow-md",z&&"ring-2 ring-blue-400 shadow-lg",L&&!z&&"cursor-crosshair"),children:e.jsx("span",{className:Pe("text-xs font-medium",(u.type==="exclusive-gateway"||u.type==="parallel-gateway"||u.type==="inclusive-gateway"||u.type==="event-based-gateway")&&"-rotate-45"),children:u.label})}),K&&!g&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair",style:{left:-6,top:ve/2-6},title:"Input port",onClick:W=>{W.stopPropagation(),a(u.id)}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair",style:{right:-6,top:ve/2-6},title:"Output port",onClick:W=>{W.stopPropagation(),L?a(u.id):(H(!0),Z(u.id))}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair",style:{left:be/2-6,top:-6},title:"Port",onClick:W=>{W.stopPropagation(),a(u.id)}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair",style:{left:be/2-6,bottom:-6},title:"Port",onClick:W=>{W.stopPropagation(),a(u.id)}})]}),!g&&U&&!L&&e.jsx("button",{onClick:W=>{W.stopPropagation(),re(u.id)},className:"absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow","aria-label":"Delete node",children:e.jsx(de,{className:"h-3 w-3"})})]},u.id)}),$&&d.length>0&&e.jsx(Ze,{items:fe,canvasWidth:b.width??1400,canvasHeight:b.height??800,position:"bottom-right"})]})}),V&&!g&&e.jsx("div",{className:"w-64 border-l bg-background overflow-y-auto flex-shrink-0",role:"complementary","aria-label":"Property panel",children:e.jsx(Oe,{title:T?`Properties: ${T.label}`:"Properties",fields:R,onChange:ie})})]})]})}function oe(...o){return ue(pe(o))}const S={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:o=>`Are you sure you want to delete ${o} element${o>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"},Jt={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}},Qt=[{type:"header",height:80,elements:[]},{type:"detail",height:400,elements:[],repeat:!0},{type:"footer",height:60,elements:[]}];function ea({reportName:o=S.untitledReport,objectName:A,pageSize:F="A4",orientation:C="portrait",margins:b={top:40,right:40,bottom:40,left:40},sections:$=[],showToolbar:f=!0,showPropertyPanel:g=!0,readOnly:v=!1,onSectionsChange:s,className:y}){const c=Se($.length>0?$:Qt),d=c.current,j=l.useCallback(w=>{c.push(w),s?.(w)},[c,s]),p=$e(),x=l.useMemo(()=>{const w=Array.from(p.selectedIds);return w.length>0?w[0]:null},[p.selectedIds]),I=Te(),P=De(),O=Ie(),k=l.useCallback(w=>{O&&O.sendOperation({...w,userId:O.currentUserId??""})},[O]),[E,N]=l.useState(!0),L=l.useRef(null),H=l.useRef(null),G=Jt[F],Z=C==="landscape"?G.height:G.width,Q=C==="landscape"?G.width:G.height,Y=w=>{switch(w){case"header":return S.sectionHeader;case"page-header":return S.sectionPageHeader;case"group-header":return S.sectionGroupHeader;case"detail":return S.sectionDetail;case"group-footer":return S.sectionGroupFooter;case"page-footer":return S.sectionPageFooter;case"footer":return S.sectionFooter;default:return w}},V=l.useMemo(()=>x?d.flatMap(w=>w.elements).find(w=>w.id===x):null,[x,d]),q=l.useCallback((w,M)=>{if(v)return;const m={id:`elem-${Date.now()}`,type:M,position:{x:b.left,y:10,width:200,height:30},properties:{text:M==="text"?"New Text":void 0,field:M==="field"?"field_name":void 0}},n=d.map((a,r)=>r===w?{...a,elements:[...a.elements,m]}:a);j(n),p.selectOne(m.id),k({type:"insert",elementId:m.id,data:{element:m}})},[d,b.left,v,j,p,k]),J=l.useCallback(w=>{if(v)return;const M=d.map(m=>({...m,elements:m.elements.filter(n=>n.id!==w)}));j(M),p.isSelected(w)&&p.clearSelection(),k({type:"delete",elementId:w,data:{}})},[d,v,j,p,k]),ae=l.useCallback(async()=>{if(v||p.count===0||!await P.confirm(S.deleteElementsTitle,S.deleteElementMessage(p.count)))return;const w=p.selectedIds,M=d.map(m=>({...m,elements:m.elements.filter(n=>!w.has(n.id))}));j(M),p.clearSelection(),w.forEach(m=>{k({type:"delete",elementId:m,data:{}})})},[v,p,P,d,j,k]),ee=l.useCallback((w,M)=>{if(v||!x)return;const m=d.map(n=>({...n,elements:n.elements.map(a=>a.id!==x?a:w==="x"?{...a,position:{...a.position,x:Number(M)}}:w==="y"?{...a,position:{...a.position,y:Number(M)}}:w==="width"?{...a,position:{...a.position,width:Number(M)}}:w==="height"?{...a,position:{...a.position,height:Number(M)}}:{...a,properties:{...a.properties,[w]:M}})}));j(m),k({type:"update",elementId:x,data:{[w]:M}})},[v,x,d,j,k]),B=l.useCallback(()=>{const w=p.selectedIds;if(w.size===0)return;const M=d.flatMap(m=>m.elements).filter(m=>w.has(m.id));I.copy(M)},[p,d,I]),le=l.useCallback(()=>{if(v)return;const w=I.paste();if(!w||w.length===0)return;let M=0;const m=w.map(t=>({...t,id:`elem-${Date.now()}-${++M}-${Math.random().toString(36).slice(2,7)}`,position:{...t.position,x:t.position.x+20,y:t.position.y+20}})),n=d.findIndex(t=>t.type==="detail"),a=n>=0?n:0,r=d.map((t,i)=>i===a?{...t,elements:[...t.elements,...m]}:t);j(r),p.selectMany(m.map(t=>t.id)),m.forEach(t=>{k({type:"insert",elementId:t.id,data:{element:t}})})},[v,I,d,j,p,k]),se=l.useCallback((w,M,m)=>{v||(L.current={id:M.id,sectionIndex:m,startX:w.clientX,startY:w.clientY},w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",M.id))},[v]),_=l.useCallback(w=>{w.preventDefault(),w.dataTransfer.dropEffect="move"},[]),ne=l.useCallback((w,M)=>{w.preventDefault();const m=L.current;if(!m||v)return;const n=w.clientX-m.startX,a=w.clientY-m.startY;if(m.sectionIndex===M){const r=d.map((t,i)=>i!==M?t:{...t,elements:t.elements.map(h=>h.id!==m.id?h:{...h,position:{...h.position,x:Math.max(0,h.position.x+n),y:Math.max(0,(typeof h.position.y=="number"?h.position.y:0)+a)}})});j(r)}else{let r=null;const t=d.map((i,h)=>{if(h!==m.sectionIndex)return i;const T=i.elements.find(R=>R.id===m.id);return T&&(r={...T,position:{...T.position,x:Math.max(0,T.position.x+n),y:Math.max(0,10)}}),{...i,elements:i.elements.filter(R=>R.id!==m.id)}});if(r){const i=t.map((h,T)=>T!==M?h:{...h,elements:[...h.elements,r]});j(i)}}k({type:"move",elementId:m.id,data:{}}),L.current=null},[v,d,j,k]),re=l.useMemo(()=>{if(!V)return[];const w=[{name:"x",label:S.propX,type:"number",value:V.position.x,group:S.groupPosition},{name:"y",label:S.propY,type:"number",value:V.position.y,group:S.groupPosition},{name:"width",label:S.propWidth,type:"number",value:V.position.width,group:S.groupSize},{name:"height",label:S.propHeight,type:"number",value:V.position.height,group:S.groupSize}];return V.type==="text"&&w.push({name:"text",label:S.propText,type:"text",value:V.properties.text??"",group:S.groupContent}),V.type==="field"&&w.push({name:"field",label:S.propField,type:"text",value:V.properties.field??"",group:S.groupContent}),w},[V]);return l.useEffect(()=>{const w=H.current;if(!w)return;const M=m=>{const n=["INPUT","TEXTAREA","SELECT"].includes(m.target.tagName),a=m.ctrlKey||m.metaKey;if((m.key==="Delete"||m.key==="Backspace")&&p.count>0&&!n){m.preventDefault(),ae();return}if(m.key==="Escape"){p.clearSelection();return}if(!n){if(a&&m.key==="z"&&!m.shiftKey&&!v){m.preventDefault(),c.undo();return}if(a&&(m.key==="z"&&m.shiftKey||m.key==="y")&&!v){m.preventDefault(),c.redo();return}if(a&&m.key==="c"){m.preventDefault(),B();return}if(a&&m.key==="v"&&!v){m.preventDefault(),le();return}if(a&&m.key==="a"){m.preventDefault();const r=d.flatMap(t=>t.elements).map(t=>t.id);p.selectMany(r);return}}};return w.addEventListener("keydown",M),()=>w.removeEventListener("keydown",M)},[p,ae,v,c,B,le,d]),e.jsxs("div",{ref:H,tabIndex:0,className:oe("flex h-full w-full border rounded-lg overflow-hidden bg-background",y),children:[e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[f&&e.jsxs("div",{role:"toolbar","aria-label":S.designerToolbar,className:"flex items-center gap-2 p-2 border-b bg-muted/20",children:[e.jsx(At,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-sm",children:o}),A&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",A,")"]}),!v&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-5 bg-border mx-1"}),e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",!c.canUndo&&"opacity-40 pointer-events-none"),title:S.undoShortcut,"aria-label":S.undo,disabled:!c.canUndo,onClick:()=>c.undo(),children:e.jsx(je,{className:"h-4 w-4"})}),e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",!c.canRedo&&"opacity-40 pointer-events-none"),title:S.redoShortcut,"aria-label":S.redo,disabled:!c.canRedo,onClick:()=>c.redo(),children:e.jsx(Ne,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!v&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",p.count===0&&"opacity-40 pointer-events-none"),title:S.copyShortcut,"aria-label":S.copy,disabled:p.count===0,onClick:B,children:e.jsx(Ce,{className:"h-4 w-4"})}),e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",!I.hasContent&&"opacity-40 pointer-events-none"),title:S.pasteShortcut,"aria-label":S.paste,disabled:!I.hasContent,onClick:le,children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!v&&e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",p.count===0&&"opacity-40 pointer-events-none"),title:S.deleteSelected,"aria-label":S.deleteSelected,disabled:p.count===0,onClick:ae,children:e.jsx(de,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1"}),O?.isConnected&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-green-500"}),S.collaborationConnected,O.users.length>1&&` (${O.users.length})`]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[F," ",C]}),g&&e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:E?S.collapsePanel:S.expandPanel,"aria-label":E?S.collapsePanel:S.expandPanel,onClick:()=>N(w=>!w),children:e.jsx(Ue,{className:oe("h-4 w-4",!E&&"rotate-180")})})]}),e.jsx("div",{role:"region","aria-label":S.reportCanvas,className:"flex-1 overflow-auto bg-muted/10 p-4 flex justify-center",children:e.jsx("div",{className:"bg-white shadow-lg border",style:{width:Z,minHeight:Q},children:d.map((w,M)=>e.jsxs("div",{className:"relative border-b border-dashed border-gray-300",style:{minHeight:w.height},onDragOver:_,onDrop:m=>ne(m,M),children:[e.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:[Y(w.type),w.repeat&&" ↻"]}),!v&&e.jsxs("div",{className:"absolute right-1 top-0 flex items-center gap-0.5",children:[e.jsx("button",{onClick:()=>q(M,"text"),className:"p-0.5 rounded hover:bg-accent",title:S.addText,"aria-label":S.addText,children:e.jsx(Mt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>q(M,"field"),className:"p-0.5 rounded hover:bg-accent",title:S.addField,"aria-label":S.addField,children:e.jsx(ce,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>q(M,"image"),className:"p-0.5 rounded hover:bg-accent",title:S.addImage,"aria-label":S.addImage,children:e.jsx(Be,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>q(M,"chart"),className:"p-0.5 rounded hover:bg-accent",title:S.addChart,"aria-label":S.addChart,children:e.jsx(Rt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>q(M,"table"),className:"p-0.5 rounded hover:bg-accent",title:S.addTable,"aria-label":S.addTable,children:e.jsx(Gt,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"relative",style:{minHeight:w.height,paddingTop:24},children:[w.elements.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground text-center pt-4",children:S.addElementsPrompt}),w.elements.map(m=>{const n=p.isSelected(m.id);return e.jsxs("div",{draggable:!v,onDragStart:a=>se(a,m,M),className:oe("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:m.position.x,top:(typeof m.position.y=="number"?m.position.y:0)+24,width:m.position.width,height:m.position.height},onClick:a=>p.toggle(m.id,a.shiftKey),children:[e.jsxs("span",{className:"text-muted-foreground",children:[m.type==="text"&&(m.properties.text??S.elementText),m.type==="field"&&`{${m.properties.field??"field"}}`,m.type==="image"&&S.elementImage,m.type==="chart"&&S.elementChart,m.type==="table"&&S.elementTable]}),!v&&n&&e.jsx("button",{onClick:a=>{a.stopPropagation(),J(m.id)},className:"absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow","aria-label":S.deleteElement,children:e.jsx(de,{className:"h-2.5 w-2.5"})})]},m.id)})]})]},`${w.type}-${M}`))})})]}),g&&e.jsx("div",{role:"region","aria-label":S.propertiesPanel,className:oe("border-l bg-muted/30 flex flex-col transition-[width] duration-200",E?"w-56":"w-0 overflow-hidden"),children:E&&(x&&V?e.jsx(Oe,{title:`${S.properties} – ${V.type}`,fields:re,onChange:ee}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:S.properties}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3",children:e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:S.selectElementPrompt})})]}))}),e.jsx(Fe,{isOpen:P.isOpen,title:P.title,message:P.message,onConfirm:P.onConfirm,onCancel:P.onCancel})]})}function Ee(...o){return ue(pe(o))}const D={title:"View Designer",saveView:"Save View",cancel:"Cancel",availableFields:"Available Fields",allFieldsAdded:"All fields added",noColumnsTitle:"No columns added yet. Select fields from the palette to add columns.",columnsCount:o=>`Columns (${o})`,viewType:"View Type",viewName:"View Name",viewNamePlaceholder:"Enter view name...",columnProperties:"Column Properties",selectColumnPrompt:"Select a column to edit its properties",labelField:"Label",widthField:"Width",widthPlaceholder:"auto",fieldLabel:"Field:",addFilter:"Add Filter",addSort:"Add Sort",valuePlaceholder:"Value",asc:"Asc",desc:"Desc",selectField:"Select field...",moveUp:"Move up",moveDown:"Move down",moveColumnUp:"Move column up",moveColumnDown:"Move column down",hideColumn:"Hide column",showColumn:"Show column",toggleVisibility:"Toggle column visibility",removeColumn:"Remove column",copyColumn:"Copy column",pasteColumn:"Paste column",deleteColumnTitle:"Delete Column",deleteColumnMessage:o=>`Are you sure you want to delete the column "${o}"? This action cannot be undone.`,undo:"Undo (Ctrl+Z)",redo:"Redo (Ctrl+Y)",gridOptionsHint:"Grid view uses the columns configured above.",groupByField:"Group By Field",startDateField:"Start Date Field",titleField:"Title Field",latitudeField:"Latitude Field",longitudeField:"Longitude Field",imageField:"Image Field",dateField:"Date Field"},We=[{type:"grid",label:"Grid",icon:mt},{type:"kanban",label:"Kanban",icon:xt},{type:"gallery",label:"Gallery",icon:Be},{type:"calendar",label:"Calendar",icon:ht},{type:"timeline",label:"Timeline",icon:bt},{type:"gantt",label:"Gantt",icon:gt},{type:"map",label:"Map",icon:qe}],ta=[{value:"equals",label:"="},{value:"contains",label:"Contains"},{value:"startsWith",label:"Starts with"},{value:"gt",label:">"},{value:"lt",label:"<"},{value:"gte",label:">="},{value:"lte",label:"<="},{value:"ne",label:"!="}];function lt({objectName:o,viewId:A,viewLabel:F="",viewType:C="grid",columns:b=[],filters:$=[],sort:f=[],availableFields:g=[],options:v={},readOnly:s=!1,onSave:y,onCancel:c,className:d}){const j=l.useRef(null),p=Se({columns:b,filters:$,sort:f,viewType:C,viewLabel:F,options:v}),{columns:x,filters:I,sort:P,viewType:O,viewLabel:k,options:E}=p.current,N=l.useCallback(a=>{p.push({...p.current,...a})},[p]),L=Te(),H=De(),G=Ie(),[Z,Q]=l.useState(null),[Y,V]=l.useState("columns"),q=l.useMemo(()=>{const a=new Set(x.map(r=>r.field));return g.filter(r=>!a.has(r.name))},[g,x]),J=l.useCallback(a=>{if(s)return;const r=g.find(i=>i.name===a),t={field:a,label:r?.label??a,visible:!0,order:x.length};N({columns:[...x,t]}),G?.sendOperation({type:"insert",userId:G.currentUserId??"",elementId:a,data:{column:t}})},[g,x,s,N,G]),ae=l.useCallback(async a=>{if(s)return;const r=x[a];!r||!await H.confirm(D.deleteColumnTitle,D.deleteColumnMessage(r.label||r.field))||(N({columns:x.filter((t,i)=>i!==a)}),Z===a&&Q(null),G?.sendOperation({type:"delete",userId:G.currentUserId??"",elementId:r.field,data:{}}))},[s,x,H,N,Z,G]),ee=l.useCallback(a=>{s||N({columns:x.map((r,t)=>t===a?{...r,visible:!r.visible}:r)})},[s,x,N]),B=l.useCallback((a,r)=>{if(s)return;const t=r==="up"?a-1:a+1;if(t<0||t>=x.length)return;const i=[...x],h=i[a];i[a]=i[t],i[t]=h,N({columns:i}),Q(t)},[s,x,N]),le=l.useCallback(()=>{s||g.length===0||N({filters:[...I,{field:g[0].name,operator:"equals",value:""}]})},[s,g,I,N]),se=l.useCallback(a=>{s||N({filters:I.filter((r,t)=>t!==a)})},[s,I,N]),_=l.useCallback((a,r)=>{s||N({filters:I.map((t,i)=>i===a?{...t,...r}:t)})},[s,I,N]),ne=l.useCallback(()=>{s||g.length===0||N({sort:[...P,{field:g[0].name,direction:"asc"}]})},[s,g,P,N]),re=l.useCallback(a=>{s||N({sort:P.filter((r,t)=>t!==a)})},[s,P,N]),w=l.useCallback((a,r)=>{s||N({sort:P.map((t,i)=>i===a?{...t,...r}:t)})},[s,P,N]),M=l.useCallback(()=>{Z===null||!x[Z]||L.copy(x[Z])},[Z,x,L]),m=l.useCallback(()=>{if(s)return;const a=L.paste();if(!a)return;const r={...a,field:`${a.field}_copy`,label:`${a.label||a.field} (Copy)`,order:x.length};N({columns:[...x,r]})},[s,L,x,N]),n=l.useCallback(()=>{y?.({viewId:A,viewLabel:k||`${o} View`,viewType:O,columns:x,filters:I,sort:P,options:E})},[y,A,k,o,O,x,I,P,E]);return l.useEffect(()=>{const a=j.current;if(!a)return;const r=t=>{const i=["INPUT","TEXTAREA","SELECT"].includes(t.target.tagName),h=t.ctrlKey||t.metaKey;if(!i){if(h&&t.key==="z"&&!t.shiftKey&&!s){t.preventDefault(),p.undo();return}if(h&&(t.key==="z"&&t.shiftKey||t.key==="y")&&!s){t.preventDefault(),p.redo();return}if(h&&t.key==="c"){t.preventDefault(),M();return}if(h&&t.key==="v"&&!s){t.preventDefault(),m();return}}};return a.addEventListener("keydown",r),()=>a.removeEventListener("keydown",r)},[s,p,M,m]),e.jsxs("div",{ref:j,tabIndex:-1,className:Ee("flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background",d),children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 border-b bg-muted/20 shrink-0",role:"toolbar",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"font-medium text-sm",children:D.title}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["— ",o]}),G?.isConnected&&G.users.length>1&&e.jsxs("div",{className:"flex items-center gap-1 ml-2",role:"status","aria-label":"Active collaborators",children:[G.users.slice(0,3).map(a=>e.jsx("div",{className:"h-5 w-5 rounded-full text-[10px] font-bold flex items-center justify-center text-white",style:{backgroundColor:a.color},title:a.userName,children:a.userName.charAt(0).toUpperCase()},a.userId)),G.users.length>3&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["+",G.users.length-3]})]}),e.jsx("div",{className:"flex-1"}),!s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:p.undo,disabled:!p.canUndo,className:"p-1.5 rounded hover:bg-accent disabled:opacity-30",title:D.undo,"aria-label":D.undo,"data-testid":"view-designer-undo",children:e.jsx(je,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:p.redo,disabled:!p.canRedo,className:"p-1.5 rounded hover:bg-accent disabled:opacity-30",title:D.redo,"aria-label":D.redo,"data-testid":"view-designer-redo",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"})]}),!s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:M,disabled:Z===null,className:"p-1.5 rounded hover:bg-accent disabled:opacity-30",title:D.copyColumn,"aria-label":D.copyColumn,"data-testid":"view-designer-copy",children:e.jsx(Ce,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:m,disabled:!L.hasContent,className:"p-1.5 rounded hover:bg-accent disabled:opacity-30",title:D.pasteColumn,"aria-label":D.pasteColumn,"data-testid":"view-designer-paste",children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"})]}),!s&&e.jsxs(e.Fragment,{children:[c&&e.jsxs("button",{onClick:c,className:"flex items-center gap-1 px-3 py-1.5 text-xs rounded border border-border hover:bg-accent","data-testid":"view-designer-cancel",children:[e.jsx(ut,{className:"h-3 w-3"})," ",D.cancel]}),e.jsxs("button",{onClick:n,className:"flex items-center gap-1 px-3 py-1.5 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90","data-testid":"view-designer-save",children:[e.jsx(pt,{className:"h-3 w-3"})," ",D.saveView]})]})]}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[!s&&e.jsxs("div",{className:"w-56 border-r bg-muted/30 flex flex-col shrink-0",children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:D.availableFields}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:q.length===0?e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:D.allFieldsAdded}):q.map(a=>e.jsxs("button",{onClick:()=>J(a.name),className:"w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-accent text-left","data-testid":`field-${a.name}`,children:[e.jsx(ce,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:a.label||a.name}),e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:a.type})]},a.name))})]}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"p-3 border-b space-y-3 shrink-0 bg-muted/10",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:D.viewType}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:We.map(({type:a,label:r,icon:t})=>e.jsxs("button",{onClick:()=>!s&&N({viewType:a}),className:Ee("flex items-center gap-2 px-3 py-2 text-sm rounded-md border-2 transition-all font-medium",O===a?"border-primary bg-primary text-primary-foreground shadow-sm":"border-border bg-background hover:border-primary/50 hover:bg-accent"),"data-testid":`view-type-${a}`,children:[e.jsx(t,{className:"h-4 w-4"}),r]},a))})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:D.viewName}),e.jsx("input",{type:"text",value:k,onChange:a=>!s&&N({viewLabel:a.target.value}),placeholder:D.viewNamePlaceholder,className:"px-3 py-2 text-sm border-2 rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-primary focus:border-primary",readOnly:s,"data-testid":"view-label-input"})]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-3",children:x.length===0?e.jsx("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ft,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:D.noColumnsTitle})]})}):e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-2",children:D.columnsCount(x.length)}),x.map((a,r)=>e.jsxs("div",{className:Ee("flex items-center gap-2 px-3 py-2 rounded border transition-colors cursor-pointer",Z===r?"border-primary bg-primary/5 ring-1 ring-primary/20":"border-border hover:border-primary/50",!a.visible&&"opacity-50"),onClick:()=>Q(r),"data-testid":`column-${a.field}`,children:[e.jsx(_e,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-sm font-medium truncate flex-1",children:a.label||a.field}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a.field}),!s&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:t=>{t.stopPropagation(),B(r,"up")},disabled:r===0,className:"p-0.5 rounded hover:bg-accent disabled:opacity-30",title:D.moveUp,"aria-label":D.moveColumnUp,children:e.jsx(yt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),B(r,"down")},disabled:r===x.length-1,className:"p-0.5 rounded hover:bg-accent disabled:opacity-30",title:D.moveDown,"aria-label":D.moveColumnDown,children:e.jsx(vt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),ee(r)},className:"p-0.5 rounded hover:bg-accent",title:a.visible!==!1?D.hideColumn:D.showColumn,"aria-label":D.toggleVisibility,children:a.visible!==!1?e.jsx(Je,{className:"h-3 w-3"}):e.jsx(wt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),ae(r)},className:"p-0.5 rounded hover:bg-destructive/10",title:D.removeColumn,"aria-label":D.removeColumn,children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]})]},`${a.field}-${r}`))]})})]}),e.jsxs("div",{className:"w-64 border-l bg-muted/30 flex flex-col shrink-0",children:[e.jsx("div",{className:"flex border-b shrink-0",role:"tablist",children:["columns","filters","sort","options"].map(a=>e.jsx("button",{onClick:()=>V(a),role:"tab","aria-selected":Y===a,className:Ee("flex-1 px-2 py-2 text-xs font-medium capitalize transition-colors",Y===a?"border-b-2 border-primary text-primary":"text-muted-foreground hover:text-foreground"),children:a},a))}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3",children:[Y==="columns"&&e.jsx("div",{children:Z!==null&&x[Z]?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs font-medium",children:D.columnProperties}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.labelField}),e.jsx("input",{type:"text",value:x[Z].label??"",onChange:a=>{if(s)return;const r=Z;N({columns:x.map((t,i)=>i===r?{...t,label:a.target.value}:t)})},className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",readOnly:s,"data-testid":"column-label-input"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.widthField}),e.jsx("input",{type:"text",value:x[Z].width??"",onChange:a=>{if(s)return;const r=Z,t=a.target.value;N({columns:x.map((i,h)=>h===r?{...i,width:/^\d+$/.test(t)?Number(t):t}:i)})},placeholder:D.widthPlaceholder,className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",readOnly:s,"data-testid":"column-width-input"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[D.fieldLabel," ",e.jsx("span",{className:"font-mono",children:x[Z].field})]})]}):e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:D.selectColumnPrompt})}),Y==="filters"&&e.jsxs("div",{className:"space-y-2",children:[I.map((a,r)=>e.jsxs("div",{className:"space-y-1 p-2 border rounded bg-background","data-testid":`filter-${r}`,children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("select",{value:a.field,onChange:t=>_(r,{field:t.target.value}),className:"flex-1 px-1 py-0.5 text-xs border rounded bg-background",disabled:s,children:g.map(t=>e.jsx("option",{value:t.name,children:t.label||t.name},t.name))}),!s&&e.jsx("button",{onClick:()=>se(r),className:"p-0.5 rounded hover:bg-destructive/10",children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("select",{value:a.operator,onChange:t=>_(r,{operator:t.target.value}),className:"w-24 px-1 py-0.5 text-xs border rounded bg-background",disabled:s,children:ta.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("input",{type:"text",value:a.value??"",onChange:t=>_(r,{value:t.target.value}),placeholder:D.valuePlaceholder,className:"flex-1 px-1 py-0.5 text-xs border rounded bg-background",readOnly:s})]})]},r)),!s&&e.jsxs("button",{onClick:le,className:"w-full flex items-center justify-center gap-1 px-2 py-1.5 text-xs rounded border border-dashed border-border hover:bg-accent","data-testid":"add-filter","aria-label":D.addFilter,children:[e.jsx(ce,{className:"h-3 w-3"})," ",D.addFilter]})]}),Y==="sort"&&e.jsxs("div",{className:"space-y-2",children:[P.map((a,r)=>e.jsxs("div",{className:"flex items-center gap-1 p-2 border rounded bg-background","data-testid":`sort-${r}`,children:[e.jsx("select",{value:a.field,onChange:t=>w(r,{field:t.target.value}),className:"flex-1 px-1 py-0.5 text-xs border rounded bg-background",disabled:s,children:g.map(t=>e.jsx("option",{value:t.name,children:t.label||t.name},t.name))}),e.jsxs("select",{value:a.direction,onChange:t=>w(r,{direction:t.target.value}),className:"w-16 px-1 py-0.5 text-xs border rounded bg-background",disabled:s,children:[e.jsx("option",{value:"asc",children:D.asc}),e.jsx("option",{value:"desc",children:D.desc})]}),!s&&e.jsx("button",{onClick:()=>re(r),className:"p-0.5 rounded hover:bg-destructive/10",children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]},r)),!s&&e.jsxs("button",{onClick:ne,className:"w-full flex items-center justify-center gap-1 px-2 py-1.5 text-xs rounded border border-dashed border-border hover:bg-accent","data-testid":"add-sort","aria-label":D.addSort,children:[e.jsx(ce,{className:"h-3 w-3"})," ",D.addSort]})]}),Y==="options"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-xs font-medium",children:[We.find(a=>a.type===O)?.label??O," Options"]}),O==="kanban"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.groupByField}),e.jsxs("select",{value:E.groupBy??"",onChange:a=>!s&&N({options:{...E,groupBy:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,"data-testid":"kanban-group-by",children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),O==="calendar"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.startDateField}),e.jsxs("select",{value:E.startDateField??"",onChange:a=>!s&&N({options:{...E,startDateField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,"data-testid":"calendar-start-date",children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.titleField}),e.jsxs("select",{value:E.titleField??"",onChange:a=>!s&&N({options:{...E,titleField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,"data-testid":"calendar-title-field",children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]})]}),O==="map"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.latitudeField}),e.jsxs("select",{value:E.latitudeField??"",onChange:a=>!s&&N({options:{...E,latitudeField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.longitudeField}),e.jsxs("select",{value:E.longitudeField??"",onChange:a=>!s&&N({options:{...E,longitudeField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]})]}),O==="gallery"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.imageField}),e.jsxs("select",{value:E.imageField??"",onChange:a=>!s&&N({options:{...E,imageField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),(O==="timeline"||O==="gantt")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.dateField}),e.jsxs("select",{value:E.dateField??E.startDateField??"",onChange:a=>!s&&N({options:{...E,dateField:a.target.value,startDateField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.titleField}),e.jsxs("select",{value:E.titleField??"",onChange:a=>!s&&N({options:{...E,titleField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]})]}),O==="grid"&&e.jsx("div",{className:"text-xs text-muted-foreground text-center py-2",children:D.gridOptionsHint})]})]})]})]}),e.jsx(Fe,{isOpen:H.isOpen,title:H.title,message:H.message,onConfirm:H.onConfirm,onCancel:H.onCancel})]})}we.register("page-designer",Kt,{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}]});we.register("data-model-designer",Bt,{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}]});we.register("process-designer",_t,{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}]});we.register("report-designer",ea,{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}]});we.register("view-designer",lt,{label:"View Designer",category:"Designer",inputs:[{name:"objectName",type:"string",label:"Object Name"},{name:"viewId",type:"string",label:"View ID"},{name:"viewLabel",type:"string",label:"View Label"},{name:"viewType",type:"string",label:"View Type",defaultValue:"grid"},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]});function ra({objects:o}){const A=it(),{objectName:F,viewId:C}=ot(),b=o.find(s=>s.name===F),$=l.useMemo(()=>{if(!b?.fields)return[];const s=b.fields;return Array.isArray(s)?s.map(y=>typeof y=="string"?{name:y,label:y,type:"text"}:{name:y.name,label:y.label||y.name,type:y.type||"text"}):Object.entries(s).map(([y,c])=>({name:y,label:c.label||y,type:c.type||"text"}))},[b]),f=l.useMemo(()=>!C||C==="new"||!b?.list_views?null:b.list_views[C]||null,[C,b]),g=l.useCallback(s=>{console.log("[ViewDesigner] Save view config:",s),dt.success(f?`View "${s.viewLabel}" updated`:`View "${s.viewLabel}" created`),A(-1)},[f,A]),v=l.useCallback(()=>{A(-1)},[A]);return b?Ae.jsx("div",{className:"h-full flex flex-col",children:Ae.jsx(lt,{objectName:b.name,viewId:C==="new"?void 0:C,viewLabel:f?.label??"",viewType:f?.type??"grid",columns:f?.columns?f.columns.map((s,y)=>({field:s,label:$.find(c=>c.name===s)?.label??s,visible:!0,order:y})):[],filters:f?.filter??[],sort:f?.sort?.map(s=>({field:s.field,direction:s.order||s.direction||"asc"}))??[],availableFields:$,options:f?.options??{},onSave:g,onCancel:v,className:"flex-1"})}):Ae.jsxs("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:['Object "',F,'" not found']})}export{ra as ViewDesignerPage};
1
+ import{r as l,i as it,h as ot,j as Ae}from"./vendor-react-Dy_xkBQQ.js";import{C as we}from"./framework-mHWN965c.js";import{d as ue,c as pe,b as dt}from"./vendor-ui-utils-h6yAcIi9.js";import{aQ as ct,aR as je,aS as Ne,aT as Ce,aU as ke,aV as ut,ar as pt,ap as ce,aW as mt,aX as xt,aY as Be,aj as ht,ak as bt,aZ as gt,a_ as qe,a$ as ft,b0 as _e,b1 as yt,b2 as vt,b3 as Je,b4 as wt,aq as de,b5 as jt,b6 as Nt,b7 as Ct,b8 as kt,b9 as Ue,an as St,ba as He,bb as Qe,bc as et,bd as tt,be as Dt,bf as Tt,bg as Ft,bh as Re,bi as Ge,bj as It,bk as Pt,bl as Et,bm as $t,bn as Ve,bo as Ot,bp as zt,bq as At,br as Mt,bs as Rt,bt as Gt}from"./vendor-icons-CQ8b-fGy.js";var Xe={exports:{}},ye={},Ke;function Ut(){if(Ke)return ye;Ke=1;var o=Symbol.for("react.transitional.element"),A=Symbol.for("react.fragment");function F(C,b,$){var f=null;if($!==void 0&&(f=""+$),b.key!==void 0&&(f=""+b.key),"key"in b){$={};for(var g in b)g!=="key"&&($[g]=b[g])}else $=b;return b=$.ref,{$$typeof:o,type:C,key:f,ref:b!==void 0?b:null,props:$}}return ye.Fragment=A,ye.jsx=F,ye.jsxs=F,ye}var Ye;function Lt(){return Ye||(Ye=1,Xe.exports=Ut()),Xe.exports}var e=Lt();function Se(o,A={}){const{maxHistory:F=50}=A,[C,b]=l.useState(o),$=l.useRef([]),f=l.useRef([]),g=l.useCallback(c=>{b(d=>($.current=[...$.current.slice(-(F-1)),d],f.current=[],c))},[F]),v=l.useCallback(()=>{$.current.length!==0&&b(c=>{const d=[...$.current],j=d.pop();return $.current=d,f.current=[c,...f.current],j})},[]),s=l.useCallback(()=>{f.current.length!==0&&b(c=>{const d=[...f.current],j=d.shift();return f.current=d,$.current=[...$.current,c],j})},[]),y=l.useCallback(c=>{$.current=[],f.current=[],b(c)},[]);return{current:C,canUndo:$.current.length>0,canRedo:f.current.length>0,undoCount:$.current.length,redoCount:f.current.length,push:g,undo:v,redo:s,reset:y}}function De(){const[o,A]=l.useState(!1),[F,C]=l.useState(""),[b,$]=l.useState(""),f=l.useRef(null),g=l.useCallback((y,c)=>(C(y),$(c),A(!0),new Promise(d=>{f.current=d})),[]),v=l.useCallback(()=>{A(!1),f.current?.(!0),f.current=null},[]),s=l.useCallback(()=>{A(!1),f.current?.(!1),f.current=null},[]);return{isOpen:o,title:F,message:b,confirm:g,onConfirm:v,onCancel:s}}function $e(){const[o,A]=l.useState(new Set),F=l.useCallback((g,v=!1)=>{A(s=>{const y=new Set(v?s:[]);return s.has(g)&&v?y.delete(g):y.add(g),y})},[]),C=l.useCallback(g=>{A(new Set([g]))},[]),b=l.useCallback(g=>{A(new Set(g))},[]),$=l.useCallback(()=>{A(new Set)},[]),f=l.useCallback(g=>o.has(g),[o]);return{selectedIds:o,toggle:F,selectOne:C,selectMany:b,clearSelection:$,isSelected:f,count:o.size}}function Te(){const[o,A]=l.useState(null),F=l.useCallback(b=>{A(structuredClone(b))},[]),C=l.useCallback(()=>o?structuredClone(o):null,[o]);return{clipboard:o,copy:F,paste:C,hasContent:o!==null}}function Le(o={}){const{minZoom:A=.25,maxZoom:F=3,zoomStep:C=.1,initialZoom:b=1}=o,[$,f]=l.useState(b),[g,v]=l.useState({x:0,y:0}),s=l.useRef(!1),y=l.useRef({x:0,y:0}),c=l.useCallback(k=>Math.min(F,Math.max(A,+k.toFixed(2))),[A,F]),d=l.useCallback(()=>f(k=>c(k+C)),[c,C]),j=l.useCallback(()=>f(k=>c(k-C)),[c,C]),p=l.useCallback(()=>{f(1),v({x:0,y:0})},[]),x=l.useCallback(k=>f(c(k)),[c]),I=l.useCallback(k=>{if(k.ctrlKey||k.metaKey){k.preventDefault();const E=k.deltaY>0?-C:C;f(N=>c(N+E))}},[c,C]),P=l.useCallback(k=>{if(k.button===1||k.button===0&&k.altKey){k.preventDefault(),s.current=!0,y.current={x:k.clientX,y:k.clientY};const E=L=>{if(!s.current)return;const H=L.clientX-y.current.x,G=L.clientY-y.current.y;y.current={x:L.clientX,y:L.clientY},v(Z=>({x:Z.x+H,y:Z.y+G}))},N=()=>{s.current=!1,document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",N)};document.addEventListener("mousemove",E),document.addEventListener("mouseup",N)}},[]),O={transform:`translate(${g.x}px, ${g.y}px) scale(${$})`,transformOrigin:"0 0"};return{zoom:$,panOffset:g,zoomIn:d,zoomOut:j,resetZoom:p,setZoom:x,handleWheel:I,startPan:P,transformStyle:O}}function Zt(...o){return ue(pe(o))}function Fe({isOpen:o,title:A,message:F,confirmLabel:C="Delete",cancelLabel:b="Cancel",destructive:$=!0,onConfirm:f,onCancel:g}){const v=l.useRef(null);return l.useEffect(()=>{const s=v.current;s&&(o&&!s.open?s.showModal():!o&&s.open&&s.close())},[o]),o?e.jsx("dialog",{ref:v,className:"fixed inset-0 z-50 m-auto rounded-lg border bg-background p-0 shadow-lg backdrop:bg-black/50",onClose:g,"aria-labelledby":"confirm-title","aria-describedby":"confirm-message",children:e.jsxs("div",{className:"w-80 p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[$&&e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-destructive/10",children:e.jsx(jt,{className:"h-5 w-5 text-destructive"})}),e.jsx("h2",{id:"confirm-title",className:"text-lg font-semibold",children:A})]}),e.jsx("p",{id:"confirm-message",className:"text-sm text-muted-foreground mb-6",children:F}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:g,className:"px-4 py-2 text-sm rounded-md border hover:bg-accent",children:b}),e.jsx("button",{onClick:f,className:Zt("px-4 py-2 text-sm rounded-md font-medium",$?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"),autoFocus:!0,children:C})]})]})}):null}function Ht(...o){return ue(pe(o))}function Oe({title:o="Properties",fields:A,onChange:F,className:C}){const[b,$]=l.useState(new Set),f=l.useCallback(v=>{$(s=>{const y=new Set(s);return y.has(v)?y.delete(v):y.add(v),y})},[]),g=A.reduce((v,s)=>{const y=s.group??"General";return v[y]||(v[y]=[]),v[y].push(s),v},{});return e.jsxs("div",{className:Ht("flex flex-col",C),role:"region","aria-label":o,children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:o}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[Object.entries(g).map(([v,s])=>e.jsxs("div",{className:"border-b last:border-b-0",children:[e.jsxs("button",{onClick:()=>f(v),className:"w-full flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50",children:[b.has(v)?e.jsx(Ge,{className:"h-3 w-3"}):e.jsx(Re,{className:"h-3 w-3"}),v]}),!b.has(v)&&e.jsx("div",{className:"px-3 pb-2 space-y-2",children:s.map(y=>e.jsx(Vt,{field:y,onChange:F},y.name))})]},v)),A.length===0&&e.jsx("div",{className:"p-3 text-xs text-muted-foreground text-center",children:"Select an element to edit its properties"})]})]})}function Vt({field:o,onChange:A}){const F=C=>{A(o.name,C)};return e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:o.label}),o.type==="text"&&e.jsx("input",{type:"text",value:String(o.value??""),onChange:C=>F(C.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background"}),o.type==="number"&&e.jsx("input",{type:"number",value:Number(o.value??0),onChange:C=>F(Number(C.target.value)),className:"w-full px-2 py-1 text-xs border rounded bg-background"}),o.type==="boolean"&&e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:!!o.value,onChange:C=>F(C.target.checked),className:"rounded"}),e.jsx("span",{className:"text-xs",children:o.value?"Yes":"No"})]}),o.type==="select"&&e.jsx("select",{value:String(o.value??""),onChange:C=>F(C.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background",children:o.options?.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))}),o.type==="color"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:String(o.value??"#000000"),onChange:C=>F(C.target.value),className:"h-6 w-6 rounded border cursor-pointer"}),e.jsx("span",{className:"text-xs font-mono",children:String(o.value??"#000000")})]}),o.type==="textarea"&&e.jsx("textarea",{value:String(o.value??""),onChange:C=>F(C.target.value),className:"w-full px-2 py-1 text-xs border rounded bg-background resize-y",rows:3}),o.description&&e.jsx("p",{className:"text-[0.65rem] text-muted-foreground/70",children:o.description})]})}function Xt(...o){return ue(pe(o))}function Ze({items:o,canvasWidth:A,canvasHeight:F,position:C="bottom-right",size:b=150,className:$}){const f=Math.min(b/A,b/F),g=A*f,v=F*f,s={"top-left":"top-2 left-2","top-right":"top-2 right-2","bottom-left":"bottom-2 left-2","bottom-right":"bottom-2 right-2"};return e.jsx("div",{className:Xt("absolute border rounded bg-background/90 shadow-sm overflow-hidden",s[C],$),role:"img","aria-label":"Canvas minimap",children:e.jsxs("svg",{width:g,height:v,viewBox:`0 0 ${A} ${F}`,children:[e.jsx("rect",{width:A,height:F,fill:"hsl(var(--muted))",opacity:"0.3"}),o.map(y=>e.jsx("rect",{x:y.x,y:y.y,width:y.width,height:y.height,fill:y.selected?"hsl(var(--primary))":y.color??"hsl(var(--foreground) / 0.3)",rx:"2"},y.id))]})})}const at=l.createContext(null);at.displayName="CollaborationContext";function Ie(){return l.useContext(at)}function te(...o){return ue(pe(o))}function Kt({canvas:o={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:A=[],palette:F=Yt,showComponentTree:C=!0,undoRedo:b=!0,propertyEditor:$=!0,readOnly:f=!1,showMinimap:g=!1,onChange:v,className:s}){const y=Se(A),c=y.current,d=l.useCallback(n=>{y.push(n),v?.(n)},[y,v]),j=Le({initialZoom:o.zoom??1}),{zoom:p}=j,x=$e(),I=l.useMemo(()=>{const n=Array.from(x.selectedIds);return n.length>0?n[0]:null},[x.selectedIds]),P=l.useMemo(()=>c.find(n=>n.id===I),[c,I]),O=Te(),k=De(),E=Ie(),N=l.useCallback(n=>{E&&E.sendOperation({...n,userId:E.currentUserId??""})},[E]),[L,H]=l.useState(!0),[G,Z]=l.useState(!0),[Q,Y]=l.useState(g),V=l.useRef(null),q=l.useRef(null),J=l.useCallback(n=>!o.snapToGrid||!o.gridSize?n:Math.round(n/o.gridSize)*o.gridSize,[o.snapToGrid,o.gridSize]),ae=l.useCallback((n,a)=>{if(f)return;const r=F.flatMap(T=>T.items).find(T=>T.type===n),t=r?.defaultSize,i={id:`comp-${Date.now()}`,type:n,label:a,position:{x:100,y:100,width:t?.width??200,height:t?.height??100},props:r?.defaultProps??{}},h=[...c,i];d(h),x.selectOne(i.id),N({type:"insert",elementId:i.id,data:{component:i}})},[c,f,F,d,x,N]),ee=l.useCallback(n=>{if(f)return;const a=c.filter(r=>r.id!==n);d(a),x.isSelected(n)&&x.clearSelection(),N({type:"delete",elementId:n,data:{}})},[c,f,d,x,N]),B=l.useCallback(async()=>{if(f||x.count===0||!await k.confirm("Delete components",`Are you sure you want to delete ${x.count} component${x.count>1?"s":""}?`))return;const n=x.selectedIds,a=c.filter(r=>!n.has(r.id));d(a),x.clearSelection(),n.forEach(r=>{N({type:"delete",elementId:r,data:{}})})},[f,x,k,c,d,N]),le=l.useCallback((n,a)=>{if(f||!I)return;const r=c.map(t=>t.id!==I?t:n==="label"?{...t,label:String(a)}:n==="x"?{...t,position:{...t.position,x:Number(a)}}:n==="y"?{...t,position:{...t.position,y:Number(a)}}:n==="width"?{...t,position:{...t.position,width:Number(a)}}:n==="height"?{...t,position:{...t.position,height:Number(a)}}:{...t,props:{...t.props,[n]:a}});d(r),N({type:"update",elementId:I,data:{[n]:a}})},[f,I,c,d,N]),se=l.useCallback(()=>{const n=x.selectedIds;if(n.size===0)return;const a=c.filter(r=>n.has(r.id));O.copy(a)},[x,c,O]),_=l.useCallback(()=>{if(f)return;const n=O.paste();if(!n||n.length===0)return;let a=0;const r=n.map(i=>({...i,id:`comp-${Date.now()}-${++a}-${Math.random().toString(36).slice(2,7)}`,position:{...i.position,x:i.position.x+20,y:i.position.y+20}})),t=[...c,...r];d(t),x.selectMany(r.map(i=>i.id)),r.forEach(i=>{N({type:"insert",elementId:i.id,data:{component:i}})})},[f,O,c,d,x,N]),ne=l.useCallback((n,a)=>{f||(V.current={id:a.id,startX:n.clientX,startY:n.clientY},n.dataTransfer.effectAllowed="move",n.dataTransfer.setData("text/plain",a.id))},[f]),re=l.useCallback(n=>{n.preventDefault(),n.dataTransfer.dropEffect="move"},[]),w=l.useCallback(n=>{n.preventDefault();const a=V.current;if(!a||f)return;const r=(n.clientX-a.startX)/p,t=(n.clientY-a.startY)/p,i=c.map(h=>h.id!==a.id?h:{...h,position:{...h.position,x:J(h.position.x+r),y:J(h.position.y+t)}});d(i),N({type:"move",elementId:a.id,data:{}}),V.current=null},[f,p,c,d,J,N]),M=l.useMemo(()=>P?[{name:"label",label:"Label",type:"text",value:P.label??"",group:"General"},{name:"x",label:"X",type:"number",value:P.position.x,group:"Position"},{name:"y",label:"Y",type:"number",value:P.position.y,group:"Position"},{name:"width",label:"Width",type:"number",value:P.position.width,group:"Size"},{name:"height",label:"Height",type:"number",value:P.position.height,group:"Size"}]:[],[P]),m=l.useMemo(()=>c.map(n=>({id:n.id,x:n.position.x,y:n.position.y,width:typeof n.position.width=="number"?n.position.width:100,height:typeof n.position.height=="number"?n.position.height:50,selected:x.isSelected(n.id)})),[c,x]);return l.useEffect(()=>{const n=q.current;if(!n)return;const a=r=>{const t=["INPUT","TEXTAREA","SELECT"].includes(r.target.tagName),i=r.ctrlKey||r.metaKey;if((r.key==="Delete"||r.key==="Backspace")&&x.count>0&&!t){r.preventDefault(),B();return}if(r.key==="Escape"){x.clearSelection();return}if(!t){if(i&&r.key==="z"&&!r.shiftKey&&b&&!f){r.preventDefault(),y.undo();return}if(i&&(r.key==="z"&&r.shiftKey||r.key==="y")&&b&&!f){r.preventDefault(),y.redo();return}if(i&&r.key==="c"){r.preventDefault(),se();return}if(i&&r.key==="v"&&!f){r.preventDefault(),_();return}if(i&&r.key==="a"){r.preventDefault(),x.selectMany(c.map(h=>h.id));return}}};return n.addEventListener("keydown",a),()=>n.removeEventListener("keydown",a)},[x,B,b,f,y,se,_,c]),e.jsxs("div",{ref:q,tabIndex:0,className:te("flex h-full w-full border rounded-lg overflow-hidden bg-background",s),children:[!f&&e.jsx("div",{className:te("border-r bg-muted/30 flex flex-col transition-[width] duration-200",L?"w-60":"w-0 overflow-hidden"),role:"region","aria-label":"Component palette",children:L&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:"Components"}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:F.map(n=>e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground px-2 py-1 uppercase",children:n.label}),n.items.map(a=>e.jsxs("button",{onClick:()=>ae(a.type,a.label),className:"w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-accent text-left",children:[e.jsx(ce,{className:"h-3 w-3"}),a.label]},a.type))]},n.name))})]})}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 border-b bg-muted/20",role:"toolbar","aria-label":"Designer toolbar",children:[!f&&e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:L?"Collapse palette":"Expand palette","aria-label":L?"Collapse palette":"Expand palette",onClick:()=>H(n=>!n),children:e.jsx(Nt,{className:te("h-4 w-4",!L&&"rotate-180")})}),b&&!f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-5 bg-border mx-1"}),e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",!y.canUndo&&"opacity-40 pointer-events-none"),title:"Undo (Ctrl+Z)","aria-label":"Undo",disabled:!y.canUndo,onClick:()=>y.undo(),children:e.jsx(je,{className:"h-4 w-4"})}),e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",!y.canRedo&&"opacity-40 pointer-events-none"),title:"Redo (Ctrl+Shift+Z)","aria-label":"Redo",disabled:!y.canRedo,onClick:()=>y.redo(),children:e.jsx(Ne,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!f&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",x.count===0&&"opacity-40 pointer-events-none"),title:"Copy (Ctrl+C)","aria-label":"Copy",disabled:x.count===0,onClick:se,children:e.jsx(Ce,{className:"h-4 w-4"})}),e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",!O.hasContent&&"opacity-40 pointer-events-none"),title:"Paste (Ctrl+V)","aria-label":"Paste",disabled:!O.hasContent,onClick:_,children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!f&&e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",x.count===0&&"opacity-40 pointer-events-none"),title:"Delete selected","aria-label":"Delete selected",disabled:x.count===0,onClick:B,children:e.jsx(de,{className:"h-4 w-4"})}),e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:"Preview","aria-label":"Preview",children:e.jsx(Je,{className:"h-4 w-4"})}),e.jsx("button",{className:te("p-1.5 rounded hover:bg-accent",Q&&"bg-accent"),title:"Toggle minimap","aria-label":"Toggle minimap",onClick:()=>Y(n=>!n),children:e.jsx(qe,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{className:"p-1 rounded hover:bg-accent text-xs","aria-label":"Zoom out",onClick:j.zoomOut,children:e.jsx(Ct,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-xs text-muted-foreground w-10 text-center",children:[Math.round(p*100),"%"]}),e.jsx("button",{className:"p-1 rounded hover:bg-accent text-xs","aria-label":"Zoom in",onClick:j.zoomIn,children:e.jsx(ce,{className:"h-3 w-3"})}),e.jsx("button",{className:"p-1 rounded hover:bg-accent text-xs","aria-label":"Reset zoom",onClick:j.resetZoom,children:e.jsx(kt,{className:"h-3 w-3"})})]}),C&&e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:G?"Collapse panel":"Expand panel","aria-label":G?"Collapse panel":"Expand panel",onClick:()=>Z(n=>!n),children:e.jsx(Ue,{className:te("h-4 w-4",!G&&"rotate-180")})})]}),e.jsx("div",{className:"flex-1 overflow-auto bg-muted/10 p-4 relative",role:"region","aria-label":"Design canvas",onWheel:j.handleWheel,onMouseDown:j.startPan,onDragOver:re,onDrop:w,children:e.jsxs("div",{className:"relative bg-background border rounded shadow-sm mx-auto",style:{width:o.width*p,height:o.height*p,transform:`translate(${j.panOffset.x}px, ${j.panOffset.y}px)`,backgroundImage:o.showGrid?"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)":void 0,backgroundSize:o.showGrid&&o.gridSize?`${o.gridSize*p}px ${o.gridSize*p}px`:void 0},children:[c.map(n=>{const a=x.isSelected(n.id);return e.jsxs("div",{draggable:!f,onDragStart:r=>ne(r,n),className:te("absolute border rounded cursor-move select-none transition-shadow",a?"border-primary ring-2 ring-primary/20 shadow-md":"border-border hover:border-primary/50"),style:{left:n.position.x*p,top:n.position.y*p,width:typeof n.position.width=="number"?n.position.width*p:n.position.width,height:typeof n.position.height=="number"?n.position.height*p:n.position.height},onClick:r=>x.toggle(n.id,r.shiftKey),children:[e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted/50 text-xs border-b",children:[e.jsx(_e,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:n.label??n.type}),!f&&e.jsx("button",{onClick:r=>{r.stopPropagation(),ee(n.id)},className:"ml-auto p-0.5 rounded hover:bg-destructive/10","aria-label":`Delete ${n.label??n.type}`,children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]}),e.jsx("div",{className:"p-2 text-xs text-muted-foreground",children:n.type})]},n.id)}),Q&&e.jsx(Ze,{items:m,canvasWidth:o.width,canvasHeight:o.height})]})})]}),C&&e.jsx("div",{className:te("border-l bg-muted/30 flex flex-col transition-[width] duration-200",G?"w-60":"w-0 overflow-hidden"),role:"region","aria-label":"Component tree",children:G&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-3 border-b font-medium text-sm flex items-center gap-2",children:[e.jsx(St,{className:"h-4 w-4"}),"Component Tree"]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:c.length===0?e.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."}):c.map(n=>e.jsx("button",{onClick:a=>x.toggle(n.id,a.shiftKey),className:te("w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded text-left",x.isSelected(n.id)?"bg-accent":"hover:bg-accent/50"),children:e.jsx("span",{className:"truncate",children:n.label??n.type})},n.id))}),$&&P?e.jsx("div",{className:"border-t",children:e.jsx(Oe,{title:`Properties – ${P.label??P.type}`,fields:M,onChange:le})}):P&&e.jsxs("div",{className:"border-t p-3",children:[e.jsx("div",{className:"text-xs font-medium mb-2",children:"Properties"}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsxs("div",{children:["Type: ",P.type]}),e.jsxs("div",{children:["ID: ",P.id]}),e.jsxs("div",{children:["Position: ",P.position.x,","," ",P.position.y]}),e.jsxs("div",{children:["Size: ",P.position.width," ×"," ",P.position.height]})]})]})]})}),e.jsx(Fe,{isOpen:k.isOpen,title:k.title,message:k.message,onConfirm:k.onConfirm,onCancel:k.onCancel})]})}const Yt=[{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 Me(...o){return ue(pe(o))}function Wt(o,A=4,F=280,C=250,b=50,$=50){return o.map((f,g)=>({...f,position:{x:b+g%A*F,y:$+Math.floor(g/A)*C}}))}function Bt({entities:o=[],relationships:A=[],canvas:F={width:1200,height:800,showGrid:!0},showRelationshipLabels:C=!0,readOnly:b=!1,onEntitiesChange:$,onRelationshipsChange:f,className:g}){const v=l.useRef(null),s=Se({entities:o,relationships:A},{maxHistory:50}),{entities:y,relationships:c}=s.current,d=l.useCallback(t=>{s.push(t),$?.(t.entities),f?.(t.relationships)},[s,$,f]),j=De(),p=$e(),x=p.count>0?Array.from(p.selectedIds)[0]:null,I=Te(),P=Le({minZoom:.25,maxZoom:3,zoomStep:.1}),O=Ie(),[k,E]=l.useState(!0),[N,L]=l.useState(!0),[H,G]=l.useState(null),[Z,Q]=l.useState(""),Y=l.useRef(null),V=l.useCallback(()=>{if(b)return;const t=s.current,i={id:`entity-${Date.now()}`,name:`new_entity_${t.entities.length+1}`,label:`New Entity ${t.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+t.entities.length%4*280,y:50+Math.floor(t.entities.length/4)*250}},h={entities:[...t.entities,i],relationships:t.relationships};d(h),p.selectOne(i.id),O?.sendOperation({type:"insert",userId:O?.currentUserId??"",elementId:i.id,data:{name:i.name,label:i.label}})},[b,s,d,p,O]),q=l.useCallback(async t=>{if(b)return;const i=y.find(R=>R.id===t);if(!await j.confirm("Delete Entity",`Are you sure you want to delete "${i?.label??t}"? This action cannot be undone.`))return;const h=s.current,T={entities:h.entities.filter(R=>R.id!==t),relationships:h.relationships.filter(R=>R.sourceEntity!==t&&R.targetEntity!==t)};d(T),p.isSelected(t)&&p.clearSelection(),O?.sendOperation({type:"delete",userId:O?.currentUserId??"",elementId:t,data:{}})},[b,y,j,s,d,p,O]),J=l.useCallback(async()=>{if(b||p.count===0)return;const t=Array.from(p.selectedIds);if(!await j.confirm("Delete Entities",`Are you sure you want to delete ${t.length} selected entity(s)? This action cannot be undone.`))return;const i=s.current,h=new Set(t),T={entities:i.entities.filter(R=>!h.has(R.id)),relationships:i.relationships.filter(R=>!h.has(R.sourceEntity)&&!h.has(R.targetEntity))};d(T),p.clearSelection()},[b,p,j,s,d]),ae=l.useCallback(()=>{if(b)return;const t=s.current,i={entities:Wt(t.entities),relationships:t.relationships};d(i)},[b,s,d]),ee=l.useCallback(()=>{const t=y.filter(i=>p.isSelected(i.id));t.length>0&&I.copy(t)},[y,p,I]),B=l.useCallback(()=>{if(b)return;const t=I.paste();if(!t||t.length===0)return;const i=s.current,h=t.map((R,ie)=>({...R,id:`entity-${Date.now()}-${ie}`,name:`${R.name}_copy`,label:`${R.label} (Copy)`,position:{x:R.position.x+30,y:R.position.y+30}})),T={entities:[...i.entities,...h],relationships:i.relationships};d(T),p.selectMany(h.map(R=>R.id))},[b,I,s,d,p]),le=l.useCallback(t=>{if(b)return;const i=s.current,h={entities:i.entities.map(T=>{if(T.id!==t)return T;const R={name:`field_${T.fields.length+1}`,type:"text",required:!1};return{...T,fields:[...T.fields,R]}}),relationships:i.relationships};d(h)},[b,s,d]),se=l.useCallback((t,i,h)=>{b||(G({entityId:t,fieldIndex:i}),Q(h))},[b]),_=l.useCallback(()=>{if(!H)return;const t=Z.trim();if(t===""){G(null);return}const i=s.current,h={entities:i.entities.map(T=>{if(T.id!==H.entityId)return T;const R=T.fields.map((ie,ge)=>ge===H.fieldIndex?{...ie,name:t}:ie);return{...T,fields:R}}),relationships:i.relationships};d(h),G(null)},[H,Z,s,d]),ne=l.useCallback(()=>{G(null)},[]),re=l.useCallback((t,i)=>{if(b||!y.find(T=>T.id===i))return;const h=t.target.getBoundingClientRect();Y.current={entityId:i,offsetX:t.clientX-h.left,offsetY:t.clientY-h.top},t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",i)},[b,y]),w=l.useCallback(t=>{t.preventDefault(),t.dataTransfer.dropEffect="move"},[]),M=l.useCallback(t=>{if(t.preventDefault(),!Y.current)return;const i=t.currentTarget.getBoundingClientRect(),h=P.zoom,T=(t.clientX-i.left-P.panOffset.x)/h-Y.current.offsetX,R=(t.clientY-i.top-P.panOffset.y)/h-Y.current.offsetY,ie=s.current,ge={entities:ie.entities.map(fe=>fe.id===Y.current.entityId?{...fe,position:{x:Math.max(0,Math.round(T)),y:Math.max(0,Math.round(R))}}:fe),relationships:ie.relationships};d(ge),Y.current=null},[P.zoom,P.panOffset,s,d]),m=x?y.find(t=>t.id===x):null,n=m?[{name:"name",label:"Name",type:"text",value:m.name,group:"General"},{name:"label",label:"Label",type:"text",value:m.label,group:"General"},{name:"description",label:"Description",type:"textarea",value:m.description??"",group:"General"},{name:"color",label:"Color",type:"color",value:m.color??"#3b82f6",group:"Appearance"},{name:"position.x",label:"X Position",type:"number",value:m.position.x,group:"Position"},{name:"position.y",label:"Y Position",type:"number",value:m.position.y,group:"Position"}]:[],a=l.useCallback((t,i)=>{if(!x)return;const h=s.current,T={entities:h.entities.map(R=>R.id!==x?R:t==="position.x"?{...R,position:{...R.position,x:Number(i)}}:t==="position.y"?{...R,position:{...R.position,y:Number(i)}}:{...R,[t]:i}),relationships:h.relationships};d(T)},[x,s,d]);l.useEffect(()=>{const t=v.current;if(!t)return;const i=h=>{const T=h.target.tagName;if(T==="INPUT"||T==="TEXTAREA"||T==="SELECT")return;const R=h.ctrlKey||h.metaKey;R&&h.key==="z"?(h.preventDefault(),s.undo()):R&&(h.key==="y"||h.shiftKey&&h.key==="Z")?(h.preventDefault(),s.redo()):R&&h.key==="c"?(h.preventDefault(),ee()):R&&h.key==="v"?(h.preventDefault(),B()):(h.key==="Delete"||h.key==="Backspace")&&p.count>0?(h.preventDefault(),J()):h.key==="Escape"&&(p.clearSelection(),G(null))};return t.addEventListener("keydown",i),()=>t.removeEventListener("keydown",i)},[s,ee,B,J,p]);const r=y.map(t=>({id:t.id,x:t.position.x,y:t.position.y,width:240,height:40+t.fields.length*24,color:t.color,selected:p.isSelected(t.id)}));return e.jsxs("div",{ref:v,tabIndex:0,className:Me("flex h-full w-full border rounded-lg overflow-hidden bg-background",g),children:[e.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[e.jsxs("div",{role:"toolbar","aria-label":"Designer toolbar",className:"flex items-center gap-2 p-2 border-b bg-muted/20 flex-wrap",children:[e.jsx(He,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-sm",children:"Data Model Designer"}),e.jsxs("div",{className:"flex items-center gap-1 ml-2 border-l pl-2",children:[e.jsx("button",{onClick:()=>s.undo(),disabled:!s.canUndo,"aria-label":"Undo",title:"Undo (Ctrl+Z)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(je,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>s.redo(),disabled:!s.canRedo,"aria-label":"Redo",title:"Redo (Ctrl+Y)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-1 border-l pl-2",children:[e.jsx("button",{onClick:P.zoomOut,"aria-label":"Zoom Out",title:"Zoom Out",className:"p-1 rounded hover:bg-accent",children:e.jsx(Qe,{className:"h-3.5 w-3.5"})}),e.jsxs("span",{className:"text-xs tabular-nums w-10 text-center",children:[Math.round(P.zoom*100),"%"]}),e.jsx("button",{onClick:P.zoomIn,"aria-label":"Zoom In",title:"Zoom In",className:"p-1 rounded hover:bg-accent",children:e.jsx(et,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:P.resetZoom,"aria-label":"Reset Zoom",title:"Reset Zoom",className:"p-1 rounded hover:bg-accent",children:e.jsx(tt,{className:"h-3 w-3"})})]}),!b&&e.jsxs("div",{className:"flex items-center gap-1 border-l pl-2",children:[e.jsx("button",{onClick:ee,disabled:p.count===0,"aria-label":"Copy",title:"Copy (Ctrl+C)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(Ce,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:B,disabled:!I.hasContent,"aria-label":"Paste",title:"Paste (Ctrl+V)",className:"p-1 rounded hover:bg-accent disabled:opacity-40",children:e.jsx(ke,{className:"h-3.5 w-3.5"})})]}),!b&&e.jsxs("button",{onClick:ae,"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:[e.jsx(Dt,{className:"h-3 w-3"})," Auto Layout"]}),e.jsx("div",{className:"flex-1"}),O?.isConnected&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",role:"status","aria-label":"Collaboration active",children:[e.jsx(Tt,{className:"h-3 w-3"}),e.jsxs("span",{children:[O.users.length," user",O.users.length!==1?"s":""]})]}),p.count>1&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[p.count," selected"]}),!b&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:V,"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:[e.jsx(ce,{className:"h-3 w-3"})," Add Entity"]}),e.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:[e.jsx(Ft,{className:"h-3 w-3"})," Add Relationship"]})]})]}),e.jsxs("div",{role:"region","aria-label":"Canvas",className:"flex-1 overflow-auto bg-muted/10 p-4 relative",onWheel:P.handleWheel,onMouseDown:P.startPan,onDragOver:w,onDrop:M,children:[e.jsxs("div",{className:"relative",style:{width:F.width,minHeight:F.height,...P.transformStyle,backgroundImage:F.showGrid?"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)":void 0,backgroundSize:F.showGrid?"20px 20px":void 0},children:[e.jsx("svg",{className:"absolute inset-0 pointer-events-none",width:F.width,height:F.height,children:c.map(t=>{const i=y.find(T=>T.id===t.sourceEntity),h=y.find(T=>T.id===t.targetEntity);return!i||!h?null:e.jsxs("g",{children:[e.jsx("line",{x1:i.position.x+120,y1:i.position.y+50,x2:h.position.x+120,y2:h.position.y+50,stroke:"hsl(var(--primary))",strokeWidth:"2",strokeDasharray:t.type==="many-to-many"?"5,5":void 0}),C&&t.label&&e.jsx("text",{x:(i.position.x+h.position.x)/2+120,y:(i.position.y+h.position.y)/2+50-8,textAnchor:"middle",className:"text-xs fill-muted-foreground",children:t.label})]},t.id)})}),y.length===0&&e.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."}),y.map(t=>e.jsxs("div",{role:"group","aria-label":t.label,draggable:!b,onDragStart:i=>re(i,t.id),className:Me("absolute rounded-lg border-2 bg-background shadow-sm w-60 select-none cursor-grab active:cursor-grabbing",p.isSelected(t.id)?"border-primary ring-2 ring-primary/20":"border-border hover:border-primary/50"),style:{left:t.position.x,top:t.position.y},onClick:i=>p.toggle(t.id,i.shiftKey),children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-t-lg font-medium text-sm",style:{backgroundColor:t.color??"hsl(var(--primary) / 0.1)"},children:[e.jsx(He,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"truncate",children:t.label}),!b&&e.jsx("button",{onClick:i=>{i.stopPropagation(),q(t.id)},"aria-label":`Delete ${t.label}`,className:"ml-auto p-0.5 rounded hover:bg-destructive/20",children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]}),e.jsx("div",{className:"px-3 py-1 divide-y",children:t.fields.map((i,h)=>e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs",children:[H&&H.entityId===t.id&&H.fieldIndex===h?e.jsx("input",{type:"text",value:Z,onChange:T=>Q(T.target.value),onBlur:_,onKeyDown:T=>{T.key==="Enter"&&_(),T.key==="Escape"&&ne()},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:T=>T.stopPropagation()}):e.jsxs("span",{className:Me("font-mono cursor-text",i.primaryKey&&"font-bold text-primary"),onClick:T=>{T.stopPropagation(),se(t.id,h,i.name)},title:"Click to edit field name",children:[i.primaryKey&&e.jsx("span",{className:"text-[0.65rem] font-semibold text-primary mr-0.5",children:"PK"}),i.name]}),e.jsx("span",{className:"text-muted-foreground ml-auto",children:i.type}),i.required&&e.jsx("span",{className:"text-destructive",children:"*"})]},`${i.name}-${h}`))}),!b&&e.jsx("div",{className:"px-3 py-1 border-t",children:e.jsxs("button",{onClick:i=>{i.stopPropagation(),le(t.id)},"aria-label":`Add field to ${t.label}`,className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground w-full py-0.5",children:[e.jsx(ce,{className:"h-3 w-3"})," Add Field"]})})]},t.id))]}),N&&y.length>0&&e.jsx(Ze,{items:r,canvasWidth:F.width,canvasHeight:F.height,position:"bottom-right",size:150})]})]}),e.jsxs("div",{className:"w-64 border-l flex flex-col bg-background shrink-0",children:[e.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[e.jsxs("button",{onClick:()=>E(t=>!t),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":k,"aria-controls":"property-editor-panel",children:[k?e.jsx(Re,{className:"h-3 w-3"}):e.jsx(Ge,{className:"h-3 w-3"}),"Properties"]}),k&&e.jsx("div",{id:"property-editor-panel",className:"flex-1 overflow-y-auto",children:e.jsx(Oe,{title:m?m.label:"Properties",fields:n,onChange:a})})]}),e.jsx("div",{className:"border-t",children:e.jsxs("button",{onClick:()=>L(t=>!t),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":N,children:[N?e.jsx(Re,{className:"h-3 w-3"}):e.jsx(Ge,{className:"h-3 w-3"}),"Minimap"]})})]}),e.jsx(Fe,{isOpen:j.isOpen,title:j.title,message:j.message,onConfirm:j.onConfirm,onCancel:j.onCancel,destructive:!0})]})}function Pe(...o){return ue(pe(o))}const be=120,ve=50;function qt(o,A){if(o.length===0)return o;const F=200,C=100,b=new Map,$=new Map;for(const c of o)b.set(c.id,0),$.set(c.id,[]);for(const c of A)b.set(c.target,(b.get(c.target)??0)+1),$.get(c.source)?.push(c.target);const f=[],g=new Set;let v=o.filter(c=>(b.get(c.id)??0)===0).map(c=>c.id);for(v.length===0&&(v=[o[0].id]);v.length>0;){f.push(v);for(const d of v)g.add(d);const c=new Set;for(const d of v)for(const j of $.get(d)??[])g.has(j)||c.add(j);v=Array.from(c)}const s=o.filter(c=>!g.has(c.id)).map(c=>c.id);s.length>0&&f.push(s);const y=new Map;for(let c=0;c<f.length;c++){const d=f[c];for(let j=0;j<d.length;j++)y.set(d[j],{x:80+c*F,y:80+j*C})}return o.map(c=>({...c,position:y.get(c.id)??c.position}))}function _t({processName:o="New Process",nodes:A=[],edges:F=[],lanes:C,canvas:b={width:1400,height:800,showGrid:!0},showMinimap:$=!0,showToolbar:f=!0,readOnly:g=!1,onNodesChange:v,onEdgesChange:s,className:y}){const c=Se({nodes:A,edges:F},{maxHistory:50}),d=c.current.nodes,j=c.current.edges,p=l.useCallback((u,U)=>{c.push({nodes:u,edges:U}),v?.(u),s?.(U)},[c,v,s]),x=De(),I=$e(),P=Te(),O=Le({initialZoom:1}),k=Ie(),[E,N]=l.useState(null),[L,H]=l.useState(!1),[G,Z]=l.useState(null),[Q,Y]=l.useState(null),[V,q]=l.useState(!0),[J,ae]=l.useState(null),[ee,B]=l.useState({x:0,y:0}),le=l.useRef(null),se=l.useRef(v),_=l.useRef(s);se.current=v,_.current=s,l.useEffect(()=>{se.current?.(d),_.current?.(j)},[c.current]);const ne=l.useCallback((u,U)=>{if(g)return;const z={id:`node-${Date.now()}`,type:u,label:U,position:{x:200+d.length*160,y:200}},X=[...d,z];p(X,j),N(z.id),I.selectOne(z.id),k?.sendOperation({type:"insert",elementId:z.id,data:{label:U},userId:k.currentUserId??""})},[d,j,g,p,I,k]),re=l.useCallback(async u=>{if(g)return;const U=d.find(K=>K.id===u);if(!await x.confirm("Delete Node",`Are you sure you want to delete "${U?.label??u}"? This will also remove all connected edges.`))return;const z=d.filter(K=>K.id!==u),X=j.filter(K=>K.source!==u&&K.target!==u);p(z,X),E===u&&N(null),I.clearSelection(),k?.sendOperation({type:"delete",elementId:u,data:{},userId:k.currentUserId??""})},[d,j,E,g,p,x,I,k]),w=l.useCallback(async()=>{if(g||I.count===0||!await x.confirm("Delete Selected Nodes",`Are you sure you want to delete ${I.count} selected node(s) and their connected edges?`))return;const u=I.selectedIds,U=d.filter(X=>!u.has(X.id)),z=j.filter(X=>!u.has(X.source)&&!u.has(X.target));p(U,z),N(null),I.clearSelection()},[d,j,g,p,x,I]),M=l.useCallback(()=>{const u=I.count>0?I.selectedIds:E?new Set([E]):new Set;if(u.size===0)return;const U=d.filter(z=>u.has(z.id));P.copy(U)},[d,E,I,P]),m=l.useCallback(()=>{if(g)return;const u=P.paste();if(!u||u.length===0)return;const U=40,z=u.map(K=>({...K,id:`node-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,position:{x:K.position.x+U,y:K.position.y+U}})),X=[...d,...z];p(X,j),I.selectMany(z.map(K=>K.id)),N(z[0].id)},[g,d,j,P,p,I]),n=l.useCallback(()=>{H(u=>u?(Z(null),!1):!0)},[]),a=l.useCallback(u=>{if(!L)return!1;if(!G)return Z(u),!0;if(G===u)return!0;const U={id:`edge-${Date.now()}`,source:G,target:u},z=[...j,U];return p(d,z),Z(null),H(!1),k?.sendOperation({type:"insert",elementId:U.id,data:{source:G,target:u},userId:k.currentUserId??""}),!0},[L,G,d,j,p,k]),r=l.useCallback(()=>{if(g||d.length===0)return;const u=qt(d,j);p(u,j)},[d,j,g,p]),t=l.useCallback((u,U)=>{if(g||!d.find(X=>X.id===U))return;ae(U);const z=u.target.getBoundingClientRect();B({x:u.clientX-z.left,y:u.clientY-z.top}),u.dataTransfer.effectAllowed="move",u.dataTransfer.setData("text/plain",U)},[g,d]),i=l.useCallback(u=>{if(u.preventDefault(),g||!J)return;const U=u.currentTarget.getBoundingClientRect(),z=O.zoom,X=(u.clientX-U.left-O.panOffset.x)/z-ee.x,K=(u.clientY-U.top-O.panOffset.y)/z-ee.y,W=Math.max(0,Math.round(X/20)*20),xe=Math.max(0,Math.round(K/20)*20),he=d.map(me=>me.id===J?{...me,position:{x:W,y:xe}}:me);p(he,j),ae(null)},[g,J,ee,d,j,O.zoom,O.panOffset,p]),h=l.useCallback(u=>{u.preventDefault(),u.dataTransfer.dropEffect="move"},[]),T=l.useMemo(()=>d.find(u=>u.id===E)??null,[d,E]),R=l.useMemo(()=>T?[{name:"label",label:"Name",type:"text",value:T.label,group:"General"},{name:"type",label:"Type",type:"select",value:T.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:T.description??"",group:"General"}]:[],[T]),ie=l.useCallback((u,U)=>{if(g||!E)return;const z=d.map(X=>X.id===E?{...X,[u]:U}:X);p(z,j)},[g,E,d,j,p]),ge=u=>{switch(u){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"}},fe=l.useMemo(()=>d.map(u=>({id:u.id,x:u.position.x,y:u.position.y,width:be,height:ve,selected:I.isSelected(u.id)||u.id===E})),[d,I,E]);l.useEffect(()=>{const u=le.current;if(!u)return;const U=z=>{const X=z.target?.tagName;if(X==="INPUT"||X==="TEXTAREA"||X==="SELECT")return;const K=z.ctrlKey||z.metaKey;if(K&&z.key==="z"&&!z.shiftKey){z.preventDefault(),c.undo();return}if(K&&z.key==="y"||K&&z.key==="z"&&z.shiftKey){z.preventDefault(),c.redo();return}if(K&&z.key==="c"){z.preventDefault(),M();return}if(K&&z.key==="v"){z.preventDefault(),m();return}if(z.key==="Delete"||z.key==="Backspace"){I.count>0?(z.preventDefault(),w()):E&&(z.preventDefault(),re(E));return}if(z.key==="Escape"){L?(H(!1),Z(null)):(N(null),I.clearSelection());return}};return u.addEventListener("keydown",U),()=>u.removeEventListener("keydown",U)},[E,L,I,c,M,m,re,w]);const st=l.useCallback(u=>{u.target===u.currentTarget&&(N(null),I.clearSelection(),L&&(H(!1),Z(null)))},[L,I]);return e.jsxs("div",{ref:le,tabIndex:0,className:Pe("flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background",y),children:[e.jsx(Fe,{isOpen:x.isOpen,title:x.title,message:x.message,onConfirm:x.onConfirm,onCancel:x.onCancel,destructive:!0}),f&&e.jsxs("div",{className:"flex items-center gap-2 p-2 border-b bg-muted/20",role:"toolbar","aria-label":"Process toolbar",children:[e.jsx(It,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-sm","aria-label":"Process name",children:o}),k?.isConnected&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",role:"status","aria-label":"Collaboration active",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-green-500"}),k.users.length," user",k.users.length!==1?"s":""]}),e.jsx("div",{className:"flex-1"}),!g&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>c.undo(),disabled:!c.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:e.jsx(je,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>c.redo(),disabled:!c.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:e.jsx(Ne,{className:"h-3 w-3"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsx("button",{onClick:M,disabled:I.count===0&&!E,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:e.jsx(Ce,{className:"h-3 w-3"})}),e.jsx("button",{onClick:m,disabled:!P.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:e.jsx(ke,{className:"h-3 w-3"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsxs("button",{onClick:n,className:Pe("flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",L&&"bg-primary text-primary-foreground"),title:"Connect nodes","aria-label":"Connect nodes","aria-pressed":L,children:[e.jsx(Pt,{className:"h-3 w-3"})," Connect"]}),e.jsxs("button",{onClick:r,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:"Auto layout","aria-label":"Auto layout",children:[e.jsx(Et,{className:"h-3 w-3"})," Layout"]}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsx("button",{onClick:O.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:e.jsx(et,{className:"h-3 w-3"})}),e.jsxs("span",{className:"text-xs tabular-nums min-w-[3ch] text-center","aria-label":"Zoom level",children:[Math.round(O.zoom*100),"%"]}),e.jsx("button",{onClick:O.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:e.jsx(Qe,{className:"h-3 w-3"})}),e.jsx("button",{onClick:O.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:e.jsx(tt,{className:"h-3 w-3"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsxs("button",{onClick:()=>ne("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:[e.jsx($t,{className:"h-3 w-3 text-green-600"})," Start"]}),e.jsxs("button",{onClick:()=>ne("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:[e.jsx(Ve,{className:"h-3 w-3 text-blue-600"})," Task"]}),e.jsxs("button",{onClick:()=>ne("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:[e.jsx(Ot,{className:"h-3 w-3 text-yellow-600"})," Gateway"]}),e.jsxs("button",{onClick:()=>ne("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:[e.jsx(Ve,{className:"h-3 w-3 text-red-600"})," End"]}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"}),e.jsx("button",{onClick:()=>q(u=>!u),className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent",title:V?"Hide properties":"Show properties","aria-label":V?"Hide property panel":"Show property panel","aria-expanded":V,children:V?e.jsx(Ue,{className:"h-3 w-3"}):e.jsx(zt,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsx("div",{className:"flex-1 overflow-auto bg-muted/10 p-4",role:"region","aria-label":"Process canvas",onWheel:O.handleWheel,onMouseDown:O.startPan,children:e.jsxs("div",{className:"relative",style:{...O.transformStyle,width:b.width,minHeight:b.height,backgroundImage:b.showGrid?"radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)":void 0,backgroundSize:b.showGrid?"20px 20px":void 0},onClick:st,onDrop:i,onDragOver:h,children:[e.jsxs("svg",{className:"absolute inset-0 pointer-events-none",width:b.width,height:b.height,children:[e.jsx("defs",{children:e.jsx("marker",{id:"arrowhead",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:e.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"hsl(var(--foreground))"})})}),j.map(u=>{const U=d.find(ze=>ze.id===u.source),z=d.find(ze=>ze.id===u.target);if(!U||!z)return null;U.position.x+be/2;const X=U.position.y+ve/2;z.position.x+be/2;const K=z.position.y+ve/2,W=U.position.x+be,xe=X,he=z.position.x,me=K,nt=(W+he)/2,rt=`M ${W} ${xe} Q ${nt} ${xe}, ${(W+he)/2} ${(xe+me)/2} T ${he} ${me}`;return e.jsxs("g",{children:[e.jsx("path",{d:rt,fill:"none",stroke:"hsl(var(--foreground) / 0.5)",strokeWidth:"2",markerEnd:"url(#arrowhead)"}),u.label&&e.jsx("text",{x:(W+he)/2,y:(xe+me)/2-8,textAnchor:"middle",className:"text-[10px] fill-muted-foreground",children:u.label})]},u.id)})]}),d.length===0&&e.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."}),d.map(u=>{const U=I.isSelected(u.id)||E===u.id,z=G===u.id,X=Q===u.id,K=L||X;return e.jsxs("div",{className:"absolute select-none",style:{left:u.position.x,top:u.position.y},role:"group","aria-label":u.label,draggable:!g&&!L,onDragStart:W=>t(W,u.id),onMouseEnter:()=>Y(u.id),onMouseLeave:()=>Y(null),onClick:W=>{a(u.id)||(W.shiftKey?I.toggle(u.id,!0):(N(u.id),I.selectOne(u.id)))},children:[e.jsx("div",{className:Pe("flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow",ge(u.type),U&&"ring-2 ring-primary shadow-md",z&&"ring-2 ring-blue-400 shadow-lg",L&&!z&&"cursor-crosshair"),children:e.jsx("span",{className:Pe("text-xs font-medium",(u.type==="exclusive-gateway"||u.type==="parallel-gateway"||u.type==="inclusive-gateway"||u.type==="event-based-gateway")&&"-rotate-45"),children:u.label})}),K&&!g&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair",style:{left:-6,top:ve/2-6},title:"Input port",onClick:W=>{W.stopPropagation(),a(u.id)}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair",style:{right:-6,top:ve/2-6},title:"Output port",onClick:W=>{W.stopPropagation(),L?a(u.id):(H(!0),Z(u.id))}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair",style:{left:be/2-6,top:-6},title:"Port",onClick:W=>{W.stopPropagation(),a(u.id)}}),e.jsx("div",{className:"absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair",style:{left:be/2-6,bottom:-6},title:"Port",onClick:W=>{W.stopPropagation(),a(u.id)}})]}),!g&&U&&!L&&e.jsx("button",{onClick:W=>{W.stopPropagation(),re(u.id)},className:"absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow","aria-label":"Delete node",children:e.jsx(de,{className:"h-3 w-3"})})]},u.id)}),$&&d.length>0&&e.jsx(Ze,{items:fe,canvasWidth:b.width??1400,canvasHeight:b.height??800,position:"bottom-right"})]})}),V&&!g&&e.jsx("div",{className:"w-64 border-l bg-background overflow-y-auto flex-shrink-0",role:"complementary","aria-label":"Property panel",children:e.jsx(Oe,{title:T?`Properties: ${T.label}`:"Properties",fields:R,onChange:ie})})]})]})}function oe(...o){return ue(pe(o))}const S={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:o=>`Are you sure you want to delete ${o} element${o>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"},Jt={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}},Qt=[{type:"header",height:80,elements:[]},{type:"detail",height:400,elements:[],repeat:!0},{type:"footer",height:60,elements:[]}];function ea({reportName:o=S.untitledReport,objectName:A,pageSize:F="A4",orientation:C="portrait",margins:b={top:40,right:40,bottom:40,left:40},sections:$=[],showToolbar:f=!0,showPropertyPanel:g=!0,readOnly:v=!1,onSectionsChange:s,className:y}){const c=Se($.length>0?$:Qt),d=c.current,j=l.useCallback(w=>{c.push(w),s?.(w)},[c,s]),p=$e(),x=l.useMemo(()=>{const w=Array.from(p.selectedIds);return w.length>0?w[0]:null},[p.selectedIds]),I=Te(),P=De(),O=Ie(),k=l.useCallback(w=>{O&&O.sendOperation({...w,userId:O.currentUserId??""})},[O]),[E,N]=l.useState(!0),L=l.useRef(null),H=l.useRef(null),G=Jt[F],Z=C==="landscape"?G.height:G.width,Q=C==="landscape"?G.width:G.height,Y=w=>{switch(w){case"header":return S.sectionHeader;case"page-header":return S.sectionPageHeader;case"group-header":return S.sectionGroupHeader;case"detail":return S.sectionDetail;case"group-footer":return S.sectionGroupFooter;case"page-footer":return S.sectionPageFooter;case"footer":return S.sectionFooter;default:return w}},V=l.useMemo(()=>x?d.flatMap(w=>w.elements).find(w=>w.id===x):null,[x,d]),q=l.useCallback((w,M)=>{if(v)return;const m={id:`elem-${Date.now()}`,type:M,position:{x:b.left,y:10,width:200,height:30},properties:{text:M==="text"?"New Text":void 0,field:M==="field"?"field_name":void 0}},n=d.map((a,r)=>r===w?{...a,elements:[...a.elements,m]}:a);j(n),p.selectOne(m.id),k({type:"insert",elementId:m.id,data:{element:m}})},[d,b.left,v,j,p,k]),J=l.useCallback(w=>{if(v)return;const M=d.map(m=>({...m,elements:m.elements.filter(n=>n.id!==w)}));j(M),p.isSelected(w)&&p.clearSelection(),k({type:"delete",elementId:w,data:{}})},[d,v,j,p,k]),ae=l.useCallback(async()=>{if(v||p.count===0||!await P.confirm(S.deleteElementsTitle,S.deleteElementMessage(p.count)))return;const w=p.selectedIds,M=d.map(m=>({...m,elements:m.elements.filter(n=>!w.has(n.id))}));j(M),p.clearSelection(),w.forEach(m=>{k({type:"delete",elementId:m,data:{}})})},[v,p,P,d,j,k]),ee=l.useCallback((w,M)=>{if(v||!x)return;const m=d.map(n=>({...n,elements:n.elements.map(a=>a.id!==x?a:w==="x"?{...a,position:{...a.position,x:Number(M)}}:w==="y"?{...a,position:{...a.position,y:Number(M)}}:w==="width"?{...a,position:{...a.position,width:Number(M)}}:w==="height"?{...a,position:{...a.position,height:Number(M)}}:{...a,properties:{...a.properties,[w]:M}})}));j(m),k({type:"update",elementId:x,data:{[w]:M}})},[v,x,d,j,k]),B=l.useCallback(()=>{const w=p.selectedIds;if(w.size===0)return;const M=d.flatMap(m=>m.elements).filter(m=>w.has(m.id));I.copy(M)},[p,d,I]),le=l.useCallback(()=>{if(v)return;const w=I.paste();if(!w||w.length===0)return;let M=0;const m=w.map(t=>({...t,id:`elem-${Date.now()}-${++M}-${Math.random().toString(36).slice(2,7)}`,position:{...t.position,x:t.position.x+20,y:t.position.y+20}})),n=d.findIndex(t=>t.type==="detail"),a=n>=0?n:0,r=d.map((t,i)=>i===a?{...t,elements:[...t.elements,...m]}:t);j(r),p.selectMany(m.map(t=>t.id)),m.forEach(t=>{k({type:"insert",elementId:t.id,data:{element:t}})})},[v,I,d,j,p,k]),se=l.useCallback((w,M,m)=>{v||(L.current={id:M.id,sectionIndex:m,startX:w.clientX,startY:w.clientY},w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",M.id))},[v]),_=l.useCallback(w=>{w.preventDefault(),w.dataTransfer.dropEffect="move"},[]),ne=l.useCallback((w,M)=>{w.preventDefault();const m=L.current;if(!m||v)return;const n=w.clientX-m.startX,a=w.clientY-m.startY;if(m.sectionIndex===M){const r=d.map((t,i)=>i!==M?t:{...t,elements:t.elements.map(h=>h.id!==m.id?h:{...h,position:{...h.position,x:Math.max(0,h.position.x+n),y:Math.max(0,(typeof h.position.y=="number"?h.position.y:0)+a)}})});j(r)}else{let r=null;const t=d.map((i,h)=>{if(h!==m.sectionIndex)return i;const T=i.elements.find(R=>R.id===m.id);return T&&(r={...T,position:{...T.position,x:Math.max(0,T.position.x+n),y:Math.max(0,10)}}),{...i,elements:i.elements.filter(R=>R.id!==m.id)}});if(r){const i=t.map((h,T)=>T!==M?h:{...h,elements:[...h.elements,r]});j(i)}}k({type:"move",elementId:m.id,data:{}}),L.current=null},[v,d,j,k]),re=l.useMemo(()=>{if(!V)return[];const w=[{name:"x",label:S.propX,type:"number",value:V.position.x,group:S.groupPosition},{name:"y",label:S.propY,type:"number",value:V.position.y,group:S.groupPosition},{name:"width",label:S.propWidth,type:"number",value:V.position.width,group:S.groupSize},{name:"height",label:S.propHeight,type:"number",value:V.position.height,group:S.groupSize}];return V.type==="text"&&w.push({name:"text",label:S.propText,type:"text",value:V.properties.text??"",group:S.groupContent}),V.type==="field"&&w.push({name:"field",label:S.propField,type:"text",value:V.properties.field??"",group:S.groupContent}),w},[V]);return l.useEffect(()=>{const w=H.current;if(!w)return;const M=m=>{const n=["INPUT","TEXTAREA","SELECT"].includes(m.target.tagName),a=m.ctrlKey||m.metaKey;if((m.key==="Delete"||m.key==="Backspace")&&p.count>0&&!n){m.preventDefault(),ae();return}if(m.key==="Escape"){p.clearSelection();return}if(!n){if(a&&m.key==="z"&&!m.shiftKey&&!v){m.preventDefault(),c.undo();return}if(a&&(m.key==="z"&&m.shiftKey||m.key==="y")&&!v){m.preventDefault(),c.redo();return}if(a&&m.key==="c"){m.preventDefault(),B();return}if(a&&m.key==="v"&&!v){m.preventDefault(),le();return}if(a&&m.key==="a"){m.preventDefault();const r=d.flatMap(t=>t.elements).map(t=>t.id);p.selectMany(r);return}}};return w.addEventListener("keydown",M),()=>w.removeEventListener("keydown",M)},[p,ae,v,c,B,le,d]),e.jsxs("div",{ref:H,tabIndex:0,className:oe("flex h-full w-full border rounded-lg overflow-hidden bg-background",y),children:[e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[f&&e.jsxs("div",{role:"toolbar","aria-label":S.designerToolbar,className:"flex items-center gap-2 p-2 border-b bg-muted/20",children:[e.jsx(At,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium text-sm",children:o}),A&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",A,")"]}),!v&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-5 bg-border mx-1"}),e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",!c.canUndo&&"opacity-40 pointer-events-none"),title:S.undoShortcut,"aria-label":S.undo,disabled:!c.canUndo,onClick:()=>c.undo(),children:e.jsx(je,{className:"h-4 w-4"})}),e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",!c.canRedo&&"opacity-40 pointer-events-none"),title:S.redoShortcut,"aria-label":S.redo,disabled:!c.canRedo,onClick:()=>c.redo(),children:e.jsx(Ne,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!v&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",p.count===0&&"opacity-40 pointer-events-none"),title:S.copyShortcut,"aria-label":S.copy,disabled:p.count===0,onClick:B,children:e.jsx(Ce,{className:"h-4 w-4"})}),e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",!I.hasContent&&"opacity-40 pointer-events-none"),title:S.pasteShortcut,"aria-label":S.paste,disabled:!I.hasContent,onClick:le,children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsx("div",{className:"w-px h-5 bg-border mx-1"})]}),!v&&e.jsx("button",{className:oe("p-1.5 rounded hover:bg-accent",p.count===0&&"opacity-40 pointer-events-none"),title:S.deleteSelected,"aria-label":S.deleteSelected,disabled:p.count===0,onClick:ae,children:e.jsx(de,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1"}),O?.isConnected&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-green-500"}),S.collaborationConnected,O.users.length>1&&` (${O.users.length})`]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[F," ",C]}),g&&e.jsx("button",{className:"p-1.5 rounded hover:bg-accent",title:E?S.collapsePanel:S.expandPanel,"aria-label":E?S.collapsePanel:S.expandPanel,onClick:()=>N(w=>!w),children:e.jsx(Ue,{className:oe("h-4 w-4",!E&&"rotate-180")})})]}),e.jsx("div",{role:"region","aria-label":S.reportCanvas,className:"flex-1 overflow-auto bg-muted/10 p-4 flex justify-center",children:e.jsx("div",{className:"bg-white shadow-lg border",style:{width:Z,minHeight:Q},children:d.map((w,M)=>e.jsxs("div",{className:"relative border-b border-dashed border-gray-300",style:{minHeight:w.height},onDragOver:_,onDrop:m=>ne(m,M),children:[e.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:[Y(w.type),w.repeat&&" ↻"]}),!v&&e.jsxs("div",{className:"absolute right-1 top-0 flex items-center gap-0.5",children:[e.jsx("button",{onClick:()=>q(M,"text"),className:"p-0.5 rounded hover:bg-accent",title:S.addText,"aria-label":S.addText,children:e.jsx(Mt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>q(M,"field"),className:"p-0.5 rounded hover:bg-accent",title:S.addField,"aria-label":S.addField,children:e.jsx(ce,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>q(M,"image"),className:"p-0.5 rounded hover:bg-accent",title:S.addImage,"aria-label":S.addImage,children:e.jsx(Be,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>q(M,"chart"),className:"p-0.5 rounded hover:bg-accent",title:S.addChart,"aria-label":S.addChart,children:e.jsx(Rt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:()=>q(M,"table"),className:"p-0.5 rounded hover:bg-accent",title:S.addTable,"aria-label":S.addTable,children:e.jsx(Gt,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"relative",style:{minHeight:w.height,paddingTop:24},children:[w.elements.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground text-center pt-4",children:S.addElementsPrompt}),w.elements.map(m=>{const n=p.isSelected(m.id);return e.jsxs("div",{draggable:!v,onDragStart:a=>se(a,m,M),className:oe("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:m.position.x,top:(typeof m.position.y=="number"?m.position.y:0)+24,width:m.position.width,height:m.position.height},onClick:a=>p.toggle(m.id,a.shiftKey),children:[e.jsxs("span",{className:"text-muted-foreground",children:[m.type==="text"&&(m.properties.text??S.elementText),m.type==="field"&&`{${m.properties.field??"field"}}`,m.type==="image"&&S.elementImage,m.type==="chart"&&S.elementChart,m.type==="table"&&S.elementTable]}),!v&&n&&e.jsx("button",{onClick:a=>{a.stopPropagation(),J(m.id)},className:"absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow","aria-label":S.deleteElement,children:e.jsx(de,{className:"h-2.5 w-2.5"})})]},m.id)})]})]},`${w.type}-${M}`))})})]}),g&&e.jsx("div",{role:"region","aria-label":S.propertiesPanel,className:oe("border-l bg-muted/30 flex flex-col transition-[width] duration-200",E?"w-56":"w-0 overflow-hidden"),children:E&&(x&&V?e.jsx(Oe,{title:`${S.properties} – ${V.type}`,fields:re,onChange:ee}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:S.properties}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3",children:e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:S.selectElementPrompt})})]}))}),e.jsx(Fe,{isOpen:P.isOpen,title:P.title,message:P.message,onConfirm:P.onConfirm,onCancel:P.onCancel})]})}function Ee(...o){return ue(pe(o))}const D={title:"View Designer",saveView:"Save View",cancel:"Cancel",availableFields:"Available Fields",allFieldsAdded:"All fields added",noColumnsTitle:"No columns added yet. Select fields from the palette to add columns.",columnsCount:o=>`Columns (${o})`,viewType:"View Type",viewName:"View Name",viewNamePlaceholder:"Enter view name...",columnProperties:"Column Properties",selectColumnPrompt:"Select a column to edit its properties",labelField:"Label",widthField:"Width",widthPlaceholder:"auto",fieldLabel:"Field:",addFilter:"Add Filter",addSort:"Add Sort",valuePlaceholder:"Value",asc:"Asc",desc:"Desc",selectField:"Select field...",moveUp:"Move up",moveDown:"Move down",moveColumnUp:"Move column up",moveColumnDown:"Move column down",hideColumn:"Hide column",showColumn:"Show column",toggleVisibility:"Toggle column visibility",removeColumn:"Remove column",copyColumn:"Copy column",pasteColumn:"Paste column",deleteColumnTitle:"Delete Column",deleteColumnMessage:o=>`Are you sure you want to delete the column "${o}"? This action cannot be undone.`,undo:"Undo (Ctrl+Z)",redo:"Redo (Ctrl+Y)",gridOptionsHint:"Grid view uses the columns configured above.",groupByField:"Group By Field",startDateField:"Start Date Field",titleField:"Title Field",latitudeField:"Latitude Field",longitudeField:"Longitude Field",imageField:"Image Field",dateField:"Date Field"},We=[{type:"grid",label:"Grid",icon:mt},{type:"kanban",label:"Kanban",icon:xt},{type:"gallery",label:"Gallery",icon:Be},{type:"calendar",label:"Calendar",icon:ht},{type:"timeline",label:"Timeline",icon:bt},{type:"gantt",label:"Gantt",icon:gt},{type:"map",label:"Map",icon:qe}],ta=[{value:"equals",label:"="},{value:"contains",label:"Contains"},{value:"startsWith",label:"Starts with"},{value:"gt",label:">"},{value:"lt",label:"<"},{value:"gte",label:">="},{value:"lte",label:"<="},{value:"ne",label:"!="}];function lt({objectName:o,viewId:A,viewLabel:F="",viewType:C="grid",columns:b=[],filters:$=[],sort:f=[],availableFields:g=[],options:v={},readOnly:s=!1,onSave:y,onCancel:c,className:d}){const j=l.useRef(null),p=Se({columns:b,filters:$,sort:f,viewType:C,viewLabel:F,options:v}),{columns:x,filters:I,sort:P,viewType:O,viewLabel:k,options:E}=p.current,N=l.useCallback(a=>{p.push({...p.current,...a})},[p]),L=Te(),H=De(),G=Ie(),[Z,Q]=l.useState(null),[Y,V]=l.useState("columns"),q=l.useMemo(()=>{const a=new Set(x.map(r=>r.field));return g.filter(r=>!a.has(r.name))},[g,x]),J=l.useCallback(a=>{if(s)return;const r=g.find(i=>i.name===a),t={field:a,label:r?.label??a,visible:!0,order:x.length};N({columns:[...x,t]}),G?.sendOperation({type:"insert",userId:G.currentUserId??"",elementId:a,data:{column:t}})},[g,x,s,N,G]),ae=l.useCallback(async a=>{if(s)return;const r=x[a];!r||!await H.confirm(D.deleteColumnTitle,D.deleteColumnMessage(r.label||r.field))||(N({columns:x.filter((t,i)=>i!==a)}),Z===a&&Q(null),G?.sendOperation({type:"delete",userId:G.currentUserId??"",elementId:r.field,data:{}}))},[s,x,H,N,Z,G]),ee=l.useCallback(a=>{s||N({columns:x.map((r,t)=>t===a?{...r,visible:!r.visible}:r)})},[s,x,N]),B=l.useCallback((a,r)=>{if(s)return;const t=r==="up"?a-1:a+1;if(t<0||t>=x.length)return;const i=[...x],h=i[a];i[a]=i[t],i[t]=h,N({columns:i}),Q(t)},[s,x,N]),le=l.useCallback(()=>{s||g.length===0||N({filters:[...I,{field:g[0].name,operator:"equals",value:""}]})},[s,g,I,N]),se=l.useCallback(a=>{s||N({filters:I.filter((r,t)=>t!==a)})},[s,I,N]),_=l.useCallback((a,r)=>{s||N({filters:I.map((t,i)=>i===a?{...t,...r}:t)})},[s,I,N]),ne=l.useCallback(()=>{s||g.length===0||N({sort:[...P,{field:g[0].name,direction:"asc"}]})},[s,g,P,N]),re=l.useCallback(a=>{s||N({sort:P.filter((r,t)=>t!==a)})},[s,P,N]),w=l.useCallback((a,r)=>{s||N({sort:P.map((t,i)=>i===a?{...t,...r}:t)})},[s,P,N]),M=l.useCallback(()=>{Z===null||!x[Z]||L.copy(x[Z])},[Z,x,L]),m=l.useCallback(()=>{if(s)return;const a=L.paste();if(!a)return;const r={...a,field:`${a.field}_copy`,label:`${a.label||a.field} (Copy)`,order:x.length};N({columns:[...x,r]})},[s,L,x,N]),n=l.useCallback(()=>{y?.({viewId:A,viewLabel:k||`${o} View`,viewType:O,columns:x,filters:I,sort:P,options:E})},[y,A,k,o,O,x,I,P,E]);return l.useEffect(()=>{const a=j.current;if(!a)return;const r=t=>{const i=["INPUT","TEXTAREA","SELECT"].includes(t.target.tagName),h=t.ctrlKey||t.metaKey;if(!i){if(h&&t.key==="z"&&!t.shiftKey&&!s){t.preventDefault(),p.undo();return}if(h&&(t.key==="z"&&t.shiftKey||t.key==="y")&&!s){t.preventDefault(),p.redo();return}if(h&&t.key==="c"){t.preventDefault(),M();return}if(h&&t.key==="v"&&!s){t.preventDefault(),m();return}}};return a.addEventListener("keydown",r),()=>a.removeEventListener("keydown",r)},[s,p,M,m]),e.jsxs("div",{ref:j,tabIndex:-1,className:Ee("flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background",d),children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 border-b bg-muted/20 shrink-0",role:"toolbar",children:[e.jsx(ct,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"font-medium text-sm",children:D.title}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["— ",o]}),G?.isConnected&&G.users.length>1&&e.jsxs("div",{className:"flex items-center gap-1 ml-2",role:"status","aria-label":"Active collaborators",children:[G.users.slice(0,3).map(a=>e.jsx("div",{className:"h-5 w-5 rounded-full text-[10px] font-bold flex items-center justify-center text-white",style:{backgroundColor:a.color},title:a.userName,children:a.userName.charAt(0).toUpperCase()},a.userId)),G.users.length>3&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["+",G.users.length-3]})]}),e.jsx("div",{className:"flex-1"}),!s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:p.undo,disabled:!p.canUndo,className:"p-1.5 rounded hover:bg-accent disabled:opacity-30",title:D.undo,"aria-label":D.undo,"data-testid":"view-designer-undo",children:e.jsx(je,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:p.redo,disabled:!p.canRedo,className:"p-1.5 rounded hover:bg-accent disabled:opacity-30",title:D.redo,"aria-label":D.redo,"data-testid":"view-designer-redo",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"})]}),!s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:M,disabled:Z===null,className:"p-1.5 rounded hover:bg-accent disabled:opacity-30",title:D.copyColumn,"aria-label":D.copyColumn,"data-testid":"view-designer-copy",children:e.jsx(Ce,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:m,disabled:!L.hasContent,className:"p-1.5 rounded hover:bg-accent disabled:opacity-30",title:D.pasteColumn,"aria-label":D.pasteColumn,"data-testid":"view-designer-paste",children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),e.jsx("div",{className:"w-px h-4 bg-border mx-1"})]}),!s&&e.jsxs(e.Fragment,{children:[c&&e.jsxs("button",{onClick:c,className:"flex items-center gap-1 px-3 py-1.5 text-xs rounded border border-border hover:bg-accent","data-testid":"view-designer-cancel",children:[e.jsx(ut,{className:"h-3 w-3"})," ",D.cancel]}),e.jsxs("button",{onClick:n,className:"flex items-center gap-1 px-3 py-1.5 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90","data-testid":"view-designer-save",children:[e.jsx(pt,{className:"h-3 w-3"})," ",D.saveView]})]})]}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[!s&&e.jsxs("div",{className:"w-56 border-r bg-muted/30 flex flex-col shrink-0",children:[e.jsx("div",{className:"p-3 border-b font-medium text-sm",children:D.availableFields}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:q.length===0?e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:D.allFieldsAdded}):q.map(a=>e.jsxs("button",{onClick:()=>J(a.name),className:"w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-accent text-left","data-testid":`field-${a.name}`,children:[e.jsx(ce,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:a.label||a.name}),e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:a.type})]},a.name))})]}),e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"p-3 border-b space-y-3 shrink-0 bg-muted/10",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:D.viewType}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:We.map(({type:a,label:r,icon:t})=>e.jsxs("button",{onClick:()=>!s&&N({viewType:a}),className:Ee("flex items-center gap-2 px-3 py-2 text-sm rounded-md border-2 transition-all font-medium",O===a?"border-primary bg-primary text-primary-foreground shadow-sm":"border-border bg-background hover:border-primary/50 hover:bg-accent"),"data-testid":`view-type-${a}`,children:[e.jsx(t,{className:"h-4 w-4"}),r]},a))})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:D.viewName}),e.jsx("input",{type:"text",value:k,onChange:a=>!s&&N({viewLabel:a.target.value}),placeholder:D.viewNamePlaceholder,className:"px-3 py-2 text-sm border-2 rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-primary focus:border-primary",readOnly:s,"data-testid":"view-label-input"})]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-3",children:x.length===0?e.jsx("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ft,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:D.noColumnsTitle})]})}):e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-2",children:D.columnsCount(x.length)}),x.map((a,r)=>e.jsxs("div",{className:Ee("flex items-center gap-2 px-3 py-2 rounded border transition-colors cursor-pointer",Z===r?"border-primary bg-primary/5 ring-1 ring-primary/20":"border-border hover:border-primary/50",!a.visible&&"opacity-50"),onClick:()=>Q(r),"data-testid":`column-${a.field}`,children:[e.jsx(_e,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-sm font-medium truncate flex-1",children:a.label||a.field}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a.field}),!s&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:t=>{t.stopPropagation(),B(r,"up")},disabled:r===0,className:"p-0.5 rounded hover:bg-accent disabled:opacity-30",title:D.moveUp,"aria-label":D.moveColumnUp,children:e.jsx(yt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),B(r,"down")},disabled:r===x.length-1,className:"p-0.5 rounded hover:bg-accent disabled:opacity-30",title:D.moveDown,"aria-label":D.moveColumnDown,children:e.jsx(vt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),ee(r)},className:"p-0.5 rounded hover:bg-accent",title:a.visible!==!1?D.hideColumn:D.showColumn,"aria-label":D.toggleVisibility,children:a.visible!==!1?e.jsx(Je,{className:"h-3 w-3"}):e.jsx(wt,{className:"h-3 w-3"})}),e.jsx("button",{onClick:t=>{t.stopPropagation(),ae(r)},className:"p-0.5 rounded hover:bg-destructive/10",title:D.removeColumn,"aria-label":D.removeColumn,children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]})]},`${a.field}-${r}`))]})})]}),e.jsxs("div",{className:"w-64 border-l bg-muted/30 flex flex-col shrink-0",children:[e.jsx("div",{className:"flex border-b shrink-0",role:"tablist",children:["columns","filters","sort","options"].map(a=>e.jsx("button",{onClick:()=>V(a),role:"tab","aria-selected":Y===a,className:Ee("flex-1 px-2 py-2 text-xs font-medium capitalize transition-colors",Y===a?"border-b-2 border-primary text-primary":"text-muted-foreground hover:text-foreground"),children:a},a))}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3",children:[Y==="columns"&&e.jsx("div",{children:Z!==null&&x[Z]?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs font-medium",children:D.columnProperties}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.labelField}),e.jsx("input",{type:"text",value:x[Z].label??"",onChange:a=>{if(s)return;const r=Z;N({columns:x.map((t,i)=>i===r?{...t,label:a.target.value}:t)})},className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",readOnly:s,"data-testid":"column-label-input"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.widthField}),e.jsx("input",{type:"text",value:x[Z].width??"",onChange:a=>{if(s)return;const r=Z,t=a.target.value;N({columns:x.map((i,h)=>h===r?{...i,width:/^\d+$/.test(t)?Number(t):t}:i)})},placeholder:D.widthPlaceholder,className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",readOnly:s,"data-testid":"column-width-input"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[D.fieldLabel," ",e.jsx("span",{className:"font-mono",children:x[Z].field})]})]}):e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:D.selectColumnPrompt})}),Y==="filters"&&e.jsxs("div",{className:"space-y-2",children:[I.map((a,r)=>e.jsxs("div",{className:"space-y-1 p-2 border rounded bg-background","data-testid":`filter-${r}`,children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("select",{value:a.field,onChange:t=>_(r,{field:t.target.value}),className:"flex-1 px-1 py-0.5 text-xs border rounded bg-background",disabled:s,children:g.map(t=>e.jsx("option",{value:t.name,children:t.label||t.name},t.name))}),!s&&e.jsx("button",{onClick:()=>se(r),className:"p-0.5 rounded hover:bg-destructive/10",children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("select",{value:a.operator,onChange:t=>_(r,{operator:t.target.value}),className:"w-24 px-1 py-0.5 text-xs border rounded bg-background",disabled:s,children:ta.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("input",{type:"text",value:a.value??"",onChange:t=>_(r,{value:t.target.value}),placeholder:D.valuePlaceholder,className:"flex-1 px-1 py-0.5 text-xs border rounded bg-background",readOnly:s})]})]},r)),!s&&e.jsxs("button",{onClick:le,className:"w-full flex items-center justify-center gap-1 px-2 py-1.5 text-xs rounded border border-dashed border-border hover:bg-accent","data-testid":"add-filter","aria-label":D.addFilter,children:[e.jsx(ce,{className:"h-3 w-3"})," ",D.addFilter]})]}),Y==="sort"&&e.jsxs("div",{className:"space-y-2",children:[P.map((a,r)=>e.jsxs("div",{className:"flex items-center gap-1 p-2 border rounded bg-background","data-testid":`sort-${r}`,children:[e.jsx("select",{value:a.field,onChange:t=>w(r,{field:t.target.value}),className:"flex-1 px-1 py-0.5 text-xs border rounded bg-background",disabled:s,children:g.map(t=>e.jsx("option",{value:t.name,children:t.label||t.name},t.name))}),e.jsxs("select",{value:a.direction,onChange:t=>w(r,{direction:t.target.value}),className:"w-16 px-1 py-0.5 text-xs border rounded bg-background",disabled:s,children:[e.jsx("option",{value:"asc",children:D.asc}),e.jsx("option",{value:"desc",children:D.desc})]}),!s&&e.jsx("button",{onClick:()=>re(r),className:"p-0.5 rounded hover:bg-destructive/10",children:e.jsx(de,{className:"h-3 w-3 text-destructive"})})]},r)),!s&&e.jsxs("button",{onClick:ne,className:"w-full flex items-center justify-center gap-1 px-2 py-1.5 text-xs rounded border border-dashed border-border hover:bg-accent","data-testid":"add-sort","aria-label":D.addSort,children:[e.jsx(ce,{className:"h-3 w-3"})," ",D.addSort]})]}),Y==="options"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-xs font-medium",children:[We.find(a=>a.type===O)?.label??O," Options"]}),O==="kanban"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.groupByField}),e.jsxs("select",{value:E.groupBy??"",onChange:a=>!s&&N({options:{...E,groupBy:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,"data-testid":"kanban-group-by",children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),O==="calendar"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.startDateField}),e.jsxs("select",{value:E.startDateField??"",onChange:a=>!s&&N({options:{...E,startDateField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,"data-testid":"calendar-start-date",children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.titleField}),e.jsxs("select",{value:E.titleField??"",onChange:a=>!s&&N({options:{...E,titleField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,"data-testid":"calendar-title-field",children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]})]}),O==="map"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.latitudeField}),e.jsxs("select",{value:E.latitudeField??"",onChange:a=>!s&&N({options:{...E,latitudeField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.longitudeField}),e.jsxs("select",{value:E.longitudeField??"",onChange:a=>!s&&N({options:{...E,longitudeField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]})]}),O==="gallery"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.imageField}),e.jsxs("select",{value:E.imageField??"",onChange:a=>!s&&N({options:{...E,imageField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),(O==="timeline"||O==="gantt")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.dateField}),e.jsxs("select",{value:E.dateField??E.startDateField??"",onChange:a=>!s&&N({options:{...E,dateField:a.target.value,startDateField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:D.titleField}),e.jsxs("select",{value:E.titleField??"",onChange:a=>!s&&N({options:{...E,titleField:a.target.value}}),className:"w-full px-2 py-1 text-sm border rounded bg-background mt-1",disabled:s,children:[e.jsx("option",{value:"",children:D.selectField}),g.map(a=>e.jsx("option",{value:a.name,children:a.label||a.name},a.name))]})]})]}),O==="grid"&&e.jsx("div",{className:"text-xs text-muted-foreground text-center py-2",children:D.gridOptionsHint})]})]})]})]}),e.jsx(Fe,{isOpen:H.isOpen,title:H.title,message:H.message,onConfirm:H.onConfirm,onCancel:H.onCancel})]})}we.register("page-designer",Kt,{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}]});we.register("data-model-designer",Bt,{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}]});we.register("process-designer",_t,{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}]});we.register("report-designer",ea,{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}]});we.register("view-designer",lt,{label:"View Designer",category:"Designer",inputs:[{name:"objectName",type:"string",label:"Object Name"},{name:"viewId",type:"string",label:"View ID"},{name:"viewLabel",type:"string",label:"View Label"},{name:"viewType",type:"string",label:"View Type",defaultValue:"grid"},{name:"readOnly",type:"boolean",label:"Read Only",defaultValue:!1}]});function ra({objects:o}){const A=it(),{objectName:F,viewId:C}=ot(),b=o.find(s=>s.name===F),$=l.useMemo(()=>{if(!b?.fields)return[];const s=b.fields;return Array.isArray(s)?s.map(y=>typeof y=="string"?{name:y,label:y,type:"text"}:{name:y.name,label:y.label||y.name,type:y.type||"text"}):Object.entries(s).map(([y,c])=>({name:y,label:c.label||y,type:c.type||"text"}))},[b]),f=l.useMemo(()=>{if(!C||C==="new")return null;const s=b?.listViews||b?.list_views;return s&&s[C]||null},[C,b]),g=l.useCallback(s=>{console.log("[ViewDesigner] Save view config:",s),dt.success(f?`View "${s.viewLabel}" updated`:`View "${s.viewLabel}" created`),A(-1)},[f,A]),v=l.useCallback(()=>{A(-1)},[A]);return b?Ae.jsx("div",{className:"h-full flex flex-col",children:Ae.jsx(lt,{objectName:b.name,viewId:C==="new"?void 0:C,viewLabel:f?.label??"",viewType:f?.type??"grid",columns:f?.columns?f.columns.map((s,y)=>({field:s,label:$.find(c=>c.name===s)?.label??s,visible:!0,order:y})):[],filters:f?.filter??[],sort:f?.sort?.map(s=>({field:s.field,direction:s.order||s.direction||"asc"}))??[],availableFields:$,options:f?.options??{},onSave:g,onCancel:v,className:"flex-1"})}):Ae.jsxs("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:['Object "',F,'" not found']})}export{ra as ViewDesignerPage};
@@ -1 +1 @@
1
- import{O}from"./vendor-objectstack-DqojdwYW.js";import{h as C}from"./framework-mHWN965c.js";class ${cache;maxSize;ttl;stats;constructor(t={}){this.cache=new Map,this.maxSize=t.maxSize||100,this.ttl=t.ttl||300*1e3,this.stats={hits:0,misses:0,evictions:0}}async get(t,e){const s=Date.now(),n=this.cache.get(t);if(n){if(s-n.timestamp<this.ttl)return n.accessCount++,n.lastAccessed=s,this.stats.hits++,this.cache.delete(t),this.cache.set(t,n),n.data;this.cache.delete(t)}this.stats.misses++;const a=await e();return this.set(t,a),a}set(t,e){const s=Date.now();this.cache.size>=this.maxSize&&!this.cache.has(t)&&this.evictLRU(),this.cache.set(t,{data:e,timestamp:s,accessCount:1,lastAccessed:s})}evictLRU(){const t=this.cache.keys().next().value;t!==void 0&&(this.cache.delete(t),this.stats.evictions++)}invalidate(t){t?this.cache.delete(t):this.cache.clear()}clear(){this.cache.clear(),this.stats={hits:0,misses:0,evictions:0}}getStats(){const t=this.stats.hits+this.stats.misses,e=t>0?this.stats.hits/t:0;return{size:this.cache.size,maxSize:this.maxSize,hits:this.stats.hits,misses:this.stats.misses,evictions:this.stats.evictions,hitRate:e}}getCachedSync(t){const e=this.cache.get(t);if(e){if(this.ttl>0&&Date.now()-e.timestamp>this.ttl){this.cache.delete(t);return}return this.cache.delete(t),this.cache.set(t,e),this.stats.hits++,e.data}}has(t){const e=this.cache.get(t);return e?Date.now()-e.timestamp>=this.ttl?(this.cache.delete(t),!1):!0:!1}}class h extends Error{constructor(t,e,s,n){super(t),this.code=e,this.statusCode=s,this.details=n,this.name="ObjectStackError",Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,message:this.message,code:this.code,statusCode:this.statusCode,details:this.details,stack:this.stack}}}class y extends h{constructor(t,e){super(`Metadata not found for object: ${t}`,"METADATA_NOT_FOUND",404,{objectName:t,...e}),this.name="MetadataNotFoundError"}}class g extends h{constructor(t,e,s,n,a){super(`Bulk ${t} operation failed: ${e} succeeded, ${s} failed`,"BULK_OPERATION_ERROR",500,{operation:t,successCount:e,failureCount:s,errors:n,...a}),this.successCount=e,this.failureCount=s,this.errors=n,this.name="BulkOperationError"}getSummary(){const t=this.successCount+this.failureCount,e=t>0?this.failureCount/t:0;return{operation:this.details?.operation,total:t,successful:this.successCount,failed:this.failureCount,failureRate:e,errors:this.errors}}}class w extends h{constructor(t,e,s,n){super(`Connection error: ${t}`,"CONNECTION_ERROR",n||503,{url:e,...s}),this.url=e,this.name="ConnectionError"}}class p extends h{constructor(t="Authentication failed",e,s){super(t,"AUTHENTICATION_ERROR",s||401,e),this.name="AuthenticationError"}}class E extends h{constructor(t,e,s,n){super(t,"VALIDATION_ERROR",400,{field:e,validationErrors:s,...n}),this.field=e,this.validationErrors=s,this.name="ValidationError"}getValidationErrors(){return this.validationErrors||[]}}function R(i,t){const e=i?.status||i?.statusCode||500,s=i?.message||i?.statusText||"Unknown error",n={context:t,response:{status:e,data:i?.data,headers:i?.headers}};switch(e){case 401:return new p(s,n,401);case 403:return new p(s,n,403);case 404:if(t?.includes("metadata")||t?.includes("schema")||t?.includes("getObjectSchema")){const a=A(t);return new y(a,n)}return new h(s,"NOT_FOUND",404,n);case 400:return new E(s,void 0,i?.data?.errors,n);case 503:return new w(s,i?.config?.url,n,503);case 504:return new w(s,i?.config?.url,n,504);default:return new h(s,"UNKNOWN_ERROR",e,n)}}function A(i){if(!i)return"unknown";const t=i.match(/\(([^)]+)\)/);return t?t[1]:"unknown"}class N{client;connected=!1;metadataCache;connectionState="disconnected";connectionStateListeners=[];batchProgressListeners=[];autoReconnect;maxReconnectAttempts;reconnectDelay;reconnectAttempts=0;baseUrl;token;constructor(t){this.client=new O(t),this.metadataCache=new $(t.cache),this.autoReconnect=t.autoReconnect??!0,this.maxReconnectAttempts=t.maxReconnectAttempts??3,this.reconnectDelay=t.reconnectDelay??1e3,this.baseUrl=t.baseUrl,this.token=t.token}async connect(){if(!this.connected){this.setConnectionState("connecting");try{await this.client.connect(),this.connected=!0,this.reconnectAttempts=0,this.setConnectionState("connected")}catch(t){const e=t instanceof Error?t.message:"Failed to connect to ObjectStack server",s=new w(e,void 0,{originalError:t});if(this.setConnectionState("error",s),this.autoReconnect&&this.reconnectAttempts<this.maxReconnectAttempts)await this.attemptReconnect();else throw s}}}async attemptReconnect(){this.reconnectAttempts++,this.setConnectionState("reconnecting");const t=this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1);await new Promise(e=>setTimeout(e,t)),this.connected=!1,await this.connect()}getConnectionState(){return this.connectionState}isConnected(){return this.connected&&this.connectionState==="connected"}onConnectionStateChange(t){return this.connectionStateListeners.push(t),()=>{const e=this.connectionStateListeners.indexOf(t);e>-1&&this.connectionStateListeners.splice(e,1)}}onBatchProgress(t){return this.batchProgressListeners.push(t),()=>{const e=this.batchProgressListeners.indexOf(t);e>-1&&this.batchProgressListeners.splice(e,1)}}setConnectionState(t,e){this.connectionState=t;const s={state:t,timestamp:Date.now(),error:e};this.connectionStateListeners.forEach(n=>{try{n(s)}catch(a){console.error("Error in connection state listener:",a)}})}emitBatchProgress(t){this.batchProgressListeners.forEach(e=>{try{e(t)}catch(s){console.error("Error in batch progress listener:",s)}})}async find(t,e){await this.connect();const s=this.convertQueryParams(e),n=await this.client.data.find(t,s);if(Array.isArray(n))return{data:n,total:n.length,page:1,pageSize:n.length,hasMore:!1};const a=n,r=a.records||a.value||[],o=a.total??a.count??r.length;return{data:r,total:o,page:e?.$skip&&e.$top?Math.floor(e.$skip/e.$top)+1:1,pageSize:e?.$top,hasMore:e?.$top?r.length===e.$top:!1}}async findOne(t,e,s){await this.connect();try{return(await this.client.data.get(t,String(e))).record}catch(n){if(n?.status===404)return null;throw n}}async create(t,e){return await this.connect(),(await this.client.data.create(t,e)).record}async update(t,e,s){return await this.connect(),(await this.client.data.update(t,String(e),s)).record}async delete(t,e){return await this.connect(),(await this.client.data.delete(t,String(e))).deleted}async bulk(t,e,s){if(await this.connect(),!s||s.length===0)return[];const n=s.length;let a=0,r=0;const o=()=>{this.emitBatchProgress({operation:e,total:n,completed:a,failed:r,percentage:n>0?(a+r)/n*100:0})};try{switch(e){case"create":{o();const c=await this.client.data.createMany(t,s);return a=c.length,r=n-a,o(),c}case"delete":{const c=s.map(l=>l.id).filter(Boolean);if(c.length===0){const l=s.map((u,d)=>({index:d,error:`Missing ID for item at index ${d}`}));throw r=s.length,o(),new g("delete",0,s.length,l)}return o(),await this.client.data.deleteMany(t,c),a=c.length,r=n-a,o(),[]}case"update":{if(typeof this.client.data.updateMany=="function")try{o();const u=this.client.data.updateMany,d=await u(t,s);return a=d.length,r=n-a,o(),d}catch{}const c=[],l=[];for(let u=0;u<s.length;u++){const d=s[u],m=d.id;if(!m){l.push({index:u,error:"Missing ID"}),r++,o();continue}try{const f=await this.client.data.update(t,String(m),d);c.push(f.record),a++,o()}catch(f){const S=f instanceof Error?f.message:String(f);l.push({index:u,error:S}),r++,o()}}if(l.length>0)throw new g("update",c.length,l.length,l,{resource:t,totalRecords:s.length});return c}default:throw new h(`Unsupported bulk operation: ${e}`,"UNSUPPORTED_OPERATION",400)}}catch(c){if(o(),c instanceof g||c instanceof h)throw c;const l=c instanceof Error?c.message:String(c),u=s.map((d,m)=>({index:m,error:l}));throw new g(e,0,s.length,u,{resource:t,originalError:c})}}convertQueryParams(t){if(!t)return{};const e={};if(t.$select&&(e.select=t.$select),t.$filter&&(Array.isArray(t.$filter)?e.filters=t.$filter:e.filters=C(t.$filter)),t.$orderby)if(Array.isArray(t.$orderby))e.sort=t.$orderby.map(s=>{if(typeof s=="string")return s;const n=s.field;return(s.order||"asc")==="desc"?`-${n}`:n});else{const s=Object.entries(t.$orderby).map(([n,a])=>a==="desc"?`-${n}`:n);e.sort=s}return t.$skip!==void 0&&(e.skip=t.$skip),t.$top!==void 0&&(e.top=t.$top),e}async getObjectSchema(t){await this.connect();try{return await this.metadataCache.get(t,async()=>{const s=await this.client.meta.getItem("object",t);return s&&s.item?s.item:s})}catch(e){const s=e;throw s?.status===404||s?.statusCode===404?new y(t,{originalError:e}):e instanceof h?e:R(s,`getObjectSchema(${t})`)}}getClient(){return this.client}async getDiscovery(){try{return await this.connect(),this.client.discoveryInfo||null}catch{return null}}async getView(t,e){await this.connect();try{const s=`view:${t}:${e}`;return await this.metadataCache.get(s,async()=>{const n=await this.client.meta.getItem(t,`views/${e}`);return n&&n.item?n.item:n??null})}catch{return null}}async getApp(t){await this.connect();try{const e=`app:${t}`;return await this.metadataCache.get(e,async()=>{const s=await this.client.meta.getItem("apps",t);return s&&s.item?s.item:s??null})}catch{return null}}async getPage(t){await this.connect();try{const e=`page:${t}`;return await this.metadataCache.get(e,async()=>{const s=await this.client.meta.getItem("pages",t);return s&&s.item?s.item:s??null})}catch{return null}}async getItems(t,e){return await this.connect(),await Promise.all(e.map(async n=>{const a=`${t}:${n}`;return this.metadataCache.get(a,async()=>{const r=await this.client.meta.getItem(t,n);return r&&r.item?r.item:r})}))}getCached(t){return this.metadataCache.getCachedSync(t)}getCacheStats(){return this.metadataCache.getStats()}invalidateCache(t){this.metadataCache.invalidate(t)}clearCache(){this.metadataCache.clear()}async uploadFile(t,e,s){await this.connect();const n=new FormData;n.append("file",e),s?.recordId&&n.append("recordId",s.recordId),s?.fieldName&&n.append("fieldName",s.fieldName),s?.metadata&&n.append("metadata",JSON.stringify(s.metadata));const a=`${this.baseUrl}/api/data/${encodeURIComponent(t)}/upload`,r=await fetch(a,{method:"POST",body:n,headers:{...this.getAuthHeaders()}});if(!r.ok){const o=await r.json().catch(()=>({message:r.statusText}));throw new h(o.message||`Upload failed with status ${r.status}`,"UPLOAD_ERROR",r.status)}return r.json()}async uploadFiles(t,e,s){await this.connect();const n=new FormData;e.forEach((o,c)=>{n.append("files",o,o.name||`file-${c}`)}),s?.recordId&&n.append("recordId",s.recordId),s?.fieldName&&n.append("fieldName",s.fieldName),s?.metadata&&n.append("metadata",JSON.stringify(s.metadata));const a=`${this.baseUrl}/api/data/${encodeURIComponent(t)}/upload`,r=await fetch(a,{method:"POST",body:n,headers:{...this.getAuthHeaders()}});if(!r.ok){const o=await r.json().catch(()=>({message:r.statusText}));throw new h(o.message||`Upload failed with status ${r.status}`,"UPLOAD_ERROR",r.status)}return r.json()}getAuthHeaders(){const t={};return this.token&&(t.Authorization=`Bearer ${this.token}`),t}}export{N as O};
1
+ import{O}from"./vendor-objectstack-Bifvxvds.js";import{h as C}from"./framework-mHWN965c.js";class ${cache;maxSize;ttl;stats;constructor(t={}){this.cache=new Map,this.maxSize=t.maxSize||100,this.ttl=t.ttl||300*1e3,this.stats={hits:0,misses:0,evictions:0}}async get(t,e){const s=Date.now(),n=this.cache.get(t);if(n){if(s-n.timestamp<this.ttl)return n.accessCount++,n.lastAccessed=s,this.stats.hits++,this.cache.delete(t),this.cache.set(t,n),n.data;this.cache.delete(t)}this.stats.misses++;const a=await e();return this.set(t,a),a}set(t,e){const s=Date.now();this.cache.size>=this.maxSize&&!this.cache.has(t)&&this.evictLRU(),this.cache.set(t,{data:e,timestamp:s,accessCount:1,lastAccessed:s})}evictLRU(){const t=this.cache.keys().next().value;t!==void 0&&(this.cache.delete(t),this.stats.evictions++)}invalidate(t){t?this.cache.delete(t):this.cache.clear()}clear(){this.cache.clear(),this.stats={hits:0,misses:0,evictions:0}}getStats(){const t=this.stats.hits+this.stats.misses,e=t>0?this.stats.hits/t:0;return{size:this.cache.size,maxSize:this.maxSize,hits:this.stats.hits,misses:this.stats.misses,evictions:this.stats.evictions,hitRate:e}}getCachedSync(t){const e=this.cache.get(t);if(e){if(this.ttl>0&&Date.now()-e.timestamp>this.ttl){this.cache.delete(t);return}return this.cache.delete(t),this.cache.set(t,e),this.stats.hits++,e.data}}has(t){const e=this.cache.get(t);return e?Date.now()-e.timestamp>=this.ttl?(this.cache.delete(t),!1):!0:!1}}class h extends Error{constructor(t,e,s,n){super(t),this.code=e,this.statusCode=s,this.details=n,this.name="ObjectStackError",Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,message:this.message,code:this.code,statusCode:this.statusCode,details:this.details,stack:this.stack}}}class y extends h{constructor(t,e){super(`Metadata not found for object: ${t}`,"METADATA_NOT_FOUND",404,{objectName:t,...e}),this.name="MetadataNotFoundError"}}class g extends h{constructor(t,e,s,n,a){super(`Bulk ${t} operation failed: ${e} succeeded, ${s} failed`,"BULK_OPERATION_ERROR",500,{operation:t,successCount:e,failureCount:s,errors:n,...a}),this.successCount=e,this.failureCount=s,this.errors=n,this.name="BulkOperationError"}getSummary(){const t=this.successCount+this.failureCount,e=t>0?this.failureCount/t:0;return{operation:this.details?.operation,total:t,successful:this.successCount,failed:this.failureCount,failureRate:e,errors:this.errors}}}class w extends h{constructor(t,e,s,n){super(`Connection error: ${t}`,"CONNECTION_ERROR",n||503,{url:e,...s}),this.url=e,this.name="ConnectionError"}}class p extends h{constructor(t="Authentication failed",e,s){super(t,"AUTHENTICATION_ERROR",s||401,e),this.name="AuthenticationError"}}class E extends h{constructor(t,e,s,n){super(t,"VALIDATION_ERROR",400,{field:e,validationErrors:s,...n}),this.field=e,this.validationErrors=s,this.name="ValidationError"}getValidationErrors(){return this.validationErrors||[]}}function R(i,t){const e=i?.status||i?.statusCode||500,s=i?.message||i?.statusText||"Unknown error",n={context:t,response:{status:e,data:i?.data,headers:i?.headers}};switch(e){case 401:return new p(s,n,401);case 403:return new p(s,n,403);case 404:if(t?.includes("metadata")||t?.includes("schema")||t?.includes("getObjectSchema")){const a=A(t);return new y(a,n)}return new h(s,"NOT_FOUND",404,n);case 400:return new E(s,void 0,i?.data?.errors,n);case 503:return new w(s,i?.config?.url,n,503);case 504:return new w(s,i?.config?.url,n,504);default:return new h(s,"UNKNOWN_ERROR",e,n)}}function A(i){if(!i)return"unknown";const t=i.match(/\(([^)]+)\)/);return t?t[1]:"unknown"}class N{client;connected=!1;metadataCache;connectionState="disconnected";connectionStateListeners=[];batchProgressListeners=[];autoReconnect;maxReconnectAttempts;reconnectDelay;reconnectAttempts=0;baseUrl;token;constructor(t){this.client=new O(t),this.metadataCache=new $(t.cache),this.autoReconnect=t.autoReconnect??!0,this.maxReconnectAttempts=t.maxReconnectAttempts??3,this.reconnectDelay=t.reconnectDelay??1e3,this.baseUrl=t.baseUrl,this.token=t.token}async connect(){if(!this.connected){this.setConnectionState("connecting");try{await this.client.connect(),this.connected=!0,this.reconnectAttempts=0,this.setConnectionState("connected")}catch(t){const e=t instanceof Error?t.message:"Failed to connect to ObjectStack server",s=new w(e,void 0,{originalError:t});if(this.setConnectionState("error",s),this.autoReconnect&&this.reconnectAttempts<this.maxReconnectAttempts)await this.attemptReconnect();else throw s}}}async attemptReconnect(){this.reconnectAttempts++,this.setConnectionState("reconnecting");const t=this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1);await new Promise(e=>setTimeout(e,t)),this.connected=!1,await this.connect()}getConnectionState(){return this.connectionState}isConnected(){return this.connected&&this.connectionState==="connected"}onConnectionStateChange(t){return this.connectionStateListeners.push(t),()=>{const e=this.connectionStateListeners.indexOf(t);e>-1&&this.connectionStateListeners.splice(e,1)}}onBatchProgress(t){return this.batchProgressListeners.push(t),()=>{const e=this.batchProgressListeners.indexOf(t);e>-1&&this.batchProgressListeners.splice(e,1)}}setConnectionState(t,e){this.connectionState=t;const s={state:t,timestamp:Date.now(),error:e};this.connectionStateListeners.forEach(n=>{try{n(s)}catch(a){console.error("Error in connection state listener:",a)}})}emitBatchProgress(t){this.batchProgressListeners.forEach(e=>{try{e(t)}catch(s){console.error("Error in batch progress listener:",s)}})}async find(t,e){await this.connect();const s=this.convertQueryParams(e),n=await this.client.data.find(t,s);if(Array.isArray(n))return{data:n,total:n.length,page:1,pageSize:n.length,hasMore:!1};const a=n,r=a.records||a.value||[],o=a.total??a.count??r.length;return{data:r,total:o,page:e?.$skip&&e.$top?Math.floor(e.$skip/e.$top)+1:1,pageSize:e?.$top,hasMore:e?.$top?r.length===e.$top:!1}}async findOne(t,e,s){await this.connect();try{return(await this.client.data.get(t,String(e))).record}catch(n){if(n?.status===404)return null;throw n}}async create(t,e){return await this.connect(),(await this.client.data.create(t,e)).record}async update(t,e,s){return await this.connect(),(await this.client.data.update(t,String(e),s)).record}async delete(t,e){return await this.connect(),(await this.client.data.delete(t,String(e))).deleted}async bulk(t,e,s){if(await this.connect(),!s||s.length===0)return[];const n=s.length;let a=0,r=0;const o=()=>{this.emitBatchProgress({operation:e,total:n,completed:a,failed:r,percentage:n>0?(a+r)/n*100:0})};try{switch(e){case"create":{o();const c=await this.client.data.createMany(t,s);return a=c.length,r=n-a,o(),c}case"delete":{const c=s.map(l=>l.id).filter(Boolean);if(c.length===0){const l=s.map((u,d)=>({index:d,error:`Missing ID for item at index ${d}`}));throw r=s.length,o(),new g("delete",0,s.length,l)}return o(),await this.client.data.deleteMany(t,c),a=c.length,r=n-a,o(),[]}case"update":{if(typeof this.client.data.updateMany=="function")try{o();const u=this.client.data.updateMany,d=await u(t,s);return a=d.length,r=n-a,o(),d}catch{}const c=[],l=[];for(let u=0;u<s.length;u++){const d=s[u],m=d.id;if(!m){l.push({index:u,error:"Missing ID"}),r++,o();continue}try{const f=await this.client.data.update(t,String(m),d);c.push(f.record),a++,o()}catch(f){const S=f instanceof Error?f.message:String(f);l.push({index:u,error:S}),r++,o()}}if(l.length>0)throw new g("update",c.length,l.length,l,{resource:t,totalRecords:s.length});return c}default:throw new h(`Unsupported bulk operation: ${e}`,"UNSUPPORTED_OPERATION",400)}}catch(c){if(o(),c instanceof g||c instanceof h)throw c;const l=c instanceof Error?c.message:String(c),u=s.map((d,m)=>({index:m,error:l}));throw new g(e,0,s.length,u,{resource:t,originalError:c})}}convertQueryParams(t){if(!t)return{};const e={};if(t.$select&&(e.select=t.$select),t.$filter&&(Array.isArray(t.$filter)?e.filters=t.$filter:e.filters=C(t.$filter)),t.$orderby)if(Array.isArray(t.$orderby))e.sort=t.$orderby.map(s=>{if(typeof s=="string")return s;const n=s.field;return(s.order||"asc")==="desc"?`-${n}`:n});else{const s=Object.entries(t.$orderby).map(([n,a])=>a==="desc"?`-${n}`:n);e.sort=s}return t.$skip!==void 0&&(e.skip=t.$skip),t.$top!==void 0&&(e.top=t.$top),e}async getObjectSchema(t){await this.connect();try{return await this.metadataCache.get(t,async()=>{const s=await this.client.meta.getItem("object",t);return s&&s.item?s.item:s})}catch(e){const s=e;throw s?.status===404||s?.statusCode===404?new y(t,{originalError:e}):e instanceof h?e:R(s,`getObjectSchema(${t})`)}}getClient(){return this.client}async getDiscovery(){try{return await this.connect(),this.client.discoveryInfo||null}catch{return null}}async getView(t,e){await this.connect();try{const s=`view:${t}:${e}`;return await this.metadataCache.get(s,async()=>{const n=await this.client.meta.getItem(t,`views/${e}`);return n&&n.item?n.item:n??null})}catch{return null}}async getApp(t){await this.connect();try{const e=`app:${t}`;return await this.metadataCache.get(e,async()=>{const s=await this.client.meta.getItem("apps",t);return s&&s.item?s.item:s??null})}catch{return null}}async getPage(t){await this.connect();try{const e=`page:${t}`;return await this.metadataCache.get(e,async()=>{const s=await this.client.meta.getItem("pages",t);return s&&s.item?s.item:s??null})}catch{return null}}async getItems(t,e){return await this.connect(),await Promise.all(e.map(async n=>{const a=`${t}:${n}`;return this.metadataCache.get(a,async()=>{const r=await this.client.meta.getItem(t,n);return r&&r.item?r.item:r})}))}getCached(t){return this.metadataCache.getCachedSync(t)}getCacheStats(){return this.metadataCache.getStats()}invalidateCache(t){this.metadataCache.invalidate(t)}clearCache(){this.metadataCache.clear()}async uploadFile(t,e,s){await this.connect();const n=new FormData;n.append("file",e),s?.recordId&&n.append("recordId",s.recordId),s?.fieldName&&n.append("fieldName",s.fieldName),s?.metadata&&n.append("metadata",JSON.stringify(s.metadata));const a=`${this.baseUrl}/api/data/${encodeURIComponent(t)}/upload`,r=await fetch(a,{method:"POST",body:n,headers:{...this.getAuthHeaders()}});if(!r.ok){const o=await r.json().catch(()=>({message:r.statusText}));throw new h(o.message||`Upload failed with status ${r.status}`,"UPLOAD_ERROR",r.status)}return r.json()}async uploadFiles(t,e,s){await this.connect();const n=new FormData;e.forEach((o,c)=>{n.append("files",o,o.name||`file-${c}`)}),s?.recordId&&n.append("recordId",s.recordId),s?.fieldName&&n.append("fieldName",s.fieldName),s?.metadata&&n.append("metadata",JSON.stringify(s.metadata));const a=`${this.baseUrl}/api/data/${encodeURIComponent(t)}/upload`,r=await fetch(a,{method:"POST",body:n,headers:{...this.getAuthHeaders()}});if(!r.ok){const o=await r.json().catch(()=>({message:r.statusText}));throw new h(o.message||`Upload failed with status ${r.status}`,"UPLOAD_ERROR",r.status)}return r.json()}getAuthHeaders(){const t={};return this.token&&(t.Authorization=`Bearer ${this.token}`),t}}export{N as O};