@object-ui/console 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +118 -0
  3. package/dist/assets/AdvancedChartImpl-DAS1mU9o.js +7 -0
  4. package/dist/assets/AdvancedChartImpl-DAS1mU9o.js.br +0 -0
  5. package/dist/assets/AdvancedChartImpl-DAS1mU9o.js.gz +0 -0
  6. package/dist/assets/AuditLogPage-BQW_Xbnm.js +1 -0
  7. package/dist/assets/AuditLogPage-BQW_Xbnm.js.br +0 -0
  8. package/dist/assets/AuditLogPage-BQW_Xbnm.js.gz +0 -0
  9. package/dist/assets/ChartImpl-2ivTljUi.js +1 -0
  10. package/dist/assets/ChartImpl-2ivTljUi.js.br +0 -0
  11. package/dist/assets/ChartImpl-2ivTljUi.js.gz +0 -0
  12. package/dist/assets/DashboardView-Dt-4VhH6.js +1 -0
  13. package/dist/assets/DashboardView-Dt-4VhH6.js.br +0 -0
  14. package/dist/assets/DashboardView-Dt-4VhH6.js.gz +0 -0
  15. package/dist/assets/ForgotPasswordPage-zr9S5vrE.js +1 -0
  16. package/dist/assets/KanbanEnhanced-BlGp--J7.js +1 -0
  17. package/dist/assets/KanbanEnhanced-BlGp--J7.js.br +0 -0
  18. package/dist/assets/KanbanEnhanced-BlGp--J7.js.gz +0 -0
  19. package/dist/assets/KanbanImpl-B5wWMXrJ.js +1 -0
  20. package/dist/assets/KanbanImpl-B5wWMXrJ.js.br +0 -0
  21. package/dist/assets/KanbanImpl-B5wWMXrJ.js.gz +0 -0
  22. package/dist/assets/LoginPage-H688gsah.js +1 -0
  23. package/dist/assets/MarkdownImpl-BshtTFK2.js +29 -0
  24. package/dist/assets/MarkdownImpl-BshtTFK2.js.br +0 -0
  25. package/dist/assets/MarkdownImpl-BshtTFK2.js.gz +0 -0
  26. package/dist/assets/OrgManagementPage-x3qIkxHL.js +1 -0
  27. package/dist/assets/OrgManagementPage-x3qIkxHL.js.br +0 -0
  28. package/dist/assets/OrgManagementPage-x3qIkxHL.js.gz +0 -0
  29. package/dist/assets/PageView-BRN1h8QD.js +1 -0
  30. package/dist/assets/PageView-BRN1h8QD.js.br +0 -0
  31. package/dist/assets/PageView-BRN1h8QD.js.gz +0 -0
  32. package/dist/assets/ProfilePage-DjAiGvFb.js +1 -0
  33. package/dist/assets/ProfilePage-DjAiGvFb.js.br +0 -0
  34. package/dist/assets/ProfilePage-DjAiGvFb.js.gz +0 -0
  35. package/dist/assets/RecordDetailView-Bfu7541n.js +1 -0
  36. package/dist/assets/RecordDetailView-Bfu7541n.js.br +0 -0
  37. package/dist/assets/RecordDetailView-Bfu7541n.js.gz +0 -0
  38. package/dist/assets/RegisterPage-CR91Lc7x.js +1 -0
  39. package/dist/assets/ReportView-CwWsv2yl.js +1 -0
  40. package/dist/assets/ReportView-CwWsv2yl.js.br +0 -0
  41. package/dist/assets/ReportView-CwWsv2yl.js.gz +0 -0
  42. package/dist/assets/RoleManagementPage-DnWuzxKJ.js +1 -0
  43. package/dist/assets/RoleManagementPage-DnWuzxKJ.js.br +0 -0
  44. package/dist/assets/RoleManagementPage-DnWuzxKJ.js.gz +0 -0
  45. package/dist/assets/SearchResultsPage-DBpjAlh2.js +1 -0
  46. package/dist/assets/SearchResultsPage-DBpjAlh2.js.br +0 -0
  47. package/dist/assets/SearchResultsPage-DBpjAlh2.js.gz +0 -0
  48. package/dist/assets/UserManagementPage-o0_K0dzR.js +1 -0
  49. package/dist/assets/UserManagementPage-o0_K0dzR.js.br +0 -0
  50. package/dist/assets/UserManagementPage-o0_K0dzR.js.gz +0 -0
  51. package/dist/assets/ViewDesignerPage-BbwrZa9D.js +1 -0
  52. package/dist/assets/ViewDesignerPage-BbwrZa9D.js.br +0 -0
  53. package/dist/assets/ViewDesignerPage-BbwrZa9D.js.gz +0 -0
  54. package/dist/assets/data-adapter-Cn800k4a.js +1 -0
  55. package/dist/assets/data-adapter-Cn800k4a.js.br +0 -0
  56. package/dist/assets/data-adapter-Cn800k4a.js.gz +0 -0
  57. package/dist/assets/framework-mHWN965c.js +10 -0
  58. package/dist/assets/framework-mHWN965c.js.br +0 -0
  59. package/dist/assets/framework-mHWN965c.js.gz +0 -0
  60. package/dist/assets/index-BjEGJcpx.js +56 -0
  61. package/dist/assets/index-BjEGJcpx.js.br +0 -0
  62. package/dist/assets/index-BjEGJcpx.js.gz +0 -0
  63. package/dist/assets/index-CUnVdETN.css +1 -0
  64. package/dist/assets/index-CUnVdETN.css.br +0 -0
  65. package/dist/assets/index-CUnVdETN.css.gz +0 -0
  66. package/dist/assets/infrastructure-aS2LF8OZ.js +1 -0
  67. package/dist/assets/infrastructure-aS2LF8OZ.js.br +0 -0
  68. package/dist/assets/infrastructure-aS2LF8OZ.js.gz +0 -0
  69. package/dist/assets/maplibre-gl-D2AsLM0J.js +811 -0
  70. package/dist/assets/maplibre-gl-D2AsLM0J.js.br +0 -0
  71. package/dist/assets/maplibre-gl-D2AsLM0J.js.gz +0 -0
  72. package/dist/assets/plugins-core-CcBSZCjG.js +4 -0
  73. package/dist/assets/plugins-core-CcBSZCjG.js.br +0 -0
  74. package/dist/assets/plugins-core-CcBSZCjG.js.gz +0 -0
  75. package/dist/assets/plugins-views-DQwkCaaO.js +60 -0
  76. package/dist/assets/plugins-views-DQwkCaaO.js.br +0 -0
  77. package/dist/assets/plugins-views-DQwkCaaO.js.gz +0 -0
  78. package/dist/assets/plugins-views-P3eB-els.css +1 -0
  79. package/dist/assets/plugins-views-P3eB-els.css.br +0 -0
  80. package/dist/assets/plugins-views-P3eB-els.css.gz +0 -0
  81. package/dist/assets/systemObjects-DSpePIIy.js +1 -0
  82. package/dist/assets/systemObjects-DSpePIIy.js.br +2 -0
  83. package/dist/assets/systemObjects-DSpePIIy.js.gz +0 -0
  84. package/dist/assets/ui-components-DVonQS7H.js +31 -0
  85. package/dist/assets/ui-components-DVonQS7H.js.br +0 -0
  86. package/dist/assets/ui-components-DVonQS7H.js.gz +0 -0
  87. package/dist/assets/ui-components-GrNdJOi1.css +1 -0
  88. package/dist/assets/ui-components-GrNdJOi1.css.br +0 -0
  89. package/dist/assets/ui-components-GrNdJOi1.css.gz +0 -0
  90. package/dist/assets/ui-layout-BENIRxAF.js +1 -0
  91. package/dist/assets/ui-layout-BENIRxAF.js.br +0 -0
  92. package/dist/assets/ui-layout-BENIRxAF.js.gz +0 -0
  93. package/dist/assets/vendor-charts-CSvoW-yB.js +65 -0
  94. package/dist/assets/vendor-charts-CSvoW-yB.js.br +0 -0
  95. package/dist/assets/vendor-charts-CSvoW-yB.js.gz +0 -0
  96. package/dist/assets/vendor-dndkit-DRGpK6sP.js +5 -0
  97. package/dist/assets/vendor-dndkit-DRGpK6sP.js.br +0 -0
  98. package/dist/assets/vendor-dndkit-DRGpK6sP.js.gz +0 -0
  99. package/dist/assets/vendor-i18n-D5KbMT7w.js +9 -0
  100. package/dist/assets/vendor-i18n-D5KbMT7w.js.br +0 -0
  101. package/dist/assets/vendor-i18n-D5KbMT7w.js.gz +0 -0
  102. package/dist/assets/vendor-icons-CQ8b-fGy.js +8671 -0
  103. package/dist/assets/vendor-icons-CQ8b-fGy.js.br +0 -0
  104. package/dist/assets/vendor-icons-CQ8b-fGy.js.gz +0 -0
  105. package/dist/assets/vendor-objectstack-DqojdwYW.js +37 -0
  106. package/dist/assets/vendor-objectstack-DqojdwYW.js.br +0 -0
  107. package/dist/assets/vendor-objectstack-DqojdwYW.js.gz +0 -0
  108. package/dist/assets/vendor-radix-BbeYj_o4.js +56 -0
  109. package/dist/assets/vendor-radix-BbeYj_o4.js.br +0 -0
  110. package/dist/assets/vendor-radix-BbeYj_o4.js.gz +0 -0
  111. package/dist/assets/vendor-react-Dy_xkBQQ.js +60 -0
  112. package/dist/assets/vendor-react-Dy_xkBQQ.js.br +0 -0
  113. package/dist/assets/vendor-react-Dy_xkBQQ.js.gz +0 -0
  114. package/dist/assets/vendor-ui-utils-h6yAcIi9.js +1 -0
  115. package/dist/assets/vendor-ui-utils-h6yAcIi9.js.br +0 -0
  116. package/dist/assets/vendor-ui-utils-h6yAcIi9.js.gz +0 -0
  117. package/dist/assets/vendor-zod-Dpl-cylz.js +39 -0
  118. package/dist/assets/vendor-zod-Dpl-cylz.js.br +0 -0
  119. package/dist/assets/vendor-zod-Dpl-cylz.js.gz +0 -0
  120. package/dist/index.html +49 -0
  121. package/dist/index.html.br +0 -0
  122. package/dist/index.html.gz +0 -0
  123. package/dist/manifest.json +19 -0
  124. package/dist/mockServiceWorker.js +349 -0
  125. package/dist/mockServiceWorker.js.br +0 -0
  126. package/dist/mockServiceWorker.js.gz +0 -0
  127. package/dist/stats.html +4949 -0
  128. package/package.json +98 -0
  129. package/plugin.ts +177 -0
@@ -0,0 +1,4 @@
1
+ import{r,j as t,R as me,d as Ot}from"./vendor-react-Dy_xkBQQ.js";import{c as _,b as de,m as ce,T as Ue,a as He,d as Ge,e as Et,B as ee,R as Dt,f as Qe,g as kt,S as Vt,h as Tt,i as zt,j as It,k as Mt,D as dt,l as ct,n as ut,o as ft,p as pt,q as At,r as Lt,s as Xe,t as Rt,u as _t,v as $t,w as Ye,N as $e,x as Ve,y as Te,z as ze,A as Ie,C as Se,E as mt,F as bt,G as gt,H as ht,I as yt,L as Pt,P as Wt,J as qt,K as Kt,M as Ce,O as Bt,Q as Ut}from"./ui-components-DVonQS7H.js";import{S as te,C as re,c as Ht,f as Gt,d as Jt,g as Qt}from"./framework-mHWN965c.js";import{a as ye}from"./vendor-ui-utils-h6yAcIi9.js";import{u as Xt}from"./plugins-views-DQwkCaaO.js";import{a as Je,C as xt,d as Yt,b as Zt,Y as en,v as tn,l as nn,Z as sn,_ as ln,j as rn,$ as on,a0 as an,a1 as dn,a2 as cn,i as un,m as fn,a3 as Ze,X as pn,a4 as mn,a5 as bn}from"./vendor-icons-CQ8b-fGy.js";const xe=({label:e,description:s,collapsible:n=!1,collapsed:i=!1,columns:l=1,children:o,className:d})=>{const[a,w]=r.useState(i),C={1:"grid-cols-1",2:"grid-cols-1 md:grid-cols-2",3:"grid-cols-1 md:grid-cols-2 lg:grid-cols-3",4:"grid-cols-1 md:grid-cols-2 lg:grid-cols-4"},m=()=>{n&&w(!a)};return t.jsxs("div",{className:_("form-section",d),children:[(e||s)&&t.jsxs("div",{className:_("flex items-start gap-2 mb-4",n&&"cursor-pointer select-none"),onClick:m,role:n?"button":void 0,"aria-expanded":n?!a:void 0,children:[n&&t.jsx("span",{className:"mt-0.5 text-muted-foreground",children:a?t.jsx(Je,{className:"h-4 w-4"}):t.jsx(xt,{className:"h-4 w-4"})}),t.jsxs("div",{className:"flex-1",children:[e&&t.jsx("h3",{className:"text-base font-semibold text-foreground",children:e}),s&&t.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:s})]})]}),!a&&t.jsx("div",{className:_("grid gap-4",C[l]),children:o})]})},gn=({schema:e,dataSource:s,className:n})=>{const[i,l]=r.useState(null),[o,d]=r.useState({}),[a,w]=r.useState(!0),[C,m]=r.useState(null),[c,g]=r.useState(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||"tab-0");me.useEffect(()=>{(async()=>{if(!s){w(!1);return}try{const u=await s.getObjectSchema(e.objectName);l(u)}catch(u){m(u)}})()},[e.objectName,s]),me.useEffect(()=>{(i||!s)&&(async()=>{if(e.mode==="create"||!e.recordId||!s){d(e.initialData||e.initialValues||{}),w(!1);return}try{const u=await s.findOne(e.objectName,e.recordId);d(u||{})}catch(u){m(u)}finally{w(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,s,e.objectName]);const F=r.useCallback(f=>{const u=[];for(const j of f.fields){const v=typeof j=="string"?j:j.name;if(typeof j=="object")u.push(j);else if(i?.fields?.[v]){const N=i.fields[v];u.push({name:v,label:N.label||v,type:ce(N.type),required:N.required||!1,disabled:e.readOnly||e.mode==="view"||N.readonly,placeholder:N.placeholder,description:N.help||N.description,validation:de(N),field:N,options:N.options,multiple:N.multiple})}else u.push({name:v,label:v,type:"input"})}return u},[i,e.readOnly,e.mode]),V=r.useCallback(async f=>{if(!s)return e.onSuccess&&await e.onSuccess(f),f;try{let u;return e.mode==="create"?u=await s.create(e.objectName,f):e.mode==="edit"&&e.recordId&&(u=await s.update(e.objectName,e.recordId,f)),e.onSuccess&&await e.onSuccess(u),u}catch(u){throw e.onError&&e.onError(u),u}},[e,s]),b=r.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),I=(f,u)=>f.name||f.label||`tab-${u}`;if(C)return t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:C.message})]});if(a)return t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});const y={type:"form",fields:e.sections.flatMap(f=>F(f)),layout:"vertical",defaultValues:o,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1,onSubmit:V,onCancel:b},x=e.tabPosition==="left"||e.tabPosition==="right";return t.jsx("div",{className:_("w-full",n,e.className),children:t.jsxs(Ue,{value:c,onValueChange:g,orientation:x?"vertical":"horizontal",className:_(x&&"flex gap-4"),children:[t.jsx(He,{className:_(x?"flex-col h-auto":"",e.tabPosition==="bottom"&&"order-last",e.tabPosition==="right"&&"order-last"),children:e.sections.map((f,u)=>t.jsx(Ge,{value:I(f,u),className:x?"w-full justify-start":"",children:f.label||`Tab ${u+1}`},I(f,u)))}),t.jsx("div",{className:"flex-1",children:e.sections.map((f,u)=>t.jsx(Et,{value:I(f,u),className:"mt-0",children:t.jsx(xe,{description:f.description,columns:f.columns||1,children:t.jsx(te,{schema:{...y,fields:F(f),showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1}})})},I(f,u)))})]})})},hn=({schema:e,dataSource:s,className:n})=>{const[i,l]=r.useState(null),[o,d]=r.useState({}),[a,w]=r.useState(!0),[C,m]=r.useState(null),[c,g]=r.useState(0),[F,V]=r.useState(new Set),[b,I]=r.useState(!1),z=e.sections.length,y=c===0,x=c===z-1;me.useEffect(()=>{(async()=>{if(!s){w(!1);return}try{const k=await s.getObjectSchema(e.objectName);l(k)}catch(k){m(k)}})()},[e.objectName,s]),me.useEffect(()=>{(i||!s)&&(async()=>{if(e.mode==="create"||!e.recordId||!s){d(e.initialData||e.initialValues||{}),w(!1);return}try{const k=await s.findOne(e.objectName,e.recordId);d(k||{})}catch(k){m(k)}finally{w(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,s,e.objectName]);const f=r.useCallback(E=>{const k=[];for(const R of E.fields){const K=typeof R=="string"?R:R.name;if(typeof R=="object")k.push(R);else if(i?.fields?.[K]){const M=i.fields[K];k.push({name:K,label:M.label||K,type:ce(M.type),required:M.required||!1,disabled:e.readOnly||e.mode==="view"||M.readonly,placeholder:M.placeholder,description:M.help||M.description,validation:de(M),field:M,options:M.options,multiple:M.multiple})}else k.push({name:K,label:K,type:"input"})}return k},[i,e.readOnly,e.mode]),u=r.useMemo(()=>c>=0&&c<z?f(e.sections[c]):[],[c,z,e.sections,f]),j=r.useCallback(async E=>{const k={...o,...E};if(d(k),V(R=>new Set(R).add(c)),x){I(!0);try{if(!s)return e.onSuccess&&await e.onSuccess(k),k;let R;return e.mode==="create"?R=await s.create(e.objectName,k):e.mode==="edit"&&e.recordId&&(R=await s.update(e.objectName,e.recordId,k)),e.onSuccess&&await e.onSuccess(R),R}catch(R){throw e.onError&&e.onError(R),R}finally{I(!1)}}else v(c+1)},[o,c,x,e,s]),v=r.useCallback(E=>{E>=0&&E<z&&(g(E),e.onStepChange&&e.onStepChange(E))},[z,e]),N=r.useCallback(()=>{v(c-1)},[c,v]),p=r.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),A=r.useCallback(E=>{(e.allowSkip||F.has(E)||E<=c)&&v(E)},[e.allowSkip,F,c,v]);if(C)return t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:C.message})]});if(a)return t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});const X=e.sections[c];return t.jsxs("div",{className:_("w-full",n,e.className),children:[e.showStepIndicator!==!1&&t.jsx("nav",{"aria-label":"Progress",className:"mb-8",children:t.jsx("ol",{className:"flex items-center",children:e.sections.map((E,k)=>{const R=k===c,K=F.has(k),M=e.allowSkip||K||k<=c;return t.jsxs("li",{className:_("relative flex-1",k!==z-1&&"pr-8 sm:pr-12"),children:[k!==z-1&&t.jsx("div",{className:"absolute top-3 sm:top-4 left-6 -right-4 sm:left-10 sm:-right-2 h-0.5","aria-hidden":"true",children:t.jsx("div",{className:_("h-full",K?"bg-primary":"bg-muted")})}),t.jsxs("button",{type:"button",className:_("group relative flex items-center",M?"cursor-pointer":"cursor-not-allowed"),onClick:()=>A(k),disabled:!M,children:[t.jsx("span",{className:_("flex h-6 w-6 sm:h-8 sm:w-8 items-center justify-center rounded-full text-xs sm:text-sm font-medium transition-colors",K&&"bg-primary text-primary-foreground",R&&!K&&"border-2 border-primary bg-background text-primary",!R&&!K&&"border-2 border-muted bg-background text-muted-foreground"),children:K?t.jsx(Yt,{className:"h-3 w-3 sm:h-4 sm:w-4"}):k+1}),t.jsx("span",{className:"ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block",children:t.jsx("span",{className:_(R?"text-foreground":"text-muted-foreground"),children:E.label||`Step ${k+1}`})})]})]},k)})})}),t.jsx("div",{className:"min-h-[200px]",children:X&&t.jsx(xe,{label:X.label,description:X.description,columns:X.columns||1,children:u.length>0?t.jsx(te,{schema:{type:"form",fields:u,layout:"vertical",defaultValues:o,showSubmit:!1,showCancel:!1,onSubmit:j}}):t.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No fields configured for this step"})})}),t.jsxs("div",{className:"flex items-center justify-between mt-6 pt-4 border-t",children:[t.jsx("div",{children:e.showCancel!==!1&&t.jsx(ee,{variant:"ghost",onClick:p,children:e.cancelText||"Cancel"})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"text-sm text-muted-foreground mr-2",children:["Step ",c+1," of ",z]}),!y&&t.jsxs(ee,{variant:"outline",onClick:N,children:[t.jsx(Zt,{className:"h-4 w-4 mr-1"}),e.prevText||"Back"]}),x?t.jsx(ee,{onClick:()=>j(o),disabled:b||e.mode==="view",children:b?"Submitting...":e.submitText||(e.mode==="create"?"Create":"Update")}):t.jsxs(ee,{onClick:()=>j(o),children:[e.nextText||"Next",t.jsx(Je,{className:"h-4 w-4 ml-1"})]})]})]})]})},yn=({schema:e,dataSource:s,className:n})=>{const[i,l]=r.useState(null),[o,d]=r.useState({}),[a,w]=r.useState(!0),[C,m]=r.useState(null);r.useEffect(()=>{(async()=>{if(!s){w(!1);return}try{const u=await s.getObjectSchema(e.objectName);l(u)}catch(u){m(u),w(!1)}})()},[e.objectName,s]),r.useEffect(()=>{(i||!s)&&(async()=>{if(e.mode==="create"||!e.recordId){d(e.initialData||e.initialValues||{}),w(!1);return}if(!s){d(e.initialData||e.initialValues||{}),w(!1);return}try{const u=await s.findOne(e.objectName,e.recordId);d(u||{})}catch(u){m(u)}finally{w(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,s,e.objectName]);const c=r.useCallback(f=>{const u=[];for(const j of f.fields){const v=typeof j=="string"?j:j.name;if(typeof j=="object")u.push(j);else if(i?.fields?.[v]){const N=i.fields[v];u.push({name:v,label:N.label||v,type:ce(N.type),required:N.required||!1,disabled:e.readOnly||e.mode==="view"||N.readonly,placeholder:N.placeholder,description:N.help||N.description,validation:de(N),field:N,options:N.options,multiple:N.multiple})}else u.push({name:v,label:v,type:"input"})}return u},[i,e.readOnly,e.mode]),g=r.useCallback(async f=>{if(!s)return e.onSuccess&&await e.onSuccess(f),f;try{let u;return e.mode==="create"?u=await s.create(e.objectName,f):e.mode==="edit"&&e.recordId&&(u=await s.update(e.objectName,e.recordId,f)),e.onSuccess&&await e.onSuccess(u),u}catch(u){throw e.onError&&e.onError(u),u}},[e,s]),F=r.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),V=r.useMemo(()=>e.sections.slice(0,1),[e.sections]),b=r.useMemo(()=>e.sections.slice(1),[e.sections]);r.useMemo(()=>e.sections.flatMap(f=>c(f)),[e.sections,c]);const I=e.splitDirection||"horizontal",z=e.splitSize||50;if(C)return t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:C.message})]});if(a)return t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});const y={type:"form",layout:"vertical",defaultValues:o,onSubmit:g,onCancel:F},x=(f,u)=>t.jsx("div",{className:"space-y-4 p-4",children:f.map((j,v)=>t.jsx(xe,{label:j.label,description:j.description,columns:j.columns||1,children:t.jsx(te,{schema:{...y,fields:c(j),showSubmit:u&&e.showSubmit!==!1&&e.mode!=="view",showCancel:u&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText}})},j.name||j.label||v))});return t.jsx("div",{className:_("w-full",n,e.className),children:t.jsxs(Dt,{orientation:I,className:"min-h-[300px] rounded-lg border",children:[t.jsx(Qe,{defaultSize:z,minSize:20,children:x(V,b.length===0)}),b.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(kt,{withHandle:e.splitResizable!==!1}),t.jsx(Qe,{defaultSize:100-z,minSize:20,children:x(b,!0)})]})]})})},xn=({schema:e,dataSource:s,className:n})=>{const[i,l]=r.useState(null),[o,d]=r.useState([]),[a,w]=r.useState({}),[C,m]=r.useState(!0),[c,g]=r.useState(null),F=e.open!==!1,V=e.drawerSide||"right";r.useEffect(()=>{(async()=>{if(!s){m(!1);return}try{const v=await s.getObjectSchema(e.objectName);l(v)}catch(v){g(v),m(!1)}})()},[e.objectName,s]),r.useEffect(()=>{(i||!s)&&(async()=>{if(e.mode==="create"||!e.recordId){w(e.initialData||e.initialValues||{}),m(!1);return}if(!s){w(e.initialData||e.initialValues||{}),m(!1);return}try{const v=await s.findOne(e.objectName,e.recordId);w(v||{})}catch(v){g(v)}finally{m(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,s,e.objectName]);const b=r.useCallback(j=>{const v=[];for(const N of j.fields){const p=typeof N=="string"?N:N.name;if(typeof N=="object")v.push(N);else if(i?.fields?.[p]){const A=i.fields[p];v.push({name:p,label:A.label||p,type:ce(A.type),required:A.required||!1,disabled:e.readOnly||e.mode==="view"||A.readonly,placeholder:A.placeholder,description:A.help||A.description,validation:de(A),field:A,options:A.options,multiple:A.multiple})}else v.push({name:p,label:p,type:"input"})}return v},[i,e.readOnly,e.mode]);r.useEffect(()=>{if(!i&&s)return;if(e.customFields?.length){d(e.customFields),m(!1);return}if(e.sections?.length){m(!1);return}if(!i)return;const j=e.fields||Object.keys(i.fields||{}),v=[];for(const N of j){const p=typeof N=="string"?N:N.name;if(!p)continue;const A=i.fields?.[p];A&&v.push({name:p,label:A.label||p,type:ce(A.type),required:A.required||!1,disabled:e.readOnly||e.mode==="view"||A.readonly,placeholder:A.placeholder,description:A.help||A.description,validation:de(A),field:A,options:A.options,multiple:A.multiple})}d(v),m(!1)},[i,e.fields,e.customFields,e.sections,e.readOnly,e.mode,s]);const I=r.useCallback(async j=>{if(!s)return e.onSuccess&&await e.onSuccess(j),e.onOpenChange?.(!1),j;try{let v;return e.mode==="create"?v=await s.create(e.objectName,j):e.mode==="edit"&&e.recordId&&(v=await s.update(e.objectName,e.recordId,j)),e.onSuccess&&await e.onSuccess(v),e.onOpenChange?.(!1),v}catch(v){throw e.onError&&e.onError(v),v}},[e,s]),z=r.useCallback(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),y=r.useMemo(()=>e.drawerWidth?V==="left"||V==="right"?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}:void 0,[e.drawerWidth,V]),f={type:"form",layout:e.layout==="vertical"||e.layout==="horizontal"?e.layout:"vertical",defaultValues:a,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1,onSubmit:I,onCancel:z},u=()=>c?t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:c.message})]}):C?t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]}):e.sections?.length?t.jsx("div",{className:"space-y-6",children:e.sections.map((j,v)=>t.jsx(xe,{label:j.label,description:j.description,columns:j.columns||1,children:t.jsx(te,{schema:{...f,fields:b(j),showSubmit:v===e.sections.length-1&&f.showSubmit,showCancel:v===e.sections.length-1&&f.showCancel}})},j.name||j.label||v))}):t.jsx(te,{schema:{...f,fields:o,columns:e.columns}});return t.jsx(Vt,{open:F,onOpenChange:e.onOpenChange,children:t.jsxs(Tt,{side:V,className:_("overflow-y-auto",n,e.className),style:y,children:[(e.title||e.description)&&t.jsxs(zt,{children:[e.title&&t.jsx(It,{children:e.title}),e.description&&t.jsx(Mt,{children:e.description})]}),t.jsx("div",{className:"py-4",children:u()})]})})},et={sm:"max-w-sm",default:"max-w-lg",lg:"max-w-2xl",xl:"max-w-4xl",full:"max-w-[95vw] w-full"},wn=({schema:e,dataSource:s,className:n})=>{const[i,l]=r.useState(null),[o,d]=r.useState([]),[a,w]=r.useState({}),[C,m]=r.useState(!0),[c,g]=r.useState(null),F=e.open!==!1,V=et[e.modalSize||"default"]||et.default;r.useEffect(()=>{(async()=>{if(!s){m(!1);return}try{const j=await s.getObjectSchema(e.objectName);l(j)}catch(j){g(j),m(!1)}})()},[e.objectName,s]),r.useEffect(()=>{(i||!s)&&(async()=>{if(e.mode==="create"||!e.recordId){w(e.initialData||e.initialValues||{}),m(!1);return}if(!s){w(e.initialData||e.initialValues||{}),m(!1);return}try{const j=await s.findOne(e.objectName,e.recordId);w(j||{})}catch(j){g(j)}finally{m(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,s,e.objectName]);const b=r.useCallback(u=>{const j=[];for(const v of u.fields){const N=typeof v=="string"?v:v.name;if(typeof v=="object")j.push(v);else if(i?.fields?.[N]){const p=i.fields[N];j.push({name:N,label:p.label||N,type:ce(p.type),required:p.required||!1,disabled:e.readOnly||e.mode==="view"||p.readonly,placeholder:p.placeholder,description:p.help||p.description,validation:de(p),field:p,options:p.options,multiple:p.multiple})}else j.push({name:N,label:N,type:"input"})}return j},[i,e.readOnly,e.mode]);r.useEffect(()=>{if(!i&&s)return;if(e.customFields?.length){d(e.customFields),m(!1);return}if(e.sections?.length){m(!1);return}if(!i)return;const u=e.fields||Object.keys(i.fields||{}),j=[];for(const v of u){const N=typeof v=="string"?v:v.name;if(!N)continue;const p=i.fields?.[N];p&&j.push({name:N,label:p.label||N,type:ce(p.type),required:p.required||!1,disabled:e.readOnly||e.mode==="view"||p.readonly,placeholder:p.placeholder,description:p.help||p.description,validation:de(p),field:p,options:p.options,multiple:p.multiple})}d(j),m(!1)},[i,e.fields,e.customFields,e.sections,e.readOnly,e.mode,s]);const I=r.useCallback(async u=>{if(!s)return e.onSuccess&&await e.onSuccess(u),e.onOpenChange?.(!1),u;try{let j;return e.mode==="create"?j=await s.create(e.objectName,u):e.mode==="edit"&&e.recordId&&(j=await s.update(e.objectName,e.recordId,u)),e.onSuccess&&await e.onSuccess(j),e.onOpenChange?.(!1),j}catch(j){throw e.onError&&e.onError(j),j}},[e,s]),z=r.useCallback(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),x={type:"form",layout:e.layout==="vertical"||e.layout==="horizontal"?e.layout:"vertical",defaultValues:a,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1,onSubmit:I,onCancel:z},f=()=>c?t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:c.message})]}):C?t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]}):e.sections?.length?t.jsx("div",{className:"space-y-6",children:e.sections.map((u,j)=>t.jsx(xe,{label:u.label,description:u.description,columns:u.columns||1,children:t.jsx(te,{schema:{...x,fields:b(u),showSubmit:j===e.sections.length-1&&x.showSubmit,showCancel:j===e.sections.length-1&&x.showCancel}})},u.name||u.label||j))}):t.jsx(te,{schema:{...x,fields:o,columns:e.columns}});return t.jsx(dt,{open:F,onOpenChange:e.onOpenChange,children:t.jsxs(ct,{className:_(V,"max-h-[90vh] overflow-y-auto",n,e.className),children:[(e.title||e.description)&&t.jsxs(ut,{children:[e.title&&t.jsx(ft,{children:e.title}),e.description&&t.jsx(pt,{children:e.description})]}),t.jsx("div",{className:"py-2",children:f()})]})})},Be=({schema:e,dataSource:s})=>{if(e.formType==="tabbed"&&e.sections?.length)return t.jsx(gn,{schema:{...e,formType:"tabbed",sections:e.sections.map(n=>({name:n.name,label:n.label,description:n.description,columns:n.columns,fields:n.fields})),defaultTab:e.defaultTab,tabPosition:e.tabPosition},dataSource:s,className:e.className});if(e.formType==="wizard"&&e.sections?.length)return t.jsx(hn,{schema:{...e,formType:"wizard",sections:e.sections.map(n=>({name:n.name,label:n.label,description:n.description,columns:n.columns,fields:n.fields})),allowSkip:e.allowSkip,showStepIndicator:e.showStepIndicator,nextText:e.nextText,prevText:e.prevText,onStepChange:e.onStepChange},dataSource:s,className:e.className});if(e.formType==="split"&&e.sections?.length)return t.jsx(yn,{schema:{...e,formType:"split",sections:e.sections.map(n=>({name:n.name,label:n.label,description:n.description,columns:n.columns,fields:n.fields})),splitDirection:e.splitDirection,splitSize:e.splitSize,splitResizable:e.splitResizable},dataSource:s,className:e.className});if(e.formType==="drawer"){const{layout:n,...i}=e,l=e.layout==="vertical"||e.layout==="horizontal"?e.layout:void 0;return t.jsx(xn,{schema:{...i,layout:l,formType:"drawer",sections:e.sections?.map(o=>({name:o.name,label:o.label,description:o.description,columns:o.columns,fields:o.fields})),open:e.open,onOpenChange:e.onOpenChange,drawerSide:e.drawerSide,drawerWidth:e.drawerWidth},dataSource:s,className:e.className})}if(e.formType==="modal"){const{layout:n,...i}=e,l=e.layout==="vertical"||e.layout==="horizontal"?e.layout:void 0;return t.jsx(wn,{schema:{...i,layout:l,formType:"modal",sections:e.sections?.map(o=>({name:o.name,label:o.label,description:o.description,columns:o.columns,fields:o.fields})),open:e.open,onOpenChange:e.onOpenChange,modalSize:e.modalSize,modalCloseButton:e.modalCloseButton},dataSource:s,className:e.className})}return t.jsx(jn,{schema:e,dataSource:s})},jn=({schema:e,dataSource:s})=>{const[n,i]=r.useState(null),[l,o]=r.useState([]),[d,a]=r.useState(null),[w,C]=r.useState(!0),[m,c]=r.useState(null),g=e.customFields&&e.customFields.length>0;r.useEffect(()=>{g&&(a(e.initialData||e.initialValues||{}),C(!1))},[g,e.initialData,e.initialValues]),r.useEffect(()=>{const x=async()=>{try{if(!s)throw new Error("DataSource is required when using ObjectQL schema fetching (inline fields not provided)");const f=await s.getObjectSchema(e.objectName);if(!f)throw new Error(`No schema found for object "${e.objectName}"`);i(f)}catch(f){c(f),C(!1)}};g?i({name:e.objectName,fields:{}}):e.objectName&&s?x():g||C(!1)},[e.objectName,s,g]),r.useEffect(()=>{n&&!g&&(async()=>{if(!e.recordId||e.mode==="create"){a(e.initialData||e.initialValues||{}),C(!1);return}if(!g){if(!s){c(new Error("DataSource is required for fetching record data (inline data not provided)")),C(!1);return}C(!0);try{const f=await s.findOne(e.objectName,e.recordId);a(f)}catch(f){console.error("Failed to fetch record:",f),c(f)}finally{C(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,s,n,g]),r.useEffect(()=>{if(g&&e.customFields){o(e.customFields),C(!1);return}if(!n)return;const x=[],f=e.fields||Object.keys(n.fields||{});(Array.isArray(f)?f:Object.keys(f)).forEach(v=>{const N=typeof v=="string"?v:v.name;if(!N)return;const p=n.fields?.[N];if(!p&&!g)return;const A=!p?.permissions||p?.permissions.write!==!1;if(e.mode!=="view"&&!A)return;const X=e.customFields?.find(E=>E.name===N);if(X)x.push(X);else if(p){const E={name:N,label:p.label||v,type:ce(p.type),required:p.required||!1,disabled:e.readOnly||e.mode==="view"||p.readonly,placeholder:p.placeholder,description:p.help||p.description,validation:de(p),field:p};if((p.type==="select"||p.type==="lookup"||p.type==="master_detail")&&(E.options=p.options||[],E.multiple=p.multiple),(p.type==="number"||p.type==="currency"||p.type==="percent")&&(E.inputType="number",E.min=p.min,E.max=p.max,E.step=p.precision?Math.pow(10,-p.precision):void 0),p.type==="date"&&(E.inputType="date"),p.type==="datetime"&&(E.inputType="datetime-local"),(p.type==="text"||p.type==="textarea"||p.type==="markdown"||p.type==="html")&&(E.maxLength=p.max_length,E.minLength=p.min_length),(p.type==="file"||p.type==="image")&&(E.inputType="file",E.multiple=p.multiple,E.accept=p.accept?p.accept.join(","):void 0,p.max_size)){const k=`Max size: ${At(p.max_size)}`;E.description=E.description?`${E.description} (${k})`:k}p.type==="email"&&(E.inputType="email"),p.type==="phone"&&(E.inputType="tel"),p.type==="url"&&(E.inputType="url"),p.type==="password"&&(E.inputType="password"),p.type==="time"&&(E.inputType="time"),(p.type==="formula"||p.type==="summary"||p.type==="auto_number")&&(E.disabled=!0),p.visible_on&&(E.visible=k=>Lt(p.visible_on,k)),x.push(E)}}),o(x),!g&&e.recordId&&e.mode!=="create"&&s||C(!1)},[n,e.fields,e.customFields,e.readOnly,e.mode,g,e.recordId,s]);const F=r.useCallback(async(x,f)=>{if(x&&(x.nativeEvent||x._reactName==="onSubmit")&&(console.warn("ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue."),f===void 0&&(f=x,x={})),g&&!s)return e.onSuccess&&await e.onSuccess(x),x;if(!s)throw new Error("DataSource is required for form submission (inline mode not configured)");try{let u;if(e.mode==="create")u=await s.create(e.objectName,x);else if(e.mode==="edit"&&e.recordId)u=await s.update(e.objectName,e.recordId,x);else throw new Error("Invalid form mode or missing record ID");return e.onSuccess&&await e.onSuccess(u),u}catch(u){throw console.error("Failed to submit form:",u),e.onError&&e.onError(u),u}},[e,s,g]),V=r.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),I={...me.useMemo(()=>{if(!n?.fields)return{};const x={};return Object.keys(n.fields).forEach(f=>{const u=n.fields[f];u.defaultValue!==void 0&&(x[f]=u.defaultValue)}),x},[n]),...d};if(m)return t.jsxs("div",{className:"p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:m.message})]});if(w)return t.jsxs("div",{className:"p-4 sm:p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});const z=e.layout==="vertical"||e.layout==="horizontal"?e.layout:"vertical";if(e.sections?.length&&(!e.formType||e.formType==="simple"))return t.jsx("div",{className:"w-full space-y-6",children:e.sections.map((x,f)=>{const u=x.fields.map(v=>typeof v=="string"?v:v.name),j=l.filter(v=>u.includes(v.name));return t.jsx(xe,{label:x.label,description:x.description,collapsible:x.collapsible,collapsed:x.collapsed,columns:x.columns,children:t.jsx(te,{schema:{type:"form",fields:j,layout:z,defaultValues:I,showSubmit:f===e.sections.length-1&&e.showSubmit!==!1&&e.mode!=="view",showCancel:f===e.sections.length-1&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,onSubmit:F,onCancel:V}})},x.name||x.label||f)})});const y={type:"form",fields:l,layout:z,columns:e.columns,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1,resetOnSubmit:e.showReset,defaultValues:I,onSubmit:F,onCancel:V,className:e.className};return t.jsx("div",{className:"w-full",children:t.jsx(te,{schema:y})})},wt=({schema:e})=>t.jsx(Be,{schema:e});re.register("object-form",wt,{namespace:"plugin-form",label:"Object Form",category:"plugin",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"fields",type:"array",label:"Fields"},{name:"mode",type:"enum",label:"Mode",enum:["create","edit","view"]},{name:"formType",type:"enum",label:"Form Type",enum:["simple","tabbed","wizard","split","drawer","modal"]},{name:"sections",type:"array",label:"Sections"},{name:"title",type:"string",label:"Title"},{name:"description",type:"string",label:"Description"},{name:"layout",type:"enum",label:"Layout",enum:["vertical","horizontal","inline","grid"]},{name:"columns",type:"number",label:"Columns"},{name:"defaultTab",type:"string",label:"Default Tab"},{name:"tabPosition",type:"enum",label:"Tab Position",enum:["top","bottom","left","right"]},{name:"allowSkip",type:"boolean",label:"Allow Skip Steps"},{name:"showStepIndicator",type:"boolean",label:"Show Step Indicator"},{name:"splitDirection",type:"enum",label:"Split Direction",enum:["horizontal","vertical"]},{name:"splitSize",type:"number",label:"Split Panel Size (%)"},{name:"splitResizable",type:"boolean",label:"Split Resizable"},{name:"drawerSide",type:"enum",label:"Drawer Side",enum:["top","bottom","left","right"]},{name:"drawerWidth",type:"string",label:"Drawer Width"},{name:"modalSize",type:"enum",label:"Modal Size",enum:["sm","default","lg","xl","full"]}]});re.register("form",wt,{namespace:"view",skipFallback:!0,label:"Data Form View",category:"view",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"fields",type:"array",label:"Fields"},{name:"mode",type:"enum",label:"Mode",enum:["create","edit","view"]}]});const vn={red:"bg-red-100",green:"bg-green-100",blue:"bg-blue-100",yellow:"bg-yellow-100",orange:"bg-orange-100",purple:"bg-purple-100",pink:"bg-pink-100",gray:"bg-gray-100",grey:"bg-gray-100",indigo:"bg-indigo-100",teal:"bg-teal-100",cyan:"bg-cyan-100",amber:"bg-amber-100",lime:"bg-lime-100",emerald:"bg-emerald-100",rose:"bg-rose-100",sky:"bg-sky-100",violet:"bg-violet-100",fuchsia:"bg-fuchsia-100",slate:"bg-slate-100",zinc:"bg-zinc-100",stone:"bg-stone-100",neutral:"bg-neutral-100"};function Cn(e){if(e.startsWith("bg-"))return e;const s=e.toLowerCase().trim();return vn[s]}function Sn(e){return r.useCallback(s=>{if(!e?.field||!e.colors)return;const n=String(s[e.field]??""),i=e.colors[n];if(i)return Cn(i)},[e?.field,e?.colors])}function Nn(e,s){return s.map(n=>String(e[n.field]??"")).join(" / ")}function Fn(e,s){return s.map(n=>{const i=e[n.field];return i!=null&&i!==""?String(i):"(empty)"}).join(" / ")}function On(e,s,n){const i=e.localeCompare(s,void 0,{numeric:!0,sensitivity:"base"});return n==="desc"?-i:i}function En(e,s){const n=e?.fields,i=!!(n&&n.length>0),[l,o]=r.useState({}),d=r.useMemo(()=>n?n.some(C=>C.collapsed):!1,[n]),a=r.useMemo(()=>{if(!i||!n)return[];const C=new Map,m=[];for(const g of s){const F=Nn(g,n);C.has(F)||(C.set(F,{label:Fn(g,n),rows:[]}),m.push(F)),C.get(F).rows.push(g)}const c=n[0]?.order??"asc";return m.sort((g,F)=>On(g,F,c)),m.map(g=>{const F=C.get(g),V=g in l?l[g]:d;return{key:g,label:F.label,rows:F.rows,collapsed:V}})},[s,n,i,l,d]),w=r.useCallback(C=>{o(m=>({...m,[C]:m[C]!==void 0?!m[C]:!d}))},[d]);return{groups:a,isGrouped:i,toggleGroup:w}}function Dn(e){return e.data?Array.isArray(e.data)?{provider:"value",items:e.data}:e.data:e.staticData?{provider:"value",items:e.staticData}:e.objectName?{provider:"object",object:e.objectName}:null}function tt(e){if(!(!e||e.length===0))return typeof e[0]=="object"&&e[0]!==null,e}const jt=({schema:e,dataSource:s,onEdit:n,onDelete:i,onRowSelect:l,onRowClick:o,onCellChange:d,onRowSave:a,onBatchSave:w,...C})=>{const[m,c]=r.useState([]),[g,F]=r.useState(!0),[V,b]=r.useState(null),[I,z]=r.useState(null),[y,x]=r.useState(!1),[f,u]=r.useState(0),j=r.useCallback(async()=>{u(T=>T+1)},[]),{ref:v,isRefreshing:N,pullDistance:p}=Xt({onRefresh:j,enabled:!!s&&!!e.objectName});r.useEffect(()=>{const T=()=>x(window.innerWidth<480);return T(),window.addEventListener("resize",T),()=>window.removeEventListener("resize",T)},[]);const A=C.data,X=Ht(e.bind),E=Dn(e),k=me.useMemo(()=>A&&Array.isArray(A)?{provider:"value",items:A}:X&&Array.isArray(X)?{provider:"value",items:X}:E,[JSON.stringify(E),X,A]),R=k?.provider==="value",K=k?.provider==="object"&&k&&"object"in k?k.object:e.objectName,M=e.fields,U=e.columns,ue=e.filter,oe=e.sort,W=e.pagination,ie=e.pageSize;r.useEffect(()=>{R&&k?.provider==="value"&&(c(T=>{const $=k.items;return JSON.stringify(T)!==JSON.stringify($)?$:T}),F(!1))},[R,k]),r.useEffect(()=>{if(R)return;let T=!1;return(async()=>{F(!0),b(null);try{let G=null;if((tt(U)||M)&&K)G={name:K,fields:{}};else if(K&&s){const D=await s.getObjectSchema(K);if(T)return;G=D}else throw K?new Error("DataSource required"):new Error("Object name required for data fetching");if(T||z(G),s&&K){const J={$select:(()=>{if(M)return M;if(U&&Array.isArray(U))return U.map(H=>typeof H=="string"?H:H.field)})(),$top:W?.pageSize||ie||50};ue&&Array.isArray(ue)?J.$filter=ue:e.defaultFilters&&(J.$filter=e.defaultFilters),oe?typeof oe=="string"?J.$orderby=oe:Array.isArray(oe)&&(J.$orderby=oe.map(H=>`${H.field} ${H.order}`).join(", ")):e.defaultSort&&(J.$orderby=`${e.defaultSort.field} ${e.defaultSort.order}`);const fe=await s.find(K,J);if(T)return;c(fe.data||[])}}catch(G){T||b(G)}finally{T||F(!1)}})(),()=>{T=!0}},[K,M,U,ue,oe,W,ie,s,R,k,f]);const q=Gt({navigation:e.navigation,objectName:e.objectName,onNavigate:e.onNavigate,onRowClick:o}),{execute:se}=Jt(),le=Sn(e.rowColor),{groups:Me,isGrouped:we,toggleGroup:Ne}=En(e.grouping,m),je=r.useCallback(()=>{const T=tt(U);if(T){if(T.length>0&&typeof T[0]=="object"&&T[0]!==null){const P=T[0];if("accessorKey"in P)return T;if("field"in P)return T.filter(D=>D?.field&&typeof D.field=="string"&&!D.hidden).map((D,J)=>{const fe=D.label||D.field.charAt(0).toUpperCase()+D.field.slice(1).replace(/_/g," ");let H;const h=D.type?Xe(D.type):null;D.link&&D.action?H=(L,Z)=>{const B=h?t.jsx(h,{value:L,field:{name:D.field,type:D.type||"text"}}):L!=null&&L!==""?String(L):t.jsx("span",{className:"text-muted-foreground",children:"-"});return t.jsx("button",{type:"button",className:"text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit",onClick:Q=>{Q.stopPropagation(),q.handleClick(Z)},children:B})}:D.link?H=(L,Z)=>{const B=h?t.jsx(h,{value:L,field:{name:D.field,type:D.type||"text"}}):L!=null&&L!==""?String(L):t.jsx("span",{className:"text-muted-foreground",children:"-"});return t.jsx("button",{type:"button",className:"text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit",onClick:Q=>{Q.stopPropagation(),q.handleClick(Z)},children:B})}:D.action?H=(L,Z)=>{const B=h?t.jsx(h,{value:L,field:{name:D.field,type:D.type||"text"}}):L!=null&&L!==""?String(L):t.jsx("span",{className:"text-muted-foreground",children:"-"});return t.jsx("button",{type:"button",className:"text-primary underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit",onClick:Q=>{Q.stopPropagation(),se({type:D.action,params:{record:Z,field:D.field,value:L}})},children:B})}:h?H=L=>t.jsx(h,{value:L,field:{name:D.field,type:D.type||"text"}}):H=L=>L!=null&&L!==""?t.jsx("span",{children:String(L)}):t.jsx("span",{className:"text-muted-foreground",children:"-"});const O=["number","currency","percent"],S=D.align||(D.type&&O.includes(D.type)?"right":void 0),Y=J===0||D.essential===!0;return{header:fe,accessorKey:D.field,...!Y&&{className:"hidden sm:table-cell"},...D.width&&{width:D.width},...S&&{align:S},sortable:D.sortable!==!1,...D.resizable!==void 0&&{resizable:D.resizable},...D.wrap!==void 0&&{wrap:D.wrap},...H&&{cell:H}}})}return T.filter(P=>typeof P=="string"&&P.trim().length>0).map(P=>({header:I?.fields?.[P]?.label||P.charAt(0).toUpperCase()+P.slice(1).replace(/_/g," "),accessorKey:P}))}if(R){const P=k?.provider==="value"?k.items:[];if(P.length>0)return(M||Object.keys(P[0])).map(J=>({header:J.charAt(0).toUpperCase()+J.slice(1).replace(/_/g," "),accessorKey:J}))}if(!I)return[];const $=[];return(M||Object.keys(I.fields||{})).forEach(P=>{const D=I.fields?.[P];if(!D||D.permissions&&D.permissions.read===!1)return;const J=Xe(D.type),fe=["number","currency","percent"];$.push({header:D.label||P,accessorKey:P,...fe.includes(D.type)&&{align:"right"},cell:H=>t.jsx(J,{value:H,field:D}),sortable:D.sortable!==!1})}),$},[I,M,U,k,R,q.handleClick,se]);if(V)return t.jsxs("div",{className:"p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading grid"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:V.message})]});if(g&&m.length===0)return t.jsxs("div",{className:"p-4 sm:p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading grid..."})]});const Fe=je(),ae="operations"in e?e.operations:void 0,Oe=ae&&(ae.update||ae.delete),Ae=Oe?[...Fe,{header:"Actions",accessorKey:"_actions",cell:(T,$)=>t.jsxs(Rt,{children:[t.jsx(_t,{asChild:!0,children:t.jsxs(ee,{variant:"ghost",size:"icon",className:"h-8 w-8 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0",children:[t.jsx(en,{className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:"Open menu"})]})}),t.jsxs($t,{align:"end",children:[ae?.update&&n&&t.jsxs(Ye,{onClick:()=>n($),children:[t.jsx(tn,{className:"mr-2 h-4 w-4"}),"Edit"]}),ae?.delete&&i&&t.jsxs(Ye,{onClick:()=>i($),children:[t.jsx(nn,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]}),sortable:!1}]:Fe;let be=!1;e.selection?.type?be=e.selection.type==="none"?!1:e.selection.type:e.selectable!==void 0&&(be=e.selectable);const Le=e.pagination!==void 0?!0:e.showPagination!==void 0?e.showPagination:!0,Re=e.pagination?.pageSize||e.pageSize||10,_e=e.searchableFields!==void 0?e.searchableFields.length>0:e.showSearch!==void 0?e.showSearch:!0,Ee={type:"data-table",caption:e.label||e.title,columns:Ae,data:m,pagination:Le,pageSize:Re,searchable:_e,selectable:be,sortable:!0,exportable:ae?.export,rowActions:Oe,resizableColumns:e.resizable??e.resizableColumns??!0,reorderableColumns:e.reorderableColumns??!1,editable:e.editable??!1,className:e.className,cellClassName:"px-2 py-1.5 sm:px-3 sm:py-2 md:px-4 md:py-2.5",rowClassName:e.rowColor?(T,$)=>le(T):void 0,onSelectionChange:l,onRowClick:q.handleClick,onCellChange:d,onRowSave:a,onBatchSave:w},De=T=>({...Ee,caption:void 0,data:T,pagination:!1,searchable:!1}),ge=e.label?`${e.label} Detail`:e.objectName?`${e.objectName.charAt(0).toUpperCase()+e.objectName.slice(1)} Detail`:"Record Detail";if(y&&m.length>0&&!we){const T=je().filter($=>$.accessorKey!=="_actions");return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"space-y-2 p-2",children:m.map(($,G)=>t.jsx("div",{className:"border rounded-lg p-3 bg-card hover:bg-accent/50 cursor-pointer transition-colors touch-manipulation",onClick:()=>q.handleClick($),children:T.slice(0,4).map(P=>t.jsxs("div",{className:"flex justify-between items-center py-1",children:[t.jsx("span",{className:"text-xs text-muted-foreground",children:P.header}),t.jsx("span",{className:"text-sm font-medium truncate ml-2 text-right",children:P.cell?P.cell($[P.accessorKey],$):String($[P.accessorKey]??"—")})]},P.accessorKey))},$.id||$._id||G))}),q.isOverlay&&t.jsx($e,{...q,title:ge,children:$=>t.jsx("div",{className:"space-y-3",children:Object.entries($).map(([G,P])=>t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:G.replace(/_/g," ")}),t.jsx("span",{className:"text-sm",children:String(P??"—")})]},G))})})]})}const ve=we?t.jsx("div",{className:"space-y-2",children:Me.map(T=>t.jsxs("div",{className:"border rounded-md",children:[t.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-sm font-medium text-left bg-muted/50 hover:bg-muted transition-colors",onClick:()=>Ne(T.key),children:[T.collapsed?t.jsx(Je,{className:"h-4 w-4 shrink-0"}):t.jsx(xt,{className:"h-4 w-4 shrink-0"}),t.jsx("span",{children:T.label}),t.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:T.rows.length})]}),!T.collapsed&&t.jsx(te,{schema:De(T.rows)})]},T.key))}):t.jsx(te,{schema:Ee});return q.isOverlay&&q.mode==="split"?t.jsx($e,{...q,title:ge,mainContent:ve,children:T=>t.jsx("div",{className:"space-y-3",children:Object.entries(T).map(([$,G])=>t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:$.replace(/_/g," ")}),t.jsx("span",{className:"text-sm",children:String(G??"—")})]},$))})}):t.jsxs("div",{ref:v,className:"relative h-full",children:[p>0&&t.jsx("div",{className:"flex items-center justify-center text-xs text-muted-foreground",style:{height:p},children:N?"Refreshing…":"Pull to refresh"}),ve,q.isOverlay&&t.jsx($e,{...q,title:ge,children:T=>t.jsx("div",{className:"space-y-3",children:Object.entries(T).map(([$,G])=>t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:$.replace(/_/g," ")}),t.jsx("span",{className:"text-sm",children:String(G??"—")})]},$))})})]})};function he(e,s,n){let i=n.initialDeps??[],l,o=!0;function d(){var a,w,C;let m;n.key&&((a=n.debug)!=null&&a.call(n))&&(m=Date.now());const c=e();if(!(c.length!==i.length||c.some((V,b)=>i[b]!==V)))return l;i=c;let F;if(n.key&&((w=n.debug)!=null&&w.call(n))&&(F=Date.now()),l=s(...c),n.key&&((C=n.debug)!=null&&C.call(n))){const V=Math.round((Date.now()-m)*100)/100,b=Math.round((Date.now()-F)*100)/100,I=b/16,z=(y,x)=>{for(y=String(y);y.length<x;)y=" "+y;return y};console.info(`%c⏱ ${z(b,5)} /${z(V,5)} ms`,`
2
+ font-size: .6rem;
3
+ font-weight: bold;
4
+ color: hsl(${Math.max(0,Math.min(120-120*I,120))}deg 100% 31%);`,n?.key)}return n?.onChange&&!(o&&n.skipInitialOnChange)&&n.onChange(l),o=!1,l}return d.updateDeps=a=>{i=a},d}function nt(e,s){if(e===void 0)throw new Error("Unexpected undefined");return e}const kn=(e,s)=>Math.abs(e-s)<1.01,Vn=(e,s,n)=>{let i;return function(...l){e.clearTimeout(i),i=e.setTimeout(()=>s.apply(this,l),n)}},it=e=>{const{offsetWidth:s,offsetHeight:n}=e;return{width:s,height:n}},Tn=e=>e,zn=e=>{const s=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1),i=[];for(let l=s;l<=n;l++)i.push(l);return i},In=(e,s)=>{const n=e.scrollElement;if(!n)return;const i=e.targetWindow;if(!i)return;const l=d=>{const{width:a,height:w}=d;s({width:Math.round(a),height:Math.round(w)})};if(l(it(n)),!i.ResizeObserver)return()=>{};const o=new i.ResizeObserver(d=>{const a=()=>{const w=d[0];if(w?.borderBoxSize){const C=w.borderBoxSize[0];if(C){l({width:C.inlineSize,height:C.blockSize});return}}l(it(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()});return o.observe(n,{box:"border-box"}),()=>{o.unobserve(n)}},st={passive:!0},lt=typeof window>"u"?!0:"onscrollend"in window,Mn=(e,s)=>{const n=e.scrollElement;if(!n)return;const i=e.targetWindow;if(!i)return;let l=0;const o=e.options.useScrollendEvent&&lt?()=>{}:Vn(i,()=>{s(l,!1)},e.options.isScrollingResetDelay),d=m=>()=>{const{horizontal:c,isRtl:g}=e.options;l=c?n.scrollLeft*(g&&-1||1):n.scrollTop,o(),s(l,m)},a=d(!0),w=d(!1);n.addEventListener("scroll",a,st);const C=e.options.useScrollendEvent&&lt;return C&&n.addEventListener("scrollend",w,st),()=>{n.removeEventListener("scroll",a),C&&n.removeEventListener("scrollend",w)}},An=(e,s,n)=>{if(s?.borderBoxSize){const i=s.borderBoxSize[0];if(i)return Math.round(i[n.options.horizontal?"inlineSize":"blockSize"])}return e[n.options.horizontal?"offsetWidth":"offsetHeight"]},Ln=(e,{adjustments:s=0,behavior:n},i)=>{var l,o;const d=e+s;(o=(l=i.scrollElement)==null?void 0:l.scrollTo)==null||o.call(l,{[i.options.horizontal?"left":"top"]:d,behavior:n})};class Rn{constructor(s){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.currentScrollToIndex=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let n=null;const i=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(l=>{l.forEach(o=>{const d=()=>{this._measureElement(o.target,o)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(d):d()})}));return{disconnect:()=>{var l;(l=i())==null||l.disconnect(),n=null},observe:l=>{var o;return(o=i())==null?void 0:o.observe(l,{box:"border-box"})},unobserve:l=>{var o;return(o=i())==null?void 0:o.unobserve(l)}}})(),this.range=null,this.setOptions=n=>{Object.entries(n).forEach(([i,l])=>{typeof l>"u"&&delete n[i]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Tn,rangeExtractor:zn,onChange:()=>{},measureElement:An,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,...n}},this.notify=n=>{var i,l;(l=(i=this.options).onChange)==null||l.call(i,this,n)},this.maybeNotify=he(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(n=>n()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const i=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==i){if(this.cleanup(),!i){this.maybeNotify();return}this.scrollElement=i,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(l=>{this.observer.observe(l)}),this.unsubs.push(this.options.observeElementRect(this,l=>{this.scrollRect=l,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(l,o)=>{this.scrollAdjustments=0,this.scrollDirection=o?this.getScrollOffset()<l?"forward":"backward":null,this.scrollOffset=l,this.isScrolling=o,this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(n,i)=>{const l=new Map,o=new Map;for(let d=i-1;d>=0;d--){const a=n[d];if(l.has(a.lane))continue;const w=o.get(a.lane);if(w==null||a.end>w.end?o.set(a.lane,a):a.end<w.end&&l.set(a.lane,!0),l.size===this.options.lanes)break}return o.size===this.options.lanes?Array.from(o.values()).sort((d,a)=>d.end===a.end?d.index-a.index:d.end-a.end)[0]:void 0},this.getMeasurementOptions=he(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(n,i,l,o,d,a)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMeasuredCacheIndexes=[],{count:n,paddingStart:i,scrollMargin:l,getItemKey:o,enabled:d,lanes:a}),{key:!1}),this.getMeasurements=he(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:n,paddingStart:i,scrollMargin:l,getItemKey:o,enabled:d,lanes:a},w)=>{if(!d)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const g of this.laneAssignments.keys())g>=n&&this.laneAssignments.delete(g);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(g=>{this.itemSizeCache.set(g.key,g.size)}));const C=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1);const m=this.measurementsCache.slice(0,C),c=new Array(a).fill(void 0);for(let g=0;g<C;g++){const F=m[g];F&&(c[F.lane]=g)}for(let g=C;g<n;g++){const F=o(g),V=this.laneAssignments.get(g);let b,I;if(V!==void 0&&this.options.lanes>1){b=V;const f=c[b],u=f!==void 0?m[f]:void 0;I=u?u.end+this.options.gap:i+l}else{const f=this.options.lanes===1?m[g-1]:this.getFurthestMeasurement(m,g);I=f?f.end+this.options.gap:i+l,b=f?f.lane:g%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(g,b)}const z=w.get(F),y=typeof z=="number"?z:this.options.estimateSize(g),x=I+y;m[g]={index:g,start:I,size:y,end:x,key:F,lane:b},c[b]=g}return this.measurementsCache=m,m},{key:!1,debug:()=>this.options.debug}),this.calculateRange=he(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,i,l,o)=>this.range=n.length>0&&i>0?_n({measurements:n,outerSize:i,scrollOffset:l,lanes:o}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=he(()=>{let n=null,i=null;const l=this.calculateRange();return l&&(n=l.startIndex,i=l.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,i]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,i]},(n,i,l,o,d)=>o===null||d===null?[]:n({startIndex:o,endIndex:d,overscan:i,count:l}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{const i=this.options.indexAttribute,l=n.getAttribute(i);return l?parseInt(l,10):(console.warn(`Missing attribute name '${i}={index}' on measured element.`),-1)},this._measureElement=(n,i)=>{const l=this.indexFromElement(n),o=this.measurementsCache[l];if(!o)return;const d=o.key,a=this.elementsCache.get(d);a!==n&&(a&&this.observer.unobserve(a),this.observer.observe(n),this.elementsCache.set(d,n)),n.isConnected&&this.resizeItem(l,this.options.measureElement(n,i,this))},this.resizeItem=(n,i)=>{const l=this.measurementsCache[n];if(!l)return;const o=this.itemSizeCache.get(l.key)??l.size,d=i-o;d!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(l,d,this):l.start<this.getScrollOffset()+this.scrollAdjustments)&&this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=d,behavior:void 0}),this.pendingMeasuredCacheIndexes.push(l.index),this.itemSizeCache=new Map(this.itemSizeCache.set(l.key,i)),this.notify(!1))},this.measureElement=n=>{if(!n){this.elementsCache.forEach((i,l)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(l))});return}this._measureElement(n,void 0)},this.getVirtualItems=he(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,i)=>{const l=[];for(let o=0,d=n.length;o<d;o++){const a=n[o],w=i[a];l.push(w)}return l},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const i=this.getMeasurements();if(i.length!==0)return nt(i[vt(0,i.length-1,l=>nt(i[l]).start,n)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(n,i,l=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),d=this.getScrollOffset();i==="auto"&&(i=n>=d+o?"end":"start"),i==="center"?n+=(l-o)/2:i==="end"&&(n-=o);const a=this.getMaxScrollOffset();return Math.max(Math.min(a,n),0)},this.getOffsetForIndex=(n,i="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const l=this.measurementsCache[n];if(!l)return;const o=this.getSize(),d=this.getScrollOffset();if(i==="auto")if(l.end>=d+o-this.options.scrollPaddingEnd)i="end";else if(l.start<=d+this.options.scrollPaddingStart)i="start";else return[d,i];if(i==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),i];const a=i==="end"?l.end+this.options.scrollPaddingEnd:l.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,i,l.size),i]},this.isDynamicMode=()=>this.elementsCache.size>0,this.scrollToOffset=(n,{align:i="start",behavior:l}={})=>{l==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(n,i),{adjustments:void 0,behavior:l})},this.scrollToIndex=(n,{align:i="auto",behavior:l}={})=>{l==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),n=Math.max(0,Math.min(n,this.options.count-1)),this.currentScrollToIndex=n;let o=0;const d=10,a=C=>{if(!this.targetWindow)return;const m=this.getOffsetForIndex(n,C);if(!m){console.warn("Failed to get offset for index:",n);return}const[c,g]=m;this._scrollToOffset(c,{adjustments:void 0,behavior:l}),this.targetWindow.requestAnimationFrame(()=>{const F=()=>{if(this.currentScrollToIndex!==n)return;const V=this.getScrollOffset(),b=this.getOffsetForIndex(n,g);if(!b){console.warn("Failed to get offset for index:",n);return}kn(b[0],V)||w(g)};this.isDynamicMode()?this.targetWindow.requestAnimationFrame(F):F()})},w=C=>{this.targetWindow&&this.currentScrollToIndex===n&&(o++,o<d?this.targetWindow.requestAnimationFrame(()=>a(C)):console.warn(`Failed to scroll to index ${n} after ${d} attempts.`))};a(i)},this.scrollBy=(n,{behavior:i}={})=>{i==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+n,{adjustments:void 0,behavior:i})},this.getTotalSize=()=>{var n;const i=this.getMeasurements();let l;if(i.length===0)l=this.options.paddingStart;else if(this.options.lanes===1)l=((n=i[i.length-1])==null?void 0:n.end)??0;else{const o=Array(this.options.lanes).fill(null);let d=i.length-1;for(;d>=0&&o.some(a=>a===null);){const a=i[d];o[a.lane]===null&&(o[a.lane]=a.end),d--}l=Math.max(...o.filter(a=>a!==null))}return Math.max(l-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(n,{adjustments:i,behavior:l})=>{this.options.scrollToFn(n,{behavior:l,adjustments:i},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(s)}}const vt=(e,s,n,i)=>{for(;e<=s;){const l=(e+s)/2|0,o=n(l);if(o<i)e=l+1;else if(o>i)s=l-1;else return l}return e>0?e-1:0};function _n({measurements:e,outerSize:s,scrollOffset:n,lanes:i}){const l=e.length-1,o=w=>e[w].start;if(e.length<=i)return{startIndex:0,endIndex:l};let d=vt(0,l,o,n),a=d;if(i===1)for(;a<l&&e[a].end<n+s;)a++;else if(i>1){const w=Array(i).fill(0);for(;a<l&&w.some(m=>m<n+s);){const m=e[a];w[m.lane]=m.end,a++}const C=Array(i).fill(n+s);for(;d>=0&&C.some(m=>m>=n);){const m=e[d];C[m.lane]=m.start,d--}d=Math.max(0,d-d%i),a=Math.min(l,a+(i-1-a%i))}return{startIndex:d,endIndex:a}}const rt=typeof document<"u"?r.useLayoutEffect:r.useEffect;function $n({useFlushSync:e=!0,...s}){const n=r.useReducer(()=>({}),{})[1],i={...s,onChange:(o,d)=>{var a;e&&d?Ot.flushSync(n):n(),(a=s.onChange)==null||a.call(s,o,d)}},[l]=r.useState(()=>new Rn(i));return l.setOptions(i),rt(()=>l._didMount(),[]),rt(()=>l._willUpdate()),l}function ui(e){return $n({observeElementRect:In,observeElementOffset:Mn,scrollToFn:Ln,...e})}const Ct=({schema:e,...s})=>{const{dataSource:n}=Qt()||{};return t.jsx(jt,{schema:e,dataSource:n,...s})};re.register("object-grid",Ct,{namespace:"plugin-grid",label:"Object Grid",category:"plugin",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"columns",type:"array",label:"Columns"},{name:"filters",type:"array",label:"Filters"}]});re.register("grid",Ct,{namespace:"view",label:"Data Grid",category:"view",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"columns",type:"array",label:"Columns"},{name:"filters",type:"array",label:"Filters"}]});const Pn={list:"List",detail:"Detail",grid:"Grid",kanban:"Kanban",calendar:"Calendar",timeline:"Timeline",map:"Map"},Wn={list:cn,detail:dn,grid:an,kanban:on,calendar:rn,timeline:ln,map:sn},qn=ye("flex gap-4",{variants:{position:{top:"flex-col",bottom:"flex-col-reverse",left:"flex-row",right:"flex-row-reverse"}},defaultVariants:{position:"top"}}),Kn=ye("w-full",{variants:{orientation:{horizontal:"w-full",vertical:"w-48"}},defaultVariants:{orientation:"horizontal"}}),Bn=ye("flex gap-2",{variants:{orientation:{horizontal:"flex-row flex-wrap",vertical:"flex-col"}},defaultVariants:{orientation:"horizontal"}}),Un=ye("",{variants:{orientation:{horizontal:"",vertical:"flex h-auto flex-col items-stretch"}},defaultVariants:{orientation:"horizontal"}});function Hn(e){return e.split("-").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join("")}const Gn={Home:"House"};function Jn(e){if(!e)return null;const s=Hn(e),n=Gn[s]||s;return un[n]||null}function Pe(e){return e.label?e.label:Pn[e.type]||e.type}function ot(e){return e.icon?Jn(e.icon):Wn[e.type]||null}function Qn(e){return e.activeView?e.activeView:e.defaultView?e.defaultView:e.views?.[0]?.type}const St=({schema:e,className:s,onViewChange:n,...i})=>{const l=r.useMemo(()=>e.storageKey?e.storageKey:`view-switcher${e.id?`-${e.id}`:""}`,[e.id,e.storageKey]),[o,d]=r.useState(()=>Qn(e));r.useEffect(()=>{if(e.activeView){d(e.activeView);return}if(e.persistPreference)try{const y=localStorage.getItem(l);if(y){const x=e.views.find(f=>f.type===y)?.type;x&&d(x)}}catch{}},[e.activeView,e.persistPreference,e.views,l]),r.useEffect(()=>{if(!(!e.persistPreference||!o||e.activeView))try{localStorage.setItem(l,o)}catch{}},[o,e.activeView,e.persistPreference,l]);const a=r.useCallback(y=>{n?.(y),e.onViewChange&&typeof window<"u"&&window.dispatchEvent(new CustomEvent(e.onViewChange,{detail:{view:y}}))},[n,e.onViewChange]),w=r.useCallback(y=>{d(y),a(y)},[a]),C=o||e.views?.[0]?.type,m=C||"",c=e.views.find(y=>y.type===C)||e.views?.[0],g=e.variant||"tabs",F=e.position||"top",V=F==="left"||F==="right",b=V?"vertical":"horizontal",I=t.jsxs("div",{className:_(Kn({orientation:b})),children:[g==="dropdown"&&t.jsxs(Ve,{value:m,onValueChange:y=>w(y),children:[t.jsx(Te,{className:_("w-full",V?"h-10":"h-9"),children:t.jsx(ze,{placeholder:"Select view"})}),t.jsx(Ie,{children:e.views.map((y,x)=>t.jsx(Se,{value:y.type,children:Pe(y)},`${y.type}-${x}`))})]}),g==="buttons"&&t.jsx("div",{className:_(Bn({orientation:b})),children:e.views.map((y,x)=>{const f=y.type===C,u=ot(y);return t.jsxs(ee,{type:"button",size:"sm",variant:f?"secondary":"ghost",className:_("justify-start gap-2",V?"w-full":""),onClick:()=>w(y.type),children:[u?t.jsx(u,{className:"h-4 w-4"}):null,t.jsx("span",{children:Pe(y)})]},`${y.type}-${x}`)})}),g==="tabs"&&t.jsx(Ue,{value:m,onValueChange:y=>w(y),children:t.jsx(He,{className:_(Un({orientation:b})),children:e.views.map((y,x)=>{const f=ot(y);return t.jsxs(Ge,{value:y.type,className:_("gap-2",V?"justify-start":""),children:[f?t.jsx(f,{className:"h-4 w-4"}):null,t.jsx("span",{children:Pe(y)})]},`${y.type}-${x}`)})})})]}),z=c?.schema?Array.isArray(c.schema)?t.jsx("div",{className:"space-y-4",children:c.schema.map((y,x)=>t.jsx(te,{schema:y,...i},`${c.type}-${x}`))}):t.jsx(te,{schema:c.schema,...i}):null;return t.jsxs("div",{className:_(qn({position:F}),s),children:[t.jsx("div",{className:_("shrink-0",V?"flex flex-col":"flex"),children:I}),t.jsx("div",{className:"flex-1 min-w-0",children:z})]})};let ke=null;try{ke=require("@object-ui/react").SchemaRenderer||null}catch{}const Xn=({schema:e,dataSource:s,className:n,views:i,activeViewId:l,onViewChange:o,onRowClick:d,onEdit:a,renderListView:w,toolbarAddon:C})=>{const[m,c]=r.useState(null),[g,F]=r.useState(!1),[V,b]=r.useState("create"),[I,z]=r.useState(null),[y,x]=r.useState(0),[f,u]=r.useState([]),[j,v]=r.useState(!1),[N,p]=r.useState({}),[A,X]=r.useState([]),E=e.listViews,k=E!=null&&Object.keys(E).length>0,[R,K]=r.useState(()=>e.defaultListView&&E?.[e.defaultListView]?e.defaultListView:E&&Object.keys(E)[0]||""),M=r.useMemo(()=>!k||!R?null:E[R]||null,[k,R,E]),U=r.useMemo(()=>i&&i.length>0?i:null,[i]),ue=U!=null&&U.length>0,oe=l||U?.[0]?.id,W=U?.find(h=>h.id===oe)||U?.[0],ie=r.useMemo(()=>M?.type?M.type:W?.type?W.type:e.defaultViewType||"grid",[M,W,e.defaultViewType]),q=e.navigation;r.useEffect(()=>{let h=!0;const O=async()=>{try{const S=await s.getObjectSchema(e.objectName);h&&c(S)}catch(S){console.error("Failed to fetch object schema:",S)}};return e.objectName&&s&&O(),()=>{h=!1}},[e.objectName,s]),r.useEffect(()=>{let h=!0;return(async()=>{if(!(ie==="grid"&&!w)&&!(!s||!e.objectName)){v(!0);try{const S=M?.filter||W?.filter||e.table?.defaultFilters||[],Y=Object.entries(N).filter(([,ne])=>ne!==void 0&&ne!==""&&ne!==null).map(([ne,pe])=>[ne,"=",pe]);let L=[];S.length>0&&Y.length>0?L=["and",...S,...Y]:Y.length===1?L=Y[0]:Y.length>1?L=["and",...Y]:L=S;const Z=A.length>0?A.map(ne=>({field:ne.field,order:ne.direction})):M?.sort||W?.sort||e.table?.defaultSort||void 0,B=await s.find(e.objectName,{$filter:L.length>0?L:void 0,$orderby:Z,$top:100});let Q=[];Array.isArray(B)?Q=B:B&&typeof B=="object"&&(Array.isArray(B.data)?Q=B.data:Array.isArray(B.records)&&(Q=B.records)),h&&u(Q)}catch(S){console.error("ObjectView data fetch error:",S)}finally{h&&v(!1)}}})(),()=>{h=!1}},[e.objectName,s,ie,N,A,y,M,W,w]);const se=e.layout||"drawer",le=e.operations||e.table?.operations||{create:!0,read:!0,update:!0,delete:!0},Me=r.useCallback(()=>{se==="page"&&e.onNavigate?e.onNavigate("new","edit"):(b("create"),z(null),F(!0))},[se,e]),we=r.useCallback(h=>{if(a){a(h);return}if(se==="page"&&e.onNavigate){const O=h._id||h.id;e.onNavigate(O,"edit")}else b("edit"),z(h),F(!0)},[se,e,a]),Ne=r.useCallback(h=>{if(se==="page"&&e.onNavigate){const O=h._id||h.id;e.onNavigate(O,"view")}else b("view"),z(h),F(!0)},[se,e]),je=r.useCallback(h=>{if(d){d(h);return}if(q){if(q.mode==="none"||q.preventNavigation)return;if(q.mode==="new_window"||q.openNewTab){const O=h._id||h.id,S=`/${e.objectName}/${O}`;window.open(S,"_blank");return}if(q.mode==="drawer"){b("view"),z(h),F(!0);return}if(q.mode==="modal"){b("view"),z(h),F(!0);return}if(q.mode==="page"){const O=h._id||h.id;e.onNavigate&&e.onNavigate(O,"view");return}}le.read!==!1&&Ne(h)},[d,q,le.read,Ne,e]),Fe=r.useCallback(h=>{x(O=>O+1)},[]),ae=r.useCallback(h=>{x(O=>O+1)},[]),Oe=r.useCallback(()=>{F(!1),z(null),x(h=>h+1)},[]),Ae=r.useCallback(()=>{F(!1),z(null)},[]);r.useCallback(()=>{x(h=>h+1)},[]);const be=r.useMemo(()=>!ue||!U||U.length<=1?null:{type:"view-switcher",variant:"tabs",position:"top",persistPreference:!0,storageKey:`view-pref-${e.objectName}`,defaultView:W?.type||"grid",activeView:W?.type||"grid",views:U.map(h=>{const O={kanban:"kanban",calendar:"calendar",map:"map",gallery:"layout-grid",timeline:"activity",gantt:"gantt-chart",grid:"table",list:"list",detail:"file-text"};return{type:h.type,label:h.label,icon:O[h.type]||"table"}})},[ue,U,W,e.objectName]),Le=r.useCallback(h=>{if(!U)return;const O=U.find(S=>S.type===h);O&&o&&o(O.id)},[U,o]),Re=r.useCallback(h=>{K(h)},[]);r.useMemo(()=>{if(e.showFilters===!1)return null;const h=e.filterableFields,O=m?.fields||{},Y=(h?h.map(L=>[L,O[L]||{label:L}]):Object.entries(O).filter(([,L])=>!L.hidden).slice(0,8)).map(([L,Z])=>{const B=Z.type||"text";let Q="text",ne;return B==="number"||B==="currency"||B==="percent"?Q="number":B==="boolean"||B==="toggle"?Q="boolean":B==="date"||B==="datetime"?Q="date":(B==="select"||Z.options)&&(Q="select",ne=(Z.options||[]).map(pe=>typeof pe=="string"?{label:pe,value:pe}:{label:pe.label,value:pe.value})),{field:L,label:Z.label||L,type:Q,placeholder:`Filter ${Z.label||L}...`,...ne?{options:ne}:{}}});return Y.length===0?null:{type:"filter-ui",layout:"popover",showClear:!0,showApply:!0,filters:Y,values:N}},[e.showFilters,e.filterableFields,m,N]),r.useMemo(()=>{const h=m?.fields||{},O=Object.entries(h).filter(([,S])=>!S.hidden).slice(0,10).map(([S,Y])=>({field:S,label:Y.label||S}));return O.length===0?null:{type:"sort-ui",variant:"dropdown",multiple:!1,fields:O,sort:A}},[m,A]);const _e=r.useCallback(h=>{const O={objectName:e.objectName,fields:M?.columns||W?.columns||e.table?.fields,className:"h-full w-full",showSearch:!1},S=M?.options||W||{};switch(h){case"kanban":return{type:"object-kanban",...O,groupBy:S.kanban?.groupField||S.groupBy||S.groupField||"status",groupField:S.kanban?.groupField||S.groupField||"status",titleField:S.kanban?.titleField||S.titleField||"name",cardFields:O.fields||[],...S.kanban||{}};case"calendar":return{type:"object-calendar",...O,startDateField:S.calendar?.startDateField||S.startDateField||"start_date",endDateField:S.calendar?.endDateField||S.endDateField||"end_date",titleField:S.calendar?.titleField||S.titleField||"name",...S.calendar||{}};case"gallery":return{type:"object-gallery",...O,imageField:S.gallery?.imageField||S.imageField,titleField:S.gallery?.titleField||S.titleField||"name",subtitleField:S.gallery?.subtitleField||S.subtitleField,...S.gallery||{}};case"timeline":return{type:"object-timeline",...O,dateField:S.timeline?.dateField||S.dateField||"created_at",titleField:S.timeline?.titleField||S.titleField||"name",...S.timeline||{}};case"gantt":return{type:"object-gantt",...O,startDateField:S.gantt?.startDateField||S.startDateField||"start_date",endDateField:S.gantt?.endDateField||S.endDateField||"end_date",progressField:S.gantt?.progressField||S.progressField||"progress",dependenciesField:S.gantt?.dependenciesField||S.dependenciesField||"dependencies",...S.gantt||{}};case"map":return{type:"object-map",...O,locationField:S.map?.locationField||S.locationField||"location",...S.map||{}};default:return null}},[e.objectName,e.table?.fields,M,W]),Ee=r.useMemo(()=>({type:"object-grid",objectName:e.objectName,title:e.table?.title,description:e.table?.description,fields:M?.columns||W?.columns||e.table?.fields,columns:M?.columns||W?.columns||e.table?.columns,operations:{...le,create:!1},defaultFilters:M?.filter||W?.filter||e.table?.defaultFilters,defaultSort:M?.sort||W?.sort||e.table?.defaultSort,pageSize:e.table?.pageSize,selectable:e.table?.selectable,className:e.table?.className}),[e,le,M,W]),De=()=>{const h=I?I._id||I.id:void 0;return{type:"object-form",objectName:e.objectName,mode:V,recordId:h,title:e.form?.title,description:e.form?.description,fields:e.form?.fields,customFields:e.form?.customFields,groups:e.form?.groups,layout:e.form?.layout,columns:e.form?.columns,showSubmit:e.form?.showSubmit,submitText:e.form?.submitText,showCancel:e.form?.showCancel,cancelText:e.form?.cancelText,showReset:e.form?.showReset,initialValues:e.form?.initialValues,readOnly:e.form?.readOnly||V==="view",className:e.form?.className,onSuccess:Oe,onCancel:Ae}},ge=()=>{if(e.form?.title)return e.form.title;const h=m?.label||e.objectName;switch(V){case"create":return`Create ${h}`;case"edit":return`Edit ${h}`;case"view":return`View ${h}`;default:return h}},ve=r.useMemo(()=>{const h=q?.width;return h?typeof h=="number"?`max-w-[${h}px]`:`max-w-[${h}]`:""},[q]),T=()=>t.jsx(mt,{open:g,onOpenChange:F,direction:"right",children:t.jsxs(bt,{className:_("w-full sm:max-w-2xl",ve),children:[t.jsxs(gt,{children:[t.jsx(ht,{children:ge()}),e.form?.description&&t.jsx(yt,{children:e.form.description})]}),t.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:t.jsx(Be,{schema:De(),dataSource:s})})]})}),$=()=>t.jsx(dt,{open:g,onOpenChange:F,children:t.jsxs(ct,{className:_("max-w-2xl max-h-[90vh] overflow-y-auto",ve),children:[t.jsxs(ut,{children:[t.jsx(ft,{children:ge()}),e.form?.description&&t.jsx(pt,{children:e.form.description})]}),t.jsx(Be,{schema:De(),dataSource:s})]})}),G=r.useMemo(()=>Object.keys(N).some(O=>N[O]!==void 0&&N[O]!==""&&N[O]!==null)?Object.entries(N).filter(([,O])=>O!==void 0&&O!==""&&O!==null).map(([O,S])=>({field:O,operator:"equals",value:S})):M?.filter||W?.filter||e.table?.defaultFilters,[N,M,W,e.table?.defaultFilters]),P=r.useMemo(()=>A.length>0?A:M?.sort||W?.sort||e.table?.defaultSort,[A,M,W,e.table?.defaultSort]),D=()=>{const h=`${e.objectName}-${R||W?.id||"default"}-${ie}-${y}`;if(w)return w({schema:{type:"list-view",objectName:e.objectName,viewType:ie,fields:M?.columns||W?.columns||e.table?.fields,filters:G,sort:P,options:M?.options||W},dataSource:s,onEdit:we,onRowClick:je,className:"h-full"});if(ie!=="grid"){const O=_e(ie);if(O&&ke)return t.jsx(ke,{schema:O,dataSource:s,data:f,loading:j},h);if(!ke)return t.jsx("div",{className:"flex items-center justify-center h-40 text-muted-foreground",children:t.jsxs("p",{children:["SchemaRenderer not available. Install @object-ui/react to render ",ie," views."]})})}return t.jsx(jt,{schema:Ee,dataSource:s,onRowClick:je,onEdit:le.update!==!1?we:void 0,onDelete:le.delete!==!1?Fe:void 0,onBulkDelete:le.delete!==!1?ae:void 0},h)},J=()=>{if(!k)return null;const h=Object.entries(E);return h.length<=1?null:t.jsx(Ue,{value:R,onValueChange:Re,className:"w-full",children:t.jsx(He,{className:"w-auto",children:h.map(([O,S])=>t.jsx(Ge,{value:O,className:"text-sm",children:S.label||O},O))})})},fe=()=>{const h=e.showCreate!==!1&&le.create!==!1,O=e.showViewSwitcher===!0,S=J();return!S&&!O&&!h&&!C?null:t.jsxs("div",{className:"flex flex-col gap-3",children:[S,(O||h||C)&&t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("div",{className:"flex items-center gap-2",children:O&&be&&t.jsx(St,{schema:be,onViewChange:Le,className:"overflow-x-auto"})}),t.jsxs("div",{className:"flex items-center gap-2",children:[C,h&&t.jsxs(ee,{size:"sm",onClick:Me,children:[t.jsx(fn,{className:"h-4 w-4"}),"Create"]})]})]})]})},H=q?.mode==="modal"?"modal":q?.mode==="drawer"?"drawer":se;return t.jsxs("div",{className:_("flex flex-col h-full",n),children:[(e.title||e.description)&&t.jsxs("div",{className:"mb-4 shrink-0",children:[e.title&&t.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:e.title}),e.description&&t.jsx("p",{className:"text-muted-foreground mt-1",children:e.description})]}),t.jsx("div",{className:"mb-4 shrink-0",children:fe()}),t.jsx("div",{className:"flex-1 min-h-0",children:D()}),H==="drawer"&&T(),H==="modal"&&$()]})},We=ye("flex",{variants:{layout:{inline:"flex-col space-y-4",popover:"items-center",drawer:"items-center"}},defaultVariants:{layout:"inline"}}),Yn=e=>e==null||e===""?!0:Array.isArray(e)?e.length===0:typeof e=="object"?Object.values(e).every(s=>s==null||s===""):!1,Zn=e=>Array.isArray(e)?{start:e[0]||"",end:e[1]||""}:e&&typeof e=="object"?{start:e.start||"",end:e.end||""}:{start:"",end:""},ei=({schema:e,className:s,onChange:n})=>{const[i,l]=r.useState(e.values||{}),[o,d]=r.useState(!1);r.useEffect(()=>{e.values&&l(e.values)},[e.values]);const a=r.useCallback(b=>{n?.(b),e.onChange&&typeof window<"u"&&window.dispatchEvent(new CustomEvent(e.onChange,{detail:{values:b}}))},[n,e.onChange]),w=r.useCallback((b,I)=>{const z={...i,[b]:I};l(z),e.showApply||a(z)},[a,e.showApply,i]),C=r.useCallback(()=>{const b={};if(l(b),e.showApply){a(b);return}a(b)},[a,e.showApply]),m=r.useCallback(()=>{a(i),d(!1)},[a,i]),c=r.useMemo(()=>Object.values(i).filter(b=>!Yn(b)).length,[i]),g=b=>{const I=b.label||b.field,z=b.placeholder||`Filter by ${I}`;switch(b.type){case"number":return t.jsx(Ce,{type:"number",value:i[b.field]??"",placeholder:z,onChange:y=>{const x=y.target.value,f=x===""?"":Number(x);w(b.field,f)}});case"select":return t.jsxs(Ve,{value:i[b.field]!==void 0?String(i[b.field]):"",onValueChange:y=>{const x=b.options?.find(f=>String(f.value)===y);w(b.field,x?x.value:y)},children:[t.jsx(Te,{children:t.jsx(ze,{placeholder:z})}),t.jsx(Ie,{children:b.options?.map(y=>t.jsx(Se,{value:String(y.value),children:y.label},String(y.value)))})]});case"date":return t.jsx(Ce,{type:"date",value:i[b.field]??"",onChange:y=>w(b.field,y.target.value)});case"date-range":{const y=Zn(i[b.field]);return t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ce,{type:"date",value:y.start??"",onChange:x=>{w(b.field,{...y,start:x.target.value})}}),t.jsx(Ce,{type:"date",value:y.end??"",onChange:x=>{w(b.field,{...y,end:x.target.value})}})]})}case"boolean":return t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Bt,{checked:!!i[b.field],onCheckedChange:y=>w(b.field,!!y)}),t.jsx("span",{className:"text-sm text-muted-foreground",children:"Enabled"})]});case"text":default:return t.jsx(Ce,{value:i[b.field]??"",placeholder:z,onChange:y=>w(b.field,y.target.value)})}},F=t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"grid gap-4 sm:grid-cols-2",children:e.filters.map(b=>t.jsxs("div",{className:"space-y-2",children:[t.jsx(Pt,{className:"text-xs text-muted-foreground",children:b.label||b.field}),g(b)]},b.field))}),(e.showApply||e.showClear)&&t.jsxs("div",{className:"flex items-center justify-end gap-2 border-t pt-3",children:[e.showClear&&t.jsx(ee,{type:"button",variant:"ghost",size:"sm",onClick:C,children:"Clear"}),e.showApply&&t.jsx(ee,{type:"button",size:"sm",onClick:m,children:"Apply"})]})]}),V=e.layout||"inline";return V==="popover"?t.jsx("div",{className:_(We({layout:V}),s),children:t.jsxs(Wt,{open:o,onOpenChange:d,children:[t.jsx(qt,{asChild:!0,children:t.jsxs(ee,{type:"button",variant:c>0?"secondary":"outline",size:"sm",className:"gap-2",children:[t.jsx(Ze,{className:"h-4 w-4"}),"Filters",c>0&&t.jsx("span",{className:"inline-flex h-5 min-w-[20px] items-center justify-center rounded-full bg-primary/10 px-1 text-xs font-medium text-primary",children:c})]})}),t.jsx(Kt,{align:"start",className:"w-[520px] p-4",children:F})]})}):V==="drawer"?t.jsxs("div",{className:_(We({layout:V}),s),children:[t.jsxs(ee,{type:"button",variant:c>0?"secondary":"outline",size:"sm",className:"gap-2",onClick:()=>d(!0),children:[t.jsx(Ze,{className:"h-4 w-4"}),"Filters",c>0&&t.jsx("span",{className:"inline-flex h-5 min-w-[20px] items-center justify-center rounded-full bg-primary/10 px-1 text-xs font-medium text-primary",children:c})]}),t.jsx(mt,{open:o,onOpenChange:d,children:t.jsxs(bt,{children:[t.jsxs(gt,{children:[t.jsx(ht,{children:"Filters"}),t.jsx(yt,{children:"Refine the data with advanced filters."})]}),t.jsx("div",{className:"px-4 pb-6",children:F})]})})]}):t.jsxs("div",{className:_(We({layout:V}),s),children:[F,!e.showApply&&e.showClear&&t.jsxs(ee,{type:"button",variant:"ghost",size:"sm",className:"gap-2",onClick:C,children:[t.jsx(pn,{className:"h-3.5 w-3.5"}),"Clear filters"]})]})},qe=ye("",{variants:{variant:{buttons:"flex flex-wrap gap-2",dropdown:"flex flex-wrap items-center gap-3",builder:"space-y-3"}},defaultVariants:{variant:"dropdown"}}),Ke=e=>e?e.map(s=>({field:s.field,direction:s.direction})):[],at=e=>e.map(s=>({id:`${s.field}-${s.direction}`,field:s.field,order:s.direction})),ti=e=>e.filter(s=>s.field).map(s=>({field:s.field,direction:s.order})),ni=({schema:e,className:s,onChange:n})=>{const[i,l]=r.useState(()=>Ke(e.sort)),[o,d]=r.useState(()=>at(Ke(e.sort)));r.useEffect(()=>{const c=Ke(e.sort);l(c),d(at(c))},[e.sort]);const a=r.useCallback(c=>{l(c),n?.(c),e.onChange&&typeof window<"u"&&window.dispatchEvent(new CustomEvent(e.onChange,{detail:{sort:c}}))},[n,e.onChange]),w=r.useCallback(c=>{const g=i.find(b=>b.field===c),F=!!e.multiple;if(!g){const b=F?[...i,{field:c,direction:"asc"}]:[{field:c,direction:"asc"}];a(b);return}if(g.direction==="asc"){const b=i.map(I=>I.field===c?{...I,direction:"desc"}:I);a(b);return}const V=i.filter(b=>b.field!==c);a(V)},[a,e.multiple,i]);if((e.variant||"dropdown")==="buttons")return t.jsx("div",{className:_(qe({variant:"buttons"}),s),children:e.fields.map(c=>{const g=i.find(V=>V.field===c.field),F=g?.direction==="asc"?mn:bn;return t.jsxs(ee,{type:"button",variant:g?"secondary":"outline",size:"sm",onClick:()=>w(c.field),className:"gap-2",children:[t.jsx("span",{children:c.label||c.field}),g&&t.jsx(F,{className:"h-3.5 w-3.5"})]},c.field)})});if(e.multiple)return t.jsx("div",{className:_(qe({variant:"builder"}),s),children:t.jsx(Ut,{fields:e.fields.map(c=>({value:c.field,label:c.label||c.field})),value:o,onChange:c=>{d(c),a(ti(c))}})});const m=i[0];return t.jsxs("div",{className:_(qe({variant:"dropdown"}),s),children:[t.jsxs(Ve,{value:m?.field||"",onValueChange:c=>{if(!c){a([]);return}a([{field:c,direction:m?.direction||"asc"}])},children:[t.jsx(Te,{className:"w-56",children:t.jsx(ze,{placeholder:"Select field"})}),t.jsx(Ie,{children:e.fields.map(c=>t.jsx(Se,{value:c.field,children:c.label||c.field},c.field))})]}),t.jsxs(Ve,{value:m?.direction||"asc",onValueChange:c=>{m?.field&&a([{field:m.field,direction:c}])},children:[t.jsx(Te,{className:"w-36",children:t.jsx(ze,{})}),t.jsxs(Ie,{children:[t.jsx(Se,{value:"asc",children:"Ascending"}),t.jsx(Se,{value:"desc",children:"Descending"})]})]})]})},ii=me.createContext(null);let Nt=ii;try{const e=require("@object-ui/react");e.SchemaRendererContext&&(Nt=e.SchemaRendererContext)}catch{}const Ft=({schema:e})=>{const n=r.useContext(Nt)?.dataSource??null;return t.jsx(Xn,{schema:e,dataSource:n})};re.register("object-view",Ft,{namespace:"plugin-view",label:"Object View",category:"view",icon:"LayoutDashboard",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"title",type:"string",label:"Title"},{name:"description",type:"string",label:"Description"},{name:"layout",type:"enum",label:"Form Layout",enum:["drawer","modal","page"]},{name:"defaultViewType",type:"enum",label:"Default View Type",enum:["grid","kanban","gallery","calendar","timeline","gantt","map"]},{name:"defaultListView",type:"string",label:"Default Named View"},{name:"showSearch",type:"boolean",label:"Show Search"},{name:"showFilters",type:"boolean",label:"Show Filters"},{name:"showCreate",type:"boolean",label:"Show Create Button"},{name:"showRefresh",type:"boolean",label:"Show Refresh Button"},{name:"showViewSwitcher",type:"boolean",label:"Show View Switcher"},{name:"listViews",type:"object",label:"Named List Views"},{name:"navigation",type:"object",label:"Navigation Config"},{name:"searchableFields",type:"array",label:"Searchable Fields"},{name:"filterableFields",type:"array",label:"Filterable Fields"}],defaultProps:{layout:"drawer",defaultViewType:"grid",showSearch:!0,showFilters:!0,showCreate:!0,showRefresh:!0,showViewSwitcher:!0}});re.register("view",Ft,{namespace:"plugin-view",label:"View",category:"view"});re.register("view-switcher",St,{namespace:"view",label:"View Switcher",category:"view",icon:"LayoutGrid",inputs:[{name:"views",type:"array",label:"Views",required:!0},{name:"defaultView",type:"string",label:"Default View"},{name:"activeView",type:"string",label:"Active View"},{name:"variant",type:"enum",label:"Variant",enum:["tabs","buttons","dropdown"]},{name:"position",type:"enum",label:"Position",enum:["top","bottom","left","right"]},{name:"persistPreference",type:"boolean",label:"Persist Preference"},{name:"storageKey",type:"string",label:"Storage Key"},{name:"onViewChange",type:"string",label:"On View Change Event"}],defaultProps:{variant:"tabs",position:"top",defaultView:"grid",views:[{type:"grid",label:"Grid",schema:{type:"text",content:"Grid view"}},{type:"list",label:"List",schema:{type:"text",content:"List view"}}]}});re.register("filter-ui",ei,{namespace:"view",label:"Filter UI",category:"view",icon:"SlidersHorizontal",inputs:[{name:"filters",type:"array",label:"Filters",required:!0},{name:"values",type:"object",label:"Values"},{name:"onChange",type:"string",label:"On Change Event"},{name:"showClear",type:"boolean",label:"Show Clear Button"},{name:"showApply",type:"boolean",label:"Show Apply Button"},{name:"layout",type:"enum",label:"Layout",enum:["inline","popover","drawer"]}],defaultProps:{layout:"inline",showApply:!1,showClear:!0,filters:[{field:"name",label:"Name",type:"text",placeholder:"Search name"},{field:"status",label:"Status",type:"select",options:[{label:"Open",value:"open"},{label:"Closed",value:"closed"}]},{field:"created_at",label:"Created",type:"date"}]}});re.register("sort-ui",ni,{namespace:"view",label:"Sort UI",category:"view",icon:"ArrowUpDown",inputs:[{name:"fields",type:"array",label:"Fields",required:!0},{name:"sort",type:"array",label:"Sort"},{name:"onChange",type:"string",label:"On Change Event"},{name:"multiple",type:"boolean",label:"Allow Multiple"},{name:"variant",type:"enum",label:"Variant",enum:["dropdown","buttons"]}],defaultProps:{variant:"dropdown",multiple:!0,fields:[{field:"name",label:"Name"},{field:"created_at",label:"Created At"}],sort:[{field:"name",direction:"asc"}]}});const si=({schema:e,className:s,children:n,dataSource:i,...l})=>{const o=e.props?.columns?{display:"grid",gridTemplateColumns:`repeat(${e.props.columns}, 1fr)`,gap:"1rem"}:void 0;return t.jsx("div",{className:s,style:o,...l,children:n})};re.register("view:simple",si,{namespace:"plugin-view",label:"Simple View",category:"view"});export{Xn as O,Be as a,ui as u};