@object-ui/console 3.1.1 → 3.1.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 (67) hide show
  1. package/dist/assets/{AdvancedChartImpl-D711bBuO.js → AdvancedChartImpl-BvIFxlPf.js} +2 -2
  2. package/dist/assets/{AppManagementPage-D_71FpIH.js → AppManagementPage-6bzxYNlP.js} +1 -1
  3. package/dist/assets/{AuditLogPage-D3g_VEdE.js → AuditLogPage-qCzdxaNq.js} +1 -1
  4. package/dist/assets/{AuthPageLayout-9l5xWV_-.js → AuthPageLayout-DkrxSZOE.js} +1 -1
  5. package/dist/assets/{ChartImpl-B9B4Fnbe.js → ChartImpl-DYQ9eXJz.js} +1 -1
  6. package/dist/assets/CreateAppPage-DNKskVHK.js +1 -0
  7. package/dist/assets/{DashboardDesignPage-Cijb3jeF.js → DashboardDesignPage-T9tEAHAx.js} +1 -1
  8. package/dist/assets/{DashboardView-DjhlMHLV.js → DashboardView-jCJCERzJ.js} +1 -1
  9. package/dist/assets/{EditAppPage-BiK_DWcO.js → EditAppPage-UGT9V29B.js} +1 -1
  10. package/dist/assets/{ForgotPasswordPage-Bzady8r_.js → ForgotPasswordPage-Ca0lLZwY.js} +1 -1
  11. package/dist/assets/{KanbanEnhanced-OvdpYe81.js → KanbanEnhanced-CyIdmKhW.js} +1 -1
  12. package/dist/assets/{KanbanImpl-EcxwmGw7.js → KanbanImpl-PGPpv-gu.js} +1 -1
  13. package/dist/assets/{LoginPage-valW4Wu1.js → LoginPage-BR2RpoGG.js} +1 -1
  14. package/dist/assets/{MarkdownImpl-C0wRapHT.js → MarkdownImpl-eDhoPCJp.js} +1 -1
  15. package/dist/assets/{OrgManagementPage-D0d52PdP.js → OrgManagementPage-DjT2mZ2x.js} +1 -1
  16. package/dist/assets/{PageDesignPage-hpFLdWCR.js → PageDesignPage-DTEQcEuR.js} +1 -1
  17. package/dist/assets/PageView-CFJhE0CN.js +2 -0
  18. package/dist/assets/{PermissionManagementPage-ELCC8HyK.js → PermissionManagementPage-C_FPnvGW.js} +1 -1
  19. package/dist/assets/{ProfilePage-Dj1N0mY3.js → ProfilePage-CQkgvEEi.js} +1 -1
  20. package/dist/assets/RecordDetailView-ClpxNRz2.js +1 -0
  21. package/dist/assets/{RegisterPage-DqUU8oW-.js → RegisterPage-6IYU4bdp.js} +1 -1
  22. package/dist/assets/{ReportView-CNi0A66t.js → ReportView-DecAJ58u.js} +1 -1
  23. package/dist/assets/{RoleManagementPage-DRvuG53j.js → RoleManagementPage-v0ia3MGn.js} +1 -1
  24. package/dist/assets/{SearchResultsPage-nMlMQCb8.js → SearchResultsPage-CaSb54ho.js} +1 -1
  25. package/dist/assets/{SystemHubPage-CAY-YvG2.js → SystemHubPage-PNaxZEht.js} +1 -1
  26. package/dist/assets/{UserManagementPage-fzvfJxav.js → UserManagementPage-KAZy5fgy.js} +1 -1
  27. package/dist/assets/data-adapter-DCM4pdG4.js +1 -0
  28. package/dist/assets/framework-jBjO8CT3.js +10 -0
  29. package/dist/assets/{index-Dv78M4Xq.js → index-BwkHrw9s.js} +1 -1
  30. package/dist/assets/index-DXak0mZe.css +1 -0
  31. package/dist/assets/index-tta28Q_N.js +9 -0
  32. package/dist/assets/infrastructure-CWeiQ12V.js +1 -0
  33. package/dist/assets/{maplibre-gl-DVmJFhI2.js → maplibre-gl-CENyyZ0G.js} +1 -1
  34. package/dist/assets/plugins-core-BV7ym-7D.js +8 -0
  35. package/dist/assets/plugins-views-gxDbTdkX.js +62 -0
  36. package/dist/assets/ui-components-BCiSmwiC.css +1 -0
  37. package/dist/assets/ui-components-BRpbeVr1.js +36 -0
  38. package/dist/assets/ui-layout-VeUu0ZVf.js +1 -0
  39. package/dist/assets/vendor-charts-DthMRf4E.js +60 -0
  40. package/dist/assets/{vendor-dndkit-CX1oDZqy.js → vendor-dndkit-_-PfuStg.js} +1 -1
  41. package/dist/assets/vendor-i18n-B3GHNV0X.js +9 -0
  42. package/dist/assets/{vendor-icons-ndICq8DC.js → vendor-icons-CnLeuN7Z.js} +3419 -3414
  43. package/dist/assets/vendor-objectstack-BkRCrdfn.js +34 -0
  44. package/dist/assets/vendor-radix-BPVlBHPl.js +56 -0
  45. package/dist/assets/{vendor-react-9M-xu2bR.js → vendor-react-Dvo_9NuO.js} +6 -6
  46. package/dist/assets/{vendor-ui-utils-3tkeUVaX.js → vendor-ui-utils-CU11aiRA.js} +1 -1
  47. package/dist/assets/vendor-zod-CZmssJWz.js +39 -0
  48. package/dist/index.html +23 -23
  49. package/package.json +39 -39
  50. package/dist/assets/CreateAppPage-mqt5j4rK.js +0 -1
  51. package/dist/assets/PageView-DxIAf-SB.js +0 -2
  52. package/dist/assets/RecordDetailView-DS9tEr5f.js +0 -1
  53. package/dist/assets/data-adapter-rvE3xy2B.js +0 -1
  54. package/dist/assets/framework-BM176iet.js +0 -10
  55. package/dist/assets/index-B6cpm7bF.css +0 -1
  56. package/dist/assets/index-CTBPkbPG.js +0 -9
  57. package/dist/assets/infrastructure-n1j_TN6w.js +0 -1
  58. package/dist/assets/plugins-core-qwgXbAqa.js +0 -8
  59. package/dist/assets/plugins-views-CveFN6PV.js +0 -62
  60. package/dist/assets/ui-components-BxvihT61.js +0 -36
  61. package/dist/assets/ui-components-CRV2BvKI.css +0 -1
  62. package/dist/assets/ui-layout-C6KWQtRO.js +0 -1
  63. package/dist/assets/vendor-charts-BLNOCZWl.js +0 -65
  64. package/dist/assets/vendor-i18n-E3-WitRV.js +0 -9
  65. package/dist/assets/vendor-objectstack-YKtcdalX.js +0 -34
  66. package/dist/assets/vendor-radix-C6qchjxv.js +0 -56
  67. package/dist/assets/vendor-zod-DxQVy2_o.js +0 -39
@@ -1,8 +0,0 @@
1
- import{r as l,j as t,R as $e,d as Sn}from"./vendor-react-9M-xu2bR.js";import{c as Z,b as Ge,m as Ye,T as Yt,a as Jt,d as Qt,e as Fn,B as ne,R as kn,f as xs,g as On,S as Dn,h as En,i as Tn,j as In,k as An,D as Xt,M as Vn,l as Zt,n as es,o as ts,p as hs,q as Rn,r as zn,C as pt,s as mt,t as Ft,u as bt,v as Lt,w as Ks,x as Us,y as Ws,z as Dt,A as Ze,E as kt,F as Mn,G as Ke,H as _t,I as Ln,N as xt,P as ss,J as ns,K as is,L as _n,O as Hs,Q as $n,U as Pn,V as Gs,W as Ys,X as Tt,Y as ht,Z as Js,_ as gt,$ as jt,a0 as wt,a1 as vt,a2 as Nt,a3 as tt,a4 as Qs,a5 as Xs,a6 as Zs,a7 as en,a8 as tn,a9 as qn,aa as He,ab as gs,ac as Bn,ad as Kn,ae as ys,af as js,ag as ws,ah as Un,ai as Wn,aj as Hn,ak as et,al as vs,am as Gn,an as Yn,ao as Jn}from"./ui-components-BxvihT61.js";import{S as Re,C as Ie,c as Qn,f as Xn,d as Zn,g as ei,h as sn,i as nn}from"./framework-BM176iet.js";import{a as dt}from"./vendor-ui-utils-3tkeUVaX.js";import{u as ti,a as Ns,K as si,P as ni,b as ii,D as ri,c as li,S as ai,h as oi,d as di,C as ci}from"./vendor-dndkit-CX1oDZqy.js";import{a as rs,C as rn,d as ln,b as ui,L as fi,a1 as pi,z as mi,l as ls,a2 as Cs,a3 as bi,a4 as xi,a5 as hi,y as Ss,a6 as $t,a7 as gi,a8 as yi,a9 as ji,aa as wi,j as It,ab as Pt,ac as vi,c as Fs,g as Ni,X as an,A as Ci,U as Si,h as on,_ as as,n as Fi,ad as At,m as os,i as ki,ae as Oi,af as Di,ag as Ei,ah as Ti,ai as dn,aj as Ii,ak as Ai,al as Vi,am as ks,an as Ri,ao as zi,ap as Gt,E as Mi,aq as qt,ar as Li,q as _i,as as $i,at as Pi,Q as Os,au as qi,G as Bi,av as Ki}from"./vendor-icons-ndICq8DC.js";import{a as st,u as Ui}from"./infrastructure-n1j_TN6w.js";import{u as Wi}from"./plugins-views-CveFN6PV.js";const ct=({label:e,description:n,collapsible:s=!1,collapsed:i=!1,columns:r=1,children:d,className:a,gridClassName:o})=>{const[u,b]=l.useState(i),g={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"},c=()=>{s&&b(!u)};return t.jsxs("div",{className:Z("form-section",a),children:[(e||n)&&t.jsxs("div",{className:Z("flex items-start gap-2 mb-4",s&&"cursor-pointer select-none"),onClick:c,role:s?"button":void 0,"aria-expanded":s?!u:void 0,children:[s&&t.jsx("span",{className:"mt-0.5 text-muted-foreground",children:u?t.jsx(rs,{className:"h-4 w-4"}):t.jsx(rn,{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}),n&&t.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:n})]})]}),!u&&t.jsx("div",{className:Z("grid gap-4",o||g[r]),children:d})]})},Hi=({schema:e,dataSource:n,className:s})=>{const{fieldLabel:i}=st(),[r,d]=l.useState(null),[a,o]=l.useState({}),[u,b]=l.useState(!0),[g,c]=l.useState(null),[x,j]=l.useState(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||"tab-0");$e.useEffect(()=>{(async()=>{if(!n){b(!1);return}try{const h=await n.getObjectSchema(e.objectName);d(h)}catch(h){c(h)}})()},[e.objectName,n]),$e.useEffect(()=>{(r||!n)&&(async()=>{if(e.mode==="create"||!e.recordId||!n){o(e.initialData||e.initialValues||{}),b(!1);return}try{const h=await n.findOne(e.objectName,e.recordId);o(h||{})}catch(h){c(h)}finally{b(!1)}})()},[r,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);const N=l.useCallback(D=>{const h=[];for(const p of D.fields){const v=typeof p=="string"?p:p.name;if(typeof p=="object")h.push(p);else if(r?.fields?.[v]){const T=r.fields[v];h.push({name:v,label:i(e.objectName,v,T.label||v),type:Ye(T.type),required:T.required||!1,disabled:e.readOnly||e.mode==="view"||T.readonly,placeholder:T.placeholder,description:T.help||T.description,validation:Ge(T),field:T,options:T.options,multiple:T.multiple})}else h.push({name:v,label:v,type:"input"})}return h},[r,e.readOnly,e.mode]),f=l.useCallback(async D=>{if(!n)return e.onSuccess&&await e.onSuccess(D),D;try{let h;return e.mode==="create"?h=await n.create(e.objectName,D):e.mode==="edit"&&e.recordId&&(h=await n.update(e.objectName,e.recordId,D)),e.onSuccess&&await e.onSuccess(h),h}catch(h){throw e.onError&&e.onError(h),h}},[e,n]),q=l.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),A=(D,h)=>D.name||D.label||`tab-${h}`;if(g)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:g.message})]});if(u)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 _={type:"form",fields:e.sections.flatMap(D=>N(D)),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:f,onCancel:q},Y=e.tabPosition==="left"||e.tabPosition==="right";return t.jsx("div",{className:Z("w-full",s,e.className),children:t.jsxs(Yt,{value:x,onValueChange:j,orientation:Y?"vertical":"horizontal",className:Z(Y&&"flex gap-4"),children:[t.jsx(Jt,{className:Z(Y?"flex-col h-auto":"",e.tabPosition==="bottom"&&"order-last",e.tabPosition==="right"&&"order-last"),children:e.sections.map((D,h)=>t.jsx(Qt,{value:A(D,h),className:Y?"w-full justify-start":"",children:D.label||`Tab ${h+1}`},A(D,h)))}),t.jsx("div",{className:"flex-1",children:e.sections.map((D,h)=>t.jsx(Fn,{value:A(D,h),className:"mt-0",children:t.jsx(ct,{description:D.description,columns:D.columns||1,children:t.jsx(Re,{schema:{..._,fields:N(D),showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1}})})},A(D,h)))})]})})},Gi=({schema:e,dataSource:n,className:s})=>{const{fieldLabel:i}=st(),[r,d]=l.useState(null),[a,o]=l.useState({}),[u,b]=l.useState(!0),[g,c]=l.useState(null),[x,j]=l.useState(0),[N,f]=l.useState(new Set),[q,A]=l.useState(!1),y=e.sections.length,_=x===0,Y=x===y-1;$e.useEffect(()=>{(async()=>{if(!n){b(!1);return}try{const V=await n.getObjectSchema(e.objectName);d(V)}catch(V){c(V)}})()},[e.objectName,n]),$e.useEffect(()=>{(r||!n)&&(async()=>{if(e.mode==="create"||!e.recordId||!n){o(e.initialData||e.initialValues||{}),b(!1);return}try{const V=await n.findOne(e.objectName,e.recordId);o(V||{})}catch(V){c(V)}finally{b(!1)}})()},[r,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);const D=l.useCallback(W=>{const V=[];for(const I of W.fields){const z=typeof I=="string"?I:I.name;if(typeof I=="object")V.push(I);else if(r?.fields?.[z]){const K=r.fields[z];V.push({name:z,label:i(e.objectName,z,K.label||z),type:Ye(K.type),required:K.required||!1,disabled:e.readOnly||e.mode==="view"||K.readonly,placeholder:K.placeholder,description:K.help||K.description,validation:Ge(K),field:K,options:K.options,multiple:K.multiple})}else V.push({name:z,label:z,type:"input"})}return V},[r,e.readOnly,e.mode]),h=l.useMemo(()=>x>=0&&x<y?D(e.sections[x]):[],[x,y,e.sections,D]),p=l.useCallback(async W=>{const V={...a,...W};if(o(V),f(I=>new Set(I).add(x)),Y){A(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(V),V;let I;return e.mode==="create"?I=await n.create(e.objectName,V):e.mode==="edit"&&e.recordId&&(I=await n.update(e.objectName,e.recordId,V)),e.onSuccess&&await e.onSuccess(I),I}catch(I){throw e.onError&&e.onError(I),I}finally{A(!1)}}else v(x+1)},[a,x,Y,e,n]),v=l.useCallback(W=>{W>=0&&W<y&&(j(W),e.onStepChange&&e.onStepChange(W))},[y,e]),T=l.useCallback(()=>{v(x-1)},[x,v]),B=l.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),U=l.useCallback(W=>{(e.allowSkip||N.has(W)||W<=x)&&v(W)},[e.allowSkip,N,x,v]);if(g)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:g.message})]});if(u)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 O=e.sections[x];return t.jsxs("div",{className:Z("w-full",s,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((W,V)=>{const I=V===x,z=N.has(V),K=e.allowSkip||z||V<=x;return t.jsxs("li",{className:Z("relative flex-1",V!==y-1&&"pr-8 sm:pr-12"),children:[V!==y-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:Z("h-full",z?"bg-primary":"bg-muted")})}),t.jsxs("button",{type:"button",className:Z("group relative flex items-center",K?"cursor-pointer":"cursor-not-allowed"),onClick:()=>U(V),disabled:!K,children:[t.jsx("span",{className:Z("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",z&&"bg-primary text-primary-foreground",I&&!z&&"border-2 border-primary bg-background text-primary",!I&&!z&&"border-2 border-muted bg-background text-muted-foreground"),children:z?t.jsx(ln,{className:"h-3 w-3 sm:h-4 sm:w-4"}):V+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:Z(I?"text-foreground":"text-muted-foreground"),children:W.label||`Step ${V+1}`})})]})]},V)})})}),t.jsx("div",{className:"min-h-[200px]",children:O&&t.jsx(ct,{label:O.label,description:O.description,columns:O.columns||1,children:h.length>0?t.jsx(Re,{schema:{type:"form",fields:h,layout:"vertical",defaultValues:a,showSubmit:!1,showCancel:!1,onSubmit:p}}):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(ne,{variant:"ghost",onClick:B,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 ",x+1," of ",y]}),!_&&t.jsxs(ne,{variant:"outline",onClick:T,children:[t.jsx(ui,{className:"h-4 w-4 mr-1"}),e.prevText||"Back"]}),Y?t.jsx(ne,{onClick:()=>p(a),disabled:q||e.mode==="view",children:q?"Submitting...":e.submitText||(e.mode==="create"?"Create":"Update")}):t.jsxs(ne,{onClick:()=>p(a),children:[e.nextText||"Next",t.jsx(rs,{className:"h-4 w-4 ml-1"})]})]})]})]})},Yi=({schema:e,dataSource:n,className:s})=>{const{fieldLabel:i}=st(),[r,d]=l.useState(null),[a,o]=l.useState({}),[u,b]=l.useState(!0),[g,c]=l.useState(null);l.useEffect(()=>{(async()=>{if(!n){b(!1);return}try{const h=await n.getObjectSchema(e.objectName);d(h)}catch(h){c(h),b(!1)}})()},[e.objectName,n]),l.useEffect(()=>{(r||!n)&&(async()=>{if(e.mode==="create"||!e.recordId){o(e.initialData||e.initialValues||{}),b(!1);return}if(!n){o(e.initialData||e.initialValues||{}),b(!1);return}try{const h=await n.findOne(e.objectName,e.recordId);o(h||{})}catch(h){c(h)}finally{b(!1)}})()},[r,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);const x=l.useCallback(D=>{const h=[];for(const p of D.fields){const v=typeof p=="string"?p:p.name;if(typeof p=="object")h.push(p);else if(r?.fields?.[v]){const T=r.fields[v];h.push({name:v,label:i(e.objectName,v,T.label||v),type:Ye(T.type),required:T.required||!1,disabled:e.readOnly||e.mode==="view"||T.readonly,placeholder:T.placeholder,description:T.help||T.description,validation:Ge(T),field:T,options:T.options,multiple:T.multiple})}else h.push({name:v,label:v,type:"input"})}return h},[r,e.readOnly,e.mode]),j=l.useCallback(async D=>{if(!n)return e.onSuccess&&await e.onSuccess(D),D;try{let h;return e.mode==="create"?h=await n.create(e.objectName,D):e.mode==="edit"&&e.recordId&&(h=await n.update(e.objectName,e.recordId,D)),e.onSuccess&&await e.onSuccess(h),h}catch(h){throw e.onError&&e.onError(h),h}},[e,n]),N=l.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),f=l.useMemo(()=>e.sections.slice(0,1),[e.sections]),q=l.useMemo(()=>e.sections.slice(1),[e.sections]);l.useMemo(()=>e.sections.flatMap(D=>x(D)),[e.sections,x]);const A=e.splitDirection||"horizontal",y=e.splitSize||50;if(g)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:g.message})]});if(u)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 _={type:"form",layout:"vertical",defaultValues:a,onSubmit:j,onCancel:N},Y=(D,h)=>t.jsx("div",{className:"space-y-4 p-4",children:D.map((p,v)=>t.jsx(ct,{label:p.label,description:p.description,columns:p.columns||1,children:t.jsx(Re,{schema:{..._,fields:x(p),showSubmit:h&&e.showSubmit!==!1&&e.mode!=="view",showCancel:h&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText}})},p.name||p.label||v))});return t.jsx("div",{className:Z("w-full",s,e.className),children:t.jsxs(kn,{orientation:A,className:"min-h-[300px] rounded-lg border",children:[t.jsx(xs,{defaultSize:y,minSize:20,children:Y(f,q.length===0)}),q.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(On,{withHandle:e.splitResizable!==!1}),t.jsx(xs,{defaultSize:100-y,minSize:20,children:Y(q,!0)})]})]})})},Ji=new Set(["field:textarea","field:markdown","field:html","field:grid","field:rich-text","textarea","markdown","html","grid","rich-text"]),Qi=new Set(["formula","summary","auto_number","autonumber"]);function Xi(e){return Ji.has(e)}function Zi(e){return Qi.has(e)}function er(e){return e<=3?1:2}function Ds(e,n){return n<=1?e:e.map(s=>s.colSpan!==void 0?s:s.type&&Xi(s.type)?{...s,colSpan:n}:s)}function tr(e,n){return n?.fields?e.filter(s=>{const i=n.fields[s.name];return i?!Zi(i.type):!0}):e}function Es(e){return e<=1?"default":e===2?"lg":e===3?"xl":"full"}function Vt(e,n,s,i){let r=[...e];if(i==="create"&&(r=tr(r,n)),s!==void 0)return r=Ds(r,s),{fields:r,columns:s};const d=er(r.length);return r=Ds(r,d),{fields:r,columns:d}}const Ts={1:void 0,2:"grid gap-4 grid-cols-1 @md:grid-cols-2",3:"grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3",4:"grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4"},sr=({schema:e,dataSource:n,className:s})=>{const{fieldLabel:i}=st(),[r,d]=l.useState(null),[a,o]=l.useState([]),[u,b]=l.useState({}),[g,c]=l.useState(!0),[x,j]=l.useState(null),N=e.open!==!1,f=e.drawerSide||"right";l.useEffect(()=>{(async()=>{if(!n){c(!1);return}try{const v=await n.getObjectSchema(e.objectName);d(v)}catch(v){j(v),c(!1)}})()},[e.objectName,n]),l.useEffect(()=>{(r||!n)&&(async()=>{if(e.mode==="create"||!e.recordId){b(e.initialData||e.initialValues||{}),c(!1);return}if(!n){b(e.initialData||e.initialValues||{}),c(!1);return}try{const v=await n.findOne(e.objectName,e.recordId);b(v||{})}catch(v){j(v)}finally{c(!1)}})()},[r,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);const q=l.useCallback(p=>{const v=[];for(const T of p.fields){const B=typeof T=="string"?T:T.name;if(typeof T=="object")v.push(T);else if(r?.fields?.[B]){const U=r.fields[B];v.push({name:B,label:i(e.objectName,B,U.label||B),type:Ye(U.type),required:U.required||!1,disabled:e.readOnly||e.mode==="view"||U.readonly,placeholder:U.placeholder,description:U.help||U.description,validation:Ge(U),field:U,options:U.options,multiple:U.multiple})}else v.push({name:B,label:B,type:"input"})}return v},[r,e.readOnly,e.mode]);l.useEffect(()=>{if(!r&&n)return;if(e.customFields?.length){o(e.customFields),c(!1);return}if(e.sections?.length){c(!1);return}if(!r)return;const p=e.fields||Object.keys(r.fields||{}),v=[];for(const T of p){const B=typeof T=="string"?T:T.name;if(!B)continue;const U=r.fields?.[B];U&&v.push({name:B,label:i(e.objectName,B,U.label||B),type:Ye(U.type),required:U.required||!1,disabled:e.readOnly||e.mode==="view"||U.readonly,placeholder:U.placeholder,description:U.help||U.description,validation:Ge(U),field:U,options:U.options,multiple:U.multiple})}o(v),c(!1)},[r,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);const A=l.useCallback(async p=>{if(!n)return e.onSuccess&&await e.onSuccess(p),e.onOpenChange?.(!1),p;try{let v;return e.mode==="create"?v=await n.create(e.objectName,p):e.mode==="edit"&&e.recordId&&(v=await n.update(e.objectName,e.recordId,p)),e.onSuccess&&await e.onSuccess(v),e.onOpenChange?.(!1),v}catch(v){throw e.onError&&e.onError(v),v}},[e,n]),y=l.useCallback(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),_=l.useMemo(()=>e.drawerWidth?f==="left"||f==="right"?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}:void 0,[e.drawerWidth,f]),D={type:"form",layout:e.layout==="vertical"||e.layout==="horizontal"?e.layout:"vertical",defaultValues:u,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1,onSubmit:A,onCancel:y},h=()=>{if(x)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:x.message})]});if(g)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..."})]});if(e.sections?.length)return t.jsx("div",{className:"space-y-6",children:e.sections.map((T,B)=>{const U=T.columns||1;return t.jsx(ct,{label:T.label,description:T.description,columns:U,gridClassName:Ts[U],children:t.jsx(Re,{schema:{...D,fields:q(T),showSubmit:B===e.sections.length-1&&D.showSubmit,showCancel:B===e.sections.length-1&&D.showCancel}})},T.name||T.label||B)})});const p=Vt(a,r,e.columns,e.mode),v=Ts[p.columns||1];return t.jsx(Re,{schema:{...D,fields:p.fields,columns:p.columns,...v?{fieldContainerClass:v}:{}}})};return t.jsx(Dn,{open:N,onOpenChange:e.onOpenChange,children:t.jsxs(En,{side:f,className:Z("overflow-y-auto",s,e.className),style:_,children:[(e.title||e.description)&&t.jsxs(Tn,{children:[e.title&&t.jsx(In,{children:e.title}),e.description&&t.jsx(An,{children:e.description})]}),t.jsx("div",{className:"@container py-4",children:h()})]})})},Is={sm:"max-w-sm",default:"max-w-lg",lg:"max-w-2xl",xl:"max-w-4xl",full:"max-w-[95vw] w-full"},As={1:void 0,2:"grid gap-4 grid-cols-1 @md:grid-cols-2",3:"grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3",4:"grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4"},nr=({schema:e,dataSource:n,className:s})=>{const{fieldLabel:i}=st(),[r,d]=l.useState(null),[a,o]=l.useState([]),[u,b]=l.useState({}),[g,c]=l.useState(!0),[x,j]=l.useState(null),[N,f]=l.useState(!1),q=e.open!==!1,A=l.useId(),y=l.useMemo(()=>e.sections?.length||e.customFields?.length?null:Vt(a,r,e.columns,e.mode),[a,r,e.columns,e.mode,e.sections,e.customFields]),_=l.useMemo(()=>{if(e.modalSize)return e.modalSize;if(y?.columns&&y.columns>1)return Es(y.columns);if(e.sections?.length){const z=Math.max(...e.sections.map(K=>Number(K.columns)||1));if(z>1)return Es(z)}return"default"},[e.modalSize,y,e.sections]),Y=Is[_]||Is.default;l.useEffect(()=>{(async()=>{if(!n){c(!1);return}try{const K=await n.getObjectSchema(e.objectName);d(K)}catch(K){j(K),c(!1)}})()},[e.objectName,n]),l.useEffect(()=>{(r||!n)&&(async()=>{if(e.mode==="create"||!e.recordId){b(e.initialData||e.initialValues||{}),c(!1);return}if(!n){b(e.initialData||e.initialValues||{}),c(!1);return}try{const K=await n.findOne(e.objectName,e.recordId);b(K||{})}catch(K){j(K)}finally{c(!1)}})()},[r,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);const D=l.useCallback(z=>{const K=[];for(const H of z.fields){const se=typeof H=="string"?H:H.name;if(typeof H=="object")K.push(H);else if(r?.fields?.[se]){const ee=r.fields[se];K.push({name:se,label:i(e.objectName,se,ee.label||se),type:Ye(ee.type),required:ee.required||!1,disabled:e.readOnly||e.mode==="view"||ee.readonly,placeholder:ee.placeholder,description:ee.help||ee.description,validation:Ge(ee),field:ee,options:ee.options,multiple:ee.multiple})}else K.push({name:se,label:se,type:"input"})}return K},[r,e.readOnly,e.mode]);l.useEffect(()=>{if(!r&&n)return;if(e.customFields?.length){o(e.customFields),c(!1);return}if(e.sections?.length){c(!1);return}if(!r)return;const z=e.fields||Object.keys(r.fields||{}),K=[];for(const H of z){const se=typeof H=="string"?H:H.name;if(!se)continue;const ee=r.fields?.[se];ee&&K.push({name:se,label:i(e.objectName,se,ee.label||se),type:Ye(ee.type),required:ee.required||!1,disabled:e.readOnly||e.mode==="view"||ee.readonly,placeholder:ee.placeholder,description:ee.help||ee.description,validation:Ge(ee),field:ee,options:ee.options,multiple:ee.multiple})}o(K),c(!1)},[r,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);const h=l.useCallback(async z=>{f(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(z),e.onOpenChange?.(!1),z;let K;return e.mode==="create"?K=await n.create(e.objectName,z):e.mode==="edit"&&e.recordId&&(K=await n.update(e.objectName,e.recordId,z)),e.onSuccess&&await e.onSuccess(K),e.onOpenChange?.(!1),K}catch(K){throw e.onError&&e.onError(K),K}finally{f(!1)}},[e,n]),p=l.useCallback(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),v=e.layout==="vertical"||e.layout==="horizontal"?e.layout:"vertical",T=e.showSubmit!==!1&&e.mode!=="view",B=e.showCancel!==!1,U=e.submitText||(e.mode==="create"?"Create":"Update"),O=e.cancelText||"Cancel",W={type:"form",layout:v,defaultValues:u,submitLabel:U,cancelLabel:O,showSubmit:T,showCancel:B,onSubmit:h,onCancel:p,showActions:!1,id:A},V=()=>{if(x)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:x.message})]});if(g)return t.jsx("div",{className:"space-y-4","data-testid":"modal-form-skeleton",children:[1,2,3].map(H=>t.jsxs("div",{className:"space-y-2",children:[t.jsx(hs,{className:"h-4 w-24"}),t.jsx(hs,{className:"h-10 w-full"})]},H))});if(e.sections?.length)return t.jsx("div",{className:"space-y-6",children:e.sections.map((H,se)=>{const ee=H.columns||1;return t.jsx(ct,{label:H.label,description:H.description,columns:ee,gridClassName:As[ee],children:t.jsx(Re,{schema:{...W,fields:D(H)}})},H.name||H.label||se)})});const z=y??Vt(a,r,e.columns,e.mode),K=As[z.columns||1];return t.jsx(Re,{schema:{...W,fields:z.fields,columns:z.columns,...K?{fieldContainerClass:K}:{}}})},I=!g&&!x&&(T||B);return t.jsx(Xt,{open:q,onOpenChange:e.onOpenChange,children:t.jsxs(Vn,{className:Z(Y,"flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0",s,e.className),children:[(e.title||e.description)&&t.jsxs(Zt,{className:"shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b",children:[e.title&&t.jsx(es,{children:e.title}),e.description&&t.jsx(ts,{children:e.description})]}),t.jsx("div",{className:"@container flex-1 overflow-y-auto px-4 sm:px-6 py-4",children:V()}),I&&t.jsx("div",{className:"shrink-0 border-t px-4 sm:px-6 py-3 bg-background","data-testid":"modal-form-footer",children:t.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 sm:justify-end",children:[B&&t.jsx(ne,{type:"button",variant:"outline",onClick:p,disabled:N,className:"w-full sm:w-auto",children:O}),T&&t.jsxs(ne,{type:"submit",form:A,disabled:N,className:"w-full sm:w-auto",children:[N&&t.jsx(fi,{className:"mr-2 h-4 w-4 animate-spin"}),U]})]})})]})})},yt=({schema:e,dataSource:n})=>{if(e.formType==="tabbed"&&e.sections?.length)return t.jsx(Hi,{schema:{...e,formType:"tabbed",sections:e.sections.map(s=>({name:s.name,label:s.label,description:s.description,columns:s.columns,fields:s.fields})),defaultTab:e.defaultTab,tabPosition:e.tabPosition},dataSource:n,className:e.className});if(e.formType==="wizard"&&e.sections?.length)return t.jsx(Gi,{schema:{...e,formType:"wizard",sections:e.sections.map(s=>({name:s.name,label:s.label,description:s.description,columns:s.columns,fields:s.fields})),allowSkip:e.allowSkip,showStepIndicator:e.showStepIndicator,nextText:e.nextText,prevText:e.prevText,onStepChange:e.onStepChange},dataSource:n,className:e.className});if(e.formType==="split"&&e.sections?.length)return t.jsx(Yi,{schema:{...e,formType:"split",sections:e.sections.map(s=>({name:s.name,label:s.label,description:s.description,columns:s.columns,fields:s.fields})),splitDirection:e.splitDirection,splitSize:e.splitSize,splitResizable:e.splitResizable},dataSource:n,className:e.className});if(e.formType==="drawer"){const{layout:s,...i}=e,r=e.layout==="vertical"||e.layout==="horizontal"?e.layout:void 0;return t.jsx(sr,{schema:{...i,layout:r,formType:"drawer",sections:e.sections?.map(d=>({name:d.name,label:d.label,description:d.description,columns:d.columns,fields:d.fields})),open:e.open,onOpenChange:e.onOpenChange,drawerSide:e.drawerSide,drawerWidth:e.drawerWidth},dataSource:n,className:e.className})}if(e.formType==="modal"){const{layout:s,...i}=e,r=e.layout==="vertical"||e.layout==="horizontal"?e.layout:void 0;return t.jsx(nr,{schema:{...i,layout:r,formType:"modal",sections:e.sections?.map(d=>({name:d.name,label:d.label,description:d.description,columns:d.columns,fields:d.fields})),open:e.open,onOpenChange:e.onOpenChange,modalSize:e.modalSize,modalCloseButton:e.modalCloseButton},dataSource:n,className:e.className})}return t.jsx(ir,{schema:e,dataSource:n})},ir=({schema:e,dataSource:n})=>{const{fieldLabel:s}=st(),[i,r]=l.useState(null),[d,a]=l.useState([]),[o,u]=l.useState(null),[b,g]=l.useState(!0),[c,x]=l.useState(null),j=e.customFields&&e.customFields.length>0;l.useEffect(()=>{j&&(u(e.initialData||e.initialValues||{}),g(!1))},[j,e.initialData,e.initialValues]),l.useEffect(()=>{const h=async()=>{try{if(!n)throw new Error("DataSource is required when using ObjectQL schema fetching (inline fields not provided)");const p=await n.getObjectSchema(e.objectName);if(!p)throw new Error(`No schema found for object "${e.objectName}"`);r(p)}catch(p){x(p),g(!1)}};j?r({name:e.objectName,fields:{}}):e.objectName&&n?h():j||g(!1)},[e.objectName,n,j]),l.useEffect(()=>{i&&!j&&(async()=>{if(!e.recordId||e.mode==="create"){u(e.initialData||e.initialValues||{}),g(!1);return}if(!j){if(!n){x(new Error("DataSource is required for fetching record data (inline data not provided)")),g(!1);return}g(!0);try{const p=await n.findOne(e.objectName,e.recordId);u(p)}catch(p){console.error("Failed to fetch record:",p),x(p)}finally{g(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,n,i,j]),l.useEffect(()=>{if(j&&e.customFields){a(e.customFields),g(!1);return}if(!i)return;const h=[],p=e.fields||Object.keys(i.fields||{});(Array.isArray(p)?p:Object.keys(p)).forEach(B=>{const U=typeof B=="string"?B:B.name;if(!U)return;const O=i.fields?.[U];if(!O&&!j)return;const W=!O?.permissions||O?.permissions.write!==!1;if(e.mode!=="view"&&!W)return;const V=e.customFields?.find(I=>I.name===U);if(V)h.push(V);else if(O){const I={name:U,label:s(e.objectName,U,O.label||B),type:Ye(O.type),required:O.required||!1,disabled:e.readOnly||e.mode==="view"||O.readonly,placeholder:O.placeholder,description:O.help||O.description,validation:Ge(O),field:O};if((O.type==="select"||O.type==="lookup"||O.type==="master_detail")&&(I.options=O.options||[],I.multiple=O.multiple),(O.type==="number"||O.type==="currency"||O.type==="percent")&&(I.inputType="number",I.min=O.min,I.max=O.max,I.step=O.precision?Math.pow(10,-O.precision):void 0),O.type==="date"&&(I.inputType="date"),O.type==="datetime"&&(I.inputType="datetime-local"),(O.type==="text"||O.type==="textarea"||O.type==="markdown"||O.type==="html")&&(I.maxLength=O.max_length,I.minLength=O.min_length),(O.type==="file"||O.type==="image")&&(I.inputType="file",I.multiple=O.multiple,I.accept=O.accept?O.accept.join(","):void 0,O.max_size)){const z=`Max size: ${Rn(O.max_size)}`;I.description=I.description?`${I.description} (${z})`:z}O.type==="email"&&(I.inputType="email"),O.type==="phone"&&(I.inputType="tel"),O.type==="url"&&(I.inputType="url"),O.type==="password"&&(I.inputType="password"),O.type==="time"&&(I.inputType="time"),(O.type==="formula"||O.type==="summary"||O.type==="auto_number")&&(I.disabled=!0),O.visible_on&&(I.visible=z=>zn(O.visible_on,z)),h.push(I)}}),a(h),!j&&e.recordId&&e.mode!=="create"&&n||g(!1)},[i,e.fields,e.customFields,e.readOnly,e.mode,j,e.recordId,n]);const N=l.useCallback(async(h,p)=>{if(h&&(h.nativeEvent||h._reactName==="onSubmit")&&(console.warn("ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue."),p===void 0&&(p=h,h={})),j&&!n)return e.onSuccess&&await e.onSuccess(h),h;if(!n)throw new Error("DataSource is required for form submission (inline mode not configured)");try{let v;if(e.mode==="create")v=await n.create(e.objectName,h);else if(e.mode==="edit"&&e.recordId)v=await n.update(e.objectName,e.recordId,h);else throw new Error("Invalid form mode or missing record ID");return e.onSuccess&&await e.onSuccess(v),v}catch(v){throw console.error("Failed to submit form:",v),e.onError&&e.onError(v),v}},[e,n,j]),f=l.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),A={...$e.useMemo(()=>{if(!i?.fields)return{};const h={};return Object.keys(i.fields).forEach(p=>{const v=i.fields[p];v.defaultValue!==void 0&&(h[p]=v.defaultValue)}),h},[i]),...o};if(c)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:c.message})]});if(b)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 y=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((h,p)=>{const v=h.fields.map(B=>typeof B=="string"?B:B.name),T=d.filter(B=>v.includes(B.name));return t.jsx(ct,{label:h.label,description:h.description,collapsible:h.collapsible,collapsed:h.collapsed,columns:h.columns,children:t.jsx(Re,{schema:{type:"form",fields:T,layout:y,defaultValues:A,showSubmit:p===e.sections.length-1&&e.showSubmit!==!1&&e.mode!=="view",showCancel:p===e.sections.length-1&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,onSubmit:N,onCancel:f}})},h.name||h.label||p)})});const Y=e.sections?.length?{fields:d,columns:e.columns}:Vt(d,i,e.columns,e.mode),D={type:"form",fields:Y.fields,layout:y,columns:Y.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:A,onSubmit:N,onCancel:f,className:e.className};return t.jsx("div",{className:"w-full",children:t.jsx(Re,{schema:D})})},rr=({config:e,dataSource:n,prefillParams:s,className:i})=>{const[r,d]=l.useState(!1),[a,o]=l.useState(!1),[u,b]=l.useState(null),g=l.useMemo(()=>{const N={};if(s)for(const[f,q]of Object.entries(s))N[f]=q;return typeof window<"u"&&new URLSearchParams(window.location.search).forEach((q,A)=>{A in N||(N[A]=q)}),Object.keys(N).length>0?N:void 0},[s]),c=l.useCallback(async N=>{o(!0),b(null);try{if(n&&await n.create(e.objectName,N),d(!0),e.thankYouPage?.redirectUrl){const f=e.thankYouPage.redirectDelay??3e3;setTimeout(()=>{window.location.href=e.thankYouPage.redirectUrl},f)}}catch(f){b(f instanceof Error?f.message:"Failed to submit form. Please try again.")}finally{o(!1)}},[n,e]),x=l.useCallback(()=>{d(!1),b(null)},[]),j=l.useMemo(()=>{const N={};return e.branding?.backgroundColor&&(N.backgroundColor=e.branding.backgroundColor),N},[e.branding]);if(r){const N=e.thankYouPage;return t.jsx("div",{className:`min-h-screen flex items-center justify-center p-4 ${i||""}`,style:j,children:t.jsxs("div",{className:"max-w-md w-full bg-card rounded-lg shadow-lg p-8 text-center space-y-4",children:[t.jsx("div",{className:"text-4xl",children:"✓"}),t.jsx("h2",{className:"text-xl font-semibold text-foreground",children:N?.title||"Thank You!"}),t.jsx("p",{className:"text-muted-foreground",children:N?.message||"Your submission has been received successfully."}),e.allowMultiple&&t.jsx("button",{onClick:x,className:"mt-4 px-4 py-2 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors",children:"Submit Another Response"}),N?.redirectUrl&&t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Redirecting in ",Math.ceil((N.redirectDelay??3e3)/1e3)," seconds..."]})]})})}return t.jsx("div",{className:`min-h-screen flex items-center justify-center p-4 ${i||""}`,style:j,children:t.jsxs("div",{className:"max-w-2xl w-full bg-card rounded-lg shadow-lg overflow-hidden",children:[t.jsxs("div",{className:"p-6 border-b",style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&t.jsx("img",{src:e.branding.logo,alt:"Logo",className:"h-8 mb-4"}),e.title&&t.jsx("h1",{className:"text-xl font-semibold text-foreground",children:e.title}),e.description&&t.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:e.description})]}),t.jsxs("div",{className:"p-6",children:[u&&t.jsx("div",{className:"mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive",children:u}),t.jsx(yt,{schema:{type:"object-form",objectName:e.objectName,mode:"create",fields:e.fields,customFields:e.customFields,initialData:g,onSuccess:c,submitLabel:a?"Submitting...":"Submit"},dataSource:n})]}),t.jsx("div",{className:"px-6 py-3 border-t bg-muted/20 text-center",children:t.jsx("p",{className:"text-xs text-muted-foreground",children:"Powered by ObjectStack"})})]})})};function lr(e){return e<60?`${Math.round(e)}s`:e<3600?`${Math.floor(e/60)}m ${Math.round(e%60)}s`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}const ar=({formId:e,formTitle:n,metrics:s,className:i})=>{const r=l.useMemo(()=>{if(!s.abandonedSubmissions)return 100;const a=s.totalSubmissions+s.abandonedSubmissions;return a===0?0:Math.round(s.totalSubmissions/a*100)},[s.totalSubmissions,s.abandonedSubmissions]),d=l.useMemo(()=>s.dailySubmissions?.length?Math.max(...s.dailySubmissions.map(a=>a.count),1):1,[s.dailySubmissions]);return t.jsxs("div",{className:`space-y-4 ${i||""}`,children:[t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-foreground",children:n||"Form Analytics"}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Form ID: ",e]})]}),t.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[t.jsx(pt,{children:t.jsxs(mt,{className:"pb-2",children:[t.jsx(Ft,{children:"Total Submissions"}),t.jsx(bt,{className:"text-2xl",children:s.totalSubmissions.toLocaleString()})]})}),t.jsxs(pt,{children:[t.jsxs(mt,{className:"pb-2",children:[t.jsx(Ft,{children:"Fill Rate"}),t.jsxs(bt,{className:"text-2xl",children:[r,"%"]})]}),t.jsx(Lt,{children:t.jsx("div",{className:"w-full bg-muted rounded-full h-2",children:t.jsx("div",{className:"bg-primary rounded-full h-2 transition-all",style:{width:`${r}%`}})})})]}),t.jsx(pt,{children:t.jsxs(mt,{className:"pb-2",children:[t.jsx(Ft,{children:"Avg. Completion Time"}),t.jsx(bt,{className:"text-2xl",children:s.avgCompletionTime?lr(s.avgCompletionTime):"—"})]})})]}),s.dailySubmissions&&s.dailySubmissions.length>0&&t.jsxs(pt,{children:[t.jsx(mt,{children:t.jsx(bt,{className:"text-sm font-medium",children:"Daily Submissions"})}),t.jsx(Lt,{children:t.jsx("div",{className:"flex items-end gap-1 h-32",children:s.dailySubmissions.map((a,o)=>t.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1",children:[t.jsx("div",{className:"w-full bg-primary/80 rounded-t transition-all hover:bg-primary",style:{height:`${a.count/d*100}%`,minHeight:a.count>0?"4px":"0"},title:`${a.date}: ${a.count} submissions`}),t.jsx("span",{className:"text-[10px] text-muted-foreground truncate w-full text-center",children:a.date.slice(-5)})]},o))})})]}),s.fieldDropOff&&s.fieldDropOff.length>0&&t.jsxs(pt,{children:[t.jsxs(mt,{children:[t.jsx(bt,{className:"text-sm font-medium",children:"Field Completion Rates"}),t.jsx(Ft,{children:"Percentage of users who completed each field"})]}),t.jsx(Lt,{children:t.jsx("div",{className:"space-y-3",children:s.fieldDropOff.map((a,o)=>t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex justify-between text-sm",children:[t.jsx("span",{className:"text-foreground",children:a.label}),t.jsxs("span",{className:"text-muted-foreground",children:[a.completionRate,"%"]})]}),t.jsx("div",{className:"w-full bg-muted rounded-full h-1.5",children:t.jsx("div",{className:`rounded-full h-1.5 transition-all ${a.completionRate>=80?"bg-green-500":a.completionRate>=50?"bg-yellow-500":"bg-destructive"}`,style:{width:`${a.completionRate}%`}})})]},o))})})]})]})},cn=({schema:e})=>t.jsx(yt,{schema:e});Ie.register("object-form",cn,{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"]}]});Ie.register("form",cn,{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 or=({schema:e})=>t.jsx(rr,{config:e});Ie.register("embeddable-form",or,{namespace:"plugin-form",label:"Embeddable Form",category:"plugin",inputs:[{name:"formId",type:"string",label:"Form ID",required:!0},{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"title",type:"string",label:"Form Title"},{name:"description",type:"string",label:"Description"},{name:"fields",type:"array",label:"Fields"},{name:"allowMultiple",type:"boolean",label:"Allow Multiple Submissions"}]});const dr=({schema:e})=>t.jsx(ar,{formId:e.formId,formTitle:e.formTitle,metrics:e.metrics||{totalSubmissions:0}});Ie.register("form-analytics",dr,{namespace:"plugin-form",label:"Form Analytics",category:"plugin",inputs:[{name:"formId",type:"string",label:"Form ID",required:!0},{name:"formTitle",type:"string",label:"Form Title"},{name:"metrics",type:"object",label:"Submission Metrics"}]});const cr={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 ur(e){if(e.startsWith("bg-"))return e;const n=e.toLowerCase().trim();return cr[n]}function fr(e){return l.useCallback(n=>{if(!e?.field||!e.colors)return;const s=String(n[e.field]??""),i=e.colors[s];if(i)return ur(i)},[e?.field,e?.colors])}function pr(e,n){return n.map(s=>String(e[s.field]??"")).join(" / ")}function mr(e,n){return n.map(s=>{const i=e[s.field];return i!=null&&i!==""?String(i):"(empty)"}).join(" / ")}function br(e,n,s){const i=e.localeCompare(n,void 0,{numeric:!0,sensitivity:"base"});return s==="desc"?-i:i}function xr(e,n,s){const i=e?.fields,r=!!(i&&i.length>0),[d,a]=l.useState({}),o=l.useMemo(()=>i?i.some(g=>g.collapsed):!1,[i]),u=l.useMemo(()=>{if(!r||!i)return[];const g=new Map,c=[];for(const j of n){const N=pr(j,i);g.has(N)||(g.set(N,{label:mr(j,i),rows:[]}),c.push(N)),g.get(N).rows.push(j)}const x=i[0]?.order??"asc";return c.sort((j,N)=>br(j,N,x)),c.map(j=>{const N=g.get(j),f=j in d?d[j]:o,q=[];return{key:j,label:N.label,rows:N.rows,collapsed:f,aggregations:q}})},[n,i,r,d,o,s]),b=l.useCallback(g=>{a(c=>({...c,[g]:c[g]!==void 0?!c[g]:!o}))},[o]);return{groups:u,isGrouped:r,toggleGroup:b}}const hr=({groupKey:e,label:n,count:s,collapsed:i,aggregations:r,onToggle:d,children:a})=>t.jsxs("div",{className:"border rounded-md","data-testid":`group-row-${e}`,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:()=>d(e),"aria-expanded":!i,children:[i?t.jsx(rs,{className:"h-4 w-4 shrink-0"}):t.jsx(rn,{className:"h-4 w-4 shrink-0"}),t.jsx("span",{className:"group-label",children:n}),r&&r.length>0&&t.jsx("span",{className:"ml-2 text-xs text-muted-foreground group-aggregations",children:r.map(o=>t.jsxs("span",{className:"mr-2",children:[o.type,": ",Number.isInteger(o.value)?o.value:o.value.toFixed(2)]},`${o.field}-${o.type}`))}),t.jsxs("span",{className:"ml-auto text-xs text-muted-foreground group-count",children:["(",s,")"]})]}),!i&&a]});function gr(e){return typeof e=="string"?{type:e}:e}function yr(e,n){if(n.length===0)return null;switch(e){case"count":return n.length;case"sum":return n.reduce((s,i)=>s+i,0);case"avg":return n.reduce((s,i)=>s+i,0)/n.length;case"min":return Math.min(...n);case"max":return Math.max(...n);default:return null}}function jr(e,n){if(n===null)return"";const i={count:"Count",sum:"Sum",avg:"Avg",min:"Min",max:"Max"}[e]||e,r=e==="avg"?n.toLocaleString(void 0,{maximumFractionDigits:2}):n.toLocaleString();return`${i}: ${r}`}function wr(e,n){return l.useMemo(()=>{const s=new Map;if(!e||e.length===0||n.length===0)return{summaries:s,hasSummary:!1};for(const i of e){if(!i.summary)continue;const r=gr(i.summary),d=r.field||i.field,a=[];for(const u of n){const b=u[d];if(b!=null&&typeof b=="number"&&!isNaN(b))a.push(b);else if(b!=null&&typeof b=="string"){const g=parseFloat(b);isNaN(g)||a.push(g)}}let o;if(r.type==="count"){const u=n.filter(b=>b[d]!=null&&b[d]!=="").length;o=u>0?u:null}else o=yr(r.type,a);s.set(i.field,{field:i.field,value:o,label:jr(r.type,o)})}return{summaries:s,hasSummary:s.size>0}},[e,n])}function ds(e){return e.replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}const vr=({row:e,rowActions:n,canEdit:s,canDelete:i,onEdit:r,onDelete:d,onAction:a})=>t.jsxs(Ks,{children:[t.jsx(Us,{asChild:!0,children:t.jsxs(ne,{variant:"ghost",size:"icon",className:"h-8 w-8 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0","data-testid":"row-action-trigger",children:[t.jsx(pi,{className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:"Open menu"})]})}),t.jsxs(Ws,{align:"end",children:[s&&r&&t.jsxs(Dt,{onClick:()=>r(e),children:[t.jsx(mi,{className:"mr-2 h-4 w-4"}),"Edit"]}),i&&d&&t.jsxs(Dt,{onClick:()=>d(e),children:[t.jsx(ls,{className:"mr-2 h-4 w-4"}),"Delete"]}),n?.map(o=>t.jsx(Dt,{onClick:()=>a?.(o,e),"data-testid":`row-action-${o}`,children:ds(o)},o))]})]}),Vs=({selectedRows:e,actions:n,onAction:s,onClearSelection:i})=>!n||n.length===0||e.length===0?null:t.jsxs("div",{className:"border-t px-4 py-1.5 flex items-center gap-2 text-xs bg-primary/5 shrink-0","data-testid":"bulk-actions-bar",children:[t.jsxs("span",{className:"text-muted-foreground font-medium",children:[e.length," selected"]}),t.jsx("div",{className:"flex items-center gap-1 ml-2",children:n.map(r=>t.jsx(ne,{variant:"outline",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>s?.(r,e),"data-testid":`bulk-action-${r}`,children:ds(r)},r))}),t.jsx(ne,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs ml-auto",onClick:i,children:"Clear"})]}),Rs={"grid.actions":"Actions","grid.edit":"Edit","grid.delete":"Delete","grid.export":"Export","grid.exportAs":"Export as {{format}}","grid.loading":"Loading grid...","grid.errorLoading":"Error loading grid","grid.pullToRefresh":"Pull to refresh","grid.refreshing":"Refreshing…","grid.openRecord":"Open record"};function Nr(){try{const e=Ui();return e.t("grid.actions")==="grid.actions"?{t:(s,i)=>{let r=Rs[s]||s;if(i)for(const[d,a]of Object.entries(i))r=r.replace(`{{${d}}}`,String(a));return r}}:{t:e.t}}catch{return{t:(e,n)=>{let s=Rs[e]||e;if(n)for(const[i,r]of Object.entries(n))s=s.replace(`{{${i}}}`,String(r));return s}}}}function Cr(e){if(e!=null)return typeof e=="string"?e:e.defaultValue||e.key}function Sr(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 Bt(e){if(!(!e||e.length===0))return typeof e[0]=="object"&&e[0]!==null,e}const un=({schema:e,dataSource:n,onEdit:s,onDelete:i,onRowSelect:r,onRowClick:d,onCellChange:a,onRowSave:o,onBatchSave:u,onAddRecord:b,...g})=>{const[c,x]=l.useState([]),[j,N]=l.useState(!0),[f,q]=l.useState(null),{t:A}=Nr(),{fieldLabel:y}=st(),[_,Y]=l.useState(null),[D,h]=l.useState(!1),[p,v]=l.useState(0),[T,B]=l.useState(!1),[U,O]=l.useState(e.rowHeight??"compact"),[W,V]=l.useState([]),I=$e.useMemo(()=>e.id?`grid-columns-${e.objectName}-${e.id}`:`grid-columns-${e.objectName}`,[e.objectName,e.id]),[z,K]=l.useState(()=>{try{const m=localStorage.getItem(I);return m?JSON.parse(m):{}}catch{return{}}}),H=l.useCallback(m=>{K(m);try{localStorage.setItem(I,JSON.stringify(m))}catch(X){console.warn("Failed to persist column state:",X)}},[I]),se=l.useCallback(async()=>{v(m=>m+1)},[]),{ref:ee,isRefreshing:Ae,pullDistance:S}=Wi({onRefresh:se,enabled:!!n&&!!e.objectName});l.useEffect(()=>{const m=()=>h(window.innerWidth<480);return m(),window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)},[]);const Ne=g.data,ae=Qn(e.bind),ze=Sr(e),de=$e.useMemo(()=>Ne&&Array.isArray(Ne)?{provider:"value",items:Ne}:ae&&Array.isArray(ae)?{provider:"value",items:ae}:ze,[JSON.stringify(ze),ae,Ne]),Me=de?.provider==="value",we=de?.provider==="object"&&de&&"object"in de?de.object:e.objectName,ke=e.fields,F=e.columns,ue=e.filter,me=e.sort,ye=e.pagination,fe=e.pageSize;l.useEffect(()=>{Me&&de?.provider==="value"&&(x(m=>{const X=de.items;return JSON.stringify(m)!==JSON.stringify(X)?X:m}),N(!1))},[Me,de]),l.useEffect(()=>{if(!Me||!we||!n)return;let m=!1;return(async()=>{try{const P=await n.getObjectSchema(we);m||Y(P)}catch(P){console.warn(`[ObjectGrid] Failed to fetch objectSchema for inline data (objectName: ${we}):`,P)}})(),()=>{m=!0}},[Me,we,n]),l.useEffect(()=>{if(Me)return;let m=!1;return(async()=>{N(!0),q(null);try{let P=null;const pe=Bt(F)||ke;if(we&&n){const Se=await n.getObjectSchema(we);if(m)return;P=Se}else if(pe&&we)P={name:we,fields:{}};else throw we?new Error("DataSource required"):new Error("Object name required for data fetching");if(m||Y(P),n&&we){const E={$select:(()=>{if(ke)return ke;if(F&&Array.isArray(F))return F.map(R=>typeof R=="string"?R:R.field)})(),$top:ye?.pageSize||fe||50};ue&&Array.isArray(ue)?E.$filter=ue:e.defaultFilters&&(E.$filter=e.defaultFilters),me?typeof me=="string"?E.$orderby=me:Array.isArray(me)&&(E.$orderby=me.map(R=>`${R.field} ${R.order}`).join(", ")):e.defaultSort&&(E.$orderby=`${e.defaultSort.field} ${e.defaultSort.order}`);const w=sn(P?.fields,F??ke);w.length>0&&(E.$expand=w);const M=await n.find(we,E);if(m)return;x(M.data||[])}}catch(P){m||q(P)}finally{m||N(!1)}})(),()=>{m=!0}},[we,ke,F,ue,me,ye,fe,n,Me,de,p]);const xe=Xn({navigation:e.navigation,objectName:e.objectName,onNavigate:e.onNavigate,onRowClick:d}),{execute:Ce}=Zn(),Ct=fr(e.rowColor),nt=l.useCallback(m=>{const X=e.conditionalFormatting;if(!(!X||X.length===0))for(const P of X){let pe=!1;const Se=("condition"in P?P.condition:void 0)||("expression"in P?P.expression:void 0)||void 0;if(Se)pe=ei(Se,m);else if("field"in P&&"operator"in P&&P.field&&P.operator){const E=P,w=m[E.field];switch(E.operator){case"equals":pe=w===E.value;break;case"not_equals":pe=w!==E.value;break;case"contains":pe=typeof w=="string"&&typeof E.value=="string"&&w.includes(E.value);break;case"greater_than":pe=typeof w=="number"&&typeof E.value=="number"&&w>E.value;break;case"less_than":pe=typeof w=="number"&&typeof E.value=="number"&&w<E.value;break;case"in":pe=Array.isArray(E.value)&&E.value.includes(w);break}}if(pe){const E={};return"style"in P&&P.style&&Object.assign(E,P.style),"backgroundColor"in P&&P.backgroundColor&&(E.backgroundColor=P.backgroundColor),"textColor"in P&&P.textColor&&(E.color=P.textColor),"borderColor"in P&&P.borderColor&&(E.borderColor=P.borderColor),E}}},[e.conditionalFormatting]),{groups:it,isGrouped:Je,toggleGroup:je}=xr(e.grouping,c),ce=$e.useMemo(()=>{const m=Bt(e.columns);if(m&&m.length>0&&typeof m[0]=="object")return m},[e.columns]),{summaries:Pe,hasSummary:ut}=wr(ce,c),Ue=l.useCallback(()=>{const m=E=>E?{text:t.jsx($t,{className:"h-3.5 w-3.5"}),number:t.jsx(Pt,{className:"h-3.5 w-3.5"}),currency:t.jsx(Pt,{className:"h-3.5 w-3.5"}),percent:t.jsx(Pt,{className:"h-3.5 w-3.5"}),date:t.jsx(It,{className:"h-3.5 w-3.5"}),datetime:t.jsx(wi,{className:"h-3.5 w-3.5"}),boolean:t.jsx(ji,{className:"h-3.5 w-3.5"}),user:t.jsx(yi,{className:"h-3.5 w-3.5"}),select:t.jsx(gi,{className:"h-3.5 w-3.5"})}[E]||t.jsx($t,{className:"h-3.5 w-3.5"}):t.jsx($t,{className:"h-3.5 w-3.5"}),X=E=>{if(E.type)return E.type;const w=E.field.toLowerCase();if(["completed","is_completed","done","active","enabled","archived"].some(J=>w===J||w===`is_${J}`))return"boolean";if(["created_time","modified_time","updated_time","created_at","updated_at","modified_at","last_login","logged_at"].some(J=>w===J||w.endsWith(`_${J}`)))return"datetime";if(["date","due","created","updated","deadline","start","end","expires"].some(J=>w.includes(J))){if(c.length>0){const J=c.find(ie=>ie[E.field]!=null)?.[E.field];if(typeof J=="string"&&!isNaN(Date.parse(J)))return"date"}return"date"}if(["probability","percent","percentage","completion","progress","rate"].some(J=>w.includes(J))&&c.length>0&&typeof c.find(ie=>ie[E.field]!=null)?.[E.field]=="number")return"percent";if(["status","priority","category","stage","type","severity","level"].some(J=>w.includes(J))&&c.length>0){const J=new Set(c.map(ie=>ie[E.field]).filter(Boolean));if(J.size>0&&J.size<=10)return"select"}if(["assignee","owner","author","reporter","creator","user"].some(J=>w.includes(J)))return"user";if(["amount","price","total","revenue","cost","budget","salary"].some(J=>w.includes(J))&&c.length>0&&typeof c.find(ie=>ie[E.field]!=null)?.[E.field]=="number")return"currency";if(c.length>0){const J=c.find(ie=>ie[E.field]!=null)?.[E.field];if(typeof J=="string"&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(J))return"datetime"}return null},P=Bt(F);if(P){if(P.length>0&&typeof P[0]=="object"&&P[0]!==null){const E=P[0];if("accessorKey"in E)return P.map(w=>{if(w.cell)return w;const M={field:w.accessorKey,label:w.header,type:w.type},R=X(M);if(!R)return w;const te=Ze(R),L={name:w.accessorKey,type:R};if(R==="select"){const C=Array.from(new Set(c.map(Q=>Q[w.accessorKey]).filter(Boolean)));L.options=C.map(Q=>({value:Q,label:kt(String(Q))}))}return{...w,headerIcon:m(R),cell:C=>t.jsx(te,{value:C,field:L})}});if("field"in E)return P.filter(w=>w?.field&&typeof w.field=="string"&&!w.hidden).map((w,M)=>{const R=Cr(w.label)||w.field.charAt(0).toUpperCase()+w.field.slice(1).replace(/_/g," "),te=e.objectName?y(e.objectName,w.field,R):R;let L;const C=_?.fields?.[w.field],Q=w.type||C?.type||X({field:w.field})||null,re=Q?Ze(Q):null,J={name:w.field,type:Q||"text"};if(C&&(C.label&&(J.label=C.label),C.currency&&(J.currency=C.currency),C.precision!==void 0&&(J.precision=C.precision),C.format&&(J.format=C.format),C.options&&(J.options=C.options)),Q==="select"&&!J.options){const oe=Array.from(new Set(c.map(Ve=>Ve[w.field]).filter(Boolean)));J.options=oe.map(Ve=>({value:Ve,label:kt(String(Ve))}))}w.options&&(J.options=w.options);const ie=M===0&&!w.link&&!w.action,Fe=w.link||ie;w.link&&w.action||ie&&w.action?L=(oe,Ve)=>{const Xe=re?t.jsx(re,{value:oe,field:J}):oe!=null&&oe!==""?String(oe):t.jsx("span",{className:"text-muted-foreground/50 text-xs italic",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","data-testid":ie?"primary-field-link":"link-cell",onClick:at=>{at.stopPropagation(),xe.handleClick(Ve)},children:Xe})}:Fe?L=(oe,Ve)=>{const Xe=re?t.jsx(re,{value:oe,field:J}):oe!=null&&oe!==""?String(oe):t.jsx("span",{className:"text-muted-foreground/50 text-xs italic",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","data-testid":ie?"primary-field-link":"link-cell",onClick:at=>{at.stopPropagation(),xe.handleClick(Ve)},children:Xe})}:w.action?L=(oe,Ve)=>t.jsx(ne,{variant:"outline",size:"sm",className:"h-7 text-xs","data-testid":"action-cell",onClick:Xe=>{Xe.stopPropagation(),Ce({type:w.action,params:{record:Ve,field:w.field,value:oe}})},children:ds(w.action)}):re?L=oe=>t.jsx(re,{value:oe,field:J}):L=oe=>oe!=null&&oe!==""?t.jsx("span",{children:String(oe)}):t.jsx("span",{className:"text-muted-foreground/50 text-xs italic",children:"—"});const _e=w.prefix;if(_e?.field){const oe=L,Ve=_e.type==="badge"?Ze("select"):null;L=(Xe,at)=>{const St=at[_e.field],Cn=St!=null&&St!==""?Ve?t.jsx(Ve,{value:St,field:{name:_e.field,type:"select"}}):t.jsx("span",{className:"text-muted-foreground text-xs mr-1.5",children:String(St)}):null;return t.jsxs("span",{className:"flex items-center gap-1.5",children:[Cn,oe(Xe,at)]})}}const Ee=["number","currency","percent"],Te=Q||w.type,We=w.align||(Te&&Ee.includes(Te)?"right":void 0),le=M===0||w.essential===!0;return{header:te,accessorKey:w.field,headerIcon:m(Q),...!le&&{className:"hidden sm:table-cell"},...w.width&&{width:w.width},...We&&{align:We},sortable:w.sortable!==!1,...w.resizable!==void 0&&{resizable:w.resizable},...w.wrap!==void 0&&{wrap:w.wrap},...L&&{cell:L},...w.pinned&&{pinned:w.pinned}}})}return P.filter(E=>typeof E=="string"&&E.trim().length>0).map((E,w)=>{const M=_?.fields?.[E],te=M?.label||E.charAt(0).toUpperCase()+E.slice(1).replace(/_/g," "),L=e.objectName?y(e.objectName,E,te):te,C=M?.type||X({field:E})||null,Q=C?Ze(C):null,re={name:E,type:C||"text"};if(M&&(M.label&&(re.label=M.label),M.currency&&(re.currency=M.currency),M.precision!==void 0&&(re.precision=M.precision),M.format&&(re.format=M.format),M.options&&(re.options=M.options)),C==="select"&&!re.options){const Ee=Array.from(new Set(c.map(Te=>Te[E]).filter(Boolean)));re.options=Ee.map(Te=>({value:Te,label:kt(String(Te))}))}const ie=C&&["number","currency","percent"].includes(C)?"right":void 0,Fe=w===0;let _e;return Fe&&Q?_e=(Ee,Te)=>{const We=t.jsx(Q,{value:Ee,field:re});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","data-testid":"primary-field-link",onClick:le=>{le.stopPropagation(),xe.handleClick(Te)},children:We})}:Fe?_e=(Ee,Te)=>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","data-testid":"primary-field-link",onClick:We=>{We.stopPropagation(),xe.handleClick(Te)},children:Ee!=null&&Ee!==""?String(Ee):t.jsx("span",{className:"text-muted-foreground/50 text-xs italic",children:"—"})}):Q&&(_e=Ee=>t.jsx(Q,{value:Ee,field:re})),{header:L,accessorKey:E,...C&&{headerIcon:m(C)},...ie&&{align:ie},..._e&&{cell:_e},sortable:M?.sortable!==!1}})}if(Me){const E=de?.provider==="value"?de.items:[];if(E.length>0)return(ke||Object.keys(E[0])).map(M=>{const R=_?.fields?.[M],te=R?.type||X({field:M})||null,L=te?Ze(te):null,C=R?.label||M.charAt(0).toUpperCase()+M.slice(1).replace(/_/g," "),Q={name:M,type:te||"text"};if(R&&(R.label&&(Q.label=R.label),R.currency&&(Q.currency=R.currency),R.precision!==void 0&&(Q.precision=R.precision),R.format&&(Q.format=R.format),R.options&&(Q.options=R.options)),te==="select"&&!Q.options){const ie=Array.from(new Set(c.map(Fe=>Fe[M]).filter(Boolean)));Q.options=ie.map(Fe=>({value:Fe,label:kt(String(Fe))}))}const J=te&&["number","currency","percent"].includes(te)?"right":void 0;return{header:C,accessorKey:M,...te&&{headerIcon:m(te)},...J&&{align:J},...L&&{cell:ie=>t.jsx(L,{value:ie,field:Q})},sortable:R?.sortable!==!1}})}if(!_)return[];const pe=[];return(ke||Object.keys(_.fields||{})).forEach(E=>{const w=_.fields?.[E];if(!w||w.permissions&&w.permissions.read===!1)return;const M=Ze(w.type),R=["number","currency","percent"];pe.push({header:e.objectName?y(e.objectName,E,w.label||E):w.label||E,accessorKey:E,...R.includes(w.type)&&{align:"right"},cell:te=>t.jsx(M,{value:te,field:w}),sortable:w.sortable!==!1})}),pe},[_,ke,F,de,Me,xe.handleClick,Ce,c,y,e.objectName]),Rt=l.useCallback(m=>{const X=e.exportOptions,P=X?.maxRecords||0,pe=X?.includeHeaders!==!1,Se=X?.fileNamePrefix||e.objectName||"export",E=P>0?c.slice(0,P):c,w=(R,te)=>{const L=URL.createObjectURL(R),C=document.createElement("a");C.href=L,C.download=te,C.click(),URL.revokeObjectURL(L)},M=R=>{const te=R==null?"":String(R);return te.includes(",")||te.includes('"')||te.includes(`
2
- `)||te.includes("\r")?`"${te.replace(/"/g,'""')}"`:te};if(m==="csv"){const R=Ue().filter(Q=>Q.accessorKey!=="_actions"),te=R.map(Q=>Q.accessorKey),L=R.map(Q=>Q.header),C=[];pe&&C.push(L.join(",")),E.forEach(Q=>{C.push(te.map(re=>M(Q[re])).join(","))}),w(new Blob([C.join(`
3
- `)],{type:"text/csv;charset=utf-8;"}),`${Se}.csv`)}else m==="json"&&w(new Blob([JSON.stringify(E,null,2)],{type:"application/json"}),`${Se}.json`);B(!1)},[c,e.exportOptions,e.objectName,Ue]);if(f)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:A("grid.errorLoading")}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:f.message})]});if(j&&c.length===0)return D?t.jsx("div",{className:"space-y-2 p-2",children:[1,2,3].map(m=>t.jsxs("div",{className:"border rounded-lg p-3 bg-card animate-pulse",children:[t.jsx("div",{className:"h-5 bg-muted rounded w-3/4 mb-3"}),t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("div",{className:"h-4 bg-muted rounded w-1/4"}),t.jsx("div",{className:"h-5 bg-muted rounded-full w-20"})]}),t.jsx("div",{className:"h-3 bg-muted rounded w-1/3"})]},m))}):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-foreground"}),t.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:A("grid.loading")})]});let qe=[...Ue()];if(z.widths&&(qe=qe.map(m=>{const X=z.widths?.[m.accessorKey];return X?{...m,size:X}:m})),z.order&&z.order.length>0){const m=new Map(z.order.map((X,P)=>[X,P]));qe.sort((X,P)=>{const pe=m.get(X.accessorKey)??1/0,Se=m.get(P.accessorKey)??1/0;return pe-Se})}const Be="operations"in e?e.operations:void 0,ft=Be&&(Be.update||Be.delete),rt=e.rowActions&&e.rowActions.length>0,Qe=ft||rt?[...qe,{header:A("grid.actions"),accessorKey:"_actions",cell:(m,X)=>t.jsx(vr,{row:X,rowActions:e.rowActions,canEdit:!!(Be?.update&&s),canDelete:!!(Be?.delete&&i),onEdit:s,onDelete:i,onAction:(P,pe)=>Ce({type:P,params:{record:pe}})}),sortable:!1}]:qe,lt=Qe.filter(m=>m.pinned==="left"),k=Qe.filter(m=>m.pinned==="right"),$=Qe.filter(m=>!m.pinned),G=lt.length>0||k.length>0,Oe="sticky right-0 z-10 bg-background border-l border-border",ge=G?[...lt,...$,...k.map(m=>({...m,className:[m.className,Oe].filter(Boolean).join(" "),cellClassName:[m.cellClassName,Oe].filter(Boolean).join(" ")}))]:Qe,Le=G?lt.length:e.frozenColumns??1,he=e.batchActions??e.bulkActions,ve=he&&he.length>0;let De=!1;e.selection?.type?De=e.selection.type==="none"?!1:e.selection.type:e.selectable!==void 0?De=e.selectable:ve&&(De="multiple");const be=e.pagination!==void 0?!0:e.showPagination!==void 0?e.showPagination:!0,zt=e.pagination?.pageSize||e.pageSize||10,yn=e.searchableFields!==void 0?e.searchableFields.length>0:e.showSearch!==void 0?e.showSearch:!0,us={type:"data-table",caption:e.label||e.title,columns:ge,data:c,pagination:be,pageSize:zt,searchable:yn,selectable:De,sortable:!0,exportable:Be?.export,rowActions:ft,resizableColumns:e.resizable??e.resizableColumns??!0,reorderableColumns:e.reorderableColumns??!1,editable:e.editable??!1,singleClickEdit:e.singleClickEdit??!0,className:e.className,cellClassName:U==="compact"?"px-3 py-1 text-[13px] leading-tight":U==="short"?"px-3 py-1 text-[13px] leading-normal":U==="tall"?"px-3 py-2.5 text-sm":U==="extra_tall"?"px-3 py-3.5 text-sm leading-relaxed":"px-3 py-1.5 text-[13px] leading-normal",showRowNumbers:!0,showAddRow:!!Be?.create,onAddRecord:b,rowClassName:e.rowColor?(m,X)=>Ct(m):void 0,rowStyle:e.conditionalFormatting?.length?(m,X)=>nt(m):void 0,frozenColumns:Le,onSelectionChange:m=>{V(m),r?.(m)},onRowClick:xe.handleClick,onCellChange:a,onRowSave:o,onBatchSave:u,onColumnResize:(m,X)=>{H({...z,widths:{...z.widths,[m]:X}})},onColumnReorder:m=>{H({...z,order:m})}},jn=m=>({...us,caption:void 0,data:m,pagination:!1,searchable:!1}),Mt=e.label?`${e.label} Detail`:e.objectName?`${e.objectName.charAt(0).toUpperCase()+e.objectName.slice(1)} Detail`:"Record Detail";if(D&&c.length>0&&!Je){const m=Ue().filter(L=>L.accessorKey!=="_actions"),X=new Map;m.forEach(L=>X.set(L.accessorKey,L));const P=m[0],pe=["amount","price","total","revenue","cost","value","budget","salary"],Se=["stage","status","priority","category","severity","level"],E=["date","due","created","updated","deadline","start","end","expires"],w=["probability","percent","rate","ratio","confidence","score"],M=L=>{const C=(L||"").toLowerCase();return C.includes("won")||C.includes("completed")||C.includes("done")||C.includes("active")?"bg-green-100 text-green-800 border-green-300":C.includes("lost")||C.includes("cancelled")||C.includes("rejected")||C.includes("closed lost")?"bg-red-100 text-red-800 border-red-300":C.includes("negotiation")||C.includes("review")||C.includes("in progress")?"bg-yellow-100 text-yellow-800 border-yellow-300":C.includes("proposal")||C.includes("pending")?"bg-blue-100 text-blue-800 border-blue-300":C.includes("qualification")||C.includes("qualified")?"bg-indigo-100 text-indigo-800 border-indigo-300":C.includes("prospecting")||C.includes("new")||C.includes("open")?"bg-purple-100 text-purple-800 border-purple-300":"bg-muted text-muted-foreground border-border"},R=L=>{const C=(L||"").toLowerCase();return C.includes("won")||C.includes("completed")||C.includes("done")||C.includes("active")?"border-l-green-500":C.includes("lost")||C.includes("cancelled")||C.includes("rejected")?"border-l-red-500":C.includes("negotiation")||C.includes("review")||C.includes("in progress")?"border-l-yellow-500":C.includes("proposal")||C.includes("pending")?"border-l-blue-500":C.includes("qualification")||C.includes("qualified")?"border-l-indigo-500":C.includes("prospecting")||C.includes("new")||C.includes("open")?"border-l-purple-500":"border-l-gray-300"},te=L=>{const C=L.toLowerCase();return pe.some(Q=>C.includes(Q))?"amount":Se.some(Q=>C.includes(Q))?"stage":E.some(Q=>C.includes(Q))?"date":w.some(Q=>C.includes(Q))?"percent":"other"};return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"space-y-2 p-2",children:c.map((L,C)=>{const Q=m.slice(1,5),re=Q.find(le=>te(le.accessorKey)==="amount"),J=Q.find(le=>te(le.accessorKey)==="stage"),ie=Q.filter(le=>te(le.accessorKey)==="date"),Fe=Q.filter(le=>te(le.accessorKey)==="percent"),_e=Q.filter(le=>le!==re&&le!==J&&!ie.includes(le)&&!Fe.includes(le)),Ee=J?String(L[J.accessorKey]??""):"",Te=Ee?R(Ee):"",We=["border rounded-lg p-2.5 bg-card hover:bg-accent/50 cursor-pointer transition-colors touch-manipulation",Te?`border-l-[3px] ${Te}`:""].filter(Boolean).join(" ");return t.jsxs("div",{className:We,onClick:()=>xe.handleClick(L),children:[P&&t.jsx("div",{className:"font-semibold text-sm truncate mb-1",children:L[P.accessorKey]??"—"}),(re||J)&&t.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[re&&t.jsx("span",{className:"text-sm tabular-nums font-medium",children:typeof L[re.accessorKey]=="number"?Mn(L[re.accessorKey]):L[re.accessorKey]??"—"}),J&&L[J.accessorKey]&&t.jsx(Ke,{variant:"outline",className:`text-xs shrink-0 max-w-[140px] truncate ${M(String(L[J.accessorKey]))}`,children:L[J.accessorKey]})]}),(ie.length>0||Fe.length>0)&&t.jsxs("div",{className:"flex items-center justify-between py-0.5 text-xs text-muted-foreground",children:[ie[0]&&t.jsx("span",{className:"tabular-nums",children:L[ie[0].accessorKey]?_t(L[ie[0].accessorKey],"short"):"—"}),Fe[0]&&L[Fe[0].accessorKey]!=null&&t.jsx("span",{className:"tabular-nums",children:Ln(Number(L[Fe[0].accessorKey]))})]}),ie.slice(1).map(le=>t.jsxs("div",{className:"flex justify-between items-center py-0.5",children:[t.jsx("span",{className:"text-xs text-muted-foreground",children:le.header}),t.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:L[le.accessorKey]?_t(L[le.accessorKey],"short"):"—"})]},le.accessorKey)),_e.map(le=>{const oe=L[le.accessorKey];return oe==null||oe===""?null:t.jsxs("div",{className:"flex justify-between items-center py-0.5",children:[t.jsx("span",{className:"text-xs text-muted-foreground",children:le.header}),t.jsx("span",{className:"text-xs font-medium truncate ml-2 text-right",children:le.cell?le.cell(oe,L):String(oe)})]},le.accessorKey)})]},L.id||L._id||C)})}),xe.isOverlay&&t.jsx(xt,{...xe,title:Mt,children:L=>t.jsx("div",{className:"space-y-3",children:Object.entries(L).map(([C,Q])=>t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:C.replace(/_/g," ")}),t.jsx("span",{className:"text-sm",children:String(Q??"—")})]},C))})})]})}const wn=()=>{O(m=>m==="compact"?"short":m==="short"?"medium":m==="medium"?"tall":m==="tall"?"extra_tall":"compact")},vn={compact:hi,short:xi,medium:bi,tall:Cs,extra_tall:Cs}[U],fs=e.rowHeight!==void 0,ps=e.exportOptions||fs?t.jsxs("div",{className:"flex items-center justify-end gap-1 px-2 py-1",children:[fs&&t.jsxs(ne,{variant:"ghost",size:"sm",className:"h-7 px-2 text-muted-foreground hover:text-primary text-xs",onClick:wn,title:`Row height: ${U}`,children:[t.jsx(vn,{className:"h-3.5 w-3.5 mr-1.5"}),t.jsx("span",{className:"hidden sm:inline capitalize",children:U})]}),e.exportOptions&&t.jsxs(ss,{open:T,onOpenChange:B,children:[t.jsx(ns,{asChild:!0,children:t.jsxs(ne,{variant:"ghost",size:"sm",className:"h-7 px-2 text-muted-foreground hover:text-primary text-xs",children:[t.jsx(Ss,{className:"h-3.5 w-3.5 mr-1.5"}),t.jsx("span",{className:"hidden sm:inline",children:A("grid.export")})]})}),t.jsx(is,{align:"end",className:"w-48 p-2",children:t.jsx("div",{className:"space-y-1",children:(e.exportOptions.formats||["csv","json"]).map(m=>t.jsxs(ne,{variant:"ghost",size:"sm",className:"w-full justify-start h-8 text-xs",onClick:()=>Rt(m),children:[t.jsx(Ss,{className:"h-3.5 w-3.5 mr-2"}),A("grid.exportAs",{format:m.toUpperCase()})]},m))})})]})]}):null,ms=m=>{const X=["_id","id","created_at","updated_at","created_by","updated_by"],P=Object.entries(m),pe=P.filter(([M])=>!X.includes(M)),Se=P.filter(([M])=>X.includes(M)&&M!=="_id"&&M!=="id"),E=M=>M.charAt(0).toUpperCase()+M.slice(1).replace(/_/g," "),w=(M,R)=>{if(R==null||R==="")return t.jsx("span",{className:"text-muted-foreground/50 text-sm italic",children:"Empty"});const te=_?.fields?.[M];if(te?.type){const C=Ze(te.type);if(C)return t.jsx(C,{value:R,field:te})}return typeof R=="boolean"?t.jsx(Ke,{variant:R?"default":"outline",children:R?"Yes":"No"}):typeof R=="string"&&!isNaN(Date.parse(R))&&(M.includes("date")||M.includes("_at")||M.includes("time"))?t.jsx("span",{className:"text-sm tabular-nums",children:_t(R)}):typeof R=="number"&&["amount","price","total","revenue","cost","value","budget","salary"].some(C=>M.toLowerCase().includes(C))?t.jsx("span",{className:"text-sm tabular-nums font-medium",children:_n(R)}):t.jsx("span",{className:"text-sm break-words",children:String(R)})};return t.jsxs("div",{className:"space-y-4","data-testid":"record-detail-panel",children:[t.jsx("div",{className:"rounded-lg border bg-card",children:t.jsx("div",{className:"divide-y",children:pe.map(([M,R])=>t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start gap-1 sm:gap-4 px-4 py-3",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground sm:w-1/3 sm:text-right sm:pt-0.5 uppercase tracking-wide shrink-0",children:E(M)}),t.jsx("div",{className:"flex-1 min-w-0",children:w(M,R)})]},M))})}),Se.length>0&&t.jsxs("div",{className:"rounded-lg border bg-muted/30",children:[t.jsx("div",{className:"px-4 py-2 border-b",children:t.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"System"})}),t.jsx("div",{className:"divide-y divide-border/50",children:Se.map(([M,R])=>t.jsxs("div",{className:"flex items-center gap-4 px-4 py-2",children:[t.jsx("span",{className:"text-xs text-muted-foreground w-1/3 text-right shrink-0",children:E(M)}),t.jsx("span",{className:"text-xs text-muted-foreground flex-1 min-w-0 break-words",children:String(R??"")})]},M))})]})]})},Nn=ut?t.jsx("div",{className:"border-t bg-muted/30 px-2 py-1.5","data-testid":"column-summary-footer",children:t.jsx("div",{className:"flex gap-4 text-xs text-muted-foreground font-medium",children:ge.filter(m=>Pe.has(m.accessorKey)).map(m=>{const X=Pe.get(m.accessorKey);return t.jsxs("span",{"data-testid":`summary-${m.accessorKey}`,children:[m.header,": ",X.label]},m.accessorKey)})})}):null,bs=Je?t.jsx("div",{className:"space-y-2",children:it.map(m=>t.jsx(hr,{groupKey:m.key,label:m.label,count:m.rows.length,collapsed:m.collapsed,aggregations:m.aggregations,onToggle:je,children:t.jsx(Re,{schema:jn(m.rows)})},m.key))}):t.jsxs(t.Fragment,{children:[t.jsx(Re,{schema:us}),Nn]});return xe.isOverlay&&xe.mode==="split"?t.jsx(xt,{...xe,title:Mt,mainContent:t.jsxs(t.Fragment,{children:[ps,bs,t.jsx(Vs,{selectedRows:W,actions:he??[],onAction:(m,X)=>Ce({type:m,params:{records:X}}),onClearSelection:()=>V([])})]}),children:m=>ms(m)}):t.jsxs("div",{ref:ee,className:"relative h-full",children:[S>0&&t.jsx("div",{className:"flex items-center justify-center text-xs text-muted-foreground",style:{height:S},children:A(Ae?"grid.refreshing":"grid.pullToRefresh")}),ps,bs,t.jsx(Vs,{selectedRows:W,actions:he??[],onAction:(m,X)=>Ce({type:m,params:{records:X}}),onClearSelection:()=>V([])}),xe.isOverlay&&t.jsx(xt,{...xe,title:Mt,children:m=>ms(m)})]})};function ot(e,n,s){let i=s.initialDeps??[],r,d=!0;function a(){var o,u,b;let g;s.key&&((o=s.debug)!=null&&o.call(s))&&(g=Date.now());const c=e();if(!(c.length!==i.length||c.some((N,f)=>i[f]!==N)))return r;i=c;let j;if(s.key&&((u=s.debug)!=null&&u.call(s))&&(j=Date.now()),r=n(...c),s.key&&((b=s.debug)!=null&&b.call(s))){const N=Math.round((Date.now()-g)*100)/100,f=Math.round((Date.now()-j)*100)/100,q=f/16,A=(y,_)=>{for(y=String(y);y.length<_;)y=" "+y;return y};console.info(`%c⏱ ${A(f,5)} /${A(N,5)} ms`,`
4
- font-size: .6rem;
5
- font-weight: bold;
6
- color: hsl(${Math.max(0,Math.min(120-120*q,120))}deg 100% 31%);`,s?.key)}return s?.onChange&&!(d&&s.skipInitialOnChange)&&s.onChange(r),d=!1,r}return a.updateDeps=o=>{i=o},a}function zs(e,n){if(e===void 0)throw new Error("Unexpected undefined");return e}const Fr=(e,n)=>Math.abs(e-n)<1.01,kr=(e,n,s)=>{let i;return function(...r){e.clearTimeout(i),i=e.setTimeout(()=>n.apply(this,r),s)}},Ms=e=>{const{offsetWidth:n,offsetHeight:s}=e;return{width:n,height:s}},Or=e=>e,Dr=e=>{const n=Math.max(e.startIndex-e.overscan,0),s=Math.min(e.endIndex+e.overscan,e.count-1),i=[];for(let r=n;r<=s;r++)i.push(r);return i},Er=(e,n)=>{const s=e.scrollElement;if(!s)return;const i=e.targetWindow;if(!i)return;const r=a=>{const{width:o,height:u}=a;n({width:Math.round(o),height:Math.round(u)})};if(r(Ms(s)),!i.ResizeObserver)return()=>{};const d=new i.ResizeObserver(a=>{const o=()=>{const u=a[0];if(u?.borderBoxSize){const b=u.borderBoxSize[0];if(b){r({width:b.inlineSize,height:b.blockSize});return}}r(Ms(s))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()});return d.observe(s,{box:"border-box"}),()=>{d.unobserve(s)}},Ls={passive:!0},_s=typeof window>"u"?!0:"onscrollend"in window,Tr=(e,n)=>{const s=e.scrollElement;if(!s)return;const i=e.targetWindow;if(!i)return;let r=0;const d=e.options.useScrollendEvent&&_s?()=>{}:kr(i,()=>{n(r,!1)},e.options.isScrollingResetDelay),a=g=>()=>{const{horizontal:c,isRtl:x}=e.options;r=c?s.scrollLeft*(x&&-1||1):s.scrollTop,d(),n(r,g)},o=a(!0),u=a(!1);s.addEventListener("scroll",o,Ls);const b=e.options.useScrollendEvent&&_s;return b&&s.addEventListener("scrollend",u,Ls),()=>{s.removeEventListener("scroll",o),b&&s.removeEventListener("scrollend",u)}},Ir=(e,n,s)=>{if(n?.borderBoxSize){const i=n.borderBoxSize[0];if(i)return Math.round(i[s.options.horizontal?"inlineSize":"blockSize"])}return e[s.options.horizontal?"offsetWidth":"offsetHeight"]},Ar=(e,{adjustments:n=0,behavior:s},i)=>{var r,d;const a=e+n;(d=(r=i.scrollElement)==null?void 0:r.scrollTo)==null||d.call(r,{[i.options.horizontal?"left":"top"]:a,behavior:s})};class Vr{constructor(n){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 s=null;const i=()=>s||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:s=new this.targetWindow.ResizeObserver(r=>{r.forEach(d=>{const a=()=>{this._measureElement(d.target,d)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()})}));return{disconnect:()=>{var r;(r=i())==null||r.disconnect(),s=null},observe:r=>{var d;return(d=i())==null?void 0:d.observe(r,{box:"border-box"})},unobserve:r=>{var d;return(d=i())==null?void 0:d.unobserve(r)}}})(),this.range=null,this.setOptions=s=>{Object.entries(s).forEach(([i,r])=>{typeof r>"u"&&delete s[i]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Or,rangeExtractor:Dr,onChange:()=>{},measureElement:Ir,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,...s}},this.notify=s=>{var i,r;(r=(i=this.options).onChange)==null||r.call(i,this,s)},this.maybeNotify=ot(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),s=>{this.notify(s)},{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(s=>s()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var s;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=((s=this.scrollElement)==null?void 0:s.window)??null,this.elementsCache.forEach(r=>{this.observer.observe(r)}),this.unsubs.push(this.options.observeElementRect(this,r=>{this.scrollRect=r,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(r,d)=>{this.scrollAdjustments=0,this.scrollDirection=d?this.getScrollOffset()<r?"forward":"backward":null,this.scrollOffset=r,this.isScrolling=d,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=(s,i)=>{const r=new Map,d=new Map;for(let a=i-1;a>=0;a--){const o=s[a];if(r.has(o.lane))continue;const u=d.get(o.lane);if(u==null||o.end>u.end?d.set(o.lane,o):o.end<u.end&&r.set(o.lane,!0),r.size===this.options.lanes)break}return d.size===this.options.lanes?Array.from(d.values()).sort((a,o)=>a.end===o.end?a.index-o.index:a.end-o.end)[0]:void 0},this.getMeasurementOptions=ot(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(s,i,r,d,a,o)=>(this.prevLanes!==void 0&&this.prevLanes!==o&&(this.lanesChangedFlag=!0),this.prevLanes=o,this.pendingMeasuredCacheIndexes=[],{count:s,paddingStart:i,scrollMargin:r,getItemKey:d,enabled:a,lanes:o}),{key:!1}),this.getMeasurements=ot(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:s,paddingStart:i,scrollMargin:r,getItemKey:d,enabled:a,lanes:o},u)=>{if(!a)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>s)for(const x of this.laneAssignments.keys())x>=s&&this.laneAssignments.delete(x);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(x=>{this.itemSizeCache.set(x.key,x.size)}));const b=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===s&&(this.lanesSettling=!1);const g=this.measurementsCache.slice(0,b),c=new Array(o).fill(void 0);for(let x=0;x<b;x++){const j=g[x];j&&(c[j.lane]=x)}for(let x=b;x<s;x++){const j=d(x),N=this.laneAssignments.get(x);let f,q;if(N!==void 0&&this.options.lanes>1){f=N;const Y=c[f],D=Y!==void 0?g[Y]:void 0;q=D?D.end+this.options.gap:i+r}else{const Y=this.options.lanes===1?g[x-1]:this.getFurthestMeasurement(g,x);q=Y?Y.end+this.options.gap:i+r,f=Y?Y.lane:x%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(x,f)}const A=u.get(j),y=typeof A=="number"?A:this.options.estimateSize(x),_=q+y;g[x]={index:x,start:q,size:y,end:_,key:j,lane:f},c[f]=x}return this.measurementsCache=g,g},{key:!1,debug:()=>this.options.debug}),this.calculateRange=ot(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(s,i,r,d)=>this.range=s.length>0&&i>0?Rr({measurements:s,outerSize:i,scrollOffset:r,lanes:d}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=ot(()=>{let s=null,i=null;const r=this.calculateRange();return r&&(s=r.startIndex,i=r.endIndex),this.maybeNotify.updateDeps([this.isScrolling,s,i]),[this.options.rangeExtractor,this.options.overscan,this.options.count,s,i]},(s,i,r,d,a)=>d===null||a===null?[]:s({startIndex:d,endIndex:a,overscan:i,count:r}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=s=>{const i=this.options.indexAttribute,r=s.getAttribute(i);return r?parseInt(r,10):(console.warn(`Missing attribute name '${i}={index}' on measured element.`),-1)},this._measureElement=(s,i)=>{const r=this.indexFromElement(s),d=this.measurementsCache[r];if(!d)return;const a=d.key,o=this.elementsCache.get(a);o!==s&&(o&&this.observer.unobserve(o),this.observer.observe(s),this.elementsCache.set(a,s)),s.isConnected&&this.resizeItem(r,this.options.measureElement(s,i,this))},this.resizeItem=(s,i)=>{const r=this.measurementsCache[s];if(!r)return;const d=this.itemSizeCache.get(r.key)??r.size,a=i-d;a!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(r,a,this):r.start<this.getScrollOffset()+this.scrollAdjustments)&&this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=a,behavior:void 0}),this.pendingMeasuredCacheIndexes.push(r.index),this.itemSizeCache=new Map(this.itemSizeCache.set(r.key,i)),this.notify(!1))},this.measureElement=s=>{if(!s){this.elementsCache.forEach((i,r)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(r))});return}this._measureElement(s,void 0)},this.getVirtualItems=ot(()=>[this.getVirtualIndexes(),this.getMeasurements()],(s,i)=>{const r=[];for(let d=0,a=s.length;d<a;d++){const o=s[d],u=i[o];r.push(u)}return r},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=s=>{const i=this.getMeasurements();if(i.length!==0)return zs(i[fn(0,i.length-1,r=>zs(i[r]).start,s)])},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 s=this.scrollElement.document.documentElement;return this.options.horizontal?s.scrollWidth-this.scrollElement.innerWidth:s.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(s,i,r=0)=>{if(!this.scrollElement)return 0;const d=this.getSize(),a=this.getScrollOffset();i==="auto"&&(i=s>=a+d?"end":"start"),i==="center"?s+=(r-d)/2:i==="end"&&(s-=d);const o=this.getMaxScrollOffset();return Math.max(Math.min(o,s),0)},this.getOffsetForIndex=(s,i="auto")=>{s=Math.max(0,Math.min(s,this.options.count-1));const r=this.measurementsCache[s];if(!r)return;const d=this.getSize(),a=this.getScrollOffset();if(i==="auto")if(r.end>=a+d-this.options.scrollPaddingEnd)i="end";else if(r.start<=a+this.options.scrollPaddingStart)i="start";else return[a,i];if(i==="end"&&s===this.options.count-1)return[this.getMaxScrollOffset(),i];const o=i==="end"?r.end+this.options.scrollPaddingEnd:r.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(o,i,r.size),i]},this.isDynamicMode=()=>this.elementsCache.size>0,this.scrollToOffset=(s,{align:i="start",behavior:r}={})=>{r==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(s,i),{adjustments:void 0,behavior:r})},this.scrollToIndex=(s,{align:i="auto",behavior:r}={})=>{r==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),s=Math.max(0,Math.min(s,this.options.count-1)),this.currentScrollToIndex=s;let d=0;const a=10,o=b=>{if(!this.targetWindow)return;const g=this.getOffsetForIndex(s,b);if(!g){console.warn("Failed to get offset for index:",s);return}const[c,x]=g;this._scrollToOffset(c,{adjustments:void 0,behavior:r}),this.targetWindow.requestAnimationFrame(()=>{if(!this.targetWindow)return;const j=()=>{if(this.currentScrollToIndex!==s)return;const N=this.getScrollOffset(),f=this.getOffsetForIndex(s,x);if(!f){console.warn("Failed to get offset for index:",s);return}Fr(f[0],N)||u(x)};this.isDynamicMode()?this.targetWindow.requestAnimationFrame(j):j()})},u=b=>{this.targetWindow&&this.currentScrollToIndex===s&&(d++,d<a?this.targetWindow.requestAnimationFrame(()=>o(b)):console.warn(`Failed to scroll to index ${s} after ${a} attempts.`))};o(i)},this.scrollBy=(s,{behavior:i}={})=>{i==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+s,{adjustments:void 0,behavior:i})},this.getTotalSize=()=>{var s;const i=this.getMeasurements();let r;if(i.length===0)r=this.options.paddingStart;else if(this.options.lanes===1)r=((s=i[i.length-1])==null?void 0:s.end)??0;else{const d=Array(this.options.lanes).fill(null);let a=i.length-1;for(;a>=0&&d.some(o=>o===null);){const o=i[a];d[o.lane]===null&&(d[o.lane]=o.end),a--}r=Math.max(...d.filter(o=>o!==null))}return Math.max(r-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(s,{adjustments:i,behavior:r})=>{this.options.scrollToFn(s,{behavior:r,adjustments:i},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(n)}}const fn=(e,n,s,i)=>{for(;e<=n;){const r=(e+n)/2|0,d=s(r);if(d<i)e=r+1;else if(d>i)n=r-1;else return r}return e>0?e-1:0};function Rr({measurements:e,outerSize:n,scrollOffset:s,lanes:i}){const r=e.length-1,d=u=>e[u].start;if(e.length<=i)return{startIndex:0,endIndex:r};let a=fn(0,r,d,s),o=a;if(i===1)for(;o<r&&e[o].end<s+n;)o++;else if(i>1){const u=Array(i).fill(0);for(;o<r&&u.some(g=>g<s+n);){const g=e[o];u[g.lane]=g.end,o++}const b=Array(i).fill(s+n);for(;a>=0&&b.some(g=>g>=s);){const g=e[a];b[g.lane]=g.start,a--}a=Math.max(0,a-a%i),o=Math.min(r,o+(i-1-o%i))}return{startIndex:a,endIndex:o}}const $s=typeof document<"u"?l.useLayoutEffect:l.useEffect;function zr({useFlushSync:e=!0,...n}){const s=l.useReducer(()=>({}),{})[1],i={...n,onChange:(d,a)=>{var o;e&&a?Sn.flushSync(s):s(),(o=n.onChange)==null||o.call(n,d,a)}},[r]=l.useState(()=>new Vr(i));return r.setOptions(i),$s(()=>r._didMount(),[]),$s(()=>r._willUpdate()),r}function Sl(e){return zr({observeElementRect:Er,observeElementOffset:Tr,scrollToFn:Ar,...e})}const Mr=10;function Lr(e){const n=[];let s=[],i="",r=!1;for(let d=0;d<e.length;d++){const a=e[d],o=e[d+1];r?a==='"'&&o==='"'?(i+='"',d++):a==='"'?r=!1:i+=a:a==='"'?r=!0:a===","?(s.push(i.trim()),i=""):a===`
7
- `||a==="\r"&&o===`
8
- `?(s.push(i.trim()),s.some(u=>u!=="")&&n.push(s),s=[],i="",a==="\r"&&d++):i+=a}return s.push(i.trim()),s.some(d=>d!=="")&&n.push(s),n}function pn(e,n){if(!e)return!0;switch(n){case"number":case"currency":case"percent":return!isNaN(Number(e));case"boolean":return["true","false","1","0","yes","no"].includes(e.toLowerCase());case"date":case"datetime":return!isNaN(Date.parse(e));default:return!0}}function _r(e,n){const s={};return e.forEach((i,r)=>{const d=i.toLowerCase().replace(/[_\s-]/g,""),a=n.find(o=>{const u=o.name.toLowerCase().replace(/[_\s-]/g,""),b=o.label.toLowerCase().replace(/[_\s-]/g,"");return u===d||b===d});a&&(s[r]=a.name)}),s}function $r(e,n,s){const i=[],r={};for(const d of n){const a=e[d.csvIdx]??"";if(d.field.required&&!a){i.push({row:s,field:d.field.name,message:"Required field is empty"});continue}if(a&&!pn(a,d.field.type)){i.push({row:s,field:d.field.name,message:`Invalid ${d.field.type} value: "${a}"`});continue}r[d.field.name]=a}return{record:r,errors:i}}const Pr=({onFileLoaded:e})=>{const[n,s]=l.useState(!1),[i,r]=l.useState(null),d=l.useCallback(a=>{if(r(null),!a.name.endsWith(".csv")){r("Only CSV files are supported.");return}const o=new FileReader;o.onload=u=>{const b=Lr(u.target?.result);if(b.length<2){r("File must contain a header row and at least one data row.");return}e(b[0],b.slice(1))},o.readAsText(a)},[e]);return t.jsxs("div",{className:"flex flex-col items-center gap-4 py-6",children:[t.jsxs("div",{className:Z("flex w-full flex-col items-center justify-center gap-3 rounded-lg border-2 border-dashed p-10 transition-colors",n?"border-primary bg-primary/5":"border-muted-foreground/25"),onDragOver:a=>{a.preventDefault(),s(!0)},onDragLeave:()=>s(!1),onDrop:a=>{a.preventDefault(),s(!1);const o=a.dataTransfer.files[0];o&&d(o)},children:[t.jsx(Si,{className:"h-10 w-10 text-muted-foreground"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Drag & drop a CSV file here, or click to browse"}),t.jsxs("label",{children:[t.jsx("input",{type:"file",accept:".csv",className:"hidden",onChange:a=>{const o=a.target.files?.[0];o&&d(o)}}),t.jsx(ne,{variant:"outline",size:"sm",asChild:!0,children:t.jsx("span",{children:"Browse Files"})})]})]}),i&&t.jsxs("p",{className:"flex items-center gap-1 text-sm text-destructive",children:[t.jsx(on,{className:"h-4 w-4"})," ",i]})]})},qr=({headers:e,fields:n,mapping:s,onMappingChange:i})=>{const r=l.useMemo(()=>new Set(Object.values(s)),[s]),d=l.useCallback((a,o)=>{const u={...s};o==="__skip__"?delete u[a]:u[a]=o,i(u)},[s,i]);return t.jsx("div",{className:"max-h-[360px] overflow-auto",children:t.jsxs(Gs,{children:[t.jsx(Ys,{children:t.jsxs(Tt,{children:[t.jsx(ht,{children:"CSV Column"}),t.jsx(ht,{children:"Maps To"}),t.jsx(ht,{className:"w-24 text-center",children:"Status"})]})}),t.jsx(Js,{children:e.map((a,o)=>t.jsxs(Tt,{children:[t.jsx(gt,{className:"font-medium",children:a}),t.jsx(gt,{children:t.jsxs(jt,{value:s[o]??"__skip__",onValueChange:u=>d(o,u),children:[t.jsx(wt,{className:"h-8 w-56",children:t.jsx(vt,{placeholder:"Skip column"})}),t.jsxs(Nt,{children:[t.jsx(tt,{value:"__skip__",children:"— Skip —"}),n.map(u=>t.jsxs(tt,{value:u.name,disabled:r.has(u.name)&&s[o]!==u.name,children:[u.label,u.required?" *":""]},u.name))]})]})}),t.jsx(gt,{className:"text-center",children:s[o]?t.jsx(Ke,{variant:"default",className:"text-xs",children:"Mapped"}):t.jsx(Ke,{variant:"secondary",className:"text-xs",children:"Skipped"})})]},o))})]})})},Br=({headers:e,rows:n,mapping:s,fields:i})=>{const r=l.useMemo(()=>Object.entries(s).map(([u,b])=>({csvIdx:Number(u),header:e[Number(u)],field:i.find(g=>g.name===b)})),[s,e,i]),d=n.slice(0,Mr),a=l.useMemo(()=>d.map((u,b)=>{const g={};for(const c of r){const x=u[c.csvIdx]??"";c.field.required&&!x?g[c.csvIdx]="Required":x&&!pn(x,c.field.type)&&(g[c.csvIdx]=`Invalid ${c.field.type}`)}return g}),[d,r]),o=a.filter(u=>Object.keys(u).length>0).length;return t.jsxs("div",{className:"max-h-[360px] overflow-auto",children:[o>0&&t.jsxs("p",{className:"mb-2 flex items-center gap-1 text-xs text-destructive",children:[t.jsx(on,{className:"h-3.5 w-3.5"})," ",o," row(s) with errors in preview"]}),t.jsxs(Gs,{children:[t.jsx(Ys,{children:t.jsxs(Tt,{children:[t.jsx(ht,{className:"w-12",children:"#"}),r.map(u=>t.jsx(ht,{children:u.field.label},u.csvIdx))]})}),t.jsx(Js,{children:d.map((u,b)=>{const g=a[b],c=Object.keys(g).length>0;return t.jsxs(Tt,{className:Z(c&&"bg-destructive/5"),children:[t.jsx(gt,{className:"text-xs text-muted-foreground",children:b+1}),r.map(x=>{const j=u[x.csvIdx]??"",N=g[x.csvIdx];return t.jsx(gt,{className:Z(N&&"text-destructive"),title:N,children:j||t.jsx("span",{className:"text-muted-foreground/50",children:"—"})},x.csvIdx)})]},b)})})]}),t.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:["Showing ",d.length," of ",n.length," rows"]})]})},Kr=({objectName:e,objectLabel:n,fields:s,dataSource:i,onComplete:r,onCancel:d,open:a,onOpenChange:o,onErrorMode:u="skip"})=>{const[b,g]=l.useState("upload"),[c,x]=l.useState([]),[j,N]=l.useState([]),[f,q]=l.useState({}),[A,y]=l.useState(!1),[_,Y]=l.useState(0),[D,h]=l.useState(null),p=n??e,v=l.useMemo(()=>{const W=new Set(Object.values(f));return s.filter(V=>V.required&&!W.has(V.name))},[s,f]),T=l.useCallback((W,V)=>{x(W),N(V),q(_r(W,s)),g("mapping")},[s]),B=l.useCallback(async()=>{y(!0),Y(0);const W=[];let V=0,I=0;const z=Object.entries(f).map(([H,se])=>({csvIdx:Number(H),field:s.find(ee=>ee.name===se)}));for(let H=0;H<j.length;H++){const{record:se,errors:ee}=$r(j[H],z,H+1);if(ee.length>0){if(I++,W.push(...ee),u==="stop")break}else try{i?.create&&await i.create(e,se),V++}catch(Ae){I++;const S=Ae instanceof Error?Ae.message:"Failed to create record";if(W.push({row:H+1,field:"",message:S}),u==="stop")break}Y(Math.round((H+1)/j.length*100))}const K={totalRows:j.length,importedRows:V,skippedRows:I,errors:W};h(K),y(!1),r?.(K)},[j,f,s,i,e,r,u]),U=l.useCallback(()=>{g("upload"),x([]),N([]),q({}),Y(0),h(null)},[]),O=l.useCallback(()=>{U(),o?.(!1),d?.()},[U,o,d]);return t.jsx(Xt,{open:a,onOpenChange:W=>{W?o?.(W):O()},children:t.jsxs(Hs,{className:"sm:max-w-2xl",children:[t.jsxs(Zt,{children:[t.jsxs(es,{className:"flex items-center gap-2",children:[t.jsx(vi,{className:"h-5 w-5"})," Import ",p]}),t.jsxs(ts,{children:[b==="upload"&&"Upload a CSV file to get started.",b==="mapping"&&"Map CSV columns to object fields.",b==="preview"&&"Review data before importing."]})]}),t.jsx("div",{className:"flex items-center justify-center gap-2 text-xs text-muted-foreground",children:["upload","mapping","preview"].map((W,V)=>t.jsxs($e.Fragment,{children:[V>0&&t.jsx(Fs,{className:"h-3 w-3"}),t.jsxs("span",{className:Z("rounded-full px-3 py-1",b===W?"bg-primary text-primary-foreground":"bg-muted"),children:[V+1,". ",W==="upload"?"Upload":W==="mapping"?"Mapping":"Preview"]})]},W))}),D?t.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[t.jsx(Ni,{className:"h-10 w-10 text-green-500"}),t.jsx("p",{className:"text-lg font-semibold",children:"Import Complete"}),t.jsxs("div",{className:"flex gap-3",children:[t.jsxs(Ke,{variant:"default",children:[D.importedRows," imported"]}),D.skippedRows>0&&t.jsxs(Ke,{variant:"destructive",children:[D.skippedRows," skipped"]})]}),D.errors.length>0&&t.jsxs("div",{className:"max-h-32 w-full overflow-auto rounded border p-2 text-xs",children:[D.errors.slice(0,10).map((W,V)=>t.jsxs("p",{className:"text-destructive",children:["Row ",W.row,W.field?` (${W.field})`:"",": ",W.message]},V)),D.errors.length>10&&t.jsxs("p",{className:"text-muted-foreground",children:["…and ",D.errors.length-10," more errors"]})]})]}):t.jsxs(t.Fragment,{children:[b==="upload"&&t.jsx(Pr,{onFileLoaded:T}),b==="mapping"&&t.jsx(qr,{headers:c,fields:s,mapping:f,onMappingChange:q}),b==="preview"&&t.jsx(Br,{headers:c,rows:j,mapping:f,fields:s}),A&&t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx($n,{value:_,className:"h-2"}),t.jsxs("p",{className:"text-center text-xs text-muted-foreground",children:["Importing… ",_,"%"]})]})]}),t.jsx(Pn,{className:"gap-2 sm:gap-0",children:D?t.jsx(ne,{onClick:O,children:"Close"}):t.jsxs(t.Fragment,{children:[t.jsxs(ne,{variant:"ghost",onClick:O,disabled:A,children:[t.jsx(an,{className:"mr-1 h-4 w-4"})," Cancel"]}),(b==="mapping"||b==="preview")&&t.jsxs(ne,{variant:"outline",onClick:()=>g(b==="mapping"?"upload":"mapping"),disabled:A,children:[t.jsx(Ci,{className:"mr-1 h-4 w-4"})," Back"]}),b==="mapping"&&t.jsxs(ne,{onClick:()=>g("preview"),disabled:Object.keys(f).length===0||v.length>0,children:["Next ",t.jsx(Fs,{className:"ml-1 h-4 w-4"})]}),b==="preview"&&t.jsx(ne,{onClick:B,disabled:A,children:A?"Importing…":`Import ${j.length} Rows`})]})})]})})},mn=({schema:e,...n})=>{const{dataSource:s}=nn()||{};return t.jsx(un,{schema:e,dataSource:s,...n})};Ie.register("object-grid",mn,{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"}]});Ie.register("grid",mn,{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 Ur=({schema:e,...n})=>{const{dataSource:s}=nn()||{};return t.jsx(Kr,{objectName:e.objectName,objectLabel:e.objectLabel,fields:e.fields??[],dataSource:s,...n})};Ie.register("import-wizard",Ur,{namespace:"plugin-grid",label:"Import Wizard",category:"plugin",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"fields",type:"array",label:"Fields",required:!0}]});const Wr={list:"List",detail:"Detail",grid:"Grid",kanban:"Kanban",calendar:"Calendar",timeline:"Timeline",map:"Map",gallery:"Gallery",gantt:"Gantt"},Hr={list:Vi,detail:Ai,grid:Ii,kanban:dn,calendar:It,timeline:Ti,map:Ei,gallery:Di,gantt:Oi},Gr=dt("flex gap-4",{variants:{position:{top:"flex-col",bottom:"flex-col-reverse",left:"flex-row",right:"flex-row-reverse"}},defaultVariants:{position:"top"}}),Yr=dt("w-full",{variants:{orientation:{horizontal:"w-full",vertical:"w-48"}},defaultVariants:{orientation:"horizontal"}}),Jr=dt("flex gap-2",{variants:{orientation:{horizontal:"flex-row flex-wrap",vertical:"flex-col"}},defaultVariants:{orientation:"horizontal"}}),Qr=dt("",{variants:{orientation:{horizontal:"",vertical:"flex h-auto flex-col items-stretch"}},defaultVariants:{orientation:"horizontal"}});function Xr(e){return e.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join("")}const Zr={Home:"House"};function bn(e){if(!e)return null;const n=Xr(e),s=Zr[n]||n;return ki[s]||null}function Kt(e){return e.label?e.label:Wr[e.type]||e.type}function Ps(e){return e.icon?bn(e.icon):Hr[e.type]||null}function el(e){return e.activeView?e.activeView:e.defaultView?e.defaultView:e.views?.[0]?.type}const qs={share:At,settings:Fi,duplicate:as,delete:ls},tl={share:"Share",settings:"Settings",duplicate:"Duplicate",delete:"Delete"},xn=({schema:e,className:n,onViewChange:s,onCreateView:i,onViewAction:r,createViewLabel:d="Create view",...a})=>{const o=l.useMemo(()=>e.storageKey?e.storageKey:`view-switcher${e.id?`-${e.id}`:""}`,[e.id,e.storageKey]),[u,b]=l.useState(()=>el(e));l.useEffect(()=>{if(e.activeView){b(e.activeView);return}if(e.persistPreference)try{const p=localStorage.getItem(o);if(p){const v=e.views.find(T=>T.type===p)?.type;v&&b(v)}}catch{}},[e.activeView,e.persistPreference,e.views,o]),l.useEffect(()=>{if(!(!e.persistPreference||!u||e.activeView))try{localStorage.setItem(o,u)}catch{}},[u,e.activeView,e.persistPreference,o]);const g=l.useCallback(p=>{s?.(p),e.onViewChange&&typeof window<"u"&&window.dispatchEvent(new CustomEvent(e.onViewChange,{detail:{view:p}}))},[s,e.onViewChange]),c=l.useCallback(p=>{b(p),g(p)},[g]),x=u||e.views?.[0]?.type,j=x||"",N=e.views.find(p=>p.type===x)||e.views?.[0],f=e.variant||"tabs",q=e.position||"top",A=q==="left"||q==="right",y=A?"vertical":"horizontal",_=e.viewActions&&e.viewActions.length>0?t.jsx("div",{className:"flex items-center gap-1",children:e.viewActions.map((p,v)=>{const T=p.icon&&bn(p.icon)||qs[p.type];return t.jsx(ne,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>r?.(p.type,x),title:tl[p.type]||p.type,children:T?t.jsx(T,{className:"h-3.5 w-3.5"}):null},`action-${p.type}-${v}`)})}):null,Y=e.allowCreateView?t.jsx(ne,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>i?.(),title:d,children:t.jsx(os,{className:"h-3.5 w-3.5"})}):null,D=t.jsxs("div",{className:Z(Yr({orientation:y}),"flex items-center gap-1"),children:[f==="dropdown"&&t.jsxs(jt,{value:j,onValueChange:p=>c(p),children:[t.jsx(wt,{className:Z("w-full",A?"h-10":"h-9"),children:t.jsx(vt,{placeholder:"Select view"})}),t.jsx(Nt,{children:e.views.map((p,v)=>t.jsx(tt,{value:p.type,children:Kt(p)},`${p.type}-${v}`))})]}),f==="buttons"&&t.jsx("div",{className:Z(Jr({orientation:y})),children:e.views.map((p,v)=>{const T=p.type===x,B=Ps(p);return t.jsxs(ne,{type:"button",size:"sm",variant:T?"secondary":"ghost",className:Z("justify-start gap-2",A?"w-full":""),onClick:()=>c(p.type),children:[B?t.jsx(B,{className:"h-4 w-4"}):null,t.jsx("span",{children:Kt(p)})]},`${p.type}-${v}`)})}),f==="tabs"&&t.jsx(Yt,{value:j,onValueChange:p=>c(p),children:t.jsx(Jt,{className:Z(Qr({orientation:y})),children:e.views.map((p,v)=>{const T=Ps(p);return t.jsxs(Qt,{value:p.type,className:Z("gap-2",A?"justify-start":""),children:[T?t.jsx(T,{className:"h-4 w-4"}):null,t.jsx("span",{children:Kt(p)})]},`${p.type}-${v}`)})})}),_,Y]}),h=N?.schema?Array.isArray(N.schema)?t.jsx("div",{className:"space-y-4",children:N.schema.map((p,v)=>t.jsx(Re,{schema:p,...a},`${N.type}-${v}`))}):t.jsx(Re,{schema:N.schema,...a}):null;return t.jsxs("div",{className:Z(Gr({position:q}),n),children:[t.jsx("div",{className:Z("shrink-0",A?"flex flex-col":"flex"),children:D}),t.jsx("div",{className:"flex-1 min-w-0",children:h})]})};let Et=null;try{Et=require("@object-ui/react").SchemaRenderer||null}catch{}const sl=({schema:e,dataSource:n,className:s,views:i,activeViewId:r,onViewChange:d,onRowClick:a,onEdit:o,renderListView:u,toolbarAddon:b,onCreateView:g,onViewAction:c})=>{const[x,j]=l.useState(null),[N,f]=l.useState(!1),[q,A]=l.useState("create"),[y,_]=l.useState(null),[Y,D]=l.useState(0),[h,p]=l.useState([]),[v,T]=l.useState(!1),[B,U]=l.useState({}),[O,W]=l.useState([]),V=e.listViews,I=V!=null&&Object.keys(V).length>0,[z,K]=l.useState(()=>e.defaultListView&&V?.[e.defaultListView]?e.defaultListView:V&&Object.keys(V)[0]||""),H=l.useMemo(()=>!I||!z?null:V[z]||null,[I,z,V]),se=l.useMemo(()=>i&&i.length>0?i:null,[i]),ee=se!=null&&se.length>0,Ae=r||se?.[0]?.id,S=se?.find(k=>k.id===Ae)||se?.[0],Ne=l.useMemo(()=>H?.type?H.type:S?.type?S.type:e.defaultViewType||"grid",[H,S,e.defaultViewType]),ae=e.navigation;l.useEffect(()=>{let k=!0;const $=async()=>{try{const G=await n.getObjectSchema(e.objectName);k&&j(G)}catch(G){console.error("Failed to fetch object schema:",G)}};return e.objectName&&n&&$(),()=>{k=!1}},[e.objectName,n]),l.useEffect(()=>{let k=!0;return(async()=>{if(!(Ne==="grid"&&!u)&&!(!n||!e.objectName)){T(!0);try{const G=H?.filter||S?.filter||e.table?.defaultFilters||[],Oe=Object.entries(B).filter(([,be])=>be!==void 0&&be!==""&&be!==null).map(([be,zt])=>[be,"=",zt]);let ge=[];G.length>0&&Oe.length>0?ge=["and",...G,...Oe]:Oe.length===1?ge=Oe[0]:Oe.length>1?ge=["and",...Oe]:ge=G;const Le=O.length>0?O.map(be=>({field:be.field,order:be.direction})):H?.sort||S?.sort||e.table?.defaultSort||void 0,he=sn(x?.fields),ve=await n.find(e.objectName,{$filter:ge.length>0?ge:void 0,$orderby:Le,$top:100,...he.length>0?{$expand:he}:{}});let De=[];Array.isArray(ve)?De=ve:ve&&typeof ve=="object"&&(Array.isArray(ve.data)?De=ve.data:Array.isArray(ve.records)&&(De=ve.records)),k&&p(De)}catch(G){console.error("ObjectView data fetch error:",G)}finally{k&&T(!1)}}})(),()=>{k=!1}},[e.objectName,n,Ne,B,O,Y,H,S,u,x]);const ze=e.layout||"drawer",de=e.operations||e.table?.operations||{create:!0,read:!0,update:!0,delete:!0},Me=l.useCallback(()=>{ze==="page"&&e.onNavigate?e.onNavigate("new","edit"):(A("create"),_(null),f(!0))},[ze,e]),we=l.useCallback(k=>{if(o){o(k);return}if(ze==="page"&&e.onNavigate){const $=k._id||k.id;e.onNavigate($,"edit")}else A("edit"),_(k),f(!0)},[ze,e,o]),ke=l.useCallback(k=>{if(ze==="page"&&e.onNavigate){const $=k._id||k.id;e.onNavigate($,"view")}else A("view"),_(k),f(!0)},[ze,e]),F=l.useCallback(k=>{if(a){a(k);return}if(ae){if(ae.mode==="none"||ae.preventNavigation)return;if(ae.mode==="new_window"||ae.openNewTab){const $=k._id||k.id,G=`/${e.objectName}/${$}`;window.open(G,"_blank");return}if(ae.mode==="drawer"){A("view"),_(k),f(!0);return}if(ae.mode==="modal"){A("view"),_(k),f(!0);return}if(ae.mode==="page"){const $=k._id||k.id;e.onNavigate&&e.onNavigate($,"view");return}if(ae.mode==="split"||ae.mode==="popover"){A("view"),_(k),f(!0);return}}de.read!==!1&&ke(k)},[a,ae,de.read,ke,e]),ue=l.useCallback(k=>{D($=>$+1)},[]),me=l.useCallback(k=>{D($=>$+1)},[]),ye=l.useCallback(()=>{f(!1),_(null),D(k=>k+1)},[]),fe=l.useCallback(()=>{f(!1),_(null)},[]);l.useCallback(()=>{D(k=>k+1)},[]);const xe=l.useMemo(()=>!ee||!se||se.length<=1?null:{type:"view-switcher",variant:"tabs",position:"top",persistPreference:!0,storageKey:`view-pref-${e.objectName}`,defaultView:S?.type||"grid",activeView:S?.type||"grid",views:se.map(k=>{const $={kanban:"kanban",calendar:"calendar",map:"map",gallery:"layout-grid",timeline:"activity",gantt:"gantt-chart",grid:"table",list:"list",detail:"file-text"};return{type:k.type,label:k.label,icon:$[k.type]||"table"}}),allowCreateView:e.allowCreateView,viewActions:e.viewActions},[ee,se,S,e.objectName,e.allowCreateView,e.viewActions]),Ce=l.useCallback(k=>{if(!se)return;const $=se.find(G=>G.type===k);$&&d&&d($.id)},[se,d]),Ct=l.useCallback(k=>{K(k)},[]);l.useMemo(()=>{if(e.showFilters===!1)return null;const k=e.filterableFields,$=x?.fields||{},Oe=(k?k.map(ge=>[ge,$[ge]||{label:ge}]):Object.entries($).filter(([,ge])=>!ge.hidden).slice(0,8)).map(([ge,Le])=>{const he=Le.type||"text";let ve="text",De;return he==="number"||he==="currency"||he==="percent"?ve="number":he==="boolean"||he==="toggle"?ve="boolean":he==="date"||he==="datetime"?ve="date":he==="select"||he==="status"||Le.options?(ve="select",De=(Le.options||[]).map(be=>typeof be=="string"?{label:be,value:be}:{label:be.label,value:be.value})):(he==="lookup"||he==="master_detail"||he==="user"||he==="owner")&&Le.options&&Le.options.length>0&&(ve="multi-select",De=(Le.options||[]).map(be=>typeof be=="string"?{label:be,value:be}:{label:be.label,value:be.value})),{field:ge,label:Le.label||ge,type:ve,placeholder:`Filter ${Le.label||ge}...`,...De?{options:De}:{}}});return Oe.length===0?null:{type:"filter-ui",layout:"popover",showClear:!0,showApply:!0,filters:Oe,values:B}},[e.showFilters,e.filterableFields,x,B]);const nt=e.showSort;l.useMemo(()=>{if(nt===!1)return null;const k=x?.fields||{},$=Object.entries(k).filter(([,G])=>!G.hidden).slice(0,10).map(([G,Oe])=>({field:G,label:Oe.label||G}));return $.length===0?null:{type:"sort-ui",variant:"dropdown",multiple:!1,fields:$,sort:O}},[x,O,nt]);const it=l.useCallback(k=>{const $={objectName:e.objectName,fields:H?.columns||S?.columns||e.table?.fields,className:"h-full w-full",showSearch:S?.showSearch??e.showSearch??!1,showSort:S?.showSort??e.showSort??!1,showFilters:S?.showFilters??e.showFilters??!1,striped:S?.striped??!1,bordered:S?.bordered??!1,color:S?.color},G=H?.options||S||{};switch(k){case"kanban":return{type:"object-kanban",...$,groupBy:G.kanban?.groupField||"status",groupField:G.kanban?.groupField||"status",titleField:G.kanban?.titleField||"name",cardFields:$.fields||[],...G.kanban||{}};case"calendar":return{type:"object-calendar",...$,startDateField:G.calendar?.startDateField||"start_date",endDateField:G.calendar?.endDateField||"end_date",titleField:G.calendar?.titleField||"name",...G.calendar||{}};case"gallery":return{type:"object-gallery",...$,imageField:G.gallery?.imageField,titleField:G.gallery?.titleField||"name",subtitleField:G.gallery?.subtitleField,...G.gallery||{}};case"timeline":return{type:"object-timeline",...$,dateField:G.timeline?.dateField||"created_at",titleField:G.timeline?.titleField||"name",...G.timeline||{}};case"gantt":return{type:"object-gantt",...$,startDateField:G.gantt?.startDateField||"start_date",endDateField:G.gantt?.endDateField||"end_date",progressField:G.gantt?.progressField||"progress",dependenciesField:G.gantt?.dependenciesField||"dependencies",...G.gantt||{}};case"map":return{type:"object-map",...$,locationField:G.map?.locationField||"location",...G.map||{}};default:return null}},[e.objectName,e.table?.fields,H,S]),Je=l.useMemo(()=>({type:"object-grid",objectName:e.objectName,title:e.table?.title,description:e.table?.description,fields:H?.columns||S?.columns||e.table?.fields,columns:H?.columns||S?.columns||e.table?.columns,operations:{...de,create:!1},defaultFilters:H?.filter||S?.filter||e.table?.defaultFilters,defaultSort:H?.sort||S?.sort||e.table?.defaultSort,pageSize:e.table?.pageSize,selectable:e.table?.selectable,striped:S?.striped??e.table?.striped,bordered:S?.bordered??e.table?.bordered,className:e.table?.className}),[e,de,H,S]),je=()=>{const k=y?y._id||y.id:void 0;return{type:"object-form",objectName:e.objectName,mode:q,recordId:k,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||q==="view",className:e.form?.className,onSuccess:ye,onCancel:fe}},ce=()=>{if(e.form?.title)return e.form.title;const k=x?.label||e.objectName;switch(q){case"create":return`Create ${k}`;case"edit":return`Edit ${k}`;case"view":return`View ${k}`;default:return k}},Pe=l.useMemo(()=>{const k=ae?.width;return k?typeof k=="number"?`max-w-[${k}px]`:`max-w-[${k}]`:""},[ae]),ut=()=>t.jsx(Qs,{open:N,onOpenChange:f,direction:"right",children:t.jsxs(Xs,{className:Z("w-full sm:max-w-2xl",Pe),children:[t.jsxs(Zs,{children:[t.jsx(en,{children:ce()}),e.form?.description&&t.jsx(tn,{children:e.form.description})]}),t.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:t.jsx(yt,{schema:je(),dataSource:n})})]})}),Ue=()=>t.jsx(Xt,{open:N,onOpenChange:f,children:t.jsxs(Hs,{className:Z("max-w-2xl max-h-[90vh] overflow-y-auto",Pe),children:[t.jsxs(Zt,{children:[t.jsx(es,{children:ce()}),e.form?.description&&t.jsx(ts,{children:e.form.description})]}),t.jsx(yt,{schema:je(),dataSource:n})]})}),Rt=l.useMemo(()=>Object.keys(B).some($=>B[$]!==void 0&&B[$]!==""&&B[$]!==null)?Object.entries(B).filter(([,$])=>$!==void 0&&$!==""&&$!==null).map(([$,G])=>({field:$,operator:"equals",value:G})):H?.filter||S?.filter||e.table?.defaultFilters,[B,H,S,e.table?.defaultFilters]),cs=l.useMemo(()=>O.length>0?O:H?.sort||S?.sort||e.table?.defaultSort,[O,H,S,e.table?.defaultSort]),qe=()=>{const k=`${e.objectName}-${z||S?.id||"default"}-${Ne}-${Y}`;if(u)return u({schema:{type:"list-view",objectName:e.objectName,viewType:Ne,fields:H?.columns||S?.columns||e.table?.fields,filters:Rt,sort:cs,rowHeight:S?.rowHeight,densityMode:S?.densityMode,groupBy:S?.groupBy,options:H?.options||S,showSearch:S?.showSearch??e.showSearch,showFilters:S?.showFilters??e.showFilters,showSort:S?.showSort??e.showSort,showHideFields:S?.showHideFields??e.showHideFields,showGroup:S?.showGroup??e.showGroup,showColor:S?.showColor??e.showColor,showDensity:S?.showDensity??e.showDensity,allowExport:S?.allowExport??e.allowExport,striped:S?.striped??e.striped,bordered:S?.bordered??e.bordered,color:S?.color??e.color,inlineEdit:S?.inlineEdit??e.inlineEdit,wrapHeaders:S?.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:S?.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:S?.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:S?.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:S?.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:S?.fieldTextColor??e.fieldTextColor,prefixField:S?.prefixField??e.prefixField,showDescription:S?.showDescription??e.showDescription,navigation:S?.navigation??e.navigation,selection:S?.selection??e.selection,pagination:S?.pagination??e.pagination,searchableFields:S?.searchableFields??e.searchableFields,filterableFields:S?.filterableFields??e.filterableFields,resizable:S?.resizable??e.resizable,hiddenFields:S?.hiddenFields??e.hiddenFields,rowActions:S?.rowActions??e.rowActions,bulkActions:S?.bulkActions??e.bulkActions,sharing:S?.sharing??e.sharing,addRecord:S?.addRecord??e.addRecord,conditionalFormatting:S?.conditionalFormatting??e.conditionalFormatting,quickFilters:S?.quickFilters??e.quickFilters,showRecordCount:S?.showRecordCount??e.showRecordCount,allowPrinting:S?.allowPrinting??e.allowPrinting,virtualScroll:S?.virtualScroll??e.virtualScroll,emptyState:S?.emptyState??e.emptyState,aria:S?.aria??e.aria,tabs:e.tabs},dataSource:n,onEdit:we,onRowClick:F,className:"h-full"});if(Ne!=="grid"){const $=it(Ne);if($&&Et)return t.jsx(Et,{schema:$,dataSource:n,data:h,loading:v},k);if(!Et)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 ",Ne," views."]})})}return t.jsx(un,{schema:Je,dataSource:n,onRowClick:F,onEdit:de.update!==!1?we:void 0,onDelete:de.delete!==!1?ue:void 0,onBulkDelete:de.delete!==!1?me:void 0},k)},Be=()=>{if(!I)return null;const k=Object.entries(V);return k.length<=1?null:t.jsx(Yt,{value:z,onValueChange:Ct,className:"w-full",children:t.jsx(Jt,{className:"w-auto",children:k.map(([$,G])=>t.jsx(Qt,{value:$,className:"text-sm",children:G.label||$},$))})})},ft=()=>{const k=e.showCreate!==!1&&de.create!==!1,$=e.showViewSwitcher===!0,G=Be();return!G&&!$&&!k&&!b?null:t.jsxs("div",{className:"flex flex-col gap-3",children:[G,($||k||b)&&t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("div",{className:"flex items-center gap-2",children:$&&xe&&t.jsx(xn,{schema:xe,onViewChange:Ce,onCreateView:g,onViewAction:c,className:"overflow-x-auto"})}),t.jsxs("div",{className:"flex items-center gap-2",children:[b,k&&t.jsxs(ne,{size:"sm",onClick:Me,children:[t.jsx(os,{className:"h-4 w-4"}),"Create"]})]})]})]})},rt=ae?.mode==="modal"?"modal":ae?.mode==="drawer"?"drawer":ae?.mode==="split"?"split":ae?.mode==="popover"?"popover":ze,Qe=k=>t.jsx("div",{className:"space-y-3",children:t.jsx(yt,{schema:je(),dataSource:n})}),lt=l.useCallback(k=>{k||fe()},[fe]);if(rt==="split"){const k=x?.label||e.objectName;return t.jsxs("div",{className:Z("flex flex-col h-full min-w-0 overflow-hidden",s),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:ft()}),t.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:N&&y?t.jsx(xt,{isOpen:N,selectedRecord:y,mode:"split",close:fe,setIsOpen:lt,width:ae?.width,isOverlay:!0,title:`${k} Detail`,mainContent:t.jsx("div",{className:"h-full overflow-auto",children:qe()}),children:Qe}):qe()})]})}return t.jsxs("div",{className:Z("flex flex-col h-full min-w-0 overflow-hidden",s),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:ft()}),t.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:qe()}),rt==="drawer"&&ut(),rt==="modal"&&Ue(),rt==="popover"&&N&&y&&t.jsx(xt,{isOpen:N,selectedRecord:y,mode:"popover",close:fe,setIsOpen:lt,width:ae?.width,isOverlay:!0,title:ce(),children:Qe})]})},Ut=dt("flex",{variants:{layout:{inline:"flex-col space-y-4",popover:"items-center",drawer:"items-center"}},defaultVariants:{layout:"inline"}}),nl=e=>e==null||e===""?!0:Array.isArray(e)?e.length===0:typeof e=="object"?Object.values(e).every(n=>n==null||n===""):!1,il=e=>Array.isArray(e)?{start:e[0]||"",end:e[1]||""}:e&&typeof e=="object"?{start:e.start||"",end:e.end||""}:{start:"",end:""},rl=({schema:e,className:n,onChange:s})=>{const[i,r]=l.useState(e.values||{}),[d,a]=l.useState(!1);l.useEffect(()=>{e.values&&r(e.values)},[e.values]);const o=l.useCallback(f=>{s?.(f),e.onChange&&typeof window<"u"&&window.dispatchEvent(new CustomEvent(e.onChange,{detail:{values:f}}))},[s,e.onChange]),u=l.useCallback((f,q)=>{const A={...i,[f]:q};r(A),e.showApply||o(A)},[o,e.showApply,i]),b=l.useCallback(()=>{const f={};if(r(f),e.showApply){o(f);return}o(f)},[o,e.showApply]),g=l.useCallback(()=>{o(i),a(!1)},[o,i]),c=l.useMemo(()=>Object.values(i).filter(f=>!nl(f)).length,[i]),x=f=>{const q=f.label||f.field,A=f.placeholder||`Filter by ${q}`;switch(f.type){case"number":return t.jsx(He,{type:"number",value:i[f.field]??"",placeholder:A,onChange:y=>{const _=y.target.value,Y=_===""?"":Number(_);u(f.field,Y)}});case"select":return t.jsxs(jt,{value:i[f.field]!==void 0?String(i[f.field]):"",onValueChange:y=>{const _=f.options?.find(Y=>String(Y.value)===y);u(f.field,_?_.value:y)},children:[t.jsx(wt,{children:t.jsx(vt,{placeholder:A})}),t.jsx(Nt,{children:f.options?.map(y=>t.jsx(tt,{value:String(y.value),children:y.label},String(y.value)))})]});case"multi-select":{const y=i[f.field],_=Array.isArray(y)?y:y?[y]:[];return t.jsx("div",{className:"max-h-40 overflow-y-auto space-y-0.5 border rounded-md p-2",children:f.options?.map(Y=>{const D=_.map(String).includes(String(Y.value));return t.jsxs("label",{className:Z("flex items-center gap-2 text-sm py-1 px-1.5 rounded cursor-pointer",D?"bg-primary/5 text-primary":"hover:bg-muted"),children:[t.jsx(gs,{checked:D,onCheckedChange:h=>{const p=h?[..._,Y.value]:_.filter(v=>String(v)!==String(Y.value));u(f.field,p)}}),t.jsx("span",{className:"truncate",children:Y.label})]},String(Y.value))})})}case"date":return t.jsx(He,{type:"date",value:i[f.field]??"",onChange:y=>u(f.field,y.target.value)});case"date-range":{const y=il(i[f.field]);return t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(He,{type:"date",value:y.start??"",onChange:_=>{u(f.field,{...y,start:_.target.value})}}),t.jsx(He,{type:"date",value:y.end??"",onChange:_=>{u(f.field,{...y,end:_.target.value})}})]})}case"boolean":return t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(gs,{checked:!!i[f.field],onCheckedChange:y=>u(f.field,!!y)}),t.jsx("span",{className:"text-sm text-muted-foreground",children:"Enabled"})]});case"text":default:return t.jsx(He,{value:i[f.field]??"",placeholder:A,onChange:y=>u(f.field,y.target.value)})}},j=t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"grid gap-4 sm:grid-cols-2",children:e.filters.map(f=>t.jsxs("div",{className:"space-y-2",children:[t.jsx(qn,{className:"text-xs text-muted-foreground",children:f.label||f.field}),x(f)]},f.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(ne,{type:"button",variant:"ghost",size:"sm",onClick:b,children:"Clear"}),e.showApply&&t.jsx(ne,{type:"button",size:"sm",onClick:g,children:"Apply"})]})]}),N=e.layout||"inline";return N==="popover"?t.jsx("div",{className:Z(Ut({layout:N}),n),children:t.jsxs(ss,{open:d,onOpenChange:a,children:[t.jsx(ns,{asChild:!0,children:t.jsxs(ne,{type:"button",variant:c>0?"secondary":"outline",size:"sm",className:"gap-2",children:[t.jsx(ks,{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(is,{align:"start",className:"w-[520px] p-4",children:j})]})}):N==="drawer"?t.jsxs("div",{className:Z(Ut({layout:N}),n),children:[t.jsxs(ne,{type:"button",variant:c>0?"secondary":"outline",size:"sm",className:"gap-2",onClick:()=>a(!0),children:[t.jsx(ks,{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(Qs,{open:d,onOpenChange:a,children:t.jsxs(Xs,{children:[t.jsxs(Zs,{children:[t.jsx(en,{children:"Filters"}),t.jsx(tn,{children:"Refine the data with advanced filters."})]}),t.jsx("div",{className:"px-4 pb-6",children:j})]})})]}):t.jsxs("div",{className:Z(Ut({layout:N}),n),children:[j,!e.showApply&&e.showClear&&t.jsxs(ne,{type:"button",variant:"ghost",size:"sm",className:"gap-2",onClick:b,children:[t.jsx(an,{className:"h-3.5 w-3.5"}),"Clear filters"]})]})},Wt=dt("",{variants:{variant:{buttons:"flex flex-wrap gap-2",dropdown:"flex flex-wrap items-center gap-3",builder:"space-y-3"}},defaultVariants:{variant:"dropdown"}}),Ht=e=>e?e.map(n=>({field:n.field,direction:n.direction})):[],Bs=e=>e.map(n=>({id:`${n.field}-${n.direction}`,field:n.field,order:n.direction})),ll=e=>e.filter(n=>n.field).map(n=>({field:n.field,direction:n.order})),al=({schema:e,className:n,onChange:s})=>{const[i,r]=l.useState(()=>Ht(e.sort)),[d,a]=l.useState(()=>Bs(Ht(e.sort)));l.useEffect(()=>{const c=Ht(e.sort);r(c),a(Bs(c))},[e.sort]);const o=l.useCallback(c=>{r(c),s?.(c),e.onChange&&typeof window<"u"&&window.dispatchEvent(new CustomEvent(e.onChange,{detail:{sort:c}}))},[s,e.onChange]),u=l.useCallback(c=>{const x=i.find(f=>f.field===c),j=!!e.multiple;if(!x){const f=j?[...i,{field:c,direction:"asc"}]:[{field:c,direction:"asc"}];o(f);return}if(x.direction==="asc"){const f=i.map(q=>q.field===c?{...q,direction:"desc"}:q);o(f);return}const N=i.filter(f=>f.field!==c);o(N)},[o,e.multiple,i]);if((e.variant||"dropdown")==="buttons")return t.jsx("div",{className:Z(Wt({variant:"buttons"}),n),children:e.fields.map(c=>{const x=i.find(N=>N.field===c.field),j=x?.direction==="asc"?Ri:zi;return t.jsxs(ne,{type:"button",variant:x?"secondary":"outline",size:"sm",onClick:()=>u(c.field),className:"gap-2",children:[t.jsx("span",{children:c.label||c.field}),x&&t.jsx(j,{className:"h-3.5 w-3.5"})]},c.field)})});if(e.multiple)return t.jsx("div",{className:Z(Wt({variant:"builder"}),n),children:t.jsx(Bn,{fields:e.fields.map(c=>({value:c.field,label:c.label||c.field})),value:d,onChange:c=>{a(c),o(ll(c))}})});const g=i[0];return t.jsxs("div",{className:Z(Wt({variant:"dropdown"}),n),children:[t.jsxs(jt,{value:g?.field||"",onValueChange:c=>{if(!c){o([]);return}o([{field:c,direction:g?.direction||"asc"}])},children:[t.jsx(wt,{className:"w-56",children:t.jsx(vt,{placeholder:"Select field"})}),t.jsx(Nt,{children:e.fields.map(c=>t.jsx(tt,{value:c.field,children:c.label||c.field},c.field))})]}),t.jsxs(jt,{value:g?.direction||"asc",onValueChange:c=>{g?.field&&o([{field:g.field,direction:c}])},children:[t.jsx(wt,{className:"w-36",children:t.jsx(vt,{})}),t.jsxs(Nt,{children:[t.jsx(tt,{value:"asc",children:"Ascending"}),t.jsx(tt,{value:"desc",children:"Descending"})]})]})]})};function ol(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto<"u"&&typeof crypto.getRandomValues=="function"){const e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,n=>n.toString(16).padStart(2,"0")).join("")}return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}function dl(e,n,s,i){return`${e}/share/${n}/${s}?mode=readonly&token=${i}`}const cl=({objectName:e,viewId:n="default",baseUrl:s,onShare:i,className:r})=>{const[d,a]=l.useState(null),[o,u]=l.useState(!1),[b,g]=l.useState(!1),[c,x]=l.useState(""),[j,N]=l.useState(""),f=s??(typeof window<"u"?window.location.origin:""),q=l.useCallback(()=>{const y=ol(),_=dl(f,e,n,y);a(_),u(!1);const Y=j?new Date(Date.now()+parseInt(j,10)*864e5).toISOString():void 0;i?.(_,{password:c||void 0,expiresAt:Y})},[f,e,n,i,c,j]),A=l.useCallback(async()=>{if(d)try{await navigator.clipboard.writeText(d),u(!0),setTimeout(()=>u(!1),2e3)}catch{const y=document.createElement("textarea");y.value=d,document.body.appendChild(y),y.select(),document.execCommand("copy"),document.body.removeChild(y),u(!0),setTimeout(()=>u(!1),2e3)}},[d]);return t.jsxs(ss,{open:b,onOpenChange:g,children:[t.jsx(ns,{asChild:!0,children:t.jsxs(ne,{variant:"outline",size:"sm",className:Z("gap-2",r),children:[t.jsx(At,{className:"h-4 w-4"}),"Share"]})}),t.jsxs(is,{className:"w-96 space-y-4",align:"end",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h4",{className:"text-sm font-medium",children:"Share View"}),t.jsx(Ke,{variant:"secondary",className:"text-xs",children:"Read-only"})]}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Generate a public link to share this view. Recipients can view data without logging in."})]}),d?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(He,{value:d,readOnly:!0,className:"h-8 text-xs",onClick:y=>y.target.select()}),t.jsx(ne,{variant:"outline",size:"sm",onClick:A,className:"shrink-0 gap-1",children:o?t.jsx(ln,{className:"h-4 w-4 text-green-500"}):t.jsx(as,{className:"h-4 w-4"})})]}),(c||j)&&t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c&&t.jsxs(Ke,{variant:"outline",className:"text-xs gap-1",children:[t.jsx(Gt,{className:"h-3 w-3"}),"Password protected"]}),j&&t.jsxs(Ke,{variant:"outline",className:"text-xs gap-1",children:[t.jsx(It,{className:"h-3 w-3"}),"Expires in ",j," day",j!=="1"?"s":""]})]})]}):t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("label",{className:"flex items-center gap-1.5 text-xs font-medium text-foreground",children:[t.jsx(Gt,{className:"h-3.5 w-3.5"}),"Password protection (optional)"]}),t.jsx(He,{type:"password",value:c,onChange:y=>x(y.target.value),placeholder:"Enter password...",className:"h-8 text-xs"})]}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("label",{className:"flex items-center gap-1.5 text-xs font-medium text-foreground",children:[t.jsx(It,{className:"h-3.5 w-3.5"}),"Expires after (optional)"]}),t.jsxs("select",{value:j,onChange:y=>N(y.target.value),className:"w-full h-8 text-xs rounded-md border border-input bg-background px-3",children:[t.jsx("option",{value:"",children:"Never"}),t.jsx("option",{value:"1",children:"1 day"}),t.jsx("option",{value:"7",children:"7 days"}),t.jsx("option",{value:"30",children:"30 days"}),t.jsx("option",{value:"90",children:"90 days"})]})]}),t.jsxs(ne,{onClick:q,className:"w-full gap-2",size:"sm",children:[t.jsx(At,{className:"h-4 w-4"}),"Generate Link"]})]})]})]})},Ot={private:0,team:1,organization:2,public:3},ul=5,fl=({id:e,disabled:n,children:s})=>{const{attributes:i,listeners:r,setNodeRef:d,transform:a,transition:o,isDragging:u}=di({id:e,disabled:n}),b={transform:ci.Transform.toString(a),transition:o,zIndex:u?10:void 0,opacity:u?.5:void 0};return t.jsx(t.Fragment,{children:s({setNodeRef:d,style:b,listeners:r,attributes:i,isDragging:u})})},Fl=({views:e,activeViewId:n,onViewChange:s,viewTypeIcons:i={},config:r={},onAddView:d,onRenameView:a,onDuplicateView:o,onDeleteView:u,onSetDefaultView:b,onShareView:g,onSaveAsView:c,onPinView:x,onReorderViews:j,onChangeViewType:N,onConfigView:f,availableViewTypes:q,hasUnsavedChanges:A=!1,onResetChanges:y,className:_})=>{const{showAddButton:Y=!0,inlineRename:D=!0,contextMenu:h=!0,reorderable:p=!1,maxVisibleTabs:v=6,showIndicators:T=!0,showSaveAsView:B=!0,showPinnedSection:U=!0,showVisibilityGroups:O=!1}=r,[W,V]=l.useState(null),[I,z]=l.useState(""),K=l.useRef(null);l.useEffect(()=>{W&&K.current&&(K.current.focus(),K.current.select())},[W]);const H=l.useCallback(F=>{if(!D||!a)return;const ue=e.find(me=>me.id===F);ue&&(V(F),z(ue.label))},[D,a,e]),se=l.useCallback(()=>{W&&I.trim()&&a&&a(W,I.trim()),V(null),z("")},[W,I,a]),ee=l.useCallback(()=>{V(null),z("")},[]),Ae=l.useMemo(()=>{const F=[...e];return F.sort((ue,me)=>{if(U){const ye=ue.isPinned?1:0,fe=me.isPinned?1:0;if(ye!==fe)return fe-ye}if(O){const ye=Ot[ue.visibility||"public"]??Ot.public,fe=Ot[me.visibility||"public"]??Ot.public;if(ye!==fe)return ye-fe}return 0}),F},[e,U,O]),S=Ae.slice(0,v),Ne=Ae.slice(v),ae=ti(Ns(ni,{activationConstraint:{distance:ul}}),Ns(si)),ze=l.useCallback(F=>{const{active:ue,over:me}=F;if(!me||ue.id===me.id||!j)return;const ye=Ae.findIndex(Ce=>Ce.id===ue.id),fe=Ae.findIndex(Ce=>Ce.id===me.id);if(ye===-1||fe===-1)return;const xe=ii(Ae,ye,fe);j(xe.map(Ce=>Ce.id))},[Ae,j]),de=Li,Me=l.useCallback(F=>{if(!O||F===0)return!1;const ue=S[F-1],me=S[F],ye=fe=>fe.visibility==="private";return ye(ue)&&!ye(me)},[O,S]),we=(F,ue)=>{const me=F.id===n,ye=i[F.type]||de,fe=W===F.id,xe=T&&(F.hasActiveFilters||F.hasActiveSort),Ce=Me(ue),nt=(je=>O?je.visibility==="private"?t.jsx(Gt,{"data-testid":`view-tab-visibility-${je.id}`,className:"h-3 w-3 text-muted-foreground shrink-0"}):je.visibility?t.jsx($i,{"data-testid":`view-tab-visibility-${je.id}`,className:"h-3 w-3 text-muted-foreground shrink-0"}):null:null)(F),it=je=>t.jsxs("button",{"data-testid":`view-tab-${F.id}`,onClick:()=>!fe&&s(F.id),onDoubleClick:()=>H(F.id),className:Z("inline-flex items-center gap-1.5 px-3 py-2 text-sm font-medium border-b-2 transition-colors whitespace-nowrap relative",me?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground hover:border-border"),children:[p&&j&&t.jsx("span",{"data-testid":`view-tab-drag-handle-${F.id}`,className:"cursor-grab active:cursor-grabbing text-muted-foreground hover:text-foreground",...je?.listeners??{},...je?.attributes??{},children:t.jsx(Bi,{className:"h-3 w-3"})}),U&&F.isPinned&&t.jsx(qt,{"data-testid":`view-tab-pin-indicator-${F.id}`,className:"h-3 w-3 text-primary shrink-0"}),nt,t.jsx(ye,{className:"h-3.5 w-3.5"}),fe?t.jsx(He,{ref:K,"data-testid":`view-tab-rename-input-${F.id}`,value:I,onChange:ce=>z(ce.target.value),onBlur:se,onKeyDown:ce=>{ce.key==="Enter"&&se(),ce.key==="Escape"&&ee()},className:"h-5 w-24 px-1 py-0 text-sm border-none focus-visible:ring-1",onClick:ce=>ce.stopPropagation()}):t.jsx("span",{children:F.label}),xe&&t.jsxs(ys,{children:[t.jsx(js,{asChild:!0,children:t.jsx("span",{"data-testid":`view-tab-indicator-${F.id}`,className:"ml-1 inline-flex items-center justify-center h-4 min-w-[16px] rounded-full bg-primary/15 text-[10px] font-medium text-primary px-1 shrink-0",children:[F.hasActiveFilters&&"F",F.hasActiveSort&&"S"].filter(Boolean).join("")})}),t.jsx(ws,{side:"bottom",className:"text-xs",children:[F.hasActiveFilters&&"Active filters",F.hasActiveSort&&"Active sort"].filter(Boolean).join(", ")})]}),F.isDefault&&t.jsx(Os,{className:"h-3 w-3 text-amber-500 fill-amber-500 shrink-0"}),me&&f&&t.jsx("button",{type:"button","data-testid":`view-tab-config-${F.id}`,className:"ml-0.5 h-4 w-4 flex items-center justify-center rounded hover:bg-accent shrink-0 opacity-60 hover:opacity-100 transition-opacity",onClick:ce=>{ce.stopPropagation(),f(F.id)},"aria-label":`Configure ${F.label}`,children:t.jsx(Ki,{className:"h-3 w-3"})})]}),Je=je=>!h||fe?je:t.jsxs(Un,{children:[t.jsx(Wn,{asChild:!0,children:je}),t.jsxs(Hn,{children:[a&&t.jsxs(et,{"data-testid":`context-menu-rename-${F.id}`,onClick:()=>H(F.id),children:[t.jsx(Pi,{className:"h-4 w-4 mr-2"})," Rename"]}),o&&t.jsxs(et,{"data-testid":`context-menu-duplicate-${F.id}`,onClick:()=>o(F.id),children:[t.jsx(as,{className:"h-4 w-4 mr-2"})," Duplicate View"]}),g&&t.jsxs(et,{"data-testid":`context-menu-share-${F.id}`,onClick:()=>g(F.id),children:[t.jsx(At,{className:"h-4 w-4 mr-2"})," Share View"]}),b&&t.jsxs(et,{"data-testid":`context-menu-default-${F.id}`,onClick:()=>b(F.id),children:[t.jsx(Os,{className:"h-4 w-4 mr-2"})," Set as Default"]}),x&&t.jsx(et,{"data-testid":`context-menu-pin-${F.id}`,onClick:()=>x(F.id,!F.isPinned),children:F.isPinned?t.jsxs(t.Fragment,{children:[t.jsx(qi,{className:"h-4 w-4 mr-2"})," Unpin View"]}):t.jsxs(t.Fragment,{children:[t.jsx(qt,{className:"h-4 w-4 mr-2"})," Pin View"]})}),N&&q&&q.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(vs,{}),t.jsxs(Gn,{children:[t.jsxs(Yn,{"data-testid":`context-menu-change-type-${F.id}`,children:[t.jsx(dn,{className:"h-4 w-4 mr-2"})," Change View Type"]}),t.jsx(Jn,{"data-testid":`context-menu-type-submenu-${F.id}`,children:q.map(ce=>{const Pe=i[ce.type]||de;return t.jsxs(et,{"data-testid":`context-menu-type-${F.id}-${ce.type}`,disabled:ce.type===F.type,onClick:()=>N(F.id,ce.type),children:[t.jsx(Pe,{className:"h-4 w-4 mr-2"}),t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{children:ce.label}),ce.description&&t.jsx("span",{className:"text-xs text-muted-foreground",children:ce.description})]})]},ce.type)})})]})]}),u&&t.jsxs(t.Fragment,{children:[t.jsx(vs,{}),t.jsxs(et,{"data-testid":`context-menu-delete-${F.id}`,onClick:()=>u(F.id),className:"text-destructive focus:text-destructive",children:[t.jsx(ls,{className:"h-4 w-4 mr-2"})," Delete View"]})]})]})]});return p&&j?t.jsxs($e.Fragment,{children:[Ce&&t.jsx("div",{"data-testid":"view-tab-visibility-separator",className:"w-px h-5 bg-border mx-1 self-center shrink-0"}),t.jsx(fl,{id:F.id,children:({setNodeRef:je,style:ce,listeners:Pe,attributes:ut,isDragging:Ue})=>t.jsx("div",{ref:je,style:ce,className:Z("flex",Ue&&"z-10"),children:Je(it({listeners:Pe,attributes:ut}))})})]},F.id):t.jsxs($e.Fragment,{children:[Ce&&t.jsx("div",{"data-testid":"view-tab-visibility-separator",className:"w-px h-5 bg-border mx-1 self-center shrink-0"}),Je(it())]},F.id)},ke=t.jsx(t.Fragment,{children:S.map((F,ue)=>we(F,ue))});return t.jsx(Kn,{children:t.jsxs("div",{"data-testid":"view-tab-bar",className:Z("flex items-center gap-0.5 -mb-px",_),children:[p&&j?t.jsx(ri,{sensors:ae,collisionDetection:li,onDragEnd:ze,children:t.jsx(ai,{items:S.map(F=>F.id),strategy:oi,children:t.jsx("div",{"data-testid":"view-tab-sortable-container",className:"flex items-center gap-0.5",children:ke})})}):ke,Ne.length>0&&t.jsxs(Ks,{children:[t.jsx(Us,{asChild:!0,children:t.jsxs("button",{"data-testid":"view-tab-overflow",className:"inline-flex items-center gap-1 px-2 py-2 text-sm text-muted-foreground hover:text-foreground transition-colors",children:[t.jsx(Mi,{className:"h-4 w-4"}),t.jsxs("span",{className:"text-xs",children:[Ne.length," more"]})]})}),t.jsx(Ws,{align:"end",children:Ne.map(F=>{const ue=i[F.type]||de;return t.jsxs(Dt,{"data-testid":`view-tab-overflow-${F.id}`,onClick:()=>s(F.id),children:[F.isPinned&&t.jsx(qt,{className:"h-3 w-3 mr-1 text-primary shrink-0"}),t.jsx(ue,{className:"h-4 w-4 mr-2"}),F.label,T&&(F.hasActiveFilters||F.hasActiveSort)&&t.jsx("span",{className:"ml-auto inline-flex items-center justify-center h-4 min-w-[16px] rounded-full bg-primary/15 text-[10px] font-medium text-primary px-1",children:[F.hasActiveFilters&&"F",F.hasActiveSort&&"S"].filter(Boolean).join("")})]},F.id)})})]}),Y&&d&&t.jsxs(ys,{children:[t.jsx(js,{asChild:!0,children:t.jsx("button",{"data-testid":"view-tab-add",onClick:d,className:"inline-flex items-center px-2 py-2 text-muted-foreground hover:text-foreground transition-colors",children:t.jsx(os,{className:"h-4 w-4"})})}),t.jsx(ws,{children:"Add View"})]}),B&&A&&t.jsxs("div",{"data-testid":"view-tab-save-as",className:"flex items-center gap-1 ml-2 text-xs text-amber-600 dark:text-amber-400",children:[t.jsx(_i,{className:"h-3.5 w-3.5"}),t.jsx("span",{className:"hidden sm:inline",children:"Unsaved changes"}),c&&t.jsx(ne,{variant:"ghost",size:"sm","data-testid":"view-tab-save-as-btn",className:"h-6 px-2 text-xs",onClick:c,children:"Save as View"}),y&&t.jsx(ne,{variant:"ghost",size:"sm","data-testid":"view-tab-reset-btn",className:"h-6 px-2 text-xs",onClick:y,children:"Reset"})]})]})})},pl=$e.createContext(null);let hn=pl;try{const e=require("@object-ui/react");e.SchemaRendererContext&&(hn=e.SchemaRendererContext)}catch{}const gn=({schema:e})=>{const s=l.useContext(hn)?.dataSource??null;return t.jsx(sl,{schema:e,dataSource:s})};Ie.register("object-view",gn,{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}});Ie.register("view",gn,{namespace:"plugin-view",label:"View",category:"view"});Ie.register("view-switcher",xn,{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"}}]}});Ie.register("filter-ui",rl,{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"}]}});Ie.register("sort-ui",al,{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"}]}});Ie.register("shared-view-link",cl,{namespace:"view",label:"Shared View Link",category:"view",icon:"Share2",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"viewId",type:"string",label:"View ID"},{name:"baseUrl",type:"string",label:"Base URL"}],defaultProps:{objectName:"objects",viewId:"default"}});const ml=({schema:e,className:n,children:s,dataSource:i,...r})=>{const d=e.props?.columns?{display:"grid",gridTemplateColumns:`repeat(${e.props.columns}, 1fr)`,gap:"1rem"}:void 0;return t.jsx("div",{className:n,style:d,...r,children:s})};Ie.register("view:simple",ml,{namespace:"plugin-view",label:"Simple View",category:"view"});export{nr as M,sl as O,Fl as V,Sl as u};