@object-ui/console 3.1.2 → 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 (63) hide show
  1. package/dist/assets/{AdvancedChartImpl-D711bBuO.js → AdvancedChartImpl-BvIFxlPf.js} +2 -2
  2. package/dist/assets/{AppManagementPage-CaWUYaXX.js → AppManagementPage-6bzxYNlP.js} +1 -1
  3. package/dist/assets/{AuditLogPage-CB1qkThp.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-DGz-5xrK.js → DashboardDesignPage-T9tEAHAx.js} +1 -1
  8. package/dist/assets/{DashboardView-v834XbaQ.js → DashboardView-jCJCERzJ.js} +1 -1
  9. package/dist/assets/{EditAppPage-DocDqKMS.js → EditAppPage-UGT9V29B.js} +1 -1
  10. package/dist/assets/{ForgotPasswordPage-8ypvh4-X.js → ForgotPasswordPage-Ca0lLZwY.js} +1 -1
  11. package/dist/assets/{KanbanEnhanced-Cw4oddBv.js → KanbanEnhanced-CyIdmKhW.js} +1 -1
  12. package/dist/assets/{KanbanImpl-D6ggfmB0.js → KanbanImpl-PGPpv-gu.js} +1 -1
  13. package/dist/assets/{LoginPage-XakThPoT.js → LoginPage-BR2RpoGG.js} +1 -1
  14. package/dist/assets/{MarkdownImpl-C0wRapHT.js → MarkdownImpl-eDhoPCJp.js} +1 -1
  15. package/dist/assets/{OrgManagementPage-Df5167oO.js → OrgManagementPage-DjT2mZ2x.js} +1 -1
  16. package/dist/assets/{PageDesignPage-BzM4EsXt.js → PageDesignPage-DTEQcEuR.js} +1 -1
  17. package/dist/assets/{PageView-CpIQvLmr.js → PageView-CFJhE0CN.js} +2 -2
  18. package/dist/assets/{PermissionManagementPage-CZH3URJU.js → PermissionManagementPage-C_FPnvGW.js} +1 -1
  19. package/dist/assets/{ProfilePage-BvIbbebc.js → ProfilePage-CQkgvEEi.js} +1 -1
  20. package/dist/assets/RecordDetailView-ClpxNRz2.js +1 -0
  21. package/dist/assets/{RegisterPage-CIeFN9rY.js → RegisterPage-6IYU4bdp.js} +1 -1
  22. package/dist/assets/{ReportView-DYhXezmy.js → ReportView-DecAJ58u.js} +1 -1
  23. package/dist/assets/{RoleManagementPage-D0X7HlqJ.js → RoleManagementPage-v0ia3MGn.js} +1 -1
  24. package/dist/assets/{SearchResultsPage-CoMB32KW.js → SearchResultsPage-CaSb54ho.js} +1 -1
  25. package/dist/assets/{SystemHubPage-Cvl3VKcV.js → SystemHubPage-PNaxZEht.js} +1 -1
  26. package/dist/assets/{UserManagementPage-5k8BQxT1.js → UserManagementPage-KAZy5fgy.js} +1 -1
  27. package/dist/assets/data-adapter-DCM4pdG4.js +1 -0
  28. package/dist/assets/{framework-52FGgFF6.js → framework-jBjO8CT3.js} +2 -2
  29. package/dist/assets/{index-D5i0wk-G.js → index-BwkHrw9s.js} +1 -1
  30. package/dist/assets/index-DXak0mZe.css +1 -0
  31. package/dist/assets/{index-fjkakZm9.js → index-tta28Q_N.js} +3 -3
  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-CxztIKgM.css → ui-components-BCiSmwiC.css} +1 -1
  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 +40 -40
  50. package/dist/assets/CreateAppPage-DLRU3TEg.js +0 -1
  51. package/dist/assets/RecordDetailView-BNnPf0DG.js +0 -1
  52. package/dist/assets/data-adapter-Bif-TtZA.js +0 -1
  53. package/dist/assets/index-h9Jznm67.css +0 -1
  54. package/dist/assets/infrastructure-Dn7jNPwf.js +0 -1
  55. package/dist/assets/plugins-core-CP8uPw4p.js +0 -8
  56. package/dist/assets/plugins-views-DZCu8Ex3.js +0 -62
  57. package/dist/assets/ui-components-BE4yvyhE.js +0 -36
  58. package/dist/assets/ui-layout-CYnH69Z2.js +0 -1
  59. package/dist/assets/vendor-charts-BLNOCZWl.js +0 -65
  60. package/dist/assets/vendor-i18n-E3-WitRV.js +0 -9
  61. package/dist/assets/vendor-objectstack-CatrkstC.js +0 -34
  62. package/dist/assets/vendor-radix-C6qchjxv.js +0 -56
  63. package/dist/assets/vendor-zod-C5j6C2CQ.js +0 -39
@@ -0,0 +1,8 @@
1
+ import{r as l,j as t,R as $e,c as Sn}from"./vendor-react-Dvo_9NuO.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 bs,g as On,S as In,h as Dn,i as En,j as Tn,k as An,D as Xt,M as Rn,l as Zt,n as es,o as ts,p as xs,q as Vn,r as Mn,C as pt,s as mt,t as Ft,u as ht,v as Lt,w as Ks,x as Us,y as Ws,z as It,A as Ze,E as kt,F as zn,G as Ke,H as _t,I as Ln,N as bt,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 Et,Y as xt,Z as Js,$ as gt,a0 as jt,a1 as wt,a2 as vt,a3 as Nt,a4 as tt,a5 as Qs,a6 as Xs,a7 as Zs,a8 as en,a9 as tn,aa as qn,ab as He,ac as gs,ad as Bn,ae as Kn,af as ys,ag as js,ah as ws,ai as Un,aj as Wn,ak as Hn,al as et,am as vs,an as Gn,ao as Yn,ap as Jn}from"./ui-components-BRpbeVr1.js";import{S as Ve,C as Te,d as Qn,g as Xn,e as Zn,h as ei,i as sn,j as nn}from"./framework-jBjO8CT3.js";import"./vendor-objectstack-BkRCrdfn.js";import{a as dt}from"./vendor-ui-utils-CU11aiRA.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-_-PfuStg.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 hi,a4 as bi,a5 as xi,y as Ss,a6 as $t,a7 as gi,a8 as yi,a9 as ji,aa as wi,j as Tt,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 Ii,ag as Di,ah as Ei,ai as dn,aj as Ti,ak as Ai,al as Ri,am as ks,an as Vi,ao as Mi,ap as Gt,E as zi,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-CnLeuN7Z.js";import{a as st,u as Ui}from"./infrastructure-CWeiQ12V.js";import{u as Wi}from"./plugins-views-gxDbTdkX.js";const ct=({label:e,description:i,collapsible:s=!1,collapsed:n=!1,columns:r=1,children:a,className:o,gridClassName:d})=>{const[u,b]=l.useState(n),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",o),children:[(e||i)&&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}),i&&t.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:i})]})]}),!u&&t.jsx("div",{className:Z("grid gap-4",d||g[r]),children:a})]})},Hi=({schema:e,dataSource:i,className:s})=>{const{fieldLabel:n}=st(),[r,a]=l.useState(null),[o,d]=l.useState({}),[u,b]=l.useState(!0),[g,c]=l.useState(null),[h,v]=l.useState(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||"tab-0");$e.useEffect(()=>{(async()=>{if(!i){b(!1);return}try{const x=await i.getObjectSchema(e.objectName);a(x)}catch(x){c(x)}})()},[e.objectName,i]),$e.useEffect(()=>{(r||!i)&&(async()=>{if(e.mode==="create"||!e.recordId||!i){d(e.initialData||e.initialValues||{}),b(!1);return}try{const x=await i.findOne(e.objectName,e.recordId);d(x||{})}catch(x){c(x)}finally{b(!1)}})()},[r,e.mode,e.recordId,e.initialData,e.initialValues,i,e.objectName]);const N=l.useCallback(I=>{const x=[];for(const f of I.fields){const w=typeof f=="string"?f:f.name;if(typeof f=="object")x.push(f);else if(r?.fields?.[w]){const E=r.fields[w];x.push({name:w,label:n(e.objectName,w,E.label||w),type:Ye(E.type),required:E.required||!1,disabled:e.readOnly||e.mode==="view"||E.readonly,placeholder:E.placeholder,description:E.help||E.description,validation:Ge(E),field:E,options:E.options,multiple:E.multiple})}else x.push({name:w,label:w,type:"input"})}return x},[r,e.readOnly,e.mode]),p=l.useCallback(async I=>{if(!i)return e.onSuccess&&await e.onSuccess(I),I;try{let x;return e.mode==="create"?x=await i.create(e.objectName,I):e.mode==="edit"&&e.recordId&&(x=await i.update(e.objectName,e.recordId,I)),e.onSuccess&&await e.onSuccess(x),x}catch(x){throw e.onError&&e.onError(x),x}},[e,i]),q=l.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),A=(I,x)=>I.name||I.label||`tab-${x}`;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(I=>N(I)),layout:"vertical",defaultValues:o,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1,onSubmit:p,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:h,onValueChange:v,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((I,x)=>t.jsx(Qt,{value:A(I,x),className:Y?"w-full justify-start":"",children:I.label||`Tab ${x+1}`},A(I,x)))}),t.jsx("div",{className:"flex-1",children:e.sections.map((I,x)=>t.jsx(Fn,{value:A(I,x),className:"mt-0",children:t.jsx(ct,{description:I.description,columns:I.columns||1,children:t.jsx(Ve,{schema:{..._,fields:N(I),showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1}})})},A(I,x)))})]})})},Gi=({schema:e,dataSource:i,className:s})=>{const{fieldLabel:n}=st(),[r,a]=l.useState(null),[o,d]=l.useState({}),[u,b]=l.useState(!0),[g,c]=l.useState(null),[h,v]=l.useState(0),[N,p]=l.useState(new Set),[q,A]=l.useState(!1),y=e.sections.length,_=h===0,Y=h===y-1;$e.useEffect(()=>{(async()=>{if(!i){b(!1);return}try{const R=await i.getObjectSchema(e.objectName);a(R)}catch(R){c(R)}})()},[e.objectName,i]),$e.useEffect(()=>{(r||!i)&&(async()=>{if(e.mode==="create"||!e.recordId||!i){d(e.initialData||e.initialValues||{}),b(!1);return}try{const R=await i.findOne(e.objectName,e.recordId);d(R||{})}catch(R){c(R)}finally{b(!1)}})()},[r,e.mode,e.recordId,e.initialData,e.initialValues,i,e.objectName]);const I=l.useCallback(W=>{const R=[];for(const T of W.fields){const M=typeof T=="string"?T:T.name;if(typeof T=="object")R.push(T);else if(r?.fields?.[M]){const K=r.fields[M];R.push({name:M,label:n(e.objectName,M,K.label||M),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 R.push({name:M,label:M,type:"input"})}return R},[r,e.readOnly,e.mode]),x=l.useMemo(()=>h>=0&&h<y?I(e.sections[h]):[],[h,y,e.sections,I]),f=l.useCallback(async W=>{const R={...o,...W};if(d(R),p(T=>new Set(T).add(h)),Y){A(!0);try{if(!i)return e.onSuccess&&await e.onSuccess(R),R;let T;return e.mode==="create"?T=await i.create(e.objectName,R):e.mode==="edit"&&e.recordId&&(T=await i.update(e.objectName,e.recordId,R)),e.onSuccess&&await e.onSuccess(T),T}catch(T){throw e.onError&&e.onError(T),T}finally{A(!1)}}else w(h+1)},[o,h,Y,e,i]),w=l.useCallback(W=>{W>=0&&W<y&&(v(W),e.onStepChange&&e.onStepChange(W))},[y,e]),E=l.useCallback(()=>{w(h-1)},[h,w]),B=l.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),U=l.useCallback(W=>{(e.allowSkip||N.has(W)||W<=h)&&w(W)},[e.allowSkip,N,h,w]);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[h];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,R)=>{const T=R===h,M=N.has(R),K=e.allowSkip||M||R<=h;return t.jsxs("li",{className:Z("relative flex-1",R!==y-1&&"pr-8 sm:pr-12"),children:[R!==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",M?"bg-primary":"bg-muted")})}),t.jsxs("button",{type:"button",className:Z("group relative flex items-center",K?"cursor-pointer":"cursor-not-allowed"),onClick:()=>U(R),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",M&&"bg-primary text-primary-foreground",T&&!M&&"border-2 border-primary bg-background text-primary",!T&&!M&&"border-2 border-muted bg-background text-muted-foreground"),children:M?t.jsx(ln,{className:"h-3 w-3 sm:h-4 sm:w-4"}):R+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(T?"text-foreground":"text-muted-foreground"),children:W.label||`Step ${R+1}`})})]})]},R)})})}),t.jsx("div",{className:"min-h-[200px]",children:O&&t.jsx(ct,{label:O.label,description:O.description,columns:O.columns||1,children:x.length>0?t.jsx(Ve,{schema:{type:"form",fields:x,layout:"vertical",defaultValues:o,showSubmit:!1,showCancel:!1,onSubmit:f}}):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 ",h+1," of ",y]}),!_&&t.jsxs(ne,{variant:"outline",onClick:E,children:[t.jsx(ui,{className:"h-4 w-4 mr-1"}),e.prevText||"Back"]}),Y?t.jsx(ne,{onClick:()=>f(o),disabled:q||e.mode==="view",children:q?"Submitting...":e.submitText||(e.mode==="create"?"Create":"Update")}):t.jsxs(ne,{onClick:()=>f(o),children:[e.nextText||"Next",t.jsx(rs,{className:"h-4 w-4 ml-1"})]})]})]})]})},Yi=({schema:e,dataSource:i,className:s})=>{const{fieldLabel:n}=st(),[r,a]=l.useState(null),[o,d]=l.useState({}),[u,b]=l.useState(!0),[g,c]=l.useState(null);l.useEffect(()=>{(async()=>{if(!i){b(!1);return}try{const x=await i.getObjectSchema(e.objectName);a(x)}catch(x){c(x),b(!1)}})()},[e.objectName,i]),l.useEffect(()=>{(r||!i)&&(async()=>{if(e.mode==="create"||!e.recordId){d(e.initialData||e.initialValues||{}),b(!1);return}if(!i){d(e.initialData||e.initialValues||{}),b(!1);return}try{const x=await i.findOne(e.objectName,e.recordId);d(x||{})}catch(x){c(x)}finally{b(!1)}})()},[r,e.mode,e.recordId,e.initialData,e.initialValues,i,e.objectName]);const h=l.useCallback(I=>{const x=[];for(const f of I.fields){const w=typeof f=="string"?f:f.name;if(typeof f=="object")x.push(f);else if(r?.fields?.[w]){const E=r.fields[w];x.push({name:w,label:n(e.objectName,w,E.label||w),type:Ye(E.type),required:E.required||!1,disabled:e.readOnly||e.mode==="view"||E.readonly,placeholder:E.placeholder,description:E.help||E.description,validation:Ge(E),field:E,options:E.options,multiple:E.multiple})}else x.push({name:w,label:w,type:"input"})}return x},[r,e.readOnly,e.mode]),v=l.useCallback(async I=>{if(!i)return e.onSuccess&&await e.onSuccess(I),I;try{let x;return e.mode==="create"?x=await i.create(e.objectName,I):e.mode==="edit"&&e.recordId&&(x=await i.update(e.objectName,e.recordId,I)),e.onSuccess&&await e.onSuccess(x),x}catch(x){throw e.onError&&e.onError(x),x}},[e,i]),N=l.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),p=l.useMemo(()=>e.sections.slice(0,1),[e.sections]),q=l.useMemo(()=>e.sections.slice(1),[e.sections]);l.useMemo(()=>e.sections.flatMap(I=>h(I)),[e.sections,h]);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:o,onSubmit:v,onCancel:N},Y=(I,x)=>t.jsx("div",{className:"space-y-4 p-4",children:I.map((f,w)=>t.jsx(ct,{label:f.label,description:f.description,columns:f.columns||1,children:t.jsx(Ve,{schema:{..._,fields:h(f),showSubmit:x&&e.showSubmit!==!1&&e.mode!=="view",showCancel:x&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText}})},f.name||f.label||w))});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(bs,{defaultSize:y,minSize:20,children:Y(p,q.length===0)}),q.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(On,{withHandle:e.splitResizable!==!1}),t.jsx(bs,{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 Is(e,i){return i<=1?e:e.map(s=>s.colSpan!==void 0?s:s.type&&Xi(s.type)?{...s,colSpan:i}:s)}function tr(e,i){return i?.fields?e.filter(s=>{const n=i.fields[s.name];return n?!Zi(n.type):!0}):e}function Ds(e){return e<=1?"default":e===2?"xl":"full"}function Rt(e,i,s,n){let r=[...e];if(n==="create"&&(r=tr(r,i)),s!==void 0)return r=Is(r,s),{fields:r,columns:s};const a=er(r.length);return r=Is(r,a),{fields:r,columns:a}}const Es={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:i,className:s})=>{const{fieldLabel:n}=st(),[r,a]=l.useState(null),[o,d]=l.useState([]),[u,b]=l.useState({}),[g,c]=l.useState(!0),[h,v]=l.useState(null),N=e.open!==!1,p=e.drawerSide||"right";l.useEffect(()=>{(async()=>{if(!i){c(!1);return}try{const w=await i.getObjectSchema(e.objectName);a(w)}catch(w){v(w),c(!1)}})()},[e.objectName,i]),l.useEffect(()=>{(r||!i)&&(async()=>{if(e.mode==="create"||!e.recordId){b(e.initialData||e.initialValues||{}),c(!1);return}if(!i){b(e.initialData||e.initialValues||{}),c(!1);return}try{const w=await i.findOne(e.objectName,e.recordId);b(w||{})}catch(w){v(w)}finally{c(!1)}})()},[r,e.mode,e.recordId,e.initialData,e.initialValues,i,e.objectName]);const q=l.useCallback(f=>{const w=[];for(const E of f.fields){const B=typeof E=="string"?E:E.name;if(typeof E=="object")w.push(E);else if(r?.fields?.[B]){const U=r.fields[B];w.push({name:B,label:n(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 w.push({name:B,label:B,type:"input"})}return w},[r,e.readOnly,e.mode]);l.useEffect(()=>{if(!r&&i)return;if(e.customFields?.length){d(e.customFields),c(!1);return}if(e.sections?.length){c(!1);return}if(!r)return;const f=e.fields||Object.keys(r.fields||{}),w=[];for(const E of f){const B=typeof E=="string"?E:E.name;if(!B)continue;const U=r.fields?.[B];U&&w.push({name:B,label:n(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})}d(w),c(!1)},[r,e.fields,e.customFields,e.sections,e.readOnly,e.mode,i]);const A=l.useCallback(async f=>{if(!i)return e.onSuccess&&await e.onSuccess(f),e.onOpenChange?.(!1),f;try{let w;return e.mode==="create"?w=await i.create(e.objectName,f):e.mode==="edit"&&e.recordId&&(w=await i.update(e.objectName,e.recordId,f)),e.onSuccess&&await e.onSuccess(w),e.onOpenChange?.(!1),w}catch(w){throw e.onError&&e.onError(w),w}},[e,i]),y=l.useCallback(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),_=l.useMemo(()=>e.drawerWidth?p==="left"||p==="right"?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}:void 0,[e.drawerWidth,p]),I={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},x=()=>{if(h)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:h.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((E,B)=>{const U=E.columns||1;return t.jsx(ct,{label:E.label,description:E.description,columns:U,gridClassName:Es[U],children:t.jsx(Ve,{schema:{...I,fields:q(E),showSubmit:B===e.sections.length-1&&I.showSubmit,showCancel:B===e.sections.length-1&&I.showCancel}})},E.name||E.label||B)})});const f=Rt(o,r,e.columns,e.mode),w=Es[f.columns||1];return t.jsx(Ve,{schema:{...I,fields:f.fields,columns:f.columns,...w?{fieldContainerClass:w}:{}}})};return t.jsx(In,{open:N,onOpenChange:e.onOpenChange,children:t.jsxs(Dn,{side:p,className:Z("overflow-y-auto",s,e.className),style:_,children:[(e.title||e.description)&&t.jsxs(En,{children:[e.title&&t.jsx(Tn,{children:e.title}),e.description&&t.jsx(An,{children:e.description})]}),t.jsx("div",{className:"@container py-4",children:x()})]})})},Ts={sm:"sm:max-w-sm",default:"sm:max-w-lg",lg:"sm:max-w-2xl",xl:"sm:max-w-5xl",full:"sm:max-w-[95vw] sm: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:i,className:s})=>{const{fieldLabel:n}=st(),[r,a]=l.useState(null),[o,d]=l.useState([]),[u,b]=l.useState({}),[g,c]=l.useState(!0),[h,v]=l.useState(null),[N,p]=l.useState(!1),q=e.open!==!1,A=l.useId(),y=l.useMemo(()=>e.sections?.length||e.customFields?.length?null:Rt(o,r,e.columns,e.mode),[o,r,e.columns,e.mode,e.sections,e.customFields]),_=l.useMemo(()=>{if(e.modalSize)return e.modalSize;if(y?.columns&&y.columns>1)return Ds(y.columns);if(e.sections?.length){const M=Math.max(...e.sections.map(K=>Number(K.columns)||1));if(M>1)return Ds(M)}return"default"},[e.modalSize,y,e.sections]),Y=Ts[_]||Ts.default;l.useEffect(()=>{(async()=>{if(!i){c(!1);return}try{const K=await i.getObjectSchema(e.objectName);a(K)}catch(K){v(K),c(!1)}})()},[e.objectName,i]),l.useEffect(()=>{(r||!i)&&(async()=>{if(e.mode==="create"||!e.recordId){b(e.initialData||e.initialValues||{}),c(!1);return}if(!i){b(e.initialData||e.initialValues||{}),c(!1);return}try{const K=await i.findOne(e.objectName,e.recordId);b(K||{})}catch(K){v(K)}finally{c(!1)}})()},[r,e.mode,e.recordId,e.initialData,e.initialValues,i,e.objectName]);const I=l.useCallback(M=>{const K=[];for(const H of M.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:n(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&&i)return;if(e.customFields?.length){d(e.customFields),c(!1);return}if(e.sections?.length){c(!1);return}if(!r)return;const M=e.fields||Object.keys(r.fields||{}),K=[];for(const H of M){const se=typeof H=="string"?H:H.name;if(!se)continue;const ee=r.fields?.[se];ee&&K.push({name:se,label:n(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})}d(K),c(!1)},[r,e.fields,e.customFields,e.sections,e.readOnly,e.mode,i]);const x=l.useCallback(async M=>{p(!0);try{if(!i)return e.onSuccess&&await e.onSuccess(M),e.onOpenChange?.(!1),M;let K;return e.mode==="create"?K=await i.create(e.objectName,M):e.mode==="edit"&&e.recordId&&(K=await i.update(e.objectName,e.recordId,M)),e.onSuccess&&await e.onSuccess(K),e.onOpenChange?.(!1),K}catch(K){throw e.onError&&e.onError(K),K}finally{p(!1)}},[e,i]),f=l.useCallback(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),w=e.layout==="vertical"||e.layout==="horizontal"?e.layout:"vertical",E=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:w,defaultValues:u,submitLabel:U,cancelLabel:O,showSubmit:E,showCancel:B,onSubmit:x,onCancel:f,showActions:!1,id:A},R=()=>{if(h)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:h.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(xs,{className:"h-4 w-24"}),t.jsx(xs,{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(Ve,{schema:{...W,fields:I(H)}})},H.name||H.label||se)})});const M=y??Rt(o,r,e.columns,e.mode),K=As[M.columns||1];return t.jsx(Ve,{schema:{...W,fields:M.fields,columns:M.columns,...K?{fieldContainerClass:K}:{}}})},T=!g&&!h&&(E||B);return t.jsx(Xt,{open:q,onOpenChange:e.onOpenChange,children:t.jsxs(Rn,{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:R()}),T&&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:f,disabled:N,className:"w-full sm:w-auto",children:O}),E&&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:i})=>{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:i,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:i,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:i,className:e.className});if(e.formType==="drawer"){const{layout:s,...n}=e,r=e.layout==="vertical"||e.layout==="horizontal"?e.layout:void 0;return t.jsx(sr,{schema:{...n,layout:r,formType:"drawer",sections:e.sections?.map(a=>({name:a.name,label:a.label,description:a.description,columns:a.columns,fields:a.fields})),open:e.open,onOpenChange:e.onOpenChange,drawerSide:e.drawerSide,drawerWidth:e.drawerWidth},dataSource:i,className:e.className})}if(e.formType==="modal"){const{layout:s,...n}=e,r=e.layout==="vertical"||e.layout==="horizontal"?e.layout:void 0;return t.jsx(nr,{schema:{...n,layout:r,formType:"modal",sections:e.sections?.map(a=>({name:a.name,label:a.label,description:a.description,columns:a.columns,fields:a.fields})),open:e.open,onOpenChange:e.onOpenChange,modalSize:e.modalSize,modalCloseButton:e.modalCloseButton},dataSource:i,className:e.className})}return t.jsx(ir,{schema:e,dataSource:i})},ir=({schema:e,dataSource:i})=>{const{fieldLabel:s}=st(),[n,r]=l.useState(null),[a,o]=l.useState([]),[d,u]=l.useState(null),[b,g]=l.useState(!0),[c,h]=l.useState(null),v=e.customFields&&e.customFields.length>0;l.useEffect(()=>{v&&(u(e.initialData||e.initialValues||{}),g(!1))},[v,e.initialData,e.initialValues]),l.useEffect(()=>{const x=async()=>{try{if(!i)throw new Error("DataSource is required when using ObjectQL schema fetching (inline fields not provided)");const f=await i.getObjectSchema(e.objectName);if(!f)throw new Error(`No schema found for object "${e.objectName}"`);r(f)}catch(f){h(f),g(!1)}};v?r({name:e.objectName,fields:{}}):e.objectName&&i?x():v||g(!1)},[e.objectName,i,v]),l.useEffect(()=>{n&&!v&&(async()=>{if(!e.recordId||e.mode==="create"){u(e.initialData||e.initialValues||{}),g(!1);return}if(!v){if(!i){h(new Error("DataSource is required for fetching record data (inline data not provided)")),g(!1);return}g(!0);try{const f=await i.findOne(e.objectName,e.recordId);u(f)}catch(f){console.error("Failed to fetch record:",f),h(f)}finally{g(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,i,n,v]),l.useEffect(()=>{if(v&&e.customFields){o(e.customFields),g(!1);return}if(!n)return;const x=[],f=e.fields||Object.keys(n.fields||{});(Array.isArray(f)?f:Object.keys(f)).forEach(B=>{const U=typeof B=="string"?B:B.name;if(!U)return;const O=n.fields?.[U];if(!O&&!v)return;const W=!O?.permissions||O?.permissions.write!==!1;if(e.mode!=="view"&&!W)return;const R=e.customFields?.find(T=>T.name===U);if(R)x.push(R);else if(O){const T={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")&&(T.options=O.options||[],T.multiple=O.multiple),(O.type==="number"||O.type==="currency"||O.type==="percent")&&(T.inputType="number",T.min=O.min,T.max=O.max,T.step=O.precision?Math.pow(10,-O.precision):void 0),O.type==="date"&&(T.inputType="date"),O.type==="datetime"&&(T.inputType="datetime-local"),(O.type==="text"||O.type==="textarea"||O.type==="markdown"||O.type==="html")&&(T.maxLength=O.max_length,T.minLength=O.min_length),(O.type==="file"||O.type==="image")&&(T.inputType="file",T.multiple=O.multiple,T.accept=O.accept?O.accept.join(","):void 0,O.max_size)){const M=`Max size: ${Vn(O.max_size)}`;T.description=T.description?`${T.description} (${M})`:M}O.type==="email"&&(T.inputType="email"),O.type==="phone"&&(T.inputType="tel"),O.type==="url"&&(T.inputType="url"),O.type==="password"&&(T.inputType="password"),O.type==="time"&&(T.inputType="time"),(O.type==="formula"||O.type==="summary"||O.type==="auto_number")&&(T.disabled=!0),O.visible_on&&(T.visible=M=>Mn(O.visible_on,M)),x.push(T)}}),o(x),!v&&e.recordId&&e.mode!=="create"&&i||g(!1)},[n,e.fields,e.customFields,e.readOnly,e.mode,v,e.recordId,i]);const N=l.useCallback(async(x,f)=>{if(x&&(x.nativeEvent||x._reactName==="onSubmit")&&(console.warn("ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue."),f===void 0&&(f=x,x={})),v&&!i)return e.onSuccess&&await e.onSuccess(x),x;if(!i)throw new Error("DataSource is required for form submission (inline mode not configured)");try{let w;if(e.mode==="create")w=await i.create(e.objectName,x);else if(e.mode==="edit"&&e.recordId)w=await i.update(e.objectName,e.recordId,x);else throw new Error("Invalid form mode or missing record ID");return e.onSuccess&&await e.onSuccess(w),w}catch(w){throw console.error("Failed to submit form:",w),e.onError&&e.onError(w),w}},[e,i,v]),p=l.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),A={...$e.useMemo(()=>{if(!n?.fields)return{};const x={};return Object.keys(n.fields).forEach(f=>{const w=n.fields[f];w.defaultValue!==void 0&&(x[f]=w.defaultValue)}),x},[n]),...d};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((x,f)=>{const w=x.fields.map(B=>typeof B=="string"?B:B.name),E=a.filter(B=>w.includes(B.name));return t.jsx(ct,{label:x.label,description:x.description,collapsible:x.collapsible,collapsed:x.collapsed,columns:x.columns,children:t.jsx(Ve,{schema:{type:"form",fields:E,layout:y,defaultValues:A,showSubmit:f===e.sections.length-1&&e.showSubmit!==!1&&e.mode!=="view",showCancel:f===e.sections.length-1&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,onSubmit:N,onCancel:p}})},x.name||x.label||f)})});const Y=e.sections?.length?{fields:a,columns:e.columns}:Rt(a,n,e.columns,e.mode),I={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:p,className:e.className};return t.jsx("div",{className:"w-full",children:t.jsx(Ve,{schema:I})})},rr=({config:e,dataSource:i,prefillParams:s,className:n})=>{const[r,a]=l.useState(!1),[o,d]=l.useState(!1),[u,b]=l.useState(null),g=l.useMemo(()=>{const N={};if(s)for(const[p,q]of Object.entries(s))N[p]=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=>{d(!0),b(null);try{if(i&&await i.create(e.objectName,N),a(!0),e.thankYouPage?.redirectUrl){const p=e.thankYouPage.redirectDelay??3e3;setTimeout(()=>{window.location.href=e.thankYouPage.redirectUrl},p)}}catch(p){b(p instanceof Error?p.message:"Failed to submit form. Please try again.")}finally{d(!1)}},[i,e]),h=l.useCallback(()=>{a(!1),b(null)},[]),v=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 ${n||""}`,style:v,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:h,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 ${n||""}`,style:v,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:o?"Submitting...":"Submit"},dataSource:i})]}),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:i,metrics:s,className:n})=>{const r=l.useMemo(()=>{if(!s.abandonedSubmissions)return 100;const o=s.totalSubmissions+s.abandonedSubmissions;return o===0?0:Math.round(s.totalSubmissions/o*100)},[s.totalSubmissions,s.abandonedSubmissions]),a=l.useMemo(()=>s.dailySubmissions?.length?Math.max(...s.dailySubmissions.map(o=>o.count),1):1,[s.dailySubmissions]);return t.jsxs("div",{className:`space-y-4 ${n||""}`,children:[t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-foreground",children:i||"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(ht,{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(ht,{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(ht,{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(ht,{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((o,d)=>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:`${o.count/a*100}%`,minHeight:o.count>0?"4px":"0"},title:`${o.date}: ${o.count} submissions`}),t.jsx("span",{className:"text-[10px] text-muted-foreground truncate w-full text-center",children:o.date.slice(-5)})]},d))})})]}),s.fieldDropOff&&s.fieldDropOff.length>0&&t.jsxs(pt,{children:[t.jsxs(mt,{children:[t.jsx(ht,{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((o,d)=>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:o.label}),t.jsxs("span",{className:"text-muted-foreground",children:[o.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 ${o.completionRate>=80?"bg-green-500":o.completionRate>=50?"bg-yellow-500":"bg-destructive"}`,style:{width:`${o.completionRate}%`}})})]},d))})})]})]})},cn=({schema:e})=>t.jsx(yt,{schema:e});Te.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"]}]});Te.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});Te.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}});Te.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 i=e.toLowerCase().trim();return cr[i]}function fr(e){return l.useCallback(i=>{if(!e?.field||!e.colors)return;const s=String(i[e.field]??""),n=e.colors[s];if(n)return ur(n)},[e?.field,e?.colors])}function pr(e,i){return i.map(s=>String(e[s.field]??"")).join(" / ")}function mr(e,i){return i.map(s=>{const n=e[s.field];return n!=null&&n!==""?String(n):"(empty)"}).join(" / ")}function hr(e,i,s){const n=e.localeCompare(i,void 0,{numeric:!0,sensitivity:"base"});return s==="desc"?-n:n}function br(e,i,s){const n=e?.fields,r=!!(n&&n.length>0),[a,o]=l.useState({}),d=l.useMemo(()=>n?n.some(g=>g.collapsed):!1,[n]),u=l.useMemo(()=>{if(!r||!n)return[];const g=new Map,c=[];for(const v of i){const N=pr(v,n);g.has(N)||(g.set(N,{label:mr(v,n),rows:[]}),c.push(N)),g.get(N).rows.push(v)}const h=n[0]?.order??"asc";return c.sort((v,N)=>hr(v,N,h)),c.map(v=>{const N=g.get(v),p=v in a?a[v]:d,q=[];return{key:v,label:N.label,rows:N.rows,collapsed:p,aggregations:q}})},[i,n,r,a,d,s]),b=l.useCallback(g=>{o(c=>({...c,[g]:c[g]!==void 0?!c[g]:!d}))},[d]);return{groups:u,isGrouped:r,toggleGroup:b}}const xr=({groupKey:e,label:i,count:s,collapsed:n,aggregations:r,onToggle:a,children:o})=>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:()=>a(e),"aria-expanded":!n,children:[n?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:i}),r&&r.length>0&&t.jsx("span",{className:"ml-2 text-xs text-muted-foreground group-aggregations",children:r.map(d=>t.jsxs("span",{className:"mr-2",children:[d.type,": ",Number.isInteger(d.value)?d.value:d.value.toFixed(2)]},`${d.field}-${d.type}`))}),t.jsxs("span",{className:"ml-auto text-xs text-muted-foreground group-count",children:["(",s,")"]})]}),!n&&o]});function gr(e){return typeof e=="string"?{type:e}:e}function yr(e,i){if(i.length===0)return null;switch(e){case"count":return i.length;case"sum":return i.reduce((s,n)=>s+n,0);case"avg":return i.reduce((s,n)=>s+n,0)/i.length;case"min":return Math.min(...i);case"max":return Math.max(...i);default:return null}}function jr(e,i){if(i===null)return"";const n={count:"Count",sum:"Sum",avg:"Avg",min:"Min",max:"Max"}[e]||e,r=e==="avg"?i.toLocaleString(void 0,{maximumFractionDigits:2}):i.toLocaleString();return`${n}: ${r}`}function wr(e,i){return l.useMemo(()=>{const s=new Map;if(!e||e.length===0||i.length===0)return{summaries:s,hasSummary:!1};for(const n of e){if(!n.summary)continue;const r=gr(n.summary),a=r.field||n.field,o=[];for(const u of i){const b=u[a];if(b!=null&&typeof b=="number"&&!isNaN(b))o.push(b);else if(b!=null&&typeof b=="string"){const g=parseFloat(b);isNaN(g)||o.push(g)}}let d;if(r.type==="count"){const u=i.filter(b=>b[a]!=null&&b[a]!=="").length;d=u>0?u:null}else d=yr(r.type,o);s.set(n.field,{field:n.field,value:d,label:jr(r.type,d)})}return{summaries:s,hasSummary:s.size>0}},[e,i])}function ds(e){return e.replace(/_/g," ").replace(/\b\w/g,i=>i.toUpperCase())}const vr=({row:e,rowActions:i,canEdit:s,canDelete:n,onEdit:r,onDelete:a,onAction:o})=>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(It,{onClick:()=>r(e),children:[t.jsx(mi,{className:"mr-2 h-4 w-4"}),"Edit"]}),n&&a&&t.jsxs(It,{onClick:()=>a(e),children:[t.jsx(ls,{className:"mr-2 h-4 w-4"}),"Delete"]}),i?.map(d=>t.jsx(It,{onClick:()=>o?.(d,e),"data-testid":`row-action-${d}`,children:ds(d)},d))]})]}),Rs=({selectedRows:e,actions:i,onAction:s,onClearSelection:n})=>!i||i.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:i.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:n,children:"Clear"})]}),Vs={"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,n)=>{let r=Vs[s]||s;if(n)for(const[a,o]of Object.entries(n))r=r.replace(`{{${a}}}`,String(o));return r}}:{t:e.t}}catch{return{t:(e,i)=>{let s=Vs[e]||e;if(i)for(const[n,r]of Object.entries(i))s=s.replace(`{{${n}}}`,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:i,onEdit:s,onDelete:n,onRowSelect:r,onRowClick:a,onCellChange:o,onRowSave:d,onBatchSave:u,onAddRecord:b,...g})=>{const[c,h]=l.useState([]),[v,N]=l.useState(!0),[p,q]=l.useState(null),{t:A}=Nr(),{fieldLabel:y}=st(),[_,Y]=l.useState(null),[I,x]=l.useState(!1),[f,w]=l.useState(0),[E,B]=l.useState(!1),[U,O]=l.useState(e.rowHeight??"compact"),[W,R]=l.useState([]),T=$e.useMemo(()=>e.id?`grid-columns-${e.objectName}-${e.id}`:`grid-columns-${e.objectName}`,[e.objectName,e.id]),[M,K]=l.useState(()=>{try{const m=localStorage.getItem(T);return m?JSON.parse(m):{}}catch{return{}}}),H=l.useCallback(m=>{K(m);try{localStorage.setItem(T,JSON.stringify(m))}catch(X){console.warn("Failed to persist column state:",X)}},[T]),se=l.useCallback(async()=>{w(m=>m+1)},[]),{ref:ee,isRefreshing:Ae,pullDistance:S}=Wi({onRefresh:se,enabled:!!i&&!!e.objectName});l.useEffect(()=>{const m=()=>x(window.innerWidth<480);return m(),window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)},[]);const Ne=g.data,ae=Qn(e.bind),Me=Sr(e),de=$e.useMemo(()=>Ne&&Array.isArray(Ne)?{provider:"value",items:Ne}:ae&&Array.isArray(ae)?{provider:"value",items:ae}:Me,[JSON.stringify(Me),ae,Ne]),ze=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(()=>{ze&&de?.provider==="value"&&(h(m=>{const X=de.items;return JSON.stringify(m)!==JSON.stringify(X)?X:m}),N(!1))},[ze,de]),l.useEffect(()=>{if(!ze||!we||!i)return;let m=!1;return(async()=>{try{const P=await i.getObjectSchema(we);m||Y(P)}catch(P){console.warn(`[ObjectGrid] Failed to fetch objectSchema for inline data (objectName: ${we}):`,P)}})(),()=>{m=!0}},[ze,we,i]),l.useEffect(()=>{if(ze)return;let m=!1;return(async()=>{N(!0),q(null);try{let P=null;const pe=Bt(F)||ke;if(we&&i){const Se=await i.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),i&&we){const D={$select:(()=>{if(ke)return ke;if(F&&Array.isArray(F))return F.map(V=>typeof V=="string"?V:V.field)})(),$top:ye?.pageSize||fe||50};ue&&Array.isArray(ue)?D.$filter=ue:e.defaultFilters&&(D.$filter=e.defaultFilters),me?typeof me=="string"?D.$orderby=me:Array.isArray(me)&&(D.$orderby=me.map(V=>`${V.field} ${V.order}`).join(", ")):e.defaultSort&&(D.$orderby=`${e.defaultSort.field} ${e.defaultSort.order}`);const j=sn(P?.fields,F??ke);j.length>0&&(D.$expand=j);const z=await i.find(we,D);if(m)return;h(z.data||[])}}catch(P){m||q(P)}finally{m||N(!1)}})(),()=>{m=!0}},[we,ke,F,ue,me,ye,fe,i,ze,de,f]);const be=Xn({navigation:e.navigation,objectName:e.objectName,onNavigate:e.onNavigate,onRowClick:a}),{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 D=P,j=m[D.field];switch(D.operator){case"equals":pe=j===D.value;break;case"not_equals":pe=j!==D.value;break;case"contains":pe=typeof j=="string"&&typeof D.value=="string"&&j.includes(D.value);break;case"greater_than":pe=typeof j=="number"&&typeof D.value=="number"&&j>D.value;break;case"less_than":pe=typeof j=="number"&&typeof D.value=="number"&&j<D.value;break;case"in":pe=Array.isArray(D.value)&&D.value.includes(j);break}}if(pe){const D={};return"style"in P&&P.style&&Object.assign(D,P.style),"backgroundColor"in P&&P.backgroundColor&&(D.backgroundColor=P.backgroundColor),"textColor"in P&&P.textColor&&(D.color=P.textColor),"borderColor"in P&&P.borderColor&&(D.borderColor=P.borderColor),D}}},[e.conditionalFormatting]),{groups:it,isGrouped:Je,toggleGroup:je}=br(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=D=>D?{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(Tt,{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"})}[D]||t.jsx($t,{className:"h-3.5 w-3.5"}):t.jsx($t,{className:"h-3.5 w-3.5"}),X=D=>{if(D.type)return D.type;const j=D.field.toLowerCase();if(["completed","is_completed","done","active","enabled","archived"].some(J=>j===J||j===`is_${J}`))return"boolean";if(["created_time","modified_time","updated_time","created_at","updated_at","modified_at","last_login","logged_at"].some(J=>j===J||j.endsWith(`_${J}`)))return"datetime";if(["date","due","created","updated","deadline","start","end","expires"].some(J=>j.includes(J))){if(c.length>0){const J=c.find(ie=>ie[D.field]!=null)?.[D.field];if(typeof J=="string"&&!isNaN(Date.parse(J)))return"date"}return"date"}if(["probability","percent","percentage","completion","progress","rate"].some(J=>j.includes(J))&&c.length>0&&typeof c.find(ie=>ie[D.field]!=null)?.[D.field]=="number")return"percent";if(["status","priority","category","stage","type","severity","level"].some(J=>j.includes(J))&&c.length>0){const J=new Set(c.map(ie=>ie[D.field]).filter(Boolean));if(J.size>0&&J.size<=10)return"select"}if(["assignee","owner","author","reporter","creator","user"].some(J=>j.includes(J)))return"user";if(["amount","price","total","revenue","cost","budget","salary"].some(J=>j.includes(J))&&c.length>0&&typeof c.find(ie=>ie[D.field]!=null)?.[D.field]=="number")return"currency";if(c.length>0){const J=c.find(ie=>ie[D.field]!=null)?.[D.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 D=P[0];if("accessorKey"in D)return P.map(j=>{if(j.cell)return j;const z={field:j.accessorKey,label:j.header,type:j.type},V=X(z);if(!V)return j;const te=Ze(V),L={name:j.accessorKey,type:V};if(V==="select"){const C=Array.from(new Set(c.map(Q=>Q[j.accessorKey]).filter(Boolean)));L.options=C.map(Q=>({value:Q,label:kt(String(Q))}))}return{...j,headerIcon:m(V),cell:C=>t.jsx(te,{value:C,field:L})}});if("field"in D)return P.filter(j=>j?.field&&typeof j.field=="string"&&!j.hidden).map((j,z)=>{const V=Cr(j.label)||j.field.charAt(0).toUpperCase()+j.field.slice(1).replace(/_/g," "),te=e.objectName?y(e.objectName,j.field,V):V;let L;const C=_?.fields?.[j.field],Q=j.type||C?.type||X({field:j.field})||null,re=Q?Ze(Q):null,J={name:j.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(Re=>Re[j.field]).filter(Boolean)));J.options=oe.map(Re=>({value:Re,label:kt(String(Re))}))}j.options&&(J.options=j.options);const ie=z===0&&!j.link&&!j.action,Fe=j.link||ie;j.link&&j.action||ie&&j.action?L=(oe,Re)=>{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(),be.handleClick(Re)},children:Xe})}:Fe?L=(oe,Re)=>{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(),be.handleClick(Re)},children:Xe})}:j.action?L=(oe,Re)=>t.jsx(ne,{variant:"outline",size:"sm",className:"h-7 text-xs","data-testid":"action-cell",onClick:Xe=>{Xe.stopPropagation(),Ce({type:j.action,params:{record:Re,field:j.field,value:oe}})},children:ds(j.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=j.prefix;if(_e?.field){const oe=L,Re=_e.type==="badge"?Ze("select"):null;L=(Xe,at)=>{const St=at[_e.field],Cn=St!=null&&St!==""?Re?t.jsx(Re,{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 De=["number","currency","percent"],Ee=Q||j.type,We=j.align||(Ee&&De.includes(Ee)?"right":void 0),le=z===0||j.essential===!0;return{header:te,accessorKey:j.field,headerIcon:m(Q),...!le&&{className:"hidden sm:table-cell"},...j.width&&{width:j.width},...We&&{align:We},sortable:j.sortable!==!1,...j.resizable!==void 0&&{resizable:j.resizable},...j.wrap!==void 0&&{wrap:j.wrap},...L&&{cell:L},...j.pinned&&{pinned:j.pinned}}})}return P.filter(D=>typeof D=="string"&&D.trim().length>0).map((D,j)=>{const z=_?.fields?.[D],te=z?.label||D.charAt(0).toUpperCase()+D.slice(1).replace(/_/g," "),L=e.objectName?y(e.objectName,D,te):te,C=z?.type||X({field:D})||null,Q=C?Ze(C):null,re={name:D,type:C||"text"};if(z&&(z.label&&(re.label=z.label),z.currency&&(re.currency=z.currency),z.precision!==void 0&&(re.precision=z.precision),z.format&&(re.format=z.format),z.options&&(re.options=z.options)),C==="select"&&!re.options){const De=Array.from(new Set(c.map(Ee=>Ee[D]).filter(Boolean)));re.options=De.map(Ee=>({value:Ee,label:kt(String(Ee))}))}const ie=C&&["number","currency","percent"].includes(C)?"right":void 0,Fe=j===0;let _e;return Fe&&Q?_e=(De,Ee)=>{const We=t.jsx(Q,{value:De,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(),be.handleClick(Ee)},children:We})}:Fe?_e=(De,Ee)=>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(),be.handleClick(Ee)},children:De!=null&&De!==""?String(De):t.jsx("span",{className:"text-muted-foreground/50 text-xs italic",children:"—"})}):Q&&(_e=De=>t.jsx(Q,{value:De,field:re})),{header:L,accessorKey:D,...C&&{headerIcon:m(C)},...ie&&{align:ie},..._e&&{cell:_e},sortable:z?.sortable!==!1}})}if(ze){const D=de?.provider==="value"?de.items:[];if(D.length>0)return(ke||Object.keys(D[0])).map(z=>{const V=_?.fields?.[z],te=V?.type||X({field:z})||null,L=te?Ze(te):null,C=V?.label||z.charAt(0).toUpperCase()+z.slice(1).replace(/_/g," "),Q={name:z,type:te||"text"};if(V&&(V.label&&(Q.label=V.label),V.currency&&(Q.currency=V.currency),V.precision!==void 0&&(Q.precision=V.precision),V.format&&(Q.format=V.format),V.options&&(Q.options=V.options)),te==="select"&&!Q.options){const ie=Array.from(new Set(c.map(Fe=>Fe[z]).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:z,...te&&{headerIcon:m(te)},...J&&{align:J},...L&&{cell:ie=>t.jsx(L,{value:ie,field:Q})},sortable:V?.sortable!==!1}})}if(!_)return[];const pe=[];return(ke||Object.keys(_.fields||{})).forEach(D=>{const j=_.fields?.[D];if(!j||j.permissions&&j.permissions.read===!1)return;const z=Ze(j.type),V=["number","currency","percent"];pe.push({header:e.objectName?y(e.objectName,D,j.label||D):j.label||D,accessorKey:D,...V.includes(j.type)&&{align:"right"},cell:te=>t.jsx(z,{value:te,field:j}),sortable:j.sortable!==!1})}),pe},[_,ke,F,de,ze,be.handleClick,Ce,c,y,e.objectName]),Vt=l.useCallback(m=>{const X=e.exportOptions,P=X?.maxRecords||0,pe=X?.includeHeaders!==!1,Se=X?.fileNamePrefix||e.objectName||"export",D=P>0?c.slice(0,P):c,j=(V,te)=>{const L=URL.createObjectURL(V),C=document.createElement("a");C.href=L,C.download=te,C.click(),URL.revokeObjectURL(L)},z=V=>{const te=V==null?"":String(V);return te.includes(",")||te.includes('"')||te.includes(`
2
+ `)||te.includes("\r")?`"${te.replace(/"/g,'""')}"`:te};if(m==="csv"){const V=Ue().filter(Q=>Q.accessorKey!=="_actions"),te=V.map(Q=>Q.accessorKey),L=V.map(Q=>Q.header),C=[];pe&&C.push(L.join(",")),D.forEach(Q=>{C.push(te.map(re=>z(Q[re])).join(","))}),j(new Blob([C.join(`
3
+ `)],{type:"text/csv;charset=utf-8;"}),`${Se}.csv`)}else m==="json"&&j(new Blob([JSON.stringify(D,null,2)],{type:"application/json"}),`${Se}.json`);B(!1)},[c,e.exportOptions,e.objectName,Ue]);if(p)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:p.message})]});if(v&&c.length===0)return I?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(M.widths&&(qe=qe.map(m=>{const X=M.widths?.[m.accessorKey];return X?{...m,size:X}:m})),M.order&&M.order.length>0){const m=new Map(M.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&&n),onEdit:s,onDelete:n,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,xe=e.batchActions??e.bulkActions,ve=xe&&xe.length>0;let Ie=!1;e.selection?.type?Ie=e.selection.type==="none"?!1:e.selection.type:e.selectable!==void 0?Ie=e.selectable:ve&&(Ie="multiple");const he=e.pagination!==void 0?!0:e.showPagination!==void 0?e.showPagination:!0,Mt=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:he,pageSize:Mt,searchable:yn,selectable:Ie,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=>{R(m),r?.(m)},onRowClick:be.handleClick,onCellChange:o,onRowSave:d,onBatchSave:u,onColumnResize:(m,X)=>{H({...M,widths:{...M.widths,[m]:X}})},onColumnReorder:m=>{H({...M,order:m})}},jn=m=>({...us,caption:void 0,data:m,pagination:!1,searchable:!1}),zt=e.label?`${e.label} Detail`:e.objectName?`${e.objectName.charAt(0).toUpperCase()+e.objectName.slice(1)} Detail`:"Record Detail";if(I&&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"],D=["date","due","created","updated","deadline","start","end","expires"],j=["probability","percent","rate","ratio","confidence","score"],z=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"},V=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":D.some(Q=>C.includes(Q))?"date":j.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)),De=J?String(L[J.accessorKey]??""):"",Ee=De?V(De):"",We=["border rounded-lg p-2.5 bg-card hover:bg-accent/50 cursor-pointer transition-colors touch-manipulation",Ee?`border-l-[3px] ${Ee}`:""].filter(Boolean).join(" ");return t.jsxs("div",{className:We,onClick:()=>be.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"?zn(L[re.accessorKey]):L[re.accessorKey]??"—"}),J&&L[J.accessorKey]&&t.jsx(Ke,{variant:"outline",className:`text-xs shrink-0 max-w-[140px] truncate ${z(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)})}),be.isOverlay&&t.jsx(bt,{...be,title:zt,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:xi,short:bi,medium:hi,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:E,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:()=>Vt(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(([z])=>!X.includes(z)),Se=P.filter(([z])=>X.includes(z)&&z!=="_id"&&z!=="id"),D=z=>z.charAt(0).toUpperCase()+z.slice(1).replace(/_/g," "),j=(z,V)=>{if(V==null||V==="")return t.jsx("span",{className:"text-muted-foreground/50 text-sm italic",children:"Empty"});const te=_?.fields?.[z];if(te?.type){const C=Ze(te.type);if(C)return t.jsx(C,{value:V,field:te})}return typeof V=="boolean"?t.jsx(Ke,{variant:V?"default":"outline",children:V?"Yes":"No"}):typeof V=="string"&&!isNaN(Date.parse(V))&&(z.includes("date")||z.includes("_at")||z.includes("time"))?t.jsx("span",{className:"text-sm tabular-nums",children:_t(V)}):typeof V=="number"&&["amount","price","total","revenue","cost","value","budget","salary"].some(C=>z.toLowerCase().includes(C))?t.jsx("span",{className:"text-sm tabular-nums font-medium",children:_n(V)}):t.jsx("span",{className:"text-sm break-words",children:String(V)})};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(([z,V])=>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:D(z)}),t.jsx("div",{className:"flex-1 min-w-0",children:j(z,V)})]},z))})}),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(([z,V])=>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:D(z)}),t.jsx("span",{className:"text-xs text-muted-foreground flex-1 min-w-0 break-words",children:String(V??"")})]},z))})]})]})},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,hs=Je?t.jsx("div",{className:"space-y-2",children:it.map(m=>t.jsx(xr,{groupKey:m.key,label:m.label,count:m.rows.length,collapsed:m.collapsed,aggregations:m.aggregations,onToggle:je,children:t.jsx(Ve,{schema:jn(m.rows)})},m.key))}):t.jsxs(t.Fragment,{children:[t.jsx(Ve,{schema:us}),Nn]});return be.isOverlay&&be.mode==="split"?t.jsx(bt,{...be,title:zt,mainContent:t.jsxs(t.Fragment,{children:[ps,hs,t.jsx(Rs,{selectedRows:W,actions:xe??[],onAction:(m,X)=>Ce({type:m,params:{records:X}}),onClearSelection:()=>R([])})]}),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,hs,t.jsx(Rs,{selectedRows:W,actions:xe??[],onAction:(m,X)=>Ce({type:m,params:{records:X}}),onClearSelection:()=>R([])}),be.isOverlay&&t.jsx(bt,{...be,title:zt,children:m=>ms(m)})]})};function ot(e,i,s){let n=s.initialDeps??[],r,a=!0;function o(){var d,u,b;let g;s.key&&((d=s.debug)!=null&&d.call(s))&&(g=Date.now());const c=e();if(!(c.length!==n.length||c.some((N,p)=>n[p]!==N)))return r;n=c;let v;if(s.key&&((u=s.debug)!=null&&u.call(s))&&(v=Date.now()),r=i(...c),s.key&&((b=s.debug)!=null&&b.call(s))){const N=Math.round((Date.now()-g)*100)/100,p=Math.round((Date.now()-v)*100)/100,q=p/16,A=(y,_)=>{for(y=String(y);y.length<_;)y=" "+y;return y};console.info(`%c⏱ ${A(p,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&&!(a&&s.skipInitialOnChange)&&s.onChange(r),a=!1,r}return o.updateDeps=d=>{n=d},o}function Ms(e,i){if(e===void 0)throw new Error("Unexpected undefined");return e}const Fr=(e,i)=>Math.abs(e-i)<1.01,kr=(e,i,s)=>{let n;return function(...r){e.clearTimeout(n),n=e.setTimeout(()=>i.apply(this,r),s)}},zs=e=>{const{offsetWidth:i,offsetHeight:s}=e;return{width:i,height:s}},Or=e=>e,Ir=e=>{const i=Math.max(e.startIndex-e.overscan,0),s=Math.min(e.endIndex+e.overscan,e.count-1),n=[];for(let r=i;r<=s;r++)n.push(r);return n},Dr=(e,i)=>{const s=e.scrollElement;if(!s)return;const n=e.targetWindow;if(!n)return;const r=o=>{const{width:d,height:u}=o;i({width:Math.round(d),height:Math.round(u)})};if(r(zs(s)),!n.ResizeObserver)return()=>{};const a=new n.ResizeObserver(o=>{const d=()=>{const u=o[0];if(u?.borderBoxSize){const b=u.borderBoxSize[0];if(b){r({width:b.inlineSize,height:b.blockSize});return}}r(zs(s))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(d):d()});return a.observe(s,{box:"border-box"}),()=>{a.unobserve(s)}},Ls={passive:!0},_s=typeof window>"u"?!0:"onscrollend"in window,Er=(e,i)=>{const s=e.scrollElement;if(!s)return;const n=e.targetWindow;if(!n)return;let r=0;const a=e.options.useScrollendEvent&&_s?()=>{}:kr(n,()=>{i(r,!1)},e.options.isScrollingResetDelay),o=g=>()=>{const{horizontal:c,isRtl:h}=e.options;r=c?s.scrollLeft*(h&&-1||1):s.scrollTop,a(),i(r,g)},d=o(!0),u=o(!1);s.addEventListener("scroll",d,Ls);const b=e.options.useScrollendEvent&&_s;return b&&s.addEventListener("scrollend",u,Ls),()=>{s.removeEventListener("scroll",d),b&&s.removeEventListener("scrollend",u)}},Tr=(e,i,s)=>{if(i?.borderBoxSize){const n=i.borderBoxSize[0];if(n)return Math.round(n[s.options.horizontal?"inlineSize":"blockSize"])}return e[s.options.horizontal?"offsetWidth":"offsetHeight"]},Ar=(e,{adjustments:i=0,behavior:s},n)=>{var r,a;const o=e+i;(a=(r=n.scrollElement)==null?void 0:r.scrollTo)==null||a.call(r,{[n.options.horizontal?"left":"top"]:o,behavior:s})};class Rr{constructor(i){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=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.now=()=>{var s,n,r;return((r=(n=(s=this.targetWindow)==null?void 0:s.performance)==null?void 0:n.now)==null?void 0:r.call(n))??Date.now()},this.observer=(()=>{let s=null;const n=()=>s||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:s=new this.targetWindow.ResizeObserver(r=>{r.forEach(a=>{const o=()=>{this._measureElement(a.target,a)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()})}));return{disconnect:()=>{var r;(r=n())==null||r.disconnect(),s=null},observe:r=>{var a;return(a=n())==null?void 0:a.observe(r,{box:"border-box"})},unobserve:r=>{var a;return(a=n())==null?void 0:a.unobserve(r)}}})(),this.range=null,this.setOptions=s=>{Object.entries(s).forEach(([n,r])=>{typeof r>"u"&&delete s[n]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Or,rangeExtractor:Ir,onChange:()=>{},measureElement:Tr,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 n,r;(r=(n=this.options).onChange)==null||r.call(n,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.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var s;const n=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==n){if(this.cleanup(),!n){this.maybeNotify();return}this.scrollElement=n,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,a)=>{this.scrollAdjustments=0,this.scrollDirection=a?this.getScrollOffset()<r?"forward":"backward":null,this.scrollOffset=r,this.isScrolling=a,this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.rafId=null,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,n)=>{const r=new Map,a=new Map;for(let o=n-1;o>=0;o--){const d=s[o];if(r.has(d.lane))continue;const u=a.get(d.lane);if(u==null||d.end>u.end?a.set(d.lane,d):d.end<u.end&&r.set(d.lane,!0),r.size===this.options.lanes)break}return a.size===this.options.lanes?Array.from(a.values()).sort((o,d)=>o.end===d.end?o.index-d.index:o.end-d.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,n,r,a,o,d)=>(this.prevLanes!==void 0&&this.prevLanes!==d&&(this.lanesChangedFlag=!0),this.prevLanes=d,this.pendingMeasuredCacheIndexes=[],{count:s,paddingStart:n,scrollMargin:r,getItemKey:a,enabled:o,lanes:d}),{key:!1}),this.getMeasurements=ot(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:s,paddingStart:n,scrollMargin:r,getItemKey:a,enabled:o,lanes:d},u)=>{if(!o)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>s)for(const h of this.laneAssignments.keys())h>=s&&this.laneAssignments.delete(h);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(h=>{this.itemSizeCache.set(h.key,h.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(d).fill(void 0);for(let h=0;h<b;h++){const v=g[h];v&&(c[v.lane]=h)}for(let h=b;h<s;h++){const v=a(h),N=this.laneAssignments.get(h);let p,q;if(N!==void 0&&this.options.lanes>1){p=N;const Y=c[p],I=Y!==void 0?g[Y]:void 0;q=I?I.end+this.options.gap:n+r}else{const Y=this.options.lanes===1?g[h-1]:this.getFurthestMeasurement(g,h);q=Y?Y.end+this.options.gap:n+r,p=Y?Y.lane:h%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(h,p)}const A=u.get(v),y=typeof A=="number"?A:this.options.estimateSize(h),_=q+y;g[h]={index:h,start:q,size:y,end:_,key:v,lane:p},c[p]=h}return this.measurementsCache=g,g},{key:!1,debug:()=>this.options.debug}),this.calculateRange=ot(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(s,n,r,a)=>this.range=s.length>0&&n>0?Vr({measurements:s,outerSize:n,scrollOffset:r,lanes:a}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=ot(()=>{let s=null,n=null;const r=this.calculateRange();return r&&(s=r.startIndex,n=r.endIndex),this.maybeNotify.updateDeps([this.isScrolling,s,n]),[this.options.rangeExtractor,this.options.overscan,this.options.count,s,n]},(s,n,r,a,o)=>a===null||o===null?[]:s({startIndex:a,endIndex:o,overscan:n,count:r}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=s=>{const n=this.options.indexAttribute,r=s.getAttribute(n);return r?parseInt(r,10):(console.warn(`Missing attribute name '${n}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=s=>{var n;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const r=this.scrollState.index??((n=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:n.index);if(r!==void 0&&this.range){const a=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),o=Math.max(0,r-a),d=Math.min(this.options.count-1,r+a);return s>=o&&s<=d}return!0},this._measureElement=(s,n)=>{if(!s.isConnected){this.observer.unobserve(s);return}const r=this.indexFromElement(s),a=this.measurementsCache[r];if(!a)return;const o=a.key,d=this.elementsCache.get(o);d!==s&&(d&&this.observer.unobserve(d),this.observer.observe(s),this.elementsCache.set(o,s)),this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(s,n,this))},this.resizeItem=(s,n)=>{var r;const a=this.measurementsCache[s];if(!a)return;const o=this.itemSizeCache.get(a.key)??a.size,d=n-o;d!==0&&(((r=this.scrollState)==null?void 0:r.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(a,d,this):a.start<this.getScrollOffset()+this.scrollAdjustments)&&this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=d,behavior:void 0}),this.pendingMeasuredCacheIndexes.push(a.index),this.itemSizeCache=new Map(this.itemSizeCache.set(a.key,n)),this.notify(!1))},this.measureElement=s=>{if(!s){this.elementsCache.forEach((n,r)=>{n.isConnected||(this.observer.unobserve(n),this.elementsCache.delete(r))});return}this._measureElement(s,void 0)},this.getVirtualItems=ot(()=>[this.getVirtualIndexes(),this.getMeasurements()],(s,n)=>{const r=[];for(let a=0,o=s.length;a<o;a++){const d=s[a],u=n[d];r.push(u)}return r},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=s=>{const n=this.getMeasurements();if(n.length!==0)return Ms(n[fn(0,n.length-1,r=>Ms(n[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,n,r=0)=>{if(!this.scrollElement)return 0;const a=this.getSize(),o=this.getScrollOffset();n==="auto"&&(n=s>=o+a?"end":"start"),n==="center"?s+=(r-a)/2:n==="end"&&(s-=a);const d=this.getMaxScrollOffset();return Math.max(Math.min(d,s),0)},this.getOffsetForIndex=(s,n="auto")=>{s=Math.max(0,Math.min(s,this.options.count-1));const r=this.getSize(),a=this.getScrollOffset(),o=this.measurementsCache[s];if(!o)return;if(n==="auto")if(o.end>=a+r-this.options.scrollPaddingEnd)n="end";else if(o.start<=a+this.options.scrollPaddingStart)n="start";else return[a,n];if(n==="end"&&s===this.options.count-1)return[this.getMaxScrollOffset(),n];const d=n==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(d,n,o.size),n]},this.scrollToOffset=(s,{align:n="start",behavior:r="auto"}={})=>{const a=this.getOffsetForAlignment(s,n),o=this.now();this.scrollState={index:null,align:n,behavior:r,startedAt:o,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToIndex=(s,{align:n="auto",behavior:r="auto"}={})=>{s=Math.max(0,Math.min(s,this.options.count-1));const a=this.getOffsetForIndex(s,n);if(!a)return;const[o,d]=a,u=this.now();this.scrollState={index:s,align:d,behavior:r,startedAt:u,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollBy=(s,{behavior:n="auto"}={})=>{const r=this.getScrollOffset()+s,a=this.now();this.scrollState={index:null,align:"start",behavior:n,startedAt:a,lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{var s;const n=this.getMeasurements();let r;if(n.length===0)r=this.options.paddingStart;else if(this.options.lanes===1)r=((s=n[n.length-1])==null?void 0:s.end)??0;else{const a=Array(this.options.lanes).fill(null);let o=n.length-1;for(;o>=0&&a.some(d=>d===null);){const d=n[o];a[d.lane]===null&&(a[d.lane]=d.end),o--}r=Math.max(...a.filter(d=>d!==null))}return Math.max(r-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(s,{adjustments:n,behavior:r})=>{this.options.scrollToFn(s,{behavior:r,adjustments:n},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(i)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const n=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,r=n?n[0]:this.scrollState.lastTargetOffset,a=1,o=r!==this.scrollState.lastTargetOffset;if(!o&&Fr(r,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=a){this.scrollState=null;return}}else this.scrollState.stableFrames=0,o&&(this.scrollState.lastTargetOffset=r,this.scrollState.behavior="auto",this._scrollToOffset(r,{adjustments:void 0,behavior:"auto"}));this.scheduleScrollReconcile()}}const fn=(e,i,s,n)=>{for(;e<=i;){const r=(e+i)/2|0,a=s(r);if(a<n)e=r+1;else if(a>n)i=r-1;else return r}return e>0?e-1:0};function Vr({measurements:e,outerSize:i,scrollOffset:s,lanes:n}){const r=e.length-1,a=u=>e[u].start;if(e.length<=n)return{startIndex:0,endIndex:r};let o=fn(0,r,a,s),d=o;if(n===1)for(;d<r&&e[d].end<s+i;)d++;else if(n>1){const u=Array(n).fill(0);for(;d<r&&u.some(g=>g<s+i);){const g=e[d];u[g.lane]=g.end,d++}const b=Array(n).fill(s+i);for(;o>=0&&b.some(g=>g>=s);){const g=e[o];b[g.lane]=g.start,o--}o=Math.max(0,o-o%n),d=Math.min(r,d+(n-1-d%n))}return{startIndex:o,endIndex:d}}const $s=typeof document<"u"?l.useLayoutEffect:l.useEffect;function Mr({useFlushSync:e=!0,...i}){const s=l.useReducer(()=>({}),{})[1],n={...i,onChange:(a,o)=>{var d;e&&o?Sn.flushSync(s):s(),(d=i.onChange)==null||d.call(i,a,o)}},[r]=l.useState(()=>new Rr(n));return r.setOptions(n),$s(()=>r._didMount(),[]),$s(()=>r._willUpdate()),r}function Fl(e){return Mr({observeElementRect:Dr,observeElementOffset:Er,scrollToFn:Ar,...e})}const zr=10;function Lr(e){const i=[];let s=[],n="",r=!1;for(let a=0;a<e.length;a++){const o=e[a],d=e[a+1];r?o==='"'&&d==='"'?(n+='"',a++):o==='"'?r=!1:n+=o:o==='"'?r=!0:o===","?(s.push(n.trim()),n=""):o===`
7
+ `||o==="\r"&&d===`
8
+ `?(s.push(n.trim()),s.some(u=>u!=="")&&i.push(s),s=[],n="",o==="\r"&&a++):n+=o}return s.push(n.trim()),s.some(a=>a!=="")&&i.push(s),i}function pn(e,i){if(!e)return!0;switch(i){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,i){const s={};return e.forEach((n,r)=>{const a=n.toLowerCase().replace(/[_\s-]/g,""),o=i.find(d=>{const u=d.name.toLowerCase().replace(/[_\s-]/g,""),b=d.label.toLowerCase().replace(/[_\s-]/g,"");return u===a||b===a});o&&(s[r]=o.name)}),s}function $r(e,i,s){const n=[],r={};for(const a of i){const o=e[a.csvIdx]??"";if(a.field.required&&!o){n.push({row:s,field:a.field.name,message:"Required field is empty"});continue}if(o&&!pn(o,a.field.type)){n.push({row:s,field:a.field.name,message:`Invalid ${a.field.type} value: "${o}"`});continue}r[a.field.name]=o}return{record:r,errors:n}}const Pr=({onFileLoaded:e})=>{const[i,s]=l.useState(!1),[n,r]=l.useState(null),a=l.useCallback(o=>{if(r(null),!o.name.endsWith(".csv")){r("Only CSV files are supported.");return}const d=new FileReader;d.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))},d.readAsText(o)},[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",i?"border-primary bg-primary/5":"border-muted-foreground/25"),onDragOver:o=>{o.preventDefault(),s(!0)},onDragLeave:()=>s(!1),onDrop:o=>{o.preventDefault(),s(!1);const d=o.dataTransfer.files[0];d&&a(d)},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:o=>{const d=o.target.files?.[0];d&&a(d)}}),t.jsx(ne,{variant:"outline",size:"sm",asChild:!0,children:t.jsx("span",{children:"Browse Files"})})]})]}),n&&t.jsxs("p",{className:"flex items-center gap-1 text-sm text-destructive",children:[t.jsx(on,{className:"h-4 w-4"})," ",n]})]})},qr=({headers:e,fields:i,mapping:s,onMappingChange:n})=>{const r=l.useMemo(()=>new Set(Object.values(s)),[s]),a=l.useCallback((o,d)=>{const u={...s};d==="__skip__"?delete u[o]:u[o]=d,n(u)},[s,n]);return t.jsx("div",{className:"max-h-[360px] overflow-auto",children:t.jsxs(Gs,{children:[t.jsx(Ys,{children:t.jsxs(Et,{children:[t.jsx(xt,{children:"CSV Column"}),t.jsx(xt,{children:"Maps To"}),t.jsx(xt,{className:"w-24 text-center",children:"Status"})]})}),t.jsx(Js,{children:e.map((o,d)=>t.jsxs(Et,{children:[t.jsx(gt,{className:"font-medium",children:o}),t.jsx(gt,{children:t.jsxs(jt,{value:s[d]??"__skip__",onValueChange:u=>a(d,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 —"}),i.map(u=>t.jsxs(tt,{value:u.name,disabled:r.has(u.name)&&s[d]!==u.name,children:[u.label,u.required?" *":""]},u.name))]})]})}),t.jsx(gt,{className:"text-center",children:s[d]?t.jsx(Ke,{variant:"default",className:"text-xs",children:"Mapped"}):t.jsx(Ke,{variant:"secondary",className:"text-xs",children:"Skipped"})})]},d))})]})})},Br=({headers:e,rows:i,mapping:s,fields:n})=>{const r=l.useMemo(()=>Object.entries(s).map(([u,b])=>({csvIdx:Number(u),header:e[Number(u)],field:n.find(g=>g.name===b)})),[s,e,n]),a=i.slice(0,zr),o=l.useMemo(()=>a.map((u,b)=>{const g={};for(const c of r){const h=u[c.csvIdx]??"";c.field.required&&!h?g[c.csvIdx]="Required":h&&!pn(h,c.field.type)&&(g[c.csvIdx]=`Invalid ${c.field.type}`)}return g}),[a,r]),d=o.filter(u=>Object.keys(u).length>0).length;return t.jsxs("div",{className:"max-h-[360px] overflow-auto",children:[d>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"})," ",d," row(s) with errors in preview"]}),t.jsxs(Gs,{children:[t.jsx(Ys,{children:t.jsxs(Et,{children:[t.jsx(xt,{className:"w-12",children:"#"}),r.map(u=>t.jsx(xt,{children:u.field.label},u.csvIdx))]})}),t.jsx(Js,{children:a.map((u,b)=>{const g=o[b],c=Object.keys(g).length>0;return t.jsxs(Et,{className:Z(c&&"bg-destructive/5"),children:[t.jsx(gt,{className:"text-xs text-muted-foreground",children:b+1}),r.map(h=>{const v=u[h.csvIdx]??"",N=g[h.csvIdx];return t.jsx(gt,{className:Z(N&&"text-destructive"),title:N,children:v||t.jsx("span",{className:"text-muted-foreground/50",children:"—"})},h.csvIdx)})]},b)})})]}),t.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:["Showing ",a.length," of ",i.length," rows"]})]})},Kr=({objectName:e,objectLabel:i,fields:s,dataSource:n,onComplete:r,onCancel:a,open:o,onOpenChange:d,onErrorMode:u="skip"})=>{const[b,g]=l.useState("upload"),[c,h]=l.useState([]),[v,N]=l.useState([]),[p,q]=l.useState({}),[A,y]=l.useState(!1),[_,Y]=l.useState(0),[I,x]=l.useState(null),f=i??e,w=l.useMemo(()=>{const W=new Set(Object.values(p));return s.filter(R=>R.required&&!W.has(R.name))},[s,p]),E=l.useCallback((W,R)=>{h(W),N(R),q(_r(W,s)),g("mapping")},[s]),B=l.useCallback(async()=>{y(!0),Y(0);const W=[];let R=0,T=0;const M=Object.entries(p).map(([H,se])=>({csvIdx:Number(H),field:s.find(ee=>ee.name===se)}));for(let H=0;H<v.length;H++){const{record:se,errors:ee}=$r(v[H],M,H+1);if(ee.length>0){if(T++,W.push(...ee),u==="stop")break}else try{n?.create&&await n.create(e,se),R++}catch(Ae){T++;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)/v.length*100))}const K={totalRows:v.length,importedRows:R,skippedRows:T,errors:W};x(K),y(!1),r?.(K)},[v,p,s,n,e,r,u]),U=l.useCallback(()=>{g("upload"),h([]),N([]),q({}),Y(0),x(null)},[]),O=l.useCallback(()=>{U(),d?.(!1),a?.()},[U,d,a]);return t.jsx(Xt,{open:o,onOpenChange:W=>{W?d?.(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 ",f]}),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,R)=>t.jsxs($e.Fragment,{children:[R>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:[R+1,". ",W==="upload"?"Upload":W==="mapping"?"Mapping":"Preview"]})]},W))}),I?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:[I.importedRows," imported"]}),I.skippedRows>0&&t.jsxs(Ke,{variant:"destructive",children:[I.skippedRows," skipped"]})]}),I.errors.length>0&&t.jsxs("div",{className:"max-h-32 w-full overflow-auto rounded border p-2 text-xs",children:[I.errors.slice(0,10).map((W,R)=>t.jsxs("p",{className:"text-destructive",children:["Row ",W.row,W.field?` (${W.field})`:"",": ",W.message]},R)),I.errors.length>10&&t.jsxs("p",{className:"text-muted-foreground",children:["…and ",I.errors.length-10," more errors"]})]})]}):t.jsxs(t.Fragment,{children:[b==="upload"&&t.jsx(Pr,{onFileLoaded:E}),b==="mapping"&&t.jsx(qr,{headers:c,fields:s,mapping:p,onMappingChange:q}),b==="preview"&&t.jsx(Br,{headers:c,rows:v,mapping:p,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:I?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(p).length===0||w.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 ${v.length} Rows`})]})})]})})},mn=({schema:e,...i})=>{const{dataSource:s}=nn()||{};return t.jsx(un,{schema:e,dataSource:s,...i})};Te.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"}]});Te.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,...i})=>{const{dataSource:s}=nn()||{};return t.jsx(Kr,{objectName:e.objectName,objectLabel:e.objectLabel,fields:e.fields??[],dataSource:s,...i})};Te.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:Ri,detail:Ai,grid:Ti,kanban:dn,calendar:Tt,timeline:Ei,map:Di,gallery:Ii,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(i=>i.charAt(0).toUpperCase()+i.slice(1)).join("")}const Zr={Home:"House"};function hn(e){if(!e)return null;const i=Xr(e),s=Zr[i]||i;return ki[s]||null}function Kt(e){return e.label?e.label:Wr[e.type]||e.type}function Ps(e){return e.icon?hn(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"},bn=({schema:e,className:i,onViewChange:s,onCreateView:n,onViewAction:r,createViewLabel:a="Create view",...o})=>{const d=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 f=localStorage.getItem(d);if(f){const w=e.views.find(E=>E.type===f)?.type;w&&b(w)}}catch{}},[e.activeView,e.persistPreference,e.views,d]),l.useEffect(()=>{if(!(!e.persistPreference||!u||e.activeView))try{localStorage.setItem(d,u)}catch{}},[u,e.activeView,e.persistPreference,d]);const g=l.useCallback(f=>{s?.(f),e.onViewChange&&typeof window<"u"&&window.dispatchEvent(new CustomEvent(e.onViewChange,{detail:{view:f}}))},[s,e.onViewChange]),c=l.useCallback(f=>{b(f),g(f)},[g]),h=u||e.views?.[0]?.type,v=h||"",N=e.views.find(f=>f.type===h)||e.views?.[0],p=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((f,w)=>{const E=f.icon&&hn(f.icon)||qs[f.type];return t.jsx(ne,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>r?.(f.type,h),title:tl[f.type]||f.type,children:E?t.jsx(E,{className:"h-3.5 w-3.5"}):null},`action-${f.type}-${w}`)})}):null,Y=e.allowCreateView?t.jsx(ne,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>n?.(),title:a,children:t.jsx(os,{className:"h-3.5 w-3.5"})}):null,I=t.jsxs("div",{className:Z(Yr({orientation:y}),"flex items-center gap-1"),children:[p==="dropdown"&&t.jsxs(jt,{value:v,onValueChange:f=>c(f),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((f,w)=>t.jsx(tt,{value:f.type,children:Kt(f)},`${f.type}-${w}`))})]}),p==="buttons"&&t.jsx("div",{className:Z(Jr({orientation:y})),children:e.views.map((f,w)=>{const E=f.type===h,B=Ps(f);return t.jsxs(ne,{type:"button",size:"sm",variant:E?"secondary":"ghost",className:Z("justify-start gap-2",A?"w-full":""),onClick:()=>c(f.type),children:[B?t.jsx(B,{className:"h-4 w-4"}):null,t.jsx("span",{children:Kt(f)})]},`${f.type}-${w}`)})}),p==="tabs"&&t.jsx(Yt,{value:v,onValueChange:f=>c(f),children:t.jsx(Jt,{className:Z(Qr({orientation:y})),children:e.views.map((f,w)=>{const E=Ps(f);return t.jsxs(Qt,{value:f.type,className:Z("gap-2",A?"justify-start":""),children:[E?t.jsx(E,{className:"h-4 w-4"}):null,t.jsx("span",{children:Kt(f)})]},`${f.type}-${w}`)})})}),_,Y]}),x=N?.schema?Array.isArray(N.schema)?t.jsx("div",{className:"space-y-4",children:N.schema.map((f,w)=>t.jsx(Ve,{schema:f,...o},`${N.type}-${w}`))}):t.jsx(Ve,{schema:N.schema,...o}):null;return t.jsxs("div",{className:Z(Gr({position:q}),i),children:[t.jsx("div",{className:Z("shrink-0",A?"flex flex-col":"flex"),children:I}),t.jsx("div",{className:"flex-1 min-w-0",children:x})]})};let Dt=null;try{Dt=require("@object-ui/react").SchemaRenderer||null}catch{}const sl=({schema:e,dataSource:i,className:s,views:n,activeViewId:r,onViewChange:a,onRowClick:o,onEdit:d,renderListView:u,toolbarAddon:b,onCreateView:g,onViewAction:c})=>{const[h,v]=l.useState(null),[N,p]=l.useState(!1),[q,A]=l.useState("create"),[y,_]=l.useState(null),[Y,I]=l.useState(0),[x,f]=l.useState([]),[w,E]=l.useState(!1),[B,U]=l.useState({}),[O,W]=l.useState([]),R=e.listViews,T=R!=null&&Object.keys(R).length>0,[M,K]=l.useState(()=>e.defaultListView&&R?.[e.defaultListView]?e.defaultListView:R&&Object.keys(R)[0]||""),H=l.useMemo(()=>!T||!M?null:R[M]||null,[T,M,R]),se=l.useMemo(()=>n&&n.length>0?n:null,[n]),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 i.getObjectSchema(e.objectName);k&&v(G)}catch(G){console.error("Failed to fetch object schema:",G)}};return e.objectName&&i&&$(),()=>{k=!1}},[e.objectName,i]),l.useEffect(()=>{let k=!0;return(async()=>{if(!(Ne==="grid"&&!u)&&!(!i||!e.objectName)){E(!0);try{const G=H?.filter||S?.filter||e.table?.defaultFilters||[],Oe=Object.entries(B).filter(([,he])=>he!==void 0&&he!==""&&he!==null).map(([he,Mt])=>[he,"=",Mt]);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(he=>({field:he.field,order:he.direction})):H?.sort||S?.sort||e.table?.defaultSort||void 0,xe=sn(h?.fields),ve=await i.find(e.objectName,{$filter:ge.length>0?ge:void 0,$orderby:Le,$top:100,...xe.length>0?{$expand:xe}:{}});let Ie=[];Array.isArray(ve)?Ie=ve:ve&&typeof ve=="object"&&(Array.isArray(ve.data)?Ie=ve.data:Array.isArray(ve.records)&&(Ie=ve.records)),k&&f(Ie)}catch(G){console.error("ObjectView data fetch error:",G)}finally{k&&E(!1)}}})(),()=>{k=!1}},[e.objectName,i,Ne,B,O,Y,H,S,u,h]);const Me=e.layout||"drawer",de=e.operations||e.table?.operations||{create:!0,read:!0,update:!0,delete:!0},ze=l.useCallback(()=>{Me==="page"&&e.onNavigate?e.onNavigate("new","edit"):(A("create"),_(null),p(!0))},[Me,e]),we=l.useCallback(k=>{if(d){d(k);return}if(Me==="page"&&e.onNavigate){const $=k.id||k._id;e.onNavigate($,"edit")}else A("edit"),_(k),p(!0)},[Me,e,d]),ke=l.useCallback(k=>{if(Me==="page"&&e.onNavigate){const $=k.id||k._id;e.onNavigate($,"view")}else A("view"),_(k),p(!0)},[Me,e]),F=l.useCallback(k=>{if(o){o(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}/${encodeURIComponent(String($))}`;window.open(G,"_blank");return}if(ae.mode==="drawer"){A("view"),_(k),p(!0);return}if(ae.mode==="modal"){A("view"),_(k),p(!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),p(!0);return}}de.read!==!1&&ke(k)},[o,ae,de.read,ke,e]),ue=l.useCallback(k=>{I($=>$+1)},[]),me=l.useCallback(k=>{I($=>$+1)},[]),ye=l.useCallback(()=>{p(!1),_(null),I(k=>k+1)},[]),fe=l.useCallback(()=>{p(!1),_(null)},[]);l.useCallback(()=>{I(k=>k+1)},[]);const be=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);$&&a&&a($.id)},[se,a]),Ct=l.useCallback(k=>{K(k)},[]);l.useMemo(()=>{if(e.showFilters===!1)return null;const k=e.filterableFields,$=h?.fields||{},Oe=(k?k.map(ge=>[ge,$[ge]||{label:ge}]):Object.entries($).filter(([,ge])=>!ge.hidden).slice(0,8)).map(([ge,Le])=>{const xe=Le.type||"text";let ve="text",Ie;return xe==="number"||xe==="currency"||xe==="percent"?ve="number":xe==="boolean"||xe==="toggle"?ve="boolean":xe==="date"||xe==="datetime"?ve="date":xe==="select"||xe==="status"||Le.options?(ve="select",Ie=(Le.options||[]).map(he=>typeof he=="string"?{label:he,value:he}:{label:he.label,value:he.value})):(xe==="lookup"||xe==="master_detail"||xe==="user"||xe==="owner")&&Le.options&&Le.options.length>0&&(ve="multi-select",Ie=(Le.options||[]).map(he=>typeof he=="string"?{label:he,value:he}:{label:he.label,value:he.value})),{field:ge,label:Le.label||ge,type:ve,placeholder:`Filter ${Le.label||ge}...`,...Ie?{options:Ie}:{}}});return Oe.length===0?null:{type:"filter-ui",layout:"popover",showClear:!0,showApply:!0,filters:Oe,values:B}},[e.showFilters,e.filterableFields,h,B]);const nt=e.showSort;l.useMemo(()=>{if(nt===!1)return null;const k=h?.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}},[h,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=h?.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:p,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:i})})]})}),Ue=()=>t.jsx(Xt,{open:N,onOpenChange:p,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:i})]})}),Vt=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}-${M||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:Vt,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,userFilters:S?.userFilters??e.userFilters,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:i,onEdit:we,onRowClick:F,className:"h-full"});if(Ne!=="grid"){const $=it(Ne);if($&&Dt)return t.jsx(Dt,{schema:$,dataSource:i,data:x,loading:w},k);if(!Dt)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:i,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(!T)return null;const k=Object.entries(R);return k.length<=1?null:t.jsx(Yt,{value:M,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:$&&be&&t.jsx(bn,{schema:be,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:ze,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":Me,Qe=k=>t.jsx("div",{className:"space-y-3",children:t.jsx(yt,{schema:je(),dataSource:i})}),lt=l.useCallback(k=>{k||fe()},[fe]);if(rt==="split"){const k=h?.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(bt,{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(bt,{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(i=>i==null||i===""):!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:i,onChange:s})=>{const[n,r]=l.useState(e.values||{}),[a,o]=l.useState(!1);l.useEffect(()=>{e.values&&r(e.values)},[e.values]);const d=l.useCallback(p=>{s?.(p),e.onChange&&typeof window<"u"&&window.dispatchEvent(new CustomEvent(e.onChange,{detail:{values:p}}))},[s,e.onChange]),u=l.useCallback((p,q)=>{const A={...n,[p]:q};r(A),e.showApply||d(A)},[d,e.showApply,n]),b=l.useCallback(()=>{const p={};if(r(p),e.showApply){d(p);return}d(p)},[d,e.showApply]),g=l.useCallback(()=>{d(n),o(!1)},[d,n]),c=l.useMemo(()=>Object.values(n).filter(p=>!nl(p)).length,[n]),h=p=>{const q=p.label||p.field,A=p.placeholder||`Filter by ${q}`;switch(p.type){case"number":return t.jsx(He,{type:"number",value:n[p.field]??"",placeholder:A,onChange:y=>{const _=y.target.value,Y=_===""?"":Number(_);u(p.field,Y)}});case"select":return t.jsxs(jt,{value:n[p.field]!==void 0?String(n[p.field]):"",onValueChange:y=>{const _=p.options?.find(Y=>String(Y.value)===y);u(p.field,_?_.value:y)},children:[t.jsx(wt,{children:t.jsx(vt,{placeholder:A})}),t.jsx(Nt,{children:p.options?.map(y=>t.jsx(tt,{value:String(y.value),children:y.label},String(y.value)))})]});case"multi-select":{const y=n[p.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:p.options?.map(Y=>{const I=_.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",I?"bg-primary/5 text-primary":"hover:bg-muted"),children:[t.jsx(gs,{checked:I,onCheckedChange:x=>{const f=x?[..._,Y.value]:_.filter(w=>String(w)!==String(Y.value));u(p.field,f)}}),t.jsx("span",{className:"truncate",children:Y.label})]},String(Y.value))})})}case"date":return t.jsx(He,{type:"date",value:n[p.field]??"",onChange:y=>u(p.field,y.target.value)});case"date-range":{const y=il(n[p.field]);return t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(He,{type:"date",value:y.start??"",onChange:_=>{u(p.field,{...y,start:_.target.value})}}),t.jsx(He,{type:"date",value:y.end??"",onChange:_=>{u(p.field,{...y,end:_.target.value})}})]})}case"boolean":return t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(gs,{checked:!!n[p.field],onCheckedChange:y=>u(p.field,!!y)}),t.jsx("span",{className:"text-sm text-muted-foreground",children:"Enabled"})]});case"text":default:return t.jsx(He,{value:n[p.field]??"",placeholder:A,onChange:y=>u(p.field,y.target.value)})}},v=t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"grid gap-4 sm:grid-cols-2",children:e.filters.map(p=>t.jsxs("div",{className:"space-y-2",children:[t.jsx(qn,{className:"text-xs text-muted-foreground",children:p.label||p.field}),h(p)]},p.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}),i),children:t.jsxs(ss,{open:a,onOpenChange:o,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:v})]})}):N==="drawer"?t.jsxs("div",{className:Z(Ut({layout:N}),i),children:[t.jsxs(ne,{type:"button",variant:c>0?"secondary":"outline",size:"sm",className:"gap-2",onClick:()=>o(!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:a,onOpenChange:o,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:v})]})})]}):t.jsxs("div",{className:Z(Ut({layout:N}),i),children:[v,!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(i=>({field:i.field,direction:i.direction})):[],Bs=e=>e.map(i=>({id:`${i.field}-${i.direction}`,field:i.field,order:i.direction})),ll=e=>e.filter(i=>i.field).map(i=>({field:i.field,direction:i.order})),al=({schema:e,className:i,onChange:s})=>{const[n,r]=l.useState(()=>Ht(e.sort)),[a,o]=l.useState(()=>Bs(Ht(e.sort)));l.useEffect(()=>{const c=Ht(e.sort);r(c),o(Bs(c))},[e.sort]);const d=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 h=n.find(p=>p.field===c),v=!!e.multiple;if(!h){const p=v?[...n,{field:c,direction:"asc"}]:[{field:c,direction:"asc"}];d(p);return}if(h.direction==="asc"){const p=n.map(q=>q.field===c?{...q,direction:"desc"}:q);d(p);return}const N=n.filter(p=>p.field!==c);d(N)},[d,e.multiple,n]);if((e.variant||"dropdown")==="buttons")return t.jsx("div",{className:Z(Wt({variant:"buttons"}),i),children:e.fields.map(c=>{const h=n.find(N=>N.field===c.field),v=h?.direction==="asc"?Vi:Mi;return t.jsxs(ne,{type:"button",variant:h?"secondary":"outline",size:"sm",onClick:()=>u(c.field),className:"gap-2",children:[t.jsx("span",{children:c.label||c.field}),h&&t.jsx(v,{className:"h-3.5 w-3.5"})]},c.field)})});if(e.multiple)return t.jsx("div",{className:Z(Wt({variant:"builder"}),i),children:t.jsx(Bn,{fields:e.fields.map(c=>({value:c.field,label:c.label||c.field})),value:a,onChange:c=>{o(c),d(ll(c))}})});const g=n[0];return t.jsxs("div",{className:Z(Wt({variant:"dropdown"}),i),children:[t.jsxs(jt,{value:g?.field||"",onValueChange:c=>{if(!c){d([]);return}d([{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&&d([{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,i=>i.toString(16).padStart(2,"0")).join("")}return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}function dl(e,i,s,n){return`${e}/share/${i}/${s}?mode=readonly&token=${n}`}const cl=({objectName:e,viewId:i="default",baseUrl:s,onShare:n,className:r})=>{const[a,o]=l.useState(null),[d,u]=l.useState(!1),[b,g]=l.useState(!1),[c,h]=l.useState(""),[v,N]=l.useState(""),p=s??(typeof window<"u"?window.location.origin:""),q=l.useCallback(()=>{const y=ol(),_=dl(p,e,i,y);o(_),u(!1);const Y=v?new Date(Date.now()+parseInt(v,10)*864e5).toISOString():void 0;n?.(_,{password:c||void 0,expiresAt:Y})},[p,e,i,n,c,v]),A=l.useCallback(async()=>{if(a)try{await navigator.clipboard.writeText(a),u(!0),setTimeout(()=>u(!1),2e3)}catch{const y=document.createElement("textarea");y.value=a,document.body.appendChild(y),y.select(),document.execCommand("copy"),document.body.removeChild(y),u(!0),setTimeout(()=>u(!1),2e3)}},[a]);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."})]}),a?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(He,{value:a,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:d?t.jsx(ln,{className:"h-4 w-4 text-green-500"}):t.jsx(as,{className:"h-4 w-4"})})]}),(c||v)&&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"]}),v&&t.jsxs(Ke,{variant:"outline",className:"text-xs gap-1",children:[t.jsx(Tt,{className:"h-3 w-3"}),"Expires in ",v," day",v!=="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=>h(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(Tt,{className:"h-3.5 w-3.5"}),"Expires after (optional)"]}),t.jsxs("select",{value:v,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:i,children:s})=>{const{attributes:n,listeners:r,setNodeRef:a,transform:o,transition:d,isDragging:u}=di({id:e,disabled:i}),b={transform:ci.Transform.toString(o),transition:d,zIndex:u?10:void 0,opacity:u?.5:void 0};return t.jsx(t.Fragment,{children:s({setNodeRef:a,style:b,listeners:r,attributes:n,isDragging:u})})},kl=({views:e,activeViewId:i,onViewChange:s,viewTypeIcons:n={},config:r={},onAddView:a,onRenameView:o,onDuplicateView:d,onDeleteView:u,onSetDefaultView:b,onShareView:g,onSaveAsView:c,onPinView:h,onReorderViews:v,onChangeViewType:N,onConfigView:p,availableViewTypes:q,hasUnsavedChanges:A=!1,onResetChanges:y,className:_})=>{const{showAddButton:Y=!0,inlineRename:I=!0,contextMenu:x=!0,reorderable:f=!1,maxVisibleTabs:w=6,showIndicators:E=!0,showSaveAsView:B=!0,showPinnedSection:U=!0,showVisibilityGroups:O=!1}=r,[W,R]=l.useState(null),[T,M]=l.useState(""),K=l.useRef(null);l.useEffect(()=>{W&&K.current&&(K.current.focus(),K.current.select())},[W]);const H=l.useCallback(F=>{if(!I||!o)return;const ue=e.find(me=>me.id===F);ue&&(R(F),M(ue.label))},[I,o,e]),se=l.useCallback(()=>{W&&T.trim()&&o&&o(W,T.trim()),R(null),M("")},[W,T,o]),ee=l.useCallback(()=>{R(null),M("")},[]),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,w),Ne=Ae.slice(w),ae=ti(Ns(ni,{activationConstraint:{distance:ul}}),Ns(si)),Me=l.useCallback(F=>{const{active:ue,over:me}=F;if(!me||ue.id===me.id||!v)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 be=ii(Ae,ye,fe);v(be.map(Ce=>Ce.id))},[Ae,v]),de=Li,ze=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===i,ye=n[F.type]||de,fe=W===F.id,be=E&&(F.hasActiveFilters||F.hasActiveSort),Ce=ze(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:[f&&v&&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:T,onChange:ce=>M(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}),be&&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&&p&&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(),p(F.id)},"aria-label":`Configure ${F.label}`,children:t.jsx(Ki,{className:"h-3 w-3"})})]}),Je=je=>!x||fe?je:t.jsxs(Un,{children:[t.jsx(Wn,{asChild:!0,children:je}),t.jsxs(Hn,{children:[o&&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"]}),d&&t.jsxs(et,{"data-testid":`context-menu-duplicate-${F.id}`,onClick:()=>d(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"]}),h&&t.jsx(et,{"data-testid":`context-menu-pin-${F.id}`,onClick:()=>h(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=n[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 f&&v?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:[f&&v?t.jsx(ri,{sensors:ae,collisionDetection:li,onDragEnd:Me,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(zi,{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=n[F.type]||de;return t.jsxs(It,{"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,E&&(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&&a&&t.jsxs(ys,{children:[t.jsx(js,{asChild:!0,children:t.jsx("button",{"data-testid":"view-tab-add",onClick:a,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 xn=pl;try{const e=require("@object-ui/react");e.SchemaRendererContext&&(xn=e.SchemaRendererContext)}catch{}const gn=({schema:e})=>{const s=l.useContext(xn)?.dataSource??null;return t.jsx(sl,{schema:e,dataSource:s})};Te.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}});Te.register("view",gn,{namespace:"plugin-view",label:"View",category:"view"});Te.register("view-switcher",bn,{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"}}]}});Te.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"}]}});Te.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"}]}});Te.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:i,children:s,dataSource:n,...r})=>{const a=e.props?.columns?{display:"grid",gridTemplateColumns:`repeat(${e.props.columns}, 1fr)`,gap:"1rem"}:void 0;return t.jsx("div",{className:i,style:a,...r,children:s})};Te.register("view:simple",ml,{namespace:"plugin-view",label:"Simple View",category:"view"});export{nr as M,sl as O,kl as V,Fl as u};