@objectstack/console 12.6.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/.objectui-sha +1 -1
  2. package/dist/assets/{AdapterProvider-BmqhWHIU.js → AdapterProvider-G7o889LL.js} +1 -1
  3. package/dist/assets/{AiPendingActionsPage-BRZ9smBE.js → AiPendingActionsPage-B_bQ89Ap.js} +1 -1
  4. package/dist/assets/{ApiConsolePage-1bt8j6wO.js → ApiConsolePage-oJexbnMd.js} +1 -1
  5. package/dist/assets/{AppDocsIndex-Bn1CdcNi.js → AppDocsIndex-B2EMS--S.js} +1 -1
  6. package/dist/assets/{AppManagementPage-CeZ7gA3p.js → AppManagementPage-BSLRnX7p.js} +1 -1
  7. package/dist/assets/{ApprovalsInboxPage-Cm6RlF50.js → ApprovalsInboxPage-DbdgZkz_.js} +1 -1
  8. package/dist/assets/{AuditLogPage-BUapxa-t.js → AuditLogPage-JHBVKm-o.js} +1 -1
  9. package/dist/assets/{ComponentNavView-CV-L0t8o.js → ComponentNavView-Be3JMpLK.js} +1 -1
  10. package/dist/assets/ConsoleFloatingChatbot-MtFbTLoq.js +1 -0
  11. package/dist/assets/{CreateViewDialog-CMNLzv6j.js → CreateViewDialog-CboUdp-q.js} +1 -1
  12. package/dist/assets/DashboardView-1nXwC0y_.js +1 -0
  13. package/dist/assets/{DeveloperHubPage-CigDAiDQ.js → DeveloperHubPage-B55QdK7b.js} +1 -1
  14. package/dist/assets/{ExpressionProvider-ODpzkcN3.js → ExpressionProvider-B3pkCzAo.js} +1 -1
  15. package/dist/assets/{FlowRunsPage-DQy0C86b.js → FlowRunsPage-CKOKC3O1.js} +1 -1
  16. package/dist/assets/{IntegrationsPage-D8453O8m.js → IntegrationsPage-gLs4Ms2t.js} +1 -1
  17. package/dist/assets/{InterfaceListPage-B_B_Fttt.js → InterfaceListPage-CwGb2Th3.js} +1 -1
  18. package/dist/assets/{ManagedByBadge-BGSB7vGi.js → ManagedByBadge-BtJfBjbT.js} +1 -1
  19. package/dist/assets/{MarketplaceAccessDenied-CAuxNcMw.js → MarketplaceAccessDenied-Bl4faFLm.js} +1 -1
  20. package/dist/assets/{MarketplaceInstalledPage-DIKAvmEt.js → MarketplaceInstalledPage-BQH-qEi5.js} +1 -1
  21. package/dist/assets/{MarketplacePackagePage-DWvYmWIA.js → MarketplacePackagePage-B2BXohna.js} +2 -2
  22. package/dist/assets/{MarketplacePage-SkUEdd3B.js → MarketplacePage-C_HnQQYH.js} +1 -1
  23. package/dist/assets/{MetadataInspector-RvnQ-QOT.js → MetadataInspector-DwPx9ueN.js} +1 -1
  24. package/dist/assets/{MetadataProvider-Cm9vi7AZ.js → MetadataProvider-seOmvY8N.js} +1 -1
  25. package/dist/assets/{ObjectDataPage-DeFtGZ6x.js → ObjectDataPage-D8W0OzJe.js} +1 -1
  26. package/dist/assets/PageView-cehnKJ9R.js +1 -0
  27. package/dist/assets/{ProfilePage-7etuxYZk.js → ProfilePage-CPk5ilAm.js} +1 -1
  28. package/dist/assets/{PublicFormsPage-BsrJk1W2.js → PublicFormsPage-5oWNwPiZ.js} +1 -1
  29. package/dist/assets/RecordDetailView-CUcCVoa1.js +9 -0
  30. package/dist/assets/{RecordFormPage-CBPvAXGe.js → RecordFormPage-Dmw4MMhg.js} +1 -1
  31. package/dist/assets/ReportDefaultInspector-BBTLmEl-.js +11 -0
  32. package/dist/assets/ReportView-BPkQVP9-.js +2 -0
  33. package/dist/assets/SearchResultsPage-quEMr1ZW.js +1 -0
  34. package/dist/assets/{SettingsHub-ZMQjBQwP.js → SettingsHub-B5Y0DjDk.js} +1 -1
  35. package/dist/assets/{SettingsView-eCnpX1vu.js → SettingsView-Q3e7GG0S.js} +1 -1
  36. package/dist/assets/{SystemHubPage-B8o4-NXd.js → SystemHubPage-SIzLdDrE.js} +1 -1
  37. package/dist/assets/appRoute-1sYdkwBz.js +1 -0
  38. package/dist/assets/conversationLanguage-CgUPnufx.js +1 -0
  39. package/dist/assets/data-adapter-BP-pyfs8.js +7 -0
  40. package/dist/assets/{framework-B3O15Lsq.js → framework-CBCX6Urh.js} +8 -8
  41. package/dist/assets/{getIcon-B5xaQx5N.js → getIcon-Ci4w4xXM.js} +1 -1
  42. package/dist/assets/{highlighted-body-OFNGDK62-B_roNkgm.js → highlighted-body-OFNGDK62-B5Pqh6xJ.js} +1 -1
  43. package/dist/assets/index-Df624lGg.js +2 -0
  44. package/dist/assets/{index-BXgUF5nO.css → index-GDbpsyLD.css} +1 -1
  45. package/dist/assets/{infrastructure-Bcx6-8du.js → infrastructure-ASGyCRMg.js} +1 -1
  46. package/dist/assets/marketplaceApi-N63OOXW-.js +1 -0
  47. package/dist/assets/mermaid-GHXKKRXX-BlWXnAVk.js +1 -0
  48. package/dist/assets/metadata-admin-Jkl-QChK.js +23 -0
  49. package/dist/assets/{plugin-calendar-BKbWgkod.js → plugin-calendar-BHRBKeJq.js} +1 -1
  50. package/dist/assets/{plugin-charts-BZo5ApEF.js → plugin-charts-DyKYgW3L.js} +1 -1
  51. package/dist/assets/plugin-chatbot-CNLp4fGv.js +120 -0
  52. package/dist/assets/{plugin-dashboard-CRFZp7gC.js → plugin-dashboard-uOZwquef.js} +1 -1
  53. package/dist/assets/plugin-form-CX8z6nsj.js +1 -0
  54. package/dist/assets/{plugin-gantt-D9YRdBGD.js → plugin-gantt-CyktuI6d.js} +1 -1
  55. package/dist/assets/{plugin-grid-eiIl2HN_.js → plugin-grid-DNGRZzGM.js} +1 -1
  56. package/dist/assets/{plugin-kanban-3rFMGC21.js → plugin-kanban-B0Dwrpca.js} +1 -1
  57. package/dist/assets/{plugin-map-BHQrQ_Wu.js → plugin-map-Co_pYpOZ.js} +1 -1
  58. package/dist/assets/{plugin-markdown-DesFSRDB.js → plugin-markdown-CS5R-t3i.js} +1 -1
  59. package/dist/assets/{plugin-report-BKD6SOp5.js → plugin-report-_y8nt0FZ.js} +1 -1
  60. package/dist/assets/{plugin-timeline-BrkABjqu.js → plugin-timeline-Cy03-xov.js} +1 -1
  61. package/dist/assets/{plugin-tree-CKck3lEJ.js → plugin-tree-DCAEE54g.js} +1 -1
  62. package/dist/assets/plugin-view-OZpEPOgT.js +1 -0
  63. package/dist/assets/plugins-views-BVxwkRdi.js +4 -0
  64. package/dist/assets/{skeletons-CzC0fiXD.js → skeletons-BjaBYe9k.js} +1 -1
  65. package/dist/assets/{src-BeTFx9-N.js → src-D6ENIa3w.js} +1 -1
  66. package/dist/assets/src-rXeXV_HX.js +16 -0
  67. package/dist/assets/{types-UYoEctl-.js → types-DXCQOIiO.js} +1 -1
  68. package/dist/assets/{ui-components-rkvkkTxO.js → ui-components-BOOpjWsQ.js} +9 -9
  69. package/dist/assets/{ui-layout-CAjjF5_S.js → ui-layout-vWAZODrs.js} +1 -1
  70. package/dist/assets/{useMetadata-DO66YueM.js → useMetadata-D-bLZoNN.js} +1 -1
  71. package/dist/assets/useOpenRecordList-B3tjtz1e.js +1 -0
  72. package/dist/assets/{useRecordApprovals-obyIj2_8.js → useRecordApprovals-jo_LH43z.js} +1 -1
  73. package/dist/assets/vendor-objectstack-Jcqd9154.js +108 -0
  74. package/dist/index.html +4 -4
  75. package/package.json +1 -1
  76. package/dist/assets/ConsoleFloatingChatbot-CO_DukxV.js +0 -1
  77. package/dist/assets/DashboardView-CnKtk1aW.js +0 -1
  78. package/dist/assets/DashboardWidgetInspector-CYPIrTyy.js +0 -1
  79. package/dist/assets/PageView-BQS9pq2N.js +0 -1
  80. package/dist/assets/RecordDetailView-CzR6BAUv.js +0 -9
  81. package/dist/assets/ReportDefaultInspector-ah_Be1RZ.js +0 -11
  82. package/dist/assets/ReportView-D5Hifbvj.js +0 -2
  83. package/dist/assets/SearchResultsPage-24ufpv2l.js +0 -1
  84. package/dist/assets/appRoute-CbCiASix.js +0 -1
  85. package/dist/assets/data-adapter-CdxWNPpK.js +0 -7
  86. package/dist/assets/index-Bp2ZvXdP.js +0 -2
  87. package/dist/assets/marketplaceApi-zYQofLEk.js +0 -1
  88. package/dist/assets/mermaid-GHXKKRXX-B7uCX_yo.js +0 -1
  89. package/dist/assets/metadata-admin-BveAqpPs.js +0 -22
  90. package/dist/assets/plugin-chatbot-D2Uv-hn9.js +0 -120
  91. package/dist/assets/plugin-form-FeZEoC2R.js +0 -1
  92. package/dist/assets/plugin-view-BJ9uLrnO.js +0 -1
  93. package/dist/assets/plugins-views-CibWNUsP.js +0 -4
  94. package/dist/assets/src--WewDM7z.js +0 -16
  95. package/dist/assets/useOpenRecordList-DsTb016S.js +0 -1
  96. package/dist/assets/useReconcileOnError-DMumPfoY.js +0 -1
  97. package/dist/assets/vendor-objectstack-Bw0HRuFa.js +0 -95
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BGDDiZfJ.js";import{n as r}from"./infrastructure-Bcx6-8du.js";import{K as i,Kt as a,N as o,Y as s,o as c,ot as l,rt as u}from"./framework-B3O15Lsq.js";import{l as d}from"./vendor-objectstack-Bw0HRuFa.js";import{$n as f,$t as p,Bs as m,Bt as h,Gn as g,H as _,Hs as v,Ht as y,Ic as b,Jn as x,Qt as S,Ra as C,Rt as w,Si as T,Un as E,Us as D,Ut as O,Vs as k,Vt as A,Wt as j,_r as M,b as N,ct as P,dt as F,en as I,er as L,fr as R,gr as z,h as B,hr as ee,js as te,kc as V,lt as ne,mr as re,nr as H,pr as ie,qn as ae,rr as U,s as W,t as oe,tr as G,ut as se,vr as ce,xr as K,yr as le,za as ue,zt as q}from"./ui-components-rkvkkTxO.js";import{r as J}from"./vendor-ui-utils-BzQBRdq3.js";var Y=e(n(),1);function X(e){try{return typeof window>`u`?!1:new URL(e,window.location.href).origin===window.location.origin}catch{return!1}}function de(e,t){if(!e)return null;let n=t?.id??t?.recordId??t?._id;if(n==null||n===``)return null;let r=e.replace(/\{(?:id|recordId)\}/g,String(n));return X(r)?r:null}var Z=t(),fe=({label:e,description:t,collapsible:n=!1,collapsed:r=!1,columns:i=1,children:a,className:o,gridClassName:s,showBorder:c})=>{let[l,u]=(0,Y.useState)(r),d={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`},p=()=>{n&&u(!l)},h=c??!!e,g=e||t?(0,Z.jsxs)(`div`,{className:V(`flex items-start gap-2`,!h&&`mb-4`,n&&`cursor-pointer select-none`),onClick:p,role:n?`button`:void 0,"aria-expanded":n?!l:void 0,children:[n&&(0,Z.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:l?(0,Z.jsx)(m,{className:`h-4 w-4`}):(0,Z.jsx)(v,{className:`h-4 w-4`})}),(0,Z.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:t})]})]}):null,_=l?null:(0,Z.jsx)(`div`,{className:V(`grid gap-4`,s||d[i]),children:a});return h?(0,Z.jsxs)(f,{className:V(`form-section bg-muted/40 shadow-none`,o),children:[g&&(0,Z.jsx)(H,{className:`border-b border-border pb-3`,children:g}),_&&(0,Z.jsx)(L,{className:`pt-4`,children:_})]}):(0,Z.jsxs)(`div`,{className:V(`form-section`,o),children:[g,_]})};function Q(e,t){return typeof t==`string`&&t.trim()||typeof t==`object`&&t&&typeof t.source==`string`&&t.source.trim()?{...e,visibleOn:t}:e}function pe(e,t){let n=t.objectSchema?.fields?.[e];return n?{name:e,label:t.fieldLabel(t.objectName,e,n.label||e),type:B(n.type),required:n.required||!1,disabled:t.readOnly||t.mode===`view`||n.readonly,placeholder:n.placeholder,description:n.help||n.description,validation:oe(n),field:n,options:n.options,multiple:n.multiple,visibleWhen:n.visibleWhen,readonlyWhen:n.readonlyWhen,requiredWhen:n.requiredWhen,conditionalRequired:n.conditionalRequired}:{name:e,label:e,type:`input`}}function me(e,t){if(typeof e==`string`){let n=t.objectSchema?.fields?.[e];return Q(pe(e,t),n?.visible_on??n?.visibleOn)}let n=e;if(typeof n.field!=`string`)return Q(n,n.visibleOn);let r=n.field,i=pe(r,t);return n.type!=null&&(i.type=B(n.type)),n.widget!=null&&(i.widget=n.widget),n.label!=null&&(i.label=n.label),n.placeholder!=null&&(i.placeholder=n.placeholder),n.helpText!=null&&(i.description=n.helpText),n.required!=null&&(i.required=n.required),n.readonly!=null&&(i.disabled=n.readonly||i.disabled),n.immutable!=null&&(i.immutable=n.immutable),n.hidden!=null&&(i.hidden=n.hidden),n.colSpan!=null&&(i.colSpan=n.colSpan),n.span!=null&&(i.span=n.span),n.options!=null&&(i.options=n.options),n.multiple!=null&&(i.multiple=n.multiple),n.reference!=null&&(i.reference=n.reference),n.maxLength!=null&&(i.maxLength=n.maxLength),n.minLength!=null&&(i.minLength=n.minLength),n.min!=null&&(i.min=n.min),n.max!=null&&(i.max=n.max),n.precision!=null&&(i.precision=n.precision),n.scale!=null&&(i.scale=n.scale),n.language!=null&&(i.language=n.language),Array.isArray(n.fields)&&(i.fields=n.fields),Q(i,n.visibleOn)}function he(e,t){return(e.fields??[]).map(e=>me(e,t))}var ge=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),_e=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),ve=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function ye(e){return _e.has(e)}function be(e){return ve.has(e)}function xe(e){return e<=3?1:e<=8?2:e<=15?3:4}function Se(e){return e&&e>0?Math.min(Math.floor(e),4):1}function Ce(e,t,n){let r=Se(t);return r<=1?1:e.span===`full`?r:e.colSpan==null?e.type&&ye(e.type)?r:Math.min(r,Math.max(1,Math.round(r/Math.min(Math.max(1,Math.floor(n||r)),r)))):Math.min(Math.max(1,Math.floor(e.colSpan)),r)}function we(e,t,n){let r=Se(t);return r<=1?e:e.map(e=>{if(e.type===`section-divider`)return e;let t=Ce(e,r,n);return t>1?{...e,colSpan:t}:e.colSpan!=null&&e.colSpan!==1?{...e,colSpan:1}:e})}var Te=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`last_modified_at`,`lastModifiedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`last_modified_by`,`lastModifiedBy`,`organization_id`,`organizationId`,`org_id`,`orgId`,`tenant_id`,`tenantId`,`owner`,`owner_id`,`_version`,`_rev`]);function Ee(e,t){return e.filter(e=>{if(Te.has(e.name))return!1;let n=t?.fields?.[e.name];return!(n?.hidden===!0||n?.readonly===!0)})}function De(e,t){return e.filter(e=>{if(e.type&&ge.has(e.type))return!1;let n=t?.fields?.[e.name];return n?!be(n.type):!0})}var Oe={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`};function ke(e){return Oe[e&&e>0?Math.min(Math.floor(e),4):1]}function Ae(e,t){let n=t&&t>1?Math.min(Math.floor(t),4):1,r=n>1?we(e,n):e,i=ke(n);return{fields:r,columns:n,...i?{fieldContainerClass:i}:{}}}function je(e){return e<=1?`default`:e===2?`xl`:`full`}function Me(e,t,n,r){let i=[...e];if(i=Ee(i,t),r===`create`&&(i=De(i,t)),n!==void 0)return i=we(i,n),{fields:i,columns:n};let a=xe(i.length);return i=we(i,a),{fields:i,columns:a}}var Ne=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=b(),[i,a]=(0,Y.useState)(null),[o,c]=(0,Y.useState)({}),[l,u]=(0,Y.useState)(!0),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`);Y.useEffect(()=>{(async()=>{if(!t){u(!1);return}try{let n=await t.getObjectSchema(e.objectName);a(n)}catch(e){f(e)}})()},[e.objectName,t]),Y.useEffect(()=>{(i||!t)&&(async()=>{if(e.mode===`create`||!e.recordId||!t){c(e.initialData||e.initialValues||{}),u(!1);return}try{let n=await t.findOne(e.objectName,e.recordId);c(n||{})}catch(e){f(e)}finally{u(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let h=(0,Y.useCallback)(t=>he(t,{objectSchema:i,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:r}),[i,e.readOnly,e.mode,e.objectName,r]),g=(0,Y.useCallback)(async n=>{if(!t)return e.onSuccess&&await e.onSuccess(n),n;try{let r;return e.mode===`create`?r=await t.create(e.objectName,n):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,n)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,t]),_=(0,Y.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),v=(e,t)=>e.name||e.label||`tab-${t}`;if(d)return(0,Z.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,Z.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,Z.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:d.message})]});if(l)return(0,Z.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,Z.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let y={type:`form`,fields:e.sections.flatMap(e=>h(e)),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:g,onCancel:_},x=e.tabPosition===`left`||e.tabPosition===`right`;return(0,Z.jsx)(`div`,{className:V(`w-full`,n,e.className),children:(0,Z.jsxs)(P,{value:p,onValueChange:m,orientation:x?`vertical`:`horizontal`,className:V(x&&`flex gap-4`),children:[(0,Z.jsx)(se,{className:V(x?`flex-col h-auto`:``,e.tabPosition===`bottom`&&`order-last`,e.tabPosition===`right`&&`order-last`),children:e.sections.map((e,t)=>(0,Z.jsx)(F,{value:v(e,t),className:x?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},v(e,t)))}),(0,Z.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,Z.jsx)(ne,{value:v(t,n),className:`mt-0`,children:(0,Z.jsx)(fe,{description:t.description,columns:1,className:t.className,gridClassName:t.gridClassName,children:(0,Z.jsx)(s,{schema:{...y,...Ae(h(t),t.columns||1),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},v(t,n)))})]})})},Pe=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=b(),[i,a]=(0,Y.useState)(null),[o,c]=(0,Y.useState)({}),[l,u]=(0,Y.useState)(!0),[d,f]=(0,Y.useState)(null),[p,h]=(0,Y.useState)(0),[g,_]=(0,Y.useState)(new Set),[v,y]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(null),C=Y.useId(),[w,T]=(0,Y.useState)(0),E=Y.useRef(!1),O=e.sections.length,A=p===0,j=p===O-1;Y.useEffect(()=>{(async()=>{if(!t){u(!1);return}try{let n=await t.getObjectSchema(e.objectName);a(n)}catch(e){f(e)}})()},[e.objectName,t]),Y.useEffect(()=>{(i||!t)&&(async()=>{if(e.mode===`create`||!e.recordId||!t){E.current||=(c(e.initialData||e.initialValues||{}),!0),u(!1);return}try{let n=await t.findOne(e.objectName,e.recordId);c(n||{})}catch(e){f(e)}finally{u(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let M=(0,Y.useCallback)(t=>he(t,{objectSchema:i,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:r}),[i,e.readOnly,e.mode,e.objectName,r]),N=(0,Y.useMemo)(()=>p>=0&&p<O?M(e.sections[p]):[],[p,O,e.sections,M]),P=(0,Y.useCallback)(async n=>{let r={...o,...n};if(c(r),_(e=>new Set(e).add(p)),j){y(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(r),r;let n;if(e.mode===`create`?n=await t.create(e.objectName,r):e.mode===`edit`&&e.recordId&&(n=await t.update(e.objectName,e.recordId,r)),e.onSuccess)await e.onSuccess(n);else if(e.submitBehavior){let t=e.submitBehavior;switch(t.kind){case`redirect`:X(t.url)&&setTimeout(()=>window.location.assign(t.url),t.delayMs??0);break;case`continue`:c({}),_(new Set),h(0),T(e=>e+1);break;default:{let n=t.kind===`thank-you`&&t.message?t.message:e.successMessage||(e.mode===`create`?`Created`:`Saved`);J.success(n),S({title:t.kind===`thank-you`?t.title:void 0,message:n});break}}}else{let t=de(e.navigateOnSuccess,n);if(t)return window.location.assign(t),n;J.success(e.successMessage||(e.mode===`create`?`Created`:`Saved`)),e.resetOnSuccess&&e.mode===`create`&&(c({}),_(new Set),h(0),T(e=>e+1))}return n}catch(t){throw e.onError&&e.onError(t),t}finally{y(!1)}}else F(p+1)},[o,p,j,e,t]),F=(0,Y.useCallback)(t=>{t>=0&&t<O&&(h(t),e.onStepChange&&e.onStepChange(t))},[O,e]),I=(0,Y.useCallback)(()=>{F(p-1)},[p,F]),L=(0,Y.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),R=(0,Y.useCallback)(t=>{(e.allowSkip||g.has(t)||t<=p)&&F(t)},[e.allowSkip,g,p,F]);if(d)return(0,Z.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,Z.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,Z.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:d.message})]});if(l)return(0,Z.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,Z.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(x)return(0,Z.jsx)(`div`,{className:V(`w-full`,n,e.className),children:(0,Z.jsxs)(`div`,{className:`rounded-md border bg-card p-8 text-center`,children:[(0,Z.jsx)(`h3`,{className:`text-lg font-semibold`,children:x.title??`Thanks!`}),x.message&&(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:x.message})]})});let z=e.sections[p];return(0,Z.jsxs)(`div`,{className:V(`w-full`,n,e.className),children:[e.showStepIndicator!==!1&&(0,Z.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,Z.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===p,i=g.has(n),a=e.allowSkip||i||n<=p;return(0,Z.jsxs)(`li`,{className:V(`relative flex-1`,n!==O-1&&`pr-8 sm:pr-12`),children:[n!==O-1&&(0,Z.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:(0,Z.jsx)(`div`,{className:V(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,Z.jsxs)(`button`,{type:`button`,className:V(`group relative flex items-center`,a?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>R(n),disabled:!a,children:[(0,Z.jsx)(`span`,{className:V(`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`,i&&`bg-primary text-primary-foreground`,r&&!i&&`border-2 border-primary bg-background text-primary`,!r&&!i&&`border-2 border-muted bg-background text-muted-foreground`),children:i?(0,Z.jsx)(D,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,Z.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,Z.jsx)(`span`,{className:V(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,Z.jsx)(`div`,{className:`min-h-[200px]`,children:z&&(0,Z.jsx)(fe,{label:z.label,description:z.description,columns:1,className:z.className,gridClassName:z.gridClassName,children:N.length>0?(0,Z.jsx)(s,{schema:{type:`form`,objectName:e.objectName,id:C,...Ae(N,z.columns||1),layout:`vertical`,defaultValues:o,showSubmit:!1,showCancel:!1,onSubmit:P}},w):(0,Z.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,Z.jsx)(`div`,{children:e.showCancel!==!1&&(0,Z.jsx)(K,{variant:`ghost`,onClick:L,children:e.cancelText||`Cancel`})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,p+1,` of `,O]}),!A&&(0,Z.jsxs)(K,{variant:`outline`,onClick:I,children:[(0,Z.jsx)(k,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),j?(0,Z.jsxs)(K,{type:`submit`,form:C,disabled:v||e.mode===`view`,children:[v&&(0,Z.jsx)(ue,{className:`mr-2 h-4 w-4 animate-spin`,"aria-hidden":!0}),v?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)]}):(0,Z.jsxs)(K,{type:`submit`,form:C,children:[e.nextText||`Next`,(0,Z.jsx)(m,{className:`h-4 w-4 ml-1`})]})]})]})]})},Fe=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=b(),[i,a]=(0,Y.useState)(null),[o,c]=(0,Y.useState)({}),[l,u]=(0,Y.useState)(!0),[d,f]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{(async()=>{if(!t){u(!1);return}try{let n=await t.getObjectSchema(e.objectName);a(n)}catch(e){f(e),u(!1)}})()},[e.objectName,t]),(0,Y.useEffect)(()=>{(i||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){c(e.initialData||e.initialValues||{}),u(!1);return}if(!t){c(e.initialData||e.initialValues||{}),u(!1);return}try{let n=await t.findOne(e.objectName,e.recordId);c(n||{})}catch(e){f(e)}finally{u(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let m=(0,Y.useCallback)(t=>he(t,{objectSchema:i,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:r}),[i,e.readOnly,e.mode,e.objectName,r]),h=(0,Y.useCallback)(async n=>{if(!t)return e.onSuccess&&await e.onSuccess(n),n;try{let r;return e.mode===`create`?r=await t.create(e.objectName,n):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,n)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,t]),g=(0,Y.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),_=(0,Y.useMemo)(()=>e.sections.slice(0,1),[e.sections]),v=(0,Y.useMemo)(()=>e.sections.slice(1),[e.sections]);(0,Y.useMemo)(()=>e.sections.flatMap(e=>m(e)),[e.sections,m]);let y=e.splitDirection||`horizontal`,x=e.splitSize||50;if(d)return(0,Z.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,Z.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,Z.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:d.message})]});if(l)return(0,Z.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,Z.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let C={type:`form`,objectName:e.objectName,layout:`vertical`,defaultValues:o,onSubmit:h,onCancel:g},w=(t,n)=>(0,Z.jsx)(`div`,{className:`space-y-6 p-4`,children:t.map((t,r)=>(0,Z.jsx)(fe,{label:t.label,description:t.description,columns:1,className:t.className,gridClassName:t.gridClassName,children:(0,Z.jsx)(s,{schema:{...C,...Ae(m(t),t.columns||1),showSubmit:n&&e.showSubmit!==!1&&e.mode!==`view`,showCancel:n&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText}})},t.name||t.label||r))});return(0,Z.jsx)(`div`,{className:V(`w-full`,n,e.className),children:(0,Z.jsxs)(I,{orientation:y,className:`min-h-[300px] rounded-lg border`,children:[(0,Z.jsx)(p,{defaultSize:x,minSize:20,children:w(_,v.length===0)}),v.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(S,{withHandle:e.splitResizable!==!1}),(0,Z.jsx)(p,{defaultSize:100-x,minSize:20,children:w(v,!0)})]})]})})},Ie=new Set([`id`,`_id`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`organization_id`,`organizationId`]),Le=new Set([`formula`,`summary`,`rollup`,`lookup_value`,`auto_number`,`autonumber`,`computed`]);function Re(e,t){if(!e||typeof e!=`object`)return e;let n={},r=t?.fields;for(let[t,i]of Object.entries(e))if(!Ie.has(t)){if(r){let e=r[t];if(!e)continue;let n=String(e.type||``).toLowerCase();if(Le.has(n)||e.computed===!0||e.formula||e.readOnly===!0||e.readonly===!0)continue}n[t]=i}return n}var $=e=>e==null?void 0:e.id??e._id??e.recordId,ze=(e,t)=>t?Re(e,t):e,Be=new Set([`id`,`_id`,`recordId`]);function Ve(e,t){return e?Object.entries(e).every(([e,n])=>e===t||Be.has(e)?!0:n==null||n===``):!0}function He(e,t,n){let r=[{object:e,action:`create`,data:t}];for(let e of n)for(let t of e.rows)Ve(t,e.relationshipField)||r.push({object:e.childObject,action:`create`,data:{...ze(t,e.childSchema),[e.relationshipField]:{$ref:0}}});return r}function Ue(e,t,n,r){let i=[{object:e,action:`update`,id:t,data:n}];for(let e of r){let n=(e.rows||[]).map(n=>({...n,[e.relationshipField]:t})),{toCreate:r,toUpdate:a,toDelete:o}=We(e.original||[],n);for(let t of r){if(Ve(t,e.relationshipField))continue;let{id:n,_id:r,recordId:a,...o}=t;i.push({object:e.childObject,action:`create`,data:ze(o,e.childSchema)})}for(let t of a)i.push({object:e.childObject,action:`update`,id:$(t),data:ze(t,e.childSchema)});for(let t of o)i.push({object:e.childObject,action:`delete`,id:t})}return i}function We(e,t){let n=new Set(t.map($).filter(Boolean));return{toCreate:t.filter(e=>!$(e)),toUpdate:t.filter(e=>$(e)),toDelete:(e||[]).map($).filter(e=>!!e&&!n.has(e))}}function Ge(e,t){return Array.isArray(e)?e.reduce((e,n)=>{let r=Number(n?.[t]);return e+(Number.isFinite(r)?r:0)},0):0}function Ke(e){return Array.isArray(e)?e:e&&Array.isArray(e.records)?e.records:e&&Array.isArray(e.data)?e.data:e&&(e.id||e._id)?[e]:[]}async function qe(e,t,n){return n.length===0?[]:typeof e.bulk==`function`?Ke(await e.bulk(t,`create`,n)):Ke(await Promise.all(n.map(n=>e.create(t,n))))}async function Je(e,t,n,r){let i=[],a=r.rows.filter(e=>$(e)||!Ve(e,r.relationshipField)).map(e=>({...e,[r.relationshipField]:n}));if(r.original!==void 0){let{toCreate:t,toUpdate:n,toDelete:o}=We(r.original,a),s=await qe(e,r.childObject,t.map(e=>ze(e,r.childSchema)));for(let e of s){let t=$(e);t&&i.push({object:r.childObject,id:t})}await Promise.all(n.map(t=>e.update(r.childObject,$(t),ze(t,r.childSchema)))),await Promise.all(o.map(t=>e.delete(r.childObject,t)))}else{let t=await qe(e,r.childObject,a.map(e=>ze(e,r.childSchema)));for(let e of t){let t=$(e);t&&i.push({object:r.childObject,id:t})}}if(r.totalField){let i=Ge(r.rows,r.amountField||`amount`);await e.update(t,n,{[r.totalField]:i})}return{created:i}}var Ye=new Set([`id`,`_id`,`recordId`,`created_at`,`updated_at`,`created_by`,`updated_by`,`createdAt`,`updatedAt`,`createdBy`,`updatedBy`,`organization_id`,`tenant_id`,`space`,`owner`]),Xe=new Set([`position`,`sort_order`,`sequence`,`line_no`,`line_number`,`sort`]),Ze=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`,`file`,`image`,`avatar`,`json`,`object`,`grid`,`table`,`location`,`vector`,`html`,`markdown`,`richtext`]);function Qe(e){switch(e){case`number`:case`percent`:case`rating`:case`slider`:return`number`;case`currency`:return`currency`;case`date`:case`datetime`:case`time`:return`date`;case`select`:case`picklist`:case`radio`:case`boolean`:case`toggle`:return`select`;case`lookup`:case`master_detail`:return`lookup`;default:return`text`}}function $e(e){if(e?.type===`boolean`||e?.type===`toggle`)return[{label:`Yes`,value:`true`},{label:`No`,value:`false`}];let t=e?.options;if(Array.isArray(t))return t.map(e=>typeof e==`object`&&e?{label:String(e.label??e.value),value:String(e.value)}:{label:String(e),value:String(e)})}function et(e,t){let n=e?.fields;if(!n||typeof n!=`object`)return;let r;for(let[e,i]of Object.entries(n)){let n=i;if(n?.reference===t){if(n?.type===`master_detail`)return e;n?.type===`lookup`&&!r&&(r=e)}}return r}var tt=[`name`,`title`,`subject`,`label`,`full_name`,`display_name`,`code`],nt={select:0,currency:1,number:1,lookup:2,date:3,text:4};function rt(e,t){if(t<=0||e.length<=t)return e;let n=new Set,r=e.find(e=>tt.includes(e.field))??e[0];r&&n.add(r.field);for(let t of e)t.required&&n.add(t.field);let i=e.map((e,t)=>({c:e,i:t})).filter(({c:e})=>!n.has(e.field)).sort((e,t)=>(nt[e.c.type]??5)-(nt[t.c.type]??5)||e.i-t.i);for(let{c:e}of i){if(n.size>=t)break;n.add(e.field)}return e.map(e=>n.has(e.field)?e:{...e,defaultHidden:!0})}function it(e,t={}){let n=e?.fields;if(!n||typeof n!=`object`)return[];let r=new Set([...t.exclude??[],...t.relationshipField?[t.relationshipField]:[]]),i=[];for(let[e,t]of Object.entries(n)){let n=t;if(Ye.has(e)||r.has(e)||Xe.has(e)||n?.system||n?.readonly||n?.hidden||Ze.has(n?.type))continue;let a={field:e,label:n?.label||e,type:Qe(n?.type),required:!!n?.required},o=$e(n);a.type===`select`&&o&&(a.options=o),a.type===`lookup`&&(a.reference=n?.reference,a.displayField=n?.display_field||n?.reference_field),n?.readonlyWhen&&(a.readonlyWhen=n.readonlyWhen),(n?.requiredWhen??n?.conditionalRequired)&&(a.requiredWhen=n.requiredWhen??n.conditionalRequired);let s=typeof n?.expression==`string`?n.expression:n?.expression?.source;s&&typeof s==`string`&&(a.computed=!0,a.expr=s,a.required=!1,typeof n?.scale==`number`&&(a.scale=n.scale)),i.push(a)}return rt(i,t.maxColumns??6)}function at(e,t){let n=e??[],r=t?.fields;return!n.length||!r||typeof r!=`object`?n:n.map(e=>{if(e.type)return e;let t=r[e.field];if(!t)return e;let n=Qe(t?.type),i={...e,type:n};i.label??=t?.label||e.field,i.required??=!!t?.required;let a=$e(t);n===`select`&&a&&!i.options&&(i.options=a),n===`lookup`&&(i.reference??=t?.reference,i.displayField??=t?.display_field||t?.reference_field),i.readonlyWhen==null&&t?.readonlyWhen&&(i.readonlyWhen=t.readonlyWhen),i.requiredWhen==null&&(t?.requiredWhen??t?.conditionalRequired)&&(i.requiredWhen=t.requiredWhen??t.conditionalRequired);let o=typeof t?.expression==`string`?t.expression:t?.expression?.source;return!i.computed&&o&&typeof o==`string`&&(i.computed=!0,i.expr=o,i.required=!1,typeof t?.scale==`number`&&(i.scale=t.scale)),i})}var ot=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`]);function st(e,t={}){let n=e?.fields;if(!n||typeof n!=`object`)return[];let r=new Set([...t.exclude??[],...t.relationshipField?[t.relationshipField]:[]]),i=[];for(let[e,t]of Object.entries(n)){let n=t;Ye.has(e)||r.has(e)||Xe.has(e)||n?.system||n?.hidden||ot.has(n?.type)||i.push(e)}return i}var ct=new Set([`textarea`,`richtext`,`html`,`markdown`,`rich-text`,`file`,`image`,`avatar`,`attachment`,`json`,`location`,`address`]);function lt(e,t,n={}){if(t===`grid`||t===`form`)return t;let r=e?.fields??{},i=st(e,{relationshipField:n.relationshipField});return i.some(e=>ct.has(r[e]?.type))||i.length>8?`form`:`grid`}var ut=[`amount`,`total`,`subtotal`,`line_total`,`line_amount`,`net_amount`];function dt(e){let t=e.filter(e=>e.type===`number`||e.type===`currency`);if(t.length===0)return;let n=t.find(e=>e.computed);if(n)return n.field;let r=t.find(e=>ut.includes(e.field));if(r)return r.field;let i=[...t].reverse().find(e=>e.type===`currency`);return i?i.field:t[t.length-1].field}function ft(e,t,n,r={}){let i=r.relationshipField||et(t,n);if(!i)throw Error(`MasterDetailForm: could not find a lookup/master_detail field on "${e}" referencing "${n}". Set relationshipField explicitly.`);let a=r.columns?.length?at(r.columns,t):it(t,{relationshipField:i}),o=r.amountField||dt(a);return{childObject:e,relationshipField:i,columns:a,formFields:st(t,{relationshipField:i}),mode:lt(t,r.inlineEdit??(t?.fields)?.[i]?.inlineEdit,{relationshipField:i}),amountField:o,sortField:Object.keys(t?.fields??{}).find(e=>Xe.has(e))}}function pt(e){if(!e)return{};let t={};return e.querySelectorAll(`[name]`).forEach(e=>{let n=e.getAttribute(`name`);if(n){if(e.tagName===`INPUT`){let r=e;if(r.type===`checkbox`){t[n]=r.checked;return}if(r.type===`radio`){r.checked&&(t[n]=r.value);return}if(r.type===`number`||r.type===`range`){if(r.value===``){t[n]=null;return}let e=Number(r.value);t[n]=Number.isFinite(e)?e:r.value;return}t[n]=r.value;return}t[n]=e.value}}),t}var mt=({details:e,state:t,setRows:n,formHostRef:r,taxRateField:i,formKey:a,onRowExpand:o,onAddViaForm:s})=>{let[c,l]=(0,Y.useState)({}),u=(0,Y.useRef)(``);(0,Y.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{let t=pt(e),n;try{n=JSON.stringify(t)}catch{n=String(Math.random())}n!==u.current&&(u.current=n,l(t))};t();let n=()=>t();e.addEventListener(`input`,n),e.addEventListener(`change`,n);let i=[120,360,800].map(e=>setTimeout(t,e));return()=>{e.removeEventListener(`input`,n),e.removeEventListener(`change`,n),i.forEach(clearTimeout)}},[r,a,e.length]);let d=c[i],f=d===void 0?null:Number.isFinite(Number(d))?Number(d):0,p=e.reduce((e,n,r)=>e+Ge(t[r]?.rows??[],n.amountField||`amount`),0),m=f!==null&&e.some(e=>!!e.amountField),h=f??0,g=h/100*p,_=p+g,v=e=>`¥${e.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`;return(0,Z.jsxs)(Z.Fragment,{children:[e.map((e,r)=>(0,Z.jsxs)(`section`,{className:`space-y-2`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:e.title||`Line Items`}),e.columns?.length?(0,Z.jsx)(N,{value:t[r]?.rows??[],onChange:e=>n(r,e),contextRecord:c,...e.inlineMode===`form`||(e.formFields?.length??0)>(e.columns?.length??0)?{onRowExpand:e=>o(r,e)}:{},displayMode:e.inlineMode===`form`?`list`:`grid`,...e.inlineMode===`form`?{onAdd:()=>s(r)}:{},field:{columns:e.columns,total_field:m?void 0:e.amountField||(e.totalField?`amount`:void 0),sort_field:e.sortField,min_rows:e.minRows,max_rows:e.maxRows,add_label:e.inlineMode===`form`?e.addLabel||`Add`:e.addLabel}}):(0,Z.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`Loading columns…`})]},`${e.childObject}-${r}`)),m&&(0,Z.jsx)(`div`,{className:`flex justify-end`,children:(0,Z.jsxs)(`dl`,{className:`w-64 space-y-1.5 text-sm`,"data-testid":`md-totals`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`dt`,{className:`text-muted-foreground`,children:`Subtotal`}),(0,Z.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-subtotal`,children:v(p)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`dt`,{className:`text-muted-foreground`,children:[`Tax (`,h,`%)`]}),(0,Z.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-tax`,children:v(g)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border-t border-border pt-1.5 text-base font-semibold`,children:[(0,Z.jsx)(`dt`,{children:`Total`}),(0,Z.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-grand-total`,children:v(_)})]})]})})]})},ht=({schema:e,dataSource:t,className:n})=>{let r=e.details||[],i=e.mode===`edit`&&!!e.recordId,a=r.some(e=>!e.relationshipField||!e.columns?.length||e.columns.some(e=>!e.type)),[o,s]=(0,Y.useState)(a?null:r),c=o??r;(0,Y.useEffect)(()=>{if(!a){s(r);return}if(!t||typeof t.getObjectSchema!=`function`)return;let n=!1;return(async()=>{let i=await Promise.all(r.map(async n=>{let r=n.columns?.length?n.columns.every(e=>!!e.type):!1;if(n.relationshipField&&r)return n;try{let r=await t.getObjectSchema(n.childObject);if(n.relationshipField&&n.columns?.length)return{...n,columns:at(n.columns,r)};let i=ft(n.childObject,r,e.objectName,{relationshipField:n.relationshipField,columns:n.columns,amountField:n.amountField});return{...n,relationshipField:i.relationshipField,columns:i.columns,formFields:n.formFields??i.formFields,inlineMode:n.inlineMode??i.mode,amountField:n.amountField??i.amountField,sortField:n.sortField??i.sortField}}catch{return n}}));n||s(i)})(),()=>{n=!0}},[t,e.objectName,e.details]);let[l,u]=(0,Y.useState)(()=>r.map(()=>({rows:[],original:[]}))),d=(0,Y.useRef)(l);d.current=l;let p=(0,Y.useRef)({});(0,Y.useEffect)(()=>{let e=t;if(!e||typeof e.getObjectSchema!=`function`)return;let n=!1,i=Array.from(new Set(r.map(e=>e.childObject).filter(Boolean)));return(async()=>{let t=await Promise.all(i.map(async t=>{try{return[t,await e.getObjectSchema(t)]}catch{return[t,null]}}));if(n)return;let r={};for(let[e,n]of t)n&&(r[e]=n);p.current=r})(),()=>{n=!0}},[t,e.objectName,e.details]);let[m,h]=(0,Y.useState)(0),[g,_]=(0,Y.useState)(!1),v=(0,Y.useRef)(!1),y=(0,Y.useRef)(null),b=(0,Y.useCallback)(()=>{v.current=!1,_(!1),y.current&&=(clearTimeout(y.current),null)},[]);(0,Y.useEffect)(()=>{let n=!1;if(!(!i||!t))return(async()=>{let r=await Promise.all(c.map(async n=>{if(!n.relationshipField)return{rows:[],original:[]};try{let r=(await t.find(n.childObject,{$filter:{[n.relationshipField]:e.recordId},$top:500}))?.data??[];return{rows:r.map(e=>({...e})),original:r.map(e=>({...e}))}}catch{return{rows:[],original:[]}}}));n||u(r)})(),()=>{n=!0}},[i,t,e.recordId,o]);let x=(0,Y.useCallback)((e,t)=>{u(n=>n.map((n,r)=>r===e?{...n,rows:t}:n))},[]),S=e.taxRateField||`tax_rate`,[C,w]=(0,Y.useState)(null),T=C?l[C.detailIdx]?.rows?.[C.rowIdx]:void 0,E=C?c[C.detailIdx]:void 0,D=(0,Y.useCallback)((e,t,n)=>{u(r=>r.map((r,i)=>i===e?{...r,rows:r.rows.map((e,r)=>r===t?{...e,...n}:e)}:r))},[]),O=(0,Y.useCallback)(e=>{u(t=>{let n=t.map((t,n)=>n===e?{...t,rows:[...t.rows,{}]}:t),r=n[e].rows.length-1;return w({detailIdx:e,rowIdx:r,isNew:!0}),n})},[]),k=(0,Y.useCallback)(()=>{w(e=>(e?.isNew&&u(t=>t.map((t,n)=>n===e.detailIdx?{...t,rows:t.rows.filter((t,n)=>n!==e.rowIdx)}:t)),null))},[]),A=(0,Y.useCallback)(async t=>{b(),e.onSuccess||J.success(i?e.title?`${e.title} saved`:`Saved`:`Created`),i||(u(c.map(()=>({rows:[],original:[]}))),h(e=>e+1)),await e.onSuccess?.(t)},[i,e.onSuccess,e.title,c.length,b]),j=(0,Y.useCallback)(t=>{b(),J.error(t?.message||`Save failed`),e.onError?.(t)},[e,b]),M=(0,Y.useCallback)(async n=>{let r=[];for(let a=0;a<c.length;a++){let o=c[a],{rows:s,original:l}=d.current[a];if(!o.relationshipField)continue;let{created:u}=await Je(t,e.objectName,n,{childObject:o.childObject,relationshipField:o.relationshipField,rows:s,original:i?l:void 0,amountField:o.amountField,totalField:o.totalField,childSchema:p.current[o.childObject]});r.push(...u)}return r},[c,i,t,e.objectName]),N=(0,Y.useCallback)(async n=>{let r=$(n)??e.recordId;if(!r)throw Error(`MasterDetailForm: parent record has no id after save`);if(!t)throw Error(`MasterDetailForm: dataSource is required`);let a=[];try{a=await M(r)}catch(n){throw i||await Promise.allSettled([...a.map(e=>t.delete(e.object,e.id)),t.delete(e.objectName,r)]),n}await A(n)},[t,i,M,e,A]),P=typeof t?.batchTransaction==`function`,F=(0,Y.useCallback)(async n=>{let r=t,a={...n};c.forEach((e,t)=>{e.totalField&&(a[e.totalField]=Ge(d.current[t]?.rows??[],e.amountField||`amount`))});let o=i?Ue(e.objectName,e.recordId,a,c.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:d.current[t]?.rows??[],original:d.current[t]?.original??[],childSchema:p.current[e.childObject]}))):He(e.objectName,a,c.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:d.current[t]?.rows??[],childSchema:p.current[e.childObject]})));return(await r.batchTransaction(o))?.results?.[0]??{...a,id:e.recordId}},[t,c,e.objectName,e.recordId,i]),I=(0,Y.useMemo)(()=>({type:`object-form`,objectName:e.objectName,mode:e.mode??`create`,recordId:e.recordId,initialValues:e.initialValues,initialData:e.initialData,formType:e.formType,sections:e.sections,fields:e.fields,title:e.title,showSubmit:!1,showCancel:!1,...P?{submitHandler:F,onSuccess:A}:{onSuccess:N},onError:j}),[e,N,P,F,A,j]),R=(0,Y.useRef)(null),z=e.submitText??(i?`Save`:`Create`),B=(0,Y.useCallback)(()=>{v.current||R.current?.querySelector(`form`)&&(v.current=!0,_(!0),setTimeout(()=>{(R.current?.querySelector(`form`))?.requestSubmit()},0),y.current=setTimeout(()=>b(),1500))},[b]);return(0,Y.useEffect)(()=>()=>{y.current&&clearTimeout(y.current)},[]),(0,Z.jsxs)(`div`,{className:V(`space-y-6`,n,e.className),children:[(0,Z.jsx)(`div`,{ref:R,children:(0,Z.jsx)(Ct,{schema:I,dataSource:t},m)}),(0,Z.jsx)(mt,{details:c,state:l,setRows:x,formHostRef:R,taxRateField:S,formKey:m,onRowExpand:(e,t)=>w({detailIdx:e,rowIdx:t}),onAddViaForm:O}),C&&E&&(0,Z.jsxs)(f,{className:`border-primary/40 shadow-none ring-1 ring-primary/10`,"data-testid":`md-row-form`,children:[(0,Z.jsxs)(H,{className:`pb-2 flex flex-row items-center justify-between gap-2 space-y-0`,children:[(0,Z.jsxs)(U,{className:`text-sm font-medium`,children:[E.title||`Line item`,` — row `,C.rowIdx+1]}),(0,Z.jsx)(K,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 text-xs text-muted-foreground`,onClick:k,children:`Close`})]}),(0,Z.jsx)(L,{children:(0,Z.jsx)(Ct,{schema:{type:`object-form`,objectName:E.childObject,mode:`edit`,initialData:T??{},...E.formFields?.length?{fields:E.formFields}:{},submitText:`Apply`,submitHandler:async e=>e,onSuccess:e=>{D(C.detailIdx,C.rowIdx,e),w(null)},onCancel:k},dataSource:t},`row-${C.detailIdx}-${C.rowIdx}`)})]}),e.showSubmit!==!1&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-border pt-4`,children:[e.onCancel&&(0,Z.jsx)(K,{type:`button`,variant:`outline`,onClick:e.onCancel,disabled:g,"data-testid":`md-form-cancel`,children:e.cancelText??`Cancel`}),(0,Z.jsx)(K,{type:`button`,onClick:B,disabled:g||a&&!o,"data-testid":`md-form-submit`,children:g?`Saving…`:z})]})]})},gt={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`},_t=c({"form.discardTitle":`Discard changes?`,"form.discardMessage":`You have unsaved changes. If you close this form now, your edits will be lost.`,"form.keepEditing":`Keep editing`,"form.discard":`Discard`},`form.discardTitle`),vt=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=b(),{t:a}=_t(),o=i(),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)([]),[f,p]=(0,Y.useState)({}),[m,g]=(0,Y.useState)(!0),[_,v]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)(!1),[T,E]=(0,Y.useState)(!1),D=(0,Y.useRef)(!1),k=e.confirmOnDiscard!==!1,N=e.open!==!1,P=e.drawerSide||`right`,F=(0,Y.useId)(),[I,L]=(0,Y.useState)(()=>{let t={};return e.sections?.forEach((e,n)=>{let r=e.name||String(n);e.collapsed&&(t[r]=!0)}),t});(0,Y.useEffect)(()=>{(async()=>{if(!t){g(!1);return}try{let n=await t.getObjectSchema(e.objectName);l(n)}catch(e){v(e),g(!1)}})()},[e.objectName,t]),(0,Y.useEffect)(()=>{(c||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){p(e.initialData||e.initialValues||{}),g(!1);return}if(!t){p(e.initialData||e.initialValues||{}),g(!1);return}try{let n=await t.findOne(e.objectName,e.recordId);p(n||{})}catch(e){v(e)}finally{g(!1)}})()},[c,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let te=(0,Y.useCallback)(t=>he(t,{objectSchema:c,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:r}),[c,e.readOnly,e.mode,e.objectName,r]);(0,Y.useEffect)(()=>{if(!c&&t)return;if(e.customFields?.length){d(e.customFields),g(!1);return}if(e.sections?.length){g(!1);return}if(!c)return;let n=e.fields||Object.keys(c.fields||{}),i=[];for(let t of n){let n=typeof t==`string`?t:t.name;if(!n)continue;let a=c.fields?.[n];a&&i.push({name:n,label:r(e.objectName,n,a.label||n),type:B(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:oe(a),field:a,options:a.options,multiple:a.multiple})}d(i),g(!1)},[c,e.fields,e.customFields,e.sections,e.readOnly,e.mode,t]);let ne=(0,Y.useCallback)(async n=>{E(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(n),e.onOpenChange?.(!1),n;let r,i=Re(n,c);return e.mode===`create`?r=await t.create(e.objectName,i):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,i)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{E(!1)}},[e,t,c]),H=(0,Y.useCallback)(()=>{w(!1),D.current&&(D.current=!1,e.onCancel?.()),e.onOpenChange?.(!1)},[e]),ae=(0,Y.useCallback)(e=>{D.current=e,k&&x?w(!0):H()},[k,x,H]),U=(0,Y.useCallback)(()=>{D.current=!0,H()},[H]),W=(0,Y.useMemo)(()=>{if(e.drawerWidth)return P===`left`||P===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,P]),G=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,se=e.showSubmit!==!1&&e.mode!==`view`,q=e.showCancel!==!1,J=e.submitText||(e.mode===`create`?`Create`:`Update`),X=e.cancelText||`Cancel`,de={type:`form`,objectName:e.objectName,layout:G,defaultValues:f,submitLabel:J,cancelLabel:X,showSubmit:se,showCancel:q,onSubmit:ne,onCancel:U,onDirtyChange:S,showActions:!1,id:F},fe=()=>{if(_)return(0,Z.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,Z.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,Z.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(m)return(0,Z.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,Z.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(e.sections?.length){let t=[];return e.sections.forEach((e,n)=>{let r=e.name||String(n),i=I[r]??e.collapsed??!1;t.push({name:`__section_${r}`,label:e.label||``,type:`section-divider`,colSpan:4,collapsible:e.collapsible,collapsed:i,onToggle:e.collapsible?()=>L(e=>({...e,[r]:!i})):void 0,className:e.className});let a=te(e);i?t.push(...a.map(e=>({...e,hidden:!0}))):t.push(...a)}),(0,Z.jsx)(s,{schema:{...de,fields:t}})}let t=Me(u,c,e.columns,e.mode),n=gt[t.columns||1];return(0,Z.jsx)(s,{schema:{...de,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},Q=e.subforms,pe=Q?.length&&e.mode!==`view`?(0,Z.jsx)(ht,{schema:{type:`object-master-detail-form`,objectName:e.objectName,mode:e.mode===`edit`?`edit`:`create`,recordId:e.recordId,fields:e.fields,sections:e.sections,submitText:e.submitText,cancelText:X,details:Q,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:t}):fe();return o?(0,Z.jsxs)(`div`,{className:`@container rounded-md border bg-card p-4`,children:[(e.title||e.description)&&(0,Z.jsxs)(`div`,{className:`mb-3 space-y-0.5`,children:[e.title&&(0,Z.jsx)(`div`,{className:`text-sm font-semibold`,children:e.title}),e.description&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),pe]}):(0,Z.jsx)(h,{open:N,onOpenChange:t=>{if(t){e.onOpenChange?.(!0);return}ae(!1)},children:(0,Z.jsxs)(A,{side:P,className:V(`overflow-y-auto`,n,e.className),style:W,children:[(e.title||e.description)&&(0,Z.jsxs)(O,{children:[e.title&&(0,Z.jsx)(j,{children:e.title}),e.description?(0,Z.jsx)(y,{children:e.description}):(0,Z.jsx)(y,{className:`sr-only`,children:`Complete the form fields, then submit or cancel.`})]}),(0,Z.jsx)(`div`,{className:`@container py-4`,children:pe}),!_&&!m&&!(Q?.length&&e.mode!==`view`)&&(se||q)&&(0,Z.jsx)(`div`,{className:`shrink-0 border-t px-4 py-3 bg-background`,"data-testid":`drawer-form-footer`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[q&&(0,Z.jsx)(K,{type:`button`,variant:`outline`,onClick:U,disabled:T,className:`w-full sm:w-auto`,children:X}),se&&(0,Z.jsxs)(K,{type:`submit`,form:F,disabled:T,className:`w-full sm:w-auto`,children:[T&&(0,Z.jsx)(ue,{className:`mr-2 h-4 w-4 animate-spin`}),J]})]})}),(0,Z.jsx)(R,{open:C,onOpenChange:w,children:(0,Z.jsxs)(ee,{children:[(0,Z.jsxs)(ce,{children:[(0,Z.jsx)(le,{children:a(`form.discardTitle`)}),(0,Z.jsx)(z,{children:a(`form.discardMessage`)})]}),(0,Z.jsxs)(M,{children:[(0,Z.jsx)(re,{onClick:()=>{D.current=!1},children:a(`form.keepEditing`)}),(0,Z.jsx)(ie,{onClick:H,children:a(`form.discard`)})]})]})})]})})};function yt(e,t){let n=d({fieldGroups:t,fields:Object.fromEntries(e.map(e=>[e.name,{group:e.group}]))});if(!n)return null;let r=new Set(n.flatMap(e=>e.fields)),i=e.map(e=>e.name).filter(e=>!r.has(e)),a=n.map(e=>({...e.key===void 0?{}:{name:e.key},...e.key===void 0?{}:{label:e.label??e.key},fields:[...e.fields],...e.collapse===`none`?{}:{collapsible:!0},...e.collapse===`collapsed`?{collapsed:!0}:{}}));if(i.length>0){let e=a[a.length-1];e&&e.name===void 0?e.fields=[...e.fields??[],...i]:a.push({fields:i})}return a}var bt=c({"form.discardTitle":`Discard changes?`,"form.discardMessage":`You have unsaved changes. If you close this form now, your edits will be lost.`,"form.keepEditing":`Keep editing`,"form.discard":`Discard`},`form.discardTitle`),xt={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`},St=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:a,sectionLabel:o}=b(),{t:c}=bt(),l=i(),u=r(),d=(0,Y.useCallback)(t=>{if(!u?.isLoaded)return t;let n=[];for(let r of t){if(!r?.name){n.push(r);continue}u.checkField(e.objectName,r.name,`read`)&&(!u.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0}):n.push(r))}return n},[u,e.objectName,e.mode]),[f,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)([]),[v,y]=(0,Y.useState)({}),[S,C]=(0,Y.useState)(!0),[T,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(!1),[A,j]=(0,Y.useState)(!1),[N,I]=(0,Y.useState)(!1),L=(0,Y.useRef)(!1),te=e.confirmOnDiscard!==!1,H=e.open!==!1,U=(0,Y.useId)(),W=(0,Y.useMemo)(()=>{if(e.sections?.length||e.customFields?.length)return null;let t=Ee(m,f);e.mode===`create`&&(t=De(t,f));let n=yt(t,f?.fieldGroups);if(!n)return null;let r=e.columns&&e.columns>0?Math.min(Math.floor(e.columns),4):xe(t.length);return n.map(e=>({...e,columns:r}))},[e.sections,e.customFields,e.columns,e.mode,m,f]),G=e.sections?.length?e.sections:W??void 0,q=(0,Y.useMemo)(()=>G?.length||e.customFields?.length?null:Me(m,f,e.columns,e.mode),[m,f,e.columns,e.mode,G,e.customFields]),J=xt[(0,Y.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(q?.columns&&q.columns>1)return je(q.columns);if(G?.length){let e=Math.max(...G.map(e=>Number(e.columns)||1));if(e>1)return je(e)}return`default`},[e.modalSize,q,G])]||xt.default;(0,Y.useEffect)(()=>{(async()=>{if(!t){C(!1);return}try{let n=await t.getObjectSchema(e.objectName);p(n)}catch(e){D(e),C(!1)}})()},[e.objectName,t]),(0,Y.useEffect)(()=>{(f||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){y(e.initialData||e.initialValues||{}),C(!1);return}if(!t){y(e.initialData||e.initialValues||{}),C(!1);return}try{let n=await t.findOne(e.objectName,e.recordId);y(n||{})}catch(e){D(e)}finally{C(!1)}})()},[f,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let X=(0,Y.useCallback)(t=>he(t,{objectSchema:f,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:a}),[f,e.readOnly,e.mode,e.objectName,a]);(0,Y.useEffect)(()=>{if(!f&&t)return;if(e.customFields?.length){h(e.customFields),C(!1);return}if(e.sections?.length){C(!1);return}if(!f)return;let n=e.fields||Object.keys(f.fields||{}),r=[];for(let t of n){let n=typeof t==`string`?t:t.name;if(!n)continue;let i=f.fields?.[n];i&&r.push({name:n,label:a(e.objectName,n,i.label||n),type:B(i.type),required:i.required||!1,disabled:e.readOnly||e.mode===`view`||i.readonly,placeholder:i.placeholder,description:i.help||i.description,validation:oe(i),field:i,options:i.options,multiple:i.multiple,visibleWhen:i.visibleWhen,readonlyWhen:i.readonlyWhen,requiredWhen:i.requiredWhen??i.conditionalRequired,group:i.group})}h(r),C(!1)},[f,e.fields,e.customFields,e.sections,e.readOnly,e.mode,t]);let de=(0,Y.useCallback)(async n=>{k(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(n),e.onOpenChange?.(!1),n;let r,i=Re(n,f);if(u?.isLoaded){let t={};for(let n of Object.keys(i))u.checkField(e.objectName,n,`write`)&&(t[n]=i[n]);i=t}return e.mode===`create`?r=await t.create(e.objectName,i):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,i)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{k(!1)}},[e,t,f,u]),Q=(0,Y.useCallback)(()=>{I(!1),L.current&&(L.current=!1,e.onCancel?.()),e.onOpenChange?.(!1)},[e]),pe=(0,Y.useCallback)(e=>{L.current=e,te&&A?I(!0):Q()},[te,A,Q]),me=(0,Y.useCallback)(()=>{L.current=!0,Q()},[Q]),ge=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,_e=e.showSubmit!==!1&&e.mode!==`view`,ve=e.showCancel!==!1,ye=e.submitText||(e.mode===`create`?`Create`:`Update`),be=e.cancelText||`Cancel`,Se={type:`form`,objectName:e.objectName,layout:ge,defaultValues:v,submitLabel:ye,cancelLabel:be,showSubmit:_e,showCancel:ve,onSubmit:de,onCancel:me,onDirtyChange:j,showActions:!1,id:U},Ce=()=>{if(T)return(0,Z.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,Z.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,Z.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:T.message})]});if(S)return(0,Z.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(w,{className:`h-4 w-24`}),(0,Z.jsx)(w,{className:`h-10 w-full`})]},e))});if(e.sections?.length){let t=e.sections,n=(e,t)=>e.name||e.label||String(t),r=t=>t.name?o(e.objectName,t.name,t.label||t.name):t.label,i=e=>(0,Z.jsx)(s,{schema:{...Se,...Ae(d(X(e)),e.columns||1)}});return e.contentLayout===`tabbed`&&t.length>1?(0,Z.jsxs)(P,{defaultValue:n(t[0],0),className:`w-full`,children:[(0,Z.jsx)(se,{className:`mb-4`,children:t.map((e,t)=>(0,Z.jsx)(F,{value:n(e,t),children:r(e)||`Section ${t+1}`},n(e,t)))}),t.map((e,t)=>(0,Z.jsx)(ne,{value:n(e,t),children:(0,Z.jsx)(fe,{description:e.description,columns:1,className:e.className,gridClassName:e.gridClassName,children:i(e)})},n(e,t)))]}):(0,Z.jsx)(`div`,{className:`space-y-6`,children:t.map((e,t)=>(0,Z.jsx)(fe,{label:r(e),description:e.description,columns:1,className:e.className,gridClassName:e.gridClassName,children:i(e)},n(e,t)))})}if(W?.length){let t=Number(W[0]?.columns)||1,n=[];W.forEach((r,i)=>{let a=d(X(r));if(!a.length)return;let s=r.name?o(e.objectName,r.name,r.label||r.name):r.label;s&&n.push({name:`__section_${r.name||i}`,label:s,type:`section-divider`}),n.push(...t>1?we(a,t):a)});let r=Oe[t];return(0,Z.jsx)(s,{schema:{...Se,fields:n,columns:t,...r?{fieldContainerClass:r}:{}}})}let t=q??Me(m,f,e.columns,e.mode),n=Oe[t.columns||1];return(0,Z.jsx)(s,{schema:{...Se,fields:d(t.fields),columns:t.columns,...n?{fieldContainerClass:n}:{}}})},Te=e.subforms;if(l)return(0,Z.jsxs)(`div`,{className:`@container rounded-md border bg-card p-4`,children:[(e.title||e.description)&&(0,Z.jsxs)(`div`,{className:`mb-3 space-y-0.5`,children:[e.title&&(0,Z.jsx)(`div`,{className:`text-sm font-semibold`,children:e.title}),e.description&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),Ce()]});if(Te?.length&&e.mode!==`view`)return(0,Z.jsx)(E,{open:H,onOpenChange:e.onOpenChange,children:(0,Z.jsxs)(_,{className:V(J,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,n,e.className),children:[(e.title||e.description)&&(0,Z.jsxs)(ae,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,Z.jsx)(x,{children:e.title}),e.description?(0,Z.jsx)(g,{children:e.description}):(0,Z.jsx)(g,{className:`sr-only`,children:`Enter the record and its line items, then save.`})]}),(0,Z.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:(0,Z.jsx)(ht,{schema:{type:`object-master-detail-form`,objectName:e.objectName,mode:e.mode===`edit`?`edit`:`create`,recordId:e.recordId,fields:e.fields,sections:e.sections,initialValues:e.initialValues,initialData:e.initialData,submitText:ye,cancelText:be,details:Te,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:t})})]})});let ke=!S&&!T&&(_e||ve);return(0,Z.jsx)(E,{open:H,onOpenChange:t=>{if(t){e.onOpenChange?.(!0);return}pe(!1)},children:(0,Z.jsxs)(_,{className:V(J,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,n,e.className),children:[(e.title||e.description)&&(0,Z.jsxs)(ae,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,Z.jsx)(x,{children:e.title}),e.description?(0,Z.jsx)(g,{children:e.description}):(0,Z.jsx)(g,{className:`sr-only`,children:`Complete the form fields, then submit or cancel.`})]}),(0,Z.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:Ce()}),ke&&(0,Z.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[ve&&(0,Z.jsx)(K,{type:`button`,variant:`outline`,onClick:me,disabled:O,className:`w-full sm:w-auto`,children:be}),_e&&(0,Z.jsxs)(K,{type:`submit`,form:U,disabled:O,className:`w-full sm:w-auto`,children:[O&&(0,Z.jsx)(ue,{className:`mr-2 h-4 w-4 animate-spin`}),ye]})]})}),(0,Z.jsx)(R,{open:N,onOpenChange:I,children:(0,Z.jsxs)(ee,{children:[(0,Z.jsxs)(ce,{children:[(0,Z.jsx)(le,{children:c(`form.discardTitle`)}),(0,Z.jsx)(z,{children:c(`form.discardMessage`)})]}),(0,Z.jsxs)(M,{children:[(0,Z.jsx)(re,{onClick:()=>{L.current=!1},children:c(`form.keepEditing`)}),(0,Z.jsx)(ie,{onClick:Q,children:c(`form.discard`)})]})]})})]})})},Ct=({schema:e,dataSource:t})=>{let n=r(),i=(0,Y.useMemo)(()=>{if(!n?.isLoaded)return e;let t=t=>t?.name?n.checkField(e.objectName,t.name,`read`)?!n.checkField(e.objectName,t.name,`write`)&&e.mode!==`view`?{...t,readOnly:!0,disabled:!0}:t:null:t,r=e=>Array.isArray(e)?e.map(t).filter(Boolean):e;return{...e,fields:r(e.fields),sections:e.sections?.map(e=>({...e,fields:r(e.fields)}))}},[e,n]),{sectionLabel:a}=b(),o=e=>e?.name?a(i.objectName,e.name,e.label||e.name):e?.label;if(i.subforms?.length&&i.mode!==`view`&&i.formType!==`drawer`&&i.formType!==`modal`)return(0,Z.jsx)(ht,{schema:{type:`object-master-detail-form`,objectName:i.objectName,mode:i.mode===`edit`?`edit`:`create`,recordId:i.recordId,initialValues:i.initialValues,initialData:i.initialData,formType:i.formType===`tabbed`?`tabbed`:`simple`,sections:i.sections,fields:i.fields,title:i.title,submitText:i.submitText,cancelText:i.cancelText,showSubmit:i.showSubmit,details:i.subforms,onSuccess:i.onSuccess,onError:i.onError,onCancel:i.onCancel,className:i.className},dataSource:t});if(i.formType===`tabbed`&&i.sections?.length)return(0,Z.jsx)(Ne,{schema:{...i,formType:`tabbed`,sections:i.sections.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields,className:e.className,gridClassName:e.gridClassName})),defaultTab:i.defaultTab,tabPosition:i.tabPosition},dataSource:t,className:i.className});if(i.formType===`wizard`&&i.sections?.length)return(0,Z.jsx)(Pe,{schema:{...i,formType:`wizard`,sections:i.sections.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields,className:e.className,gridClassName:e.gridClassName})),allowSkip:i.allowSkip,showStepIndicator:i.showStepIndicator,nextText:i.nextText,prevText:i.prevText,onStepChange:i.onStepChange},dataSource:t,className:i.className});if(i.formType===`split`&&i.sections?.length)return(0,Z.jsx)(Fe,{schema:{...i,formType:`split`,sections:i.sections.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields,className:e.className,gridClassName:e.gridClassName})),splitDirection:i.splitDirection,splitSize:i.splitSize,splitResizable:i.splitResizable},dataSource:t,className:i.className});if(i.formType===`drawer`){let{layout:e,...n}=i,r=i.layout===`vertical`||i.layout===`horizontal`?i.layout:void 0;return(0,Z.jsx)(vt,{schema:{...n,layout:r,formType:`drawer`,sections:i.sections?.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields,collapsible:e.collapsible,collapsed:e.collapsed,className:e.className})),open:i.open,onOpenChange:i.onOpenChange,drawerSide:i.drawerSide,drawerWidth:i.drawerWidth},dataSource:t,className:i.className})}if(i.formType===`modal`){let{layout:e,...n}=i,r=i.layout===`vertical`||i.layout===`horizontal`?i.layout:void 0;return(0,Z.jsx)(St,{schema:{...n,layout:r,formType:`modal`,sections:i.sections?.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields,className:e.className,gridClassName:e.gridClassName})),open:i.open,onOpenChange:i.onOpenChange,modalSize:i.modalSize,modalCloseButton:i.modalCloseButton},dataSource:t,className:i.className})}return(0,Z.jsx)(wt,{schema:i,dataSource:t})},wt=({schema:e,dataSource:t})=>{let{fieldLabel:n,sectionLabel:i}=b(),a=q(),o=r(),c=(0,Y.useCallback)(t=>{if(!o?.isLoaded)return t;let n=[];for(let r of t)o.checkField(e.objectName,r.name,`read`)&&(!o.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0,description:r.description??`You do not have edit access to this field.`}):n.push(r));return n},[o,e.objectName,e.mode]),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(!0),[_,v]=(0,Y.useState)(null),[y,x]=(0,Y.useState)(null),S=e.customFields&&e.customFields.length>0;(0,Y.useEffect)(()=>{S&&(m(e.initialData||e.initialValues||{}),g(!1))},[S,e.initialData,e.initialValues]),(0,Y.useEffect)(()=>{S?u({name:e.objectName,fields:{}}):e.objectName&&t?(async()=>{try{if(!t)throw Error(`DataSource is required when using ObjectQL schema fetching (inline fields not provided)`);let n=await t.getObjectSchema(e.objectName);if(!n)throw Error(`No schema found for object "${e.objectName}"`);u(n)}catch(e){v(e),g(!1)}})():S||g(!1)},[e.objectName,t,S]),(0,Y.useEffect)(()=>{l&&!S&&(async()=>{if(!e.recordId||e.mode===`create`){m(e.initialData||e.initialValues||{}),g(!1);return}if(!S){if(!t){v(Error(`DataSource is required for fetching record data (inline data not provided)`)),g(!1);return}g(!0);try{let n=await t.findOne(e.objectName,e.recordId);m(n)}catch(e){console.error(`Failed to fetch record:`,e),v(e)}finally{g(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,t,l,S]);let C=(0,Y.useCallback)(e=>e,[]);(0,Y.useEffect)(()=>{if(S&&e.customFields){f(e.customFields.map(C)),g(!1);return}if(!l)return;let r=[],i=e.fields||Object.keys(l.fields||{});(Array.isArray(i)?i:Object.keys(i)).forEach(t=>{let i=typeof t==`string`?t:t.name;if(!i)return;let a=l.fields?.[i];if(!a&&!S)return;let o=!a?.permissions||a?.permissions.write!==!1;if(e.mode!==`view`&&!o)return;let s=e.customFields?.find(e=>e.name===i);if(s)r.push(C(s));else if(a){let o={name:i,label:n(e.objectName,i,a.label||t),type:B(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly||l?.managedBy&&l.managedBy!==`platform`,placeholder:a.placeholder,description:a.help||a.description,validation:oe(a),visibleWhen:a.visibleWhen,readonlyWhen:a.readonlyWhen,requiredWhen:a.requiredWhen??a.conditionalRequired,group:a.group,field:a};if((a.type===`select`||a.type===`lookup`||a.type===`master_detail`)&&(o.options=a.options||[],o.multiple=a.multiple),(a.type===`number`||a.type===`currency`||a.type===`percent`)&&(o.inputType=`number`,o.min=a.min,o.max=a.max,o.step=a.precision?10**-a.precision:void 0),a.type===`date`&&(o.inputType=`date`),a.type===`datetime`&&(o.inputType=`datetime-local`),(a.type===`text`||a.type===`textarea`||a.type===`markdown`||a.type===`html`)&&(o.maxLength=a.max_length,o.minLength=a.min_length),(a.type===`file`||a.type===`image`)&&(o.inputType=`file`,o.multiple=a.multiple,o.accept=a.accept?a.accept.join(`,`):void 0,a.max_size)){let e=`Max size: ${W(a.max_size)}`;o.description=o.description?`${o.description} (${e})`:e}a.type===`email`&&(o.inputType=`email`),a.type===`phone`&&(o.inputType=`tel`),a.type===`url`&&(o.inputType=`url`),a.type===`password`&&(o.inputType=`password`),a.type===`time`&&(o.inputType=`time`),(a.type===`formula`||a.type===`summary`||a.type===`auto_number`)&&(o.disabled=!0),a.visible_on&&(o.visibleOn=a.visible_on),r.push(o)}}),f(r),!S&&e.recordId&&e.mode!==`create`&&t||g(!1)},[l,e.fields,e.customFields,e.readOnly,e.mode,S,e.recordId,t]);let w=(0,Y.useCallback)(async(n,r)=>{if(n&&(n.nativeEvent||n._reactName===`onSubmit`)&&(console.warn(`ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue.`),r===void 0&&(n={})),S&&!t)return e.onSuccess&&await e.onSuccess(n),n;if(!t)throw Error(`DataSource is required for form submission (inline mode not configured)`);let i=Re(n,S?null:l);if(o?.isLoaded&&i&&typeof i==`object`){let t={};for(let n of Object.keys(i))o.checkField(e.objectName,n,`write`)&&(t[n]=i[n]);i=t}try{let n;if(e.submitHandler)n=await e.submitHandler(i);else if(e.mode===`create`)n=await t.create(e.objectName,i);else if(e.mode===`edit`&&e.recordId)n=await t.update(e.objectName,e.recordId,i);else throw Error(`Invalid form mode or missing record ID`);if(e.onSuccess)await e.onSuccess(n);else if(!e.submitHandler&&e.submitBehavior){let t=e.submitBehavior;switch(t.kind){case`redirect`:X(t.url)&&setTimeout(()=>window.location.assign(t.url),t.delayMs??0);break;case`continue`:break;default:{let n=t.kind===`thank-you`&&t.message?t.message:e.successMessage||(e.mode===`create`?`Created`:`Saved`);J.success(n),x({title:t.kind===`thank-you`?t.title:void 0,message:n});break}}}else if(!e.submitHandler){let t=de(e.navigateOnSuccess,n);if(t)return window.location.assign(t),n;J.success(e.successMessage||(e.mode===`create`?`Created`:`Saved`))}return n}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,t,S,o,l]),T=(0,Y.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),E={...Y.useMemo(()=>{if(!l?.fields)return{};let e={};return Object.keys(l.fields).forEach(t=>{let n=l.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[l]),...p},D=Y.useMemo(()=>{let t=Ee(d,l);return e.mode===`create`&&(t=De(t,l)),t},[d,l,e.mode]),O=Y.useMemo(()=>e.sections?.length?null:yt(D,l?.fieldGroups),[e.sections,D,l]),k=e.sections?.length?e.sections:O,[A,j]=(0,Y.useState)({});if(_)return(0,Z.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,Z.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,Z.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(h)return(0,Z.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,Z.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(y)return(0,Z.jsxs)(`div`,{className:`rounded-md border bg-card p-6 sm:p-8 text-center`,children:[(0,Z.jsx)(`h3`,{className:`text-lg font-semibold`,children:y.title??`Thanks!`}),y.message&&(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:y.message})]});let M=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(k?.length&&(!e.formType||e.formType===`simple`)){let t=O?D:d,n=e=>typeof e==`number`&&e>0?Math.min(Math.floor(e),4):void 0,r=k.map(e=>n(e.columns)).filter(e=>e!=null),a=k.reduce((e,t)=>e+(Array.isArray(t.fields)?t.fields.length:0),0),o=n(e.columns)??(r.length?Math.max(...r):xe(a)),l=[];k.forEach((r,a)=>{let s=new Map(r.fields.map(e=>[typeof e==`string`?e:e.field??e.name,e])),u=Array.from(s.keys()),d=c(t.filter(e=>u.includes(e.name))).map(e=>{let t=s.get(e.name);if(!t||typeof t!=`object`)return e;let n=t,r={...e};return n.visibleOn!=null&&(r.visibleOn=n.visibleOn),n.colSpan!=null&&(r.colSpan=n.colSpan),n.span!=null&&(r.span=n.span),r});if(d.length===0)return;let f=r.name||r.label||String(a),p=r.name?i(e.objectName,r.name,r.label||r.name):r.label,m=A[f]??r.collapsed??!1;p&&l.push({name:`__section_${f}`,label:p,type:`section-divider`,colSpan:4,collapsible:r.collapsible,collapsed:m,onToggle:r.collapsible?()=>j(e=>({...e,[f]:!m})):void 0,className:r.className});let h=n(r.columns),g=o>1?we(d,o,h):d;p&&m?l.push(...g.map(e=>({...e,hidden:!0}))):l.push(...g)});let u=l,f=ke(o);return(0,Z.jsx)(`div`,{className:`w-full @container`,children:(0,Z.jsx)(s,{schema:{type:`form`,objectName:e.objectName,fields:u,layout:M,columns:o,...f?{fieldContainerClass:f}:{},defaultValues:E,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,onSubmit:w,onCancel:T}})})}let N=e.sections?.length,P=c(d),F=N?{fields:P,columns:e.columns}:Me(P,l,e.columns,e.mode),I=e.mobile,L=I?.fullscreenLongText?F.fields.map(e=>{let t=e.type;return t===`textarea`||t===`field:textarea`||t===`string-multiline`||t===`field:markdown`||t===`field:html`?{...e,mobile_fullscreen:!0}:e}):F.fields,R=I?.stepper,z=I?.stepperMinFields??8,ee=Math.max(1,I?.stepperFieldsPerStep??1);if(!e.formType&&!N&&L.length>=2&&(R===!0||R===`auto`&&a&&L.length>=z)){let n=L,r=[];for(let e=0;e<n.length;e+=ee){let t=n.slice(e,e+ee);r.push({name:`step-${Math.floor(e/ee)+1}`,label:t[0]?.label||t[0]?.name||`Step ${Math.floor(e/ee)+1}`,fields:t})}return(0,Z.jsx)(Pe,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:t,className:e.className})}let te={type:`form`,objectName:e.objectName,fields:L,layout:M,columns:F.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||e.submitBehavior?.kind===`continue`||!e.submitBehavior&&e.resetOnSuccess&&e.mode===`create`,defaultValues:E,onSubmit:w,onCancel:T,className:e.className,mobileStickyActions:!!I?.stickyActions};return(0,Z.jsx)(`div`,{className:I?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":I?`true`:void 0,children:(0,Z.jsx)(s,{schema:te})})},Tt={text:200,email:254,url:2048,phone:32,textarea:5e3,markdown:5e3,html:5e3},Et=`_company_website_2`,Dt=1500;function Ot(e,t=[]){try{let n=new URL(e,typeof window<`u`?window.location.href:`http://localhost`);return typeof window<`u`&&n.origin===window.location.origin?!0:n.protocol!==`https:`&&n.protocol!==`http:`?!1:t.some(e=>{if(e===n.host)return!0;if(e.startsWith(`*.`)){let t=e.slice(1);return n.host.endsWith(t)&&n.host.length>t.length}return!1})}catch{return!1}}function kt(e){return e&&e.map(e=>{let t=Tt[String(e.type||``).toLowerCase()];return!t||(e.maxLength??e.max_length)?e:{...e,maxLength:t}})}var At=({config:e,dataSource:t,prefillParams:n,className:r})=>{let[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(!(e.consent?.required??!!e.consent)),[f,p]=(0,Y.useState)(null),m=(0,Y.useRef)(null),h=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{i||(h.current=Date.now())},[i]);let g=e.honeypot===!1?null:e.honeypot||Et,_=e.minFillTime??Dt,v=(0,Y.useMemo)(()=>kt(e.customFields),[e.customFields]),y=(0,Y.useMemo)(()=>{if(!t||v&&v.length>0||!e.fields||e.fields.length===0)return;let n=async(e,t)=>t;return{...t,create:n,update:(e,t,n)=>Promise.resolve(n),delete:()=>Promise.reject(Error(`Not permitted on public form`))}},[t,v,e.fields]),b=(0,Y.useMemo)(()=>{let t={};if(n)for(let[e,r]of Object.entries(n))t[e]=r;if(typeof window<`u`&&e.allowedPrefillFields?.length){let n=new Set(e.allowedPrefillFields);new URLSearchParams(window.location.search).forEach((e,r)=>{n.has(r)&&!(r in t)&&(t[r]=e)})}return Object.keys(t).length>0?t:void 0},[n,e.allowedPrefillFields]),x=(0,Y.useCallback)(async n=>{if(e.consent?.required&&!u){p(e.texts?.consentRequired??`Please accept the privacy policy to continue.`);return}if(p(null),g&&m.current?.value){a(!0);return}if(_>0&&Date.now()-h.current<_){l(e.texts?.rateLimited??`Please take a moment to review your answers before submitting.`);return}let r={...n};g&&delete r[g],e.captchaToken&&(r._captcha=e.captchaToken),s(!0),l(null);try{t&&await t.create(e.objectName,r),a(!0);let n=e.thankYouPage?.redirectUrl;if(n)if(Ot(n,e.allowedRedirectHosts)){let t=e.thankYouPage?.redirectDelay??3e3;setTimeout(()=>{window.location.href=n},t)}else console.warn(`[EmbeddableForm] Blocked unsafe redirect target:`,n),l(e.texts?.redirectBlocked??null)}catch(e){l(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{s(!1)}},[t,e,u,g,_]),S=(0,Y.useCallback)(()=>{a(!1),l(null)},[]),w=(0,Y.useMemo)(()=>{let t={};return e.branding?.backgroundColor&&(t.backgroundColor=e.branding.backgroundColor),t},[e.branding]);if(i){let t=e.thankYouPage,n=e.texts??{},i=Math.ceil((t?.redirectDelay??3e3)/1e3),a=(n.redirecting??`Redirecting in {{seconds}} seconds…`).replace(`{{seconds}}`,String(i));return(0,Z.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 bg-gradient-to-b from-muted/40 via-background to-background ${r||``}`,style:w,children:(0,Z.jsxs)(`div`,{className:`max-w-md w-full bg-card border rounded-xl shadow-sm p-8 text-center space-y-4`,children:[(0,Z.jsx)(`div`,{className:`mx-auto inline-flex h-14 w-14 items-center justify-center rounded-full bg-emerald-50 text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400`,children:(0,Z.jsx)(te,{className:`h-8 w-8`,"aria-hidden":`true`})}),(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||n.thankYouTitle||`Thank You!`}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t?.message||n.thankYouMessage||`Your submission has been received successfully.`}),e.allowMultiple&&(0,Z.jsx)(K,{variant:`outline`,size:`sm`,onClick:S,className:`mt-2`,children:n.submitAnother??`Submit Another Response`}),t?.redirectUrl&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a})]})})}let E=e.texts??{},D=!!e.consent?.required,O=`${e.formId}-consent`;return(0,Z.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 sm:p-6 bg-gradient-to-b from-muted/40 via-background to-background ${r||``}`,style:w,children:(0,Z.jsxs)(`div`,{className:`max-w-2xl w-full bg-card border rounded-xl shadow-sm overflow-hidden`,children:[e.branding?.coverImage&&(0,Z.jsx)(`div`,{className:`h-28 sm:h-32 w-full bg-cover bg-center`,style:{backgroundImage:`url(${JSON.stringify(e.branding.coverImage)})`},role:`presentation`}),(0,Z.jsxs)(`div`,{className:`px-6 sm:px-8 pt-7 pb-5 border-b bg-muted/20`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,Z.jsx)(`img`,{src:e.branding.logo,alt:``,className:`h-8 mb-4`}),e.title&&(0,Z.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground`,children:e.title}),e.description&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 leading-relaxed`,children:e.description}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 mt-3`,"aria-hidden":`true`,children:E.requiredHint??`* Required field`})]}),(0,Z.jsxs)(`div`,{className:`relative px-6 sm:px-8 py-6`,children:[c&&(0,Z.jsx)(`div`,{role:`alert`,"aria-live":`assertive`,className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:c}),(0,Z.jsx)(Ct,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:v,initialData:b,onSuccess:x,submitText:o?E.submitting??`Submitting...`:E.submit??`Submit`},dataSource:y}),g&&(0,Z.jsxs)(`div`,{"aria-hidden":`true`,className:`absolute left-[-10000px] top-auto h-px w-px overflow-hidden`,children:[(0,Z.jsx)(`label`,{htmlFor:`${e.formId}-${g}`,children:`Do not fill this field`}),(0,Z.jsx)(`input`,{ref:m,id:`${e.formId}-${g}`,type:`text`,name:g,tabIndex:-1,autoComplete:`off`,defaultValue:``})]}),e.consent&&(0,Z.jsxs)(`div`,{className:`mt-4`,children:[(0,Z.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-foreground cursor-pointer select-none`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,id:O,checked:u,onChange:e=>{d(e.target.checked),e.target.checked&&p(null)},"aria-required":D||void 0,"aria-invalid":f?`true`:void 0,"aria-describedby":f?`${O}-error`:void 0,className:`mt-0.5 h-4 w-4 rounded border-input accent-primary`}),(0,Z.jsxs)(`span`,{className:`leading-relaxed`,children:[e.consent.label??E.consentLabelDefault??`I agree to the privacy policy.`,D&&(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`text-destructive ml-0.5`,children:`*`}),e.consent.privacyUrl&&(0,Z.jsxs)(Z.Fragment,{children:[` `,(0,Z.jsx)(`a`,{href:e.consent.privacyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`underline text-primary hover:opacity-80`,children:E.consentLink??`Privacy policy`})]})]})]}),f&&(0,Z.jsx)(`p`,{id:`${O}-error`,role:`alert`,className:`mt-1.5 text-xs text-destructive`,children:f})]}),o&&(0,Z.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Z.jsx)(ue,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:E.submitting??`Submitting…`})]})]}),(0,Z.jsxs)(`div`,{className:`px-6 sm:px-8 py-4 border-t bg-muted/20 flex flex-col sm:flex-row items-center justify-between gap-2`,children:[(0,Z.jsxs)(`p`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,Z.jsx)(C,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{children:E.secureNotice??`Your information is transmitted securely and only used to respond to your request.`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground/80`,children:[e.privacyPolicyUrl&&(0,Z.jsxs)(`a`,{href:e.privacyPolicyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 underline hover:text-foreground`,children:[(0,Z.jsx)(T,{className:`h-3 w-3`,"aria-hidden":`true`}),E.consentLink??`Privacy policy`]}),(0,Z.jsx)(`span`,{children:E.poweredBy??`Powered by ObjectStack`})]})]})]})})};function jt(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`}var Mt=({formId:e,formTitle:t,metrics:n,className:r})=>{let i=(0,Y.useMemo)(()=>{if(!n.abandonedSubmissions)return 100;let e=n.totalSubmissions+n.abandonedSubmissions;return e===0?0:Math.round(n.totalSubmissions/e*100)},[n.totalSubmissions,n.abandonedSubmissions]),a=(0,Y.useMemo)(()=>n.dailySubmissions?.length?Math.max(...n.dailySubmissions.map(e=>e.count),1):1,[n.dailySubmissions]);return(0,Z.jsxs)(`div`,{className:`space-y-4 ${r||``}`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:t||`Form Analytics`}),(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,Z.jsx)(f,{children:(0,Z.jsxs)(H,{className:`pb-2`,children:[(0,Z.jsx)(G,{children:`Total Submissions`}),(0,Z.jsx)(U,{className:`text-2xl`,children:n.totalSubmissions.toLocaleString()})]})}),(0,Z.jsxs)(f,{children:[(0,Z.jsxs)(H,{className:`pb-2`,children:[(0,Z.jsx)(G,{children:`Fill Rate`}),(0,Z.jsxs)(U,{className:`text-2xl`,children:[i,`%`]})]}),(0,Z.jsx)(L,{children:(0,Z.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,Z.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${i}%`}})})})]}),(0,Z.jsx)(f,{children:(0,Z.jsxs)(H,{className:`pb-2`,children:[(0,Z.jsx)(G,{children:`Avg. Completion Time`}),(0,Z.jsx)(U,{className:`text-2xl`,children:n.avgCompletionTime?jt(n.avgCompletionTime):`—`})]})})]}),n.dailySubmissions&&n.dailySubmissions.length>0&&(0,Z.jsxs)(f,{children:[(0,Z.jsx)(H,{children:(0,Z.jsx)(U,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,Z.jsx)(L,{children:(0,Z.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:n.dailySubmissions.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,Z.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/a*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate w-full text-center`,children:e.date.slice(-5)})]},t))})})]}),n.fieldDropOff&&n.fieldDropOff.length>0&&(0,Z.jsxs)(f,{children:[(0,Z.jsxs)(H,{children:[(0,Z.jsx)(U,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,Z.jsx)(G,{children:`Percentage of users who completed each field`})]}),(0,Z.jsx)(L,{children:(0,Z.jsx)(`div`,{className:`space-y-3`,children:n.fieldDropOff.map((e,t)=>(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,Z.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,Z.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,Z.jsx)(`div`,{className:`rounded-full h-1.5 transition-all ${e.completionRate>=80?`bg-green-500`:e.completionRate>=50?`bg-yellow-500`:`bg-destructive`}`,style:{width:`${e.completionRate}%`}})})]},t))})})]})]})},Nt=({schema:e})=>{let t=l()?.dataSource,n=o(),r=e.parentObject||n?.objectName,i=e.parentId||e.recordId||n?.recordId,[a,s]=(0,Y.useState)([]),[c,u]=(0,Y.useState)([]),[d,p]=(0,Y.useState)(!0),[m,h]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(!1),[v,y]=(0,Y.useState)(null),[b,x]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`)return;let r=!1;return n.getObjectSchema(e.childObject).then(e=>{r||x(e??null)}).catch(()=>{r||x(null)}),()=>{r=!0}},[t,e.childObject]);let S=(0,Y.useCallback)(async()=>{if(!t||!i){p(!1);return}p(!0);try{let n=(await t.find(e.childObject,{$filter:{[e.relationshipField]:i},$top:500}))?.data??[];s(n.map(e=>({...e}))),u(n.map(e=>({...e}))),_(!1)}catch(e){y(e?.message||`Failed to load line items`)}finally{p(!1)}},[t,i,e.childObject,e.relationshipField]);(0,Y.useEffect)(()=>{S()},[S]);let C=(0,Y.useCallback)(e=>{s(e),_(!0)},[]),w=(0,Y.useCallback)(async()=>{if(!(!t||!i)){h(!0),y(null);try{await Je(t,r||e.childObject,i,{childObject:e.childObject,relationshipField:e.relationshipField,rows:a,original:c,amountField:e.amountField,totalField:r?e.totalField:void 0,childSchema:b}),await S()}catch(e){y(e?.message||`Failed to save line items`)}finally{h(!1)}}},[t,i,a,c,e,r,S,b]),T=(0,Y.useMemo)(()=>({columns:e.columns,total_field:e.totalField?e.amountField||`amount`:void 0,min_rows:e.minRows,max_rows:e.maxRows,allow_add:!e.readonly,allow_delete:!e.readonly}),[e]);return(0,Z.jsxs)(f,{className:V(`shadow-none`),children:[(0,Z.jsxs)(H,{className:`flex-row items-center justify-between gap-2 pb-2`,children:[(0,Z.jsx)(U,{className:`text-sm font-medium`,children:e.title||`Line Items`}),!e.readonly&&(0,Z.jsx)(K,{type:`button`,size:`sm`,onClick:w,disabled:m||d||!g||!i,children:m?`Saving…`:`Save`})]}),(0,Z.jsxs)(L,{children:[v&&(0,Z.jsx)(`p`,{className:`mb-2 text-sm text-destructive`,children:v}),d?(0,Z.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Loading…`}):i?(0,Z.jsx)(N,{value:a,onChange:C,field:T,readonly:e.readonly}):(0,Z.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Save the record first to add line items.`})]})]})},Pt=({schema:e})=>(0,Z.jsx)(Ct,{schema:e,dataSource:(0,Y.useContext)(u)?.dataSource??void 0});a.register(`object-form`,Pt,{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`]}]}),a.register(`form`,Pt,{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`]}]}),a.register(`embeddable-form`,({schema:e})=>(0,Z.jsx)(At,{config:e}),{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`}]}),a.register(`form-analytics`,({schema:e})=>(0,Z.jsx)(Mt,{formId:e.formId,formTitle:e.formTitle,metrics:e.metrics||{totalSubmissions:0}}),{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`}]}),a.register(`object-master-detail-form`,({schema:e})=>(0,Z.jsx)(ht,{schema:e,dataSource:(0,Y.useContext)(u)?.dataSource??void 0}),{namespace:`plugin-form`,label:`Master-Detail Form`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Parent Object`,required:!0},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`]},{name:`sections`,type:`array`,label:`Parent Sections`},{name:`details`,type:`array`,label:`Detail Collections`,required:!0}]}),a.register(`line_items`,({schema:e})=>(0,Z.jsx)(Nt,{schema:e}),{namespace:`record`,skipFallback:!0,label:`Line Items`,category:`record`,inputs:[{name:`childObject`,type:`string`,label:`Child Object`,required:!0},{name:`relationshipField`,type:`string`,label:`Relationship Field`,required:!0},{name:`columns`,type:`array`,label:`Columns`,required:!0},{name:`totalField`,type:`string`,label:`Parent Total Field`},{name:`amountField`,type:`string`,label:`Amount Column`}]});export{lt as i,St as n,vt as r,Ct as t};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BGDDiZfJ.js";import{Kt as r,Ut as i,Y as a,l as o,rt as s}from"./framework-B3O15Lsq.js";import{d as c,s as l}from"./vendor-objectstack-Bw0HRuFa.js";import{$i as u,$s as d,An as f,Ba as p,Cn as m,Cr as h,Dn as g,Ei as _,En as v,Fo as y,Ft as b,Gn as x,Ha as S,Hs as C,It as w,Jn as T,Jt as E,Kn as D,Kt as O,Lt as k,Mn as ee,Na as te,Nn as ne,Oc as re,Oi as ie,On as A,Or as ae,Pn as j,Pt as oe,Qi as M,Qn as N,Ra as P,Sn as se,Ti as ce,Tn as le,Un as ue,Us as F,V as I,Va as L,Wn as de,Xt as R,Ya as fe,Yi as pe,Yo as z,Yt as B,Z as V,_i as me,_n as H,_o as U,an as he,ar as W,bc as ge,bn as _e,ci as ve,cs as ye,ct as be,dn as xe,dt as Se,fn as G,go as Ce,hn as K,in as we,ji as Te,jn as Ee,kc as q,kn as J,mi as Y,na as De,on as Oe,oo as ke,pn as Ae,qn as je,qr as Me,qt as Ne,ri as Pe,sn as X,ut as Fe,vc as Ie,vn as Le,vo as Re,wi as ze,wn as Be,wo as Ve,xn as He,xr as Z,yn as Ue,zt as We}from"./ui-components-rkvkkTxO.js";import{i as Ge}from"./vendor-ui-utils-BzQBRdq3.js";import{t as Ke}from"./plugin-form-FeZEoC2R.js";import{_ as qe,a as Je,c as Ye,d as Xe,n as Ze,o as Qe,p as $e,r as et,s as tt,t as nt,u as rt,v as it,y as at}from"./vendor-dndkit-CzBh0_98.js";import{r as ot}from"./plugin-grid-eiIl2HN_.js";var Q=e(n(),1),$=t(),st={list:`List`,detail:`Detail`,grid:`Grid`,kanban:`Kanban`,calendar:`Calendar`,timeline:`Timeline`,map:`Map`,gallery:`Gallery`,gantt:`Gantt`,tree:`Tree`},ct={list:p,detail:y,grid:U,kanban:fe,calendar:d,timeline:re,map:te,gallery:ke,gantt:Y,tree:L},lt=Ge(`flex gap-4`,{variants:{position:{top:`flex-col`,bottom:`flex-col-reverse`,left:`flex-row`,right:`flex-row-reverse`}},defaultVariants:{position:`top`}}),ut=Ge(`w-full`,{variants:{orientation:{horizontal:`w-full`,vertical:`w-48`}},defaultVariants:{orientation:`horizontal`}}),dt=Ge(`flex gap-2`,{variants:{orientation:{horizontal:`flex-row flex-wrap`,vertical:`flex-col`}},defaultVariants:{orientation:`horizontal`}}),ft=Ge(``,{variants:{orientation:{horizontal:``,vertical:`flex h-auto flex-col items-stretch`}},defaultVariants:{orientation:`horizontal`}});function pt(e){return e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}var mt={Home:`House`};function ht(e){if(!e)return null;let t=pt(e);return h[mt[t]||t]||null}function gt(e){return e.label?e.label:st[e.type]||e.type}function _t(e){return e.icon?ht(e.icon):ct[e.type]||null}function vt(e){return e.activeView?e.activeView:e.defaultView?e.defaultView:e.views?.[0]?.type}var yt={share:ze,settings:ce,duplicate:ye,delete:Me},bt={share:`Share`,settings:`Settings`,duplicate:`Duplicate`,delete:`Delete`},xt=({schema:e,className:t,onViewChange:n,onCreateView:r,onViewAction:i,createViewLabel:o=`Create view`,...s})=>{let c=Q.useMemo(()=>e.storageKey?e.storageKey:`view-switcher${e.id?`-${e.id}`:``}`,[e.id,e.storageKey]),[l,u]=Q.useState(()=>vt(e));Q.useEffect(()=>{if(e.activeView){u(e.activeView);return}if(e.persistPreference)try{let t=localStorage.getItem(c);if(t){let n=e.views.find(e=>e.type===t)?.type;n&&u(n)}}catch{}},[e.activeView,e.persistPreference,e.views,c]),Q.useEffect(()=>{if(!(!e.persistPreference||!l||e.activeView))try{localStorage.setItem(c,l)}catch{}},[l,e.activeView,e.persistPreference,c]);let d=Q.useCallback(t=>{n?.(t),e.onViewChange&&typeof window<`u`&&window.dispatchEvent(new CustomEvent(e.onViewChange,{detail:{view:t}}))},[n,e.onViewChange]),f=Q.useCallback(e=>{u(e),d(e)},[d]),p=l||e.views?.[0]?.type,m=p||``,h=e.views.find(e=>e.type===p)||e.views?.[0],g=e.variant||`tabs`,_=e.position||`top`,v=_===`left`||_===`right`,y=v?`vertical`:`horizontal`,b=e.viewActions&&e.viewActions.length>0?(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:e.viewActions.map((e,t)=>{let n=e.icon&&ht(e.icon)||yt[e.type];return(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>i?.(e.type,p),title:bt[e.type]||e.type,children:n?(0,$.jsx)(n,{className:`h-3.5 w-3.5`}):null},`action-${e.type}-${t}`)})}):null,x=e.allowCreateView?(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>r?.(),title:o,children:(0,$.jsx)(pe,{className:`h-3.5 w-3.5`})}):null,S=(0,$.jsxs)(`div`,{className:q(ut({orientation:y}),`flex items-center gap-1`),children:[g===`dropdown`&&(0,$.jsxs)(O,{value:m,onValueChange:e=>f(e),children:[(0,$.jsx)(B,{className:q(`w-full`,v?`h-10`:`h-9`),children:(0,$.jsx)(R,{placeholder:`Select view`})}),(0,$.jsx)(Ne,{children:e.views.map((e,t)=>(0,$.jsx)(E,{value:e.type,children:gt(e)},`${e.type}-${t}`))})]}),g===`buttons`&&(0,$.jsx)(`div`,{className:q(dt({orientation:y})),children:e.views.map((e,t)=>{let n=e.type===p,r=_t(e);return(0,$.jsxs)(Z,{type:`button`,size:`sm`,variant:n?`secondary`:`ghost`,className:q(`justify-start gap-2`,v?`w-full`:``),onClick:()=>f(e.type),children:[r?(0,$.jsx)(r,{className:`h-4 w-4`}):null,(0,$.jsx)(`span`,{children:gt(e)})]},`${e.type}-${t}`)})}),g===`tabs`&&(0,$.jsx)(be,{value:m,onValueChange:e=>f(e),children:(0,$.jsx)(Fe,{className:q(ft({orientation:y})),children:e.views.map((e,t)=>{let n=_t(e);return(0,$.jsxs)(Se,{value:e.type,className:q(`gap-2`,v?`justify-start`:``),children:[n?(0,$.jsx)(n,{className:`h-4 w-4`}):null,(0,$.jsx)(`span`,{children:gt(e)})]},`${e.type}-${t}`)})})}),b,x]}),C=h?.schema?Array.isArray(h.schema)?(0,$.jsx)(`div`,{className:`space-y-4`,children:h.schema.map((e,t)=>(0,$.jsx)(a,{schema:e,...s},`${h.type}-${t}`))}):(0,$.jsx)(a,{schema:h.schema,...s}):null;return(0,$.jsxs)(`div`,{className:q(lt({position:_}),t),children:[(0,$.jsx)(`div`,{className:q(`shrink-0`,v?`flex flex-col`:`flex`),children:S}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:C})]})},St={sm:480,md:720,lg:960,xl:1200,full:1600};function Ct(e){let t=l(e);return t<=3?`sm`:t<=8?`md`:t<=15?`lg`:`xl`}function wt(e,t){return`min(92vw, ${St[!e||e===`auto`?Ct(t):e]}px)`}var Tt=a;function Et(){try{let{t:e}=o(),t=e(`console.objectView.new`);return t===`console.objectView.new`?`New`:t}catch{return`New`}}var Dt=({schema:e,dataSource:t,className:n,views:r,activeViewId:a,onViewChange:o,onRowClick:s,onEdit:l,renderListView:u,hideNamedViewTabs:d,toolbarAddon:f,onCreateView:p,onViewAction:h})=>{let g=Et(),[_,y]=(0,Q.useState)(null),b=(0,Q.useRef)(null);b.current=_;let[S,C]=(0,Q.useState)(!1),[w,E]=(0,Q.useState)(`create`),[D,O]=(0,Q.useState)(null),[k,ee]=(0,Q.useState)(0);(0,Q.useEffect)(()=>{if(!(!t?.onMutation||!e.objectName)&&!u)return t.onMutation(t=>{t.resource===e.objectName&&ee(e=>e+1)})},[t,e.objectName,u]);let[te,ne]=(0,Q.useState)([]),[re,ie]=(0,Q.useState)(!1),[A,ae]=(0,Q.useState)({}),[j,oe]=(0,Q.useState)([]),M=e.listViews,N=M!=null&&Object.keys(M).length>0,[P,ce]=(0,Q.useState)(()=>e.defaultListView&&M?.[e.defaultListView]?e.defaultListView:M&&Object.keys(M)[0]||``),F=(0,Q.useMemo)(()=>!N||!P?null:M[P]||null,[N,P,M]),L=(0,Q.useMemo)(()=>r&&r.length>0?r:null,[r]),R=L!=null&&L.length>0,fe=a||L?.[0]?.id,z=L?.find(e=>e.id===fe)||L?.[0],B=(0,Q.useMemo)(()=>F?.type?F.type:z?.type?z.type:e.defaultViewType||`grid`,[F,z,e.defaultViewType]),V=e.navigation;(0,Q.useEffect)(()=>{let n=!0;return e.objectName&&t&&(async()=>{try{let r=await t.getObjectSchema(e.objectName);n&&y(r)}catch(e){console.error(`Failed to fetch object schema:`,e)}})(),()=>{n=!1}},[e.objectName,t]),(0,Q.useEffect)(()=>{let n=!0;return(async()=>{if(!u&&B!==`grid`&&!(!t||!e.objectName)){ie(!0);try{let r=F?.filter||z?.filter||e.table?.defaultFilters||[],a=Object.entries(A).filter(([,e])=>e!==void 0&&e!==``&&e!==null).map(([e,t])=>[e,`=`,t]),o=[];o=r.length>0&&a.length>0?[`and`,...r,...a]:a.length===1?a[0]:a.length>1?[`and`,...a]:r;let s=j.length>0?j.map(e=>({field:e.field,order:e.direction})):F?.sort||z?.sort||e.table?.defaultSort||void 0,c=i(b.current?.fields),l=await t.find(e.objectName,{$filter:o.length>0?o:void 0,$orderby:s,$top:100,...c.length>0?{$expand:c}:{}}),u=[];Array.isArray(l)?u=l:l&&typeof l==`object`&&(Array.isArray(l.data)?u=l.data:Array.isArray(l.records)?u=l.records:Array.isArray(l.value)&&(u=l.value)),n&&ne(u)}catch(e){console.error(`ObjectView data fetch error:`,e)}finally{n&&ie(!1)}}})(),()=>{n=!1}},[e.objectName,t,B,A,j,k,F,z,u]);let me=We(),H=e.layout||c(_,{viewport:me?`mobile`:`desktop`}),U=e.operations||e.table?.operations||{create:!0,read:!0,update:!0,delete:!0},he=(0,Q.useCallback)(()=>{H===`page`&&e.onNavigate?e.onNavigate(`new`,`edit`):(E(`create`),O(null),C(!0))},[H,e]),W=(0,Q.useCallback)(t=>{if(l){l(t);return}if(H===`page`&&e.onNavigate){let n=t.id||t._id;e.onNavigate(n,`edit`)}else E(`edit`),O(t),C(!0)},[H,e,l]),ge=(0,Q.useCallback)(t=>{if(H===`page`&&e.onNavigate){let n=t.id||t._id;e.onNavigate(n,`view`)}else E(`view`),O(t),C(!0)},[H,e]),_e=(0,Q.useCallback)(t=>{if(s){s(t);return}if(V){if(V.mode===`none`||V.preventNavigation)return;if(V.mode===`new_window`||V.openNewTab){let n=t.id||t._id,r=`/${e.objectName}/${encodeURIComponent(String(n))}`;window.open(r,`_blank`);return}if(V.mode===`drawer`){E(`view`),O(t),C(!0);return}if(V.mode===`modal`){E(`view`),O(t),C(!0);return}if(V.mode===`page`){let n=t.id||t._id;e.onNavigate&&e.onNavigate(n,`view`);return}if(V.mode===`split`||V.mode===`popover`){E(`view`),O(t),C(!0);return}}U.read!==!1&&ge(t)},[s,V,U.read,ge,e]),ve=(0,Q.useCallback)(e=>{ee(e=>e+1)},[]),ye=(0,Q.useCallback)(e=>{ee(e=>e+1)},[]),xe=(0,Q.useCallback)(()=>{C(!1),O(null),ee(e=>e+1)},[]),G=(0,Q.useCallback)(()=>{C(!1),O(null)},[]);(0,Q.useCallback)(()=>{ee(e=>e+1)},[]);let Ce=(0,Q.useMemo)(()=>!R||!L||L.length<=1?null:{type:`view-switcher`,variant:`tabs`,position:`top`,persistPreference:!0,storageKey:`view-pref-${e.objectName}`,defaultView:z?.type||`grid`,activeView:z?.type||`grid`,views:L.map(e=>({type:e.type,label:e.label,icon:{kanban:`kanban`,calendar:`calendar`,map:`map`,gallery:`layout-grid`,timeline:`activity`,gantt:`gantt-chart`,grid:`table`,list:`list`,detail:`file-text`,chart:`bar-chart-3`}[e.type]||`table`})),allowCreateView:e.allowCreateView,viewActions:e.viewActions},[R,L,z,e.objectName,e.allowCreateView,e.viewActions]),K=(0,Q.useCallback)(e=>{if(!L)return;let t=L.find(t=>t.type===e);t&&o&&o(t.id)},[L,o]),we=(0,Q.useCallback)(e=>{ce(e)},[]);(0,Q.useMemo)(()=>{if(e.showFilters===!1)return null;let t=e.filterableFields,n=_?.fields||{},r=(t?t.map(e=>[e,n[e]||{label:e}]):Object.entries(n).filter(([,e])=>!e.hidden).slice(0,8)).map(([e,t])=>{let n=t.type||`text`,r=`text`,i;return n===`number`||n===`currency`||n===`percent`?r=`number`:n===`boolean`||n===`toggle`?r=`boolean`:n===`date`||n===`datetime`?r=`date`:n===`select`||n===`status`||t.options?(r=`select`,i=(t.options||[]).map(e=>typeof e==`string`?{label:e,value:e}:{label:e.label,value:e.value})):(n===`lookup`||n===`master_detail`||n===`user`||n===`owner`)&&t.options&&t.options.length>0&&(r=`multi-select`,i=(t.options||[]).map(e=>typeof e==`string`?{label:e,value:e}:{label:e.label,value:e.value})),{field:e,label:t.label||e,type:r,placeholder:`Filter ${t.label||e}...`,...i?{options:i}:{}}});return r.length===0?null:{type:`filter-ui`,layout:`popover`,showClear:!0,showApply:!0,filters:r,values:A}},[e.showFilters,e.filterableFields,_,A]);let Te=e.showSort;(0,Q.useMemo)(()=>{if(Te===!1)return null;let e=_?.fields||{},t=Object.entries(e).filter(([,e])=>!e.hidden).slice(0,10).map(([e,t])=>({field:e,label:t.label||e}));return t.length===0?null:{type:`sort-ui`,variant:`dropdown`,multiple:!1,fields:t,sort:j}},[_,j,Te]);let Ee=(0,Q.useCallback)(t=>{let n={objectName:e.objectName,fields:F?.columns||z?.columns||e.table?.fields,className:`h-full w-full`,showSearch:z?.showSearch??e.showSearch??!1,showSort:z?.showSort??e.showSort??!1,showFilters:z?.showFilters??e.showFilters??!1,striped:z?.striped??!1,bordered:z?.bordered??!1,color:z?.color},r=F?.options||z||{};switch(t){case`kanban`:{let e=r.kanban||{},t=e.groupByField||e.groupField||`status`,i=(Array.isArray(e.columns)&&e.columns.length>0?e.columns:n.fields)||[],{columns:a,groupByField:o,groupField:s,titleField:c,...l}=e;return{type:`object-kanban`,...n,groupBy:t,groupField:t,titleField:e.titleField||`name`,cardFields:i,...l}}case`calendar`:return{type:`object-calendar`,...n,startDateField:r.calendar?.startDateField||`start_date`,endDateField:r.calendar?.endDateField||`end_date`,titleField:r.calendar?.titleField||`name`,...r.calendar||{}};case`gallery`:return{type:`object-gallery`,...n,imageField:r.gallery?.imageField,titleField:r.gallery?.titleField||`name`,subtitleField:r.gallery?.subtitleField,...r.gallery||{}};case`timeline`:return{type:`object-timeline`,...n,dateField:r.timeline?.dateField||`created_at`,titleField:r.timeline?.titleField||`name`,...r.timeline||{}};case`gantt`:return{type:`object-gantt`,...n,startDateField:r.gantt?.startDateField||`start_date`,endDateField:r.gantt?.endDateField||`end_date`,progressField:r.gantt?.progressField||`progress`,dependenciesField:r.gantt?.dependenciesField||`dependencies`,...r.gantt||{}};case`map`:return{type:`object-map`,...n,locationField:r.map?.locationField||`location`,...r.map||{}};case`tree`:return{type:`object-tree`,...n,parentField:r.tree?.parentField,labelField:r.tree?.labelField||r.tree?.titleField||`name`,fields:r.tree?.fields||n.fields,defaultExpandedDepth:r.tree?.defaultExpandedDepth,...r.tree||{}};case`chart`:{let t=r.chart||{};if(t.dataset){let e=Array.isArray(t.dimensions)?t.dimensions:[],n=Array.isArray(t.values)?t.values:[];return{type:`object-chart`,dataset:t.dataset,dimensions:e,values:n,chartType:t.chartType||`bar`,xAxisKey:e[0],series:n.map(e=>({dataKey:e,label:e})),className:`h-[400px] w-full`}}let n=Array.isArray(t.yAxisFields)&&t.yAxisFields[0]||t.valueField||`value`,i=t.xAxisField||t.categoryField||`name`;return{type:`object-chart`,objectName:e.objectName,chartType:t.chartType||`bar`,aggregate:{field:n,function:t.aggregation||`count`,groupBy:i},xAxisKey:i,series:[{dataKey:n,label:n}],className:`h-[400px] w-full`}}default:return null}},[e.objectName,e.table?.fields,F,z]),J=(0,Q.useMemo)(()=>({type:`object-grid`,objectName:e.objectName,title:e.table?.title,description:e.table?.description,fields:F?.columns||z?.columns||e.table?.fields,columns:F?.columns||z?.columns||e.table?.columns,operations:{...U,create:!1},defaultFilters:F?.filter||z?.filter||e.table?.defaultFilters,defaultSort:F?.sort||z?.sort||e.table?.defaultSort,pageSize:e.table?.pageSize,selectable:e.table?.selectable,striped:z?.striped??e.table?.striped,bordered:z?.bordered??e.table?.bordered,className:e.table?.className}),[e,U,F,z]),Y=()=>{let t=D?D.id||D._id:void 0;return{type:`object-form`,objectName:e.objectName,mode:w,recordId:t,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||w===`view`,className:e.form?.className,subforms:e.form?.subforms,onSuccess:xe,onCancel:G}},De=()=>{if(e.form?.title)return e.form.title;let t=_?.label||e.objectName;switch(w){case`create`:return`Create ${t}`;case`edit`:return`Edit ${t}`;case`view`:return`View ${t}`;default:return t}},Oe=(0,Q.useMemo)(()=>{let e=V?.width;return e?typeof e==`number`?`max-w-[${e}px]`:`max-w-[${e}]`:``},[V]),ke=()=>(0,$.jsx)(se,{open:S,onOpenChange:C,direction:`right`,children:(0,$.jsxs)(m,{className:q(`w-full sm:max-w-2xl`,Oe),children:[(0,$.jsxs)(le,{children:[(0,$.jsx)(v,{children:De()}),e.form?.description&&(0,$.jsx)(Be,{children:e.form.description})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto px-4 pb-4`,children:(0,$.jsx)(Ke,{schema:Y(),dataSource:t})})]})}),Ae=()=>(0,$.jsx)(ue,{open:S,onOpenChange:C,children:(0,$.jsxs)(de,{className:q(`max-w-2xl max-h-[90vh] overflow-y-auto`,Oe),children:[(0,$.jsxs)(je,{children:[(0,$.jsx)(T,{children:De()}),e.form?.description&&(0,$.jsx)(x,{children:e.form.description})]}),(0,$.jsx)(Ke,{schema:Y(),dataSource:t})]})}),Me=(0,Q.useMemo)(()=>Object.keys(A).some(e=>A[e]!==void 0&&A[e]!==``&&A[e]!==null)?Object.entries(A).filter(([,e])=>e!==void 0&&e!==``&&e!==null).map(([e,t])=>({field:e,operator:`equals`,value:t})):F?.filter||z?.filter||e.table?.defaultFilters,[A,F,z,e.table?.defaultFilters]),Ne=(0,Q.useMemo)(()=>j.length>0?j:F?.sort||z?.sort||e.table?.defaultSort,[j,F,z,e.table?.defaultSort]),Pe=()=>{let n=`${e.objectName}-${P||z?.id||`default`}-${B}-${k}`;if(u)return u({schema:{type:`list-view`,objectName:e.objectName,viewType:B,fields:F?.columns||z?.columns||e.table?.fields,filters:Me,sort:Ne,rowHeight:z?.rowHeight,densityMode:z?.densityMode,groupBy:z?.groupBy,groupBy2:z?.groupBy2,grouping:z?.grouping,options:F?.options||z,showSearch:z?.showSearch??e.showSearch,showFilters:z?.showFilters??e.showFilters,showSort:z?.showSort??e.showSort,showHideFields:z?.showHideFields??e.showHideFields,showGroup:z?.showGroup??e.showGroup,showColor:z?.showColor??e.showColor,showDensity:z?.showDensity??e.showDensity,compactToolbar:z?.compactToolbar??e.compactToolbar,allowExport:z?.allowExport??e.allowExport,striped:z?.striped??e.striped,bordered:z?.bordered??e.bordered,color:z?.color??e.color,inlineEdit:z?.inlineEdit??e.inlineEdit,wrapHeaders:z?.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:z?.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:z?.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:z?.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:z?.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:z?.fieldTextColor??e.fieldTextColor,prefixField:z?.prefixField??e.prefixField,showDescription:z?.showDescription??e.showDescription,navigation:z?.navigation??e.navigation,selection:z?.selection??e.selection,pagination:z?.pagination??e.pagination,searchableFields:z?.searchableFields??e.searchableFields,filterableFields:z?.filterableFields??e.filterableFields,resizable:z?.resizable??e.resizable,hiddenFields:z?.hiddenFields??e.hiddenFields,rowActions:z?.rowActions??e.rowActions,rowActionDefs:z?.rowActionDefs??e.rowActionDefs,bulkActions:z?.bulkActions??e.bulkActions,sharing:z?.sharing??e.sharing,addRecord:z?.addRecord??e.addRecord,conditionalFormatting:z?.conditionalFormatting??e.conditionalFormatting,userFilters:z?.userFilters??e.userFilters,showRecordCount:z?.showRecordCount??e.showRecordCount,allowPrinting:z?.allowPrinting??e.allowPrinting,virtualScroll:z?.virtualScroll??e.virtualScroll,emptyState:z?.emptyState??e.emptyState,aria:z?.aria??e.aria,refreshTrigger:k},dataSource:t,onEdit:W,onRowClick:_e,className:`h-full`,refreshKey:k,onAddRecord:he});if(B!==`grid`){let e=Ee(B);if(e&&Tt)return(0,$.jsx)(Tt,{schema:e,dataSource:t,data:te,loading:re},n);if(!Tt)return(0,$.jsx)(`div`,{className:`flex items-center justify-center h-40 text-muted-foreground`,children:(0,$.jsxs)(`p`,{children:[`SchemaRenderer not available. Install @object-ui/react to render `,B,` views.`]})})}return(0,$.jsx)(ot,{schema:J,dataSource:t,onRowClick:_e,onEdit:U.update===!1?void 0:W,onDelete:U.delete===!1?void 0:ve,onBulkDelete:U.delete===!1?void 0:ye},n)},X=()=>{if(d||!N)return null;let e=Object.entries(M);return e.length<=1?null:(0,$.jsx)(be,{value:P,onValueChange:we,className:`w-full`,children:(0,$.jsx)(Fe,{className:`w-auto`,children:e.map(([e,t])=>(0,$.jsx)(Se,{value:e,className:`text-sm`,children:t.label||e},e))})})},Ie=()=>{let t=e.showCreate!==!1&&U.create!==!1,n=e.showViewSwitcher===!0,r=X();return!r&&!n&&!t&&!f?null:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[r,(n||t||f)&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:n&&Ce&&(0,$.jsx)(xt,{schema:Ce,onViewChange:K,onCreateView:p,onViewAction:h,className:`overflow-x-auto`})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[f,t&&(0,$.jsxs)(Z,{size:`sm`,onClick:he,children:[(0,$.jsx)(pe,{className:`h-4 w-4`}),g]})]})]})]})},Le=V?.mode===`modal`?`modal`:V?.mode===`drawer`?`drawer`:V?.mode===`split`?`split`:V?.mode===`popover`?`popover`:H,Re=e=>(0,$.jsx)(`div`,{className:`space-y-3`,children:(0,$.jsx)(Ke,{schema:Y(),dataSource:t})}),ze=(0,Q.useCallback)(e=>{e||G()},[G]),Ve=Ie();if(Le===`split`){let t=_?.label||e.objectName;return(0,$.jsxs)(`div`,{className:q(`flex flex-col h-full min-w-0 overflow-hidden`,n),children:[(e.title||e.description)&&(0,$.jsxs)(`div`,{className:`mb-4 shrink-0`,children:[e.title&&(0,$.jsx)(`h2`,{className:`text-2xl font-bold tracking-tight`,children:e.title}),e.description&&(0,$.jsx)(`p`,{className:`text-muted-foreground mt-1`,children:e.description})]}),Ve&&(0,$.jsx)(`div`,{className:`mb-4 shrink-0`,children:Ve}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:S&&D?(0,$.jsx)(I,{isOpen:S,selectedRecord:D,mode:`split`,close:G,setIsOpen:ze,width:V?.width,isOverlay:!0,title:`${t} Detail`,mainContent:(0,$.jsx)(`div`,{className:`h-full overflow-auto`,children:Pe()}),children:Re}):Pe()})]})}return(0,$.jsxs)(`div`,{className:q(`flex flex-col h-full min-w-0 overflow-hidden`,n),children:[(e.title||e.description)&&(0,$.jsxs)(`div`,{className:`mb-4 shrink-0`,children:[e.title&&(0,$.jsx)(`h2`,{className:`text-2xl font-bold tracking-tight`,children:e.title}),e.description&&(0,$.jsx)(`p`,{className:`text-muted-foreground mt-1`,children:e.description})]}),Ve&&(0,$.jsx)(`div`,{className:`mb-4 shrink-0`,children:Ve}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:Pe()}),Le===`drawer`&&ke(),Le===`modal`&&Ae(),Le===`popover`&&S&&D&&(0,$.jsx)(I,{isOpen:S,selectedRecord:D,mode:`popover`,close:G,setIsOpen:ze,width:V?.width,isOverlay:!0,title:De(),children:Re})]})},Ot=Ge(`flex`,{variants:{layout:{inline:`flex-col space-y-4`,popover:`items-center`,drawer:`items-center`}},defaultVariants:{layout:`inline`}}),kt=e=>e==null||e===``?!0:Array.isArray(e)?e.length===0:typeof e==`object`?Object.values(e).every(e=>e==null||e===``):!1,At=e=>Array.isArray(e)?{start:e[0]||``,end:e[1]||``}:e&&typeof e==`object`?{start:e.start||``,end:e.end||``}:{start:``,end:``},jt=({schema:e,className:t,onChange:n})=>{let[r,i]=Q.useState(e.values||{}),[a,o]=Q.useState(!1);Q.useEffect(()=>{e.values&&i(e.values)},[e.values]);let s=Q.useCallback(t=>{n?.(t),e.onChange&&typeof window<`u`&&window.dispatchEvent(new CustomEvent(e.onChange,{detail:{values:t}}))},[n,e.onChange]),c=Q.useCallback((t,n)=>{let a={...r,[t]:n};i(a),e.showApply||s(a)},[s,e.showApply,r]),l=Q.useCallback(()=>{let t={};if(i(t),e.showApply){s(t);return}s(t)},[s,e.showApply]),u=Q.useCallback(()=>{s(r),o(!1)},[s,r]),d=Q.useMemo(()=>Object.values(r).filter(e=>!kt(e)).length,[r]),f=e=>{let t=e.label||e.field,n=e.placeholder||`Filter by ${t}`;switch(e.type){case`number`:return(0,$.jsx)(X,{type:`number`,value:r[e.field]??``,placeholder:n,onChange:t=>{let n=t.target.value,r=n===``?``:Number(n);c(e.field,r)}});case`select`:return(0,$.jsxs)(O,{value:r[e.field]===void 0?``:String(r[e.field]),onValueChange:t=>{let n=e.options?.find(e=>String(e.value)===t);c(e.field,n?n.value:t)},children:[(0,$.jsx)(B,{children:(0,$.jsx)(R,{placeholder:n})}),(0,$.jsx)(Ne,{children:e.options?.map(e=>(0,$.jsx)(E,{value:String(e.value),children:e.label},String(e.value)))})]});case`multi-select`:{let t=r[e.field],n=Array.isArray(t)?t:t?[t]:[];return(0,$.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-0.5 border rounded-md p-2`,children:e.options?.map(t=>{let r=n.map(String).includes(String(t.value));return(0,$.jsxs)(`label`,{className:q(`flex items-center gap-2 text-sm py-1 px-1.5 rounded cursor-pointer`,r?`bg-primary/5 text-primary`:`hover:bg-muted`),children:[(0,$.jsx)(N,{checked:r,onCheckedChange:r=>{let i=r?[...n,t.value]:n.filter(e=>String(e)!==String(t.value));c(e.field,i)}}),(0,$.jsx)(`span`,{className:`truncate`,children:t.label})]},String(t.value))})})}case`date`:return(0,$.jsx)(X,{type:`date`,value:r[e.field]??``,onChange:t=>c(e.field,t.target.value)});case`date-range`:{let t=At(r[e.field]);return(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{type:`date`,value:t.start??``,onChange:n=>{c(e.field,{...t,start:n.target.value})}}),(0,$.jsx)(X,{type:`date`,value:t.end??``,onChange:n=>{c(e.field,{...t,end:n.target.value})}})]})}case`boolean`:return(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(N,{checked:!!r[e.field],onCheckedChange:t=>c(e.field,!!t)}),(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Enabled`})]});default:return(0,$.jsx)(X,{value:r[e.field]??``,placeholder:n,onChange:t=>c(e.field,t.target.value)})}},p=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:e.filters.map(e=>(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(xe,{className:`text-xs text-muted-foreground`,children:e.label||e.field}),f(e)]},e.field))}),(e.showApply||e.showClear)&&(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t pt-3`,children:[e.showClear&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:l,children:`Clear`}),e.showApply&&(0,$.jsx)(Z,{type:`button`,size:`sm`,onClick:u,children:`Apply`})]})]}),h=e.layout||`inline`;return h===`popover`?(0,$.jsx)(`div`,{className:q(Ot({layout:h}),t),children:(0,$.jsxs)(we,{open:a,onOpenChange:o,children:[(0,$.jsx)(Oe,{asChild:!0,children:(0,$.jsxs)(Z,{type:`button`,variant:d>0?`secondary`:`outline`,size:`sm`,className:`gap-2`,children:[(0,$.jsx)(me,{className:`h-4 w-4`}),`Filters`,d>0&&(0,$.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:d})]})}),(0,$.jsx)(he,{align:`start`,className:`w-[520px] p-4`,children:p})]})}):h===`drawer`?(0,$.jsxs)(`div`,{className:q(Ot({layout:h}),t),children:[(0,$.jsxs)(Z,{type:`button`,variant:d>0?`secondary`:`outline`,size:`sm`,className:`gap-2`,onClick:()=>o(!0),children:[(0,$.jsx)(me,{className:`h-4 w-4`}),`Filters`,d>0&&(0,$.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:d})]}),(0,$.jsx)(se,{open:a,onOpenChange:o,children:(0,$.jsxs)(m,{children:[(0,$.jsxs)(le,{children:[(0,$.jsx)(v,{children:`Filters`}),(0,$.jsx)(Be,{children:`Refine the data with advanced filters.`})]}),(0,$.jsx)(`div`,{className:`px-4 pb-6`,children:p})]})})]}):(0,$.jsxs)(`div`,{className:q(Ot({layout:h}),t),children:[p,!e.showApply&&e.showClear&&(0,$.jsxs)(Z,{type:`button`,variant:`ghost`,size:`sm`,className:`gap-2`,onClick:l,children:[(0,$.jsx)(ae,{className:`h-3.5 w-3.5`}),`Clear filters`]})]})},Mt=Ge(``,{variants:{variant:{buttons:`flex flex-wrap gap-2`,dropdown:`flex flex-wrap items-center gap-3`,builder:`space-y-3`}},defaultVariants:{variant:`dropdown`}}),Nt=e=>e?e.map(e=>({field:e.field,direction:e.direction})):[],Pt=e=>e.map(e=>({id:`${e.field}-${e.direction}`,field:e.field,order:e.direction})),Ft=e=>e.filter(e=>e.field).map(e=>({field:e.field,direction:e.order})),It=({schema:e,className:t,onChange:n})=>{let[r,i]=Q.useState(()=>Nt(e.sort)),[a,o]=Q.useState(()=>Pt(Nt(e.sort)));Q.useEffect(()=>{let t=Nt(e.sort);i(t),o(Pt(t))},[e.sort]);let s=Q.useCallback(t=>{i(t),n?.(t),e.onChange&&typeof window<`u`&&window.dispatchEvent(new CustomEvent(e.onChange,{detail:{sort:t}}))},[n,e.onChange]),c=Q.useCallback(t=>{let n=r.find(e=>e.field===t),i=!!e.multiple;if(!n){let e=i?[...r,{field:t,direction:`asc`}]:[{field:t,direction:`asc`}];s(e);return}if(n.direction===`asc`){let e=r.map(e=>e.field===t?{...e,direction:`desc`}:e);s(e);return}let a=r.filter(e=>e.field!==t);s(a)},[s,e.multiple,r]);if((e.variant||`dropdown`)===`buttons`)return(0,$.jsx)(`div`,{className:q(Mt({variant:`buttons`}),t),children:e.fields.map(e=>{let t=r.find(t=>t.field===e.field);return(0,$.jsxs)(Z,{type:`button`,variant:t?`secondary`:`outline`,size:`sm`,onClick:()=>c(e.field),className:`gap-2`,children:[(0,$.jsx)(`span`,{children:e.label||e.field}),t&&(0,$.jsx)(Ie,{className:q(`h-3.5 w-3.5 motion-safe:transition-transform motion-safe:duration-200`,t.direction===`desc`&&`rotate-180`),"aria-label":t.direction===`asc`?`ascending`:`descending`})]},e.field)})});if(e.multiple)return(0,$.jsx)(`div`,{className:q(Mt({variant:`builder`}),t),children:(0,$.jsx)(V,{fields:e.fields.map(e=>({value:e.field,label:e.label||e.field})),value:a,onChange:e=>{o(e),s(Ft(e))}})});let l=r[0];return(0,$.jsxs)(`div`,{className:q(Mt({variant:`dropdown`}),t),children:[(0,$.jsxs)(O,{value:l?.field||``,onValueChange:e=>{if(!e){s([]);return}s([{field:e,direction:l?.direction||`asc`}])},children:[(0,$.jsx)(B,{className:`w-56`,children:(0,$.jsx)(R,{placeholder:`Select field`})}),(0,$.jsx)(Ne,{children:e.fields.map(e=>(0,$.jsx)(E,{value:e.field,children:e.label||e.field},e.field))})]}),(0,$.jsxs)(O,{value:l?.direction||`asc`,onValueChange:e=>{l?.field&&s([{field:l.field,direction:e}])},children:[(0,$.jsx)(B,{className:`w-36`,children:(0,$.jsx)(R,{})}),(0,$.jsxs)(Ne,{children:[(0,$.jsx)(E,{value:`asc`,children:`Ascending`}),(0,$.jsx)(E,{value:`desc`,children:`Descending`})]})]})]})};function Lt(){if(typeof crypto<`u`&&typeof crypto.randomUUID==`function`)return crypto.randomUUID();if(typeof crypto<`u`&&typeof crypto.getRandomValues==`function`){let e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}function Rt(e,t,n,r){return`${e}/share/${t}/${n}?mode=readonly&token=${r}`}var zt=({objectName:e,viewId:t=`default`,baseUrl:n,onShare:r,className:i})=>{let[a,o]=Q.useState(null),[s,c]=Q.useState(!1),[l,u]=Q.useState(!1),[f,p]=Q.useState(``),[m,h]=Q.useState(``),g=n??(typeof window<`u`?window.location.origin:``),_=Q.useCallback(()=>{let n=Lt(),i=Rt(g,e,t,n);o(i),c(!1);let a=m?new Date(Date.now()+parseInt(m,10)*864e5).toISOString():void 0;r?.(i,{password:f||void 0,expiresAt:a})},[g,e,t,r,f,m]),v=Q.useCallback(async()=>{if(a)try{await navigator.clipboard.writeText(a),c(!0),setTimeout(()=>c(!1),2e3)}catch{let e=document.createElement(`textarea`);e.value=a,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e),c(!0),setTimeout(()=>c(!1),2e3)}},[a]);return(0,$.jsxs)(we,{open:l,onOpenChange:u,children:[(0,$.jsx)(Oe,{asChild:!0,children:(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,className:q(`gap-2`,i),children:[(0,$.jsx)(ze,{className:`h-4 w-4`}),`Share`]})}),(0,$.jsxs)(he,{className:`w-96 space-y-4`,align:`end`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium`,children:`Share View`}),(0,$.jsx)(W,{variant:`secondary`,className:`text-xs`,children:`Read-only`})]}),(0,$.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?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{value:a,readOnly:!0,className:`h-8 text-xs`,onClick:e=>e.target.select()}),(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:v,className:`shrink-0 gap-1`,children:s?(0,$.jsx)(F,{className:`h-4 w-4 text-green-500`}):(0,$.jsx)(ye,{className:`h-4 w-4`})})]}),(f||m)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[f&&(0,$.jsxs)(W,{variant:`outline`,className:`text-xs gap-1`,children:[(0,$.jsx)(P,{className:`h-3 w-3`}),`Password protected`]}),m&&(0,$.jsxs)(W,{variant:`outline`,className:`text-xs gap-1`,children:[(0,$.jsx)(d,{className:`h-3 w-3`}),`Expires in `,m,` day`,m===`1`?``:`s`]})]})]}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs font-medium text-foreground`,children:[(0,$.jsx)(P,{className:`h-3.5 w-3.5`}),`Password protection (optional)`]}),(0,$.jsx)(X,{type:`password`,value:f,onChange:e=>p(e.target.value),placeholder:`Enter password...`,className:`h-8 text-xs`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs font-medium text-foreground`,children:[(0,$.jsx)(d,{className:`h-3.5 w-3.5`}),`Expires after (optional)`]}),(0,$.jsxs)(`select`,{value:m,onChange:e=>h(e.target.value),className:`w-full h-8 text-xs rounded-md border border-input bg-background px-3`,children:[(0,$.jsx)(`option`,{value:``,children:`Never`}),(0,$.jsx)(`option`,{value:`1`,children:`1 day`}),(0,$.jsx)(`option`,{value:`7`,children:`7 days`}),(0,$.jsx)(`option`,{value:`30`,children:`30 days`}),(0,$.jsx)(`option`,{value:`90`,children:`90 days`})]})]}),(0,$.jsxs)(Z,{onClick:_,className:`w-full gap-2`,size:`sm`,children:[(0,$.jsx)(ze,{className:`h-4 w-4`}),`Generate Link`]})]})]})]})};function Bt(){try{let{t:e}=o();return(t,n,r)=>{let i=e(t,r);return!i||i===t?n:i}}catch{return(e,t)=>t}}var Vt={private:0,team:1,organization:2,public:3},Ht=8,Ut=({id:e,disabled:t,children:n})=>{let{attributes:r,listeners:i,setNodeRef:a,transform:o,transition:s,isDragging:c}=Qe({id:e,disabled:t,attributes:{role:`tab`,roleDescription:`view tab`,tabIndex:0}});return(0,$.jsx)($.Fragment,{children:n({setNodeRef:a,style:{transform:at.Transform.toString(o),transition:s,zIndex:c?10:void 0,opacity:c?.5:void 0},listeners:i,attributes:r,isDragging:c})})},Wt=({views:e,activeViewId:t,onViewChange:n,viewTypeIcons:r={},config:i={},onAddView:a,onRenameView:o,onDuplicateView:s,onDeleteView:c,onSetDefaultView:l,onShareView:d,onSaveAsView:p,onPinView:m,onReorderViews:h,onChangeViewType:v,onConfigView:y,onManageViews:x,availableViewTypes:T,hasUnsavedChanges:E=!1,onResetChanges:D,className:O})=>{let{showAddButton:te=!0,inlineRename:re=!0,contextMenu:ie=!0,reorderable:ae=!1,maxVisibleTabs:N=4,showIndicators:se=!0,showSaveAsView:ce=!0,showPinnedSection:le=!0,showVisibilityGroups:ue=!1}=i,F=Bt(),[I,L]=(0,Q.useState)(null),[de,R]=(0,Q.useState)(``),B=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{I&&B.current&&(B.current.focus(),B.current.select())},[I]);let V=(0,Q.useCallback)(t=>{if(!re||!o)return;let n=e.find(e=>e.id===t);n&&(n.readonly||(L(t),R(n.label)))},[re,o,e]),me=(0,Q.useCallback)(()=>{I&&de.trim()&&o&&o(I,de.trim()),L(null),R(``)},[I,de,o]),U=(0,Q.useCallback)(()=>{L(null),R(``)},[]),he=(0,Q.useMemo)(()=>e.length>0&&e.every(e=>!!e.readonly),[e]),W=(0,Q.useMemo)(()=>{let t=[...e];return t.sort((e,t)=>{if(le){let n=+!!e.isPinned,r=+!!t.isPinned;if(n!==r)return r-n}if(ue){let n=Vt[e.visibility||`public`]??Vt.public,r=Vt[t.visibility||`public`]??Vt.public;if(n!==r)return n-r}return 0}),t},[e,le,ue]),{visibleViews:be,overflowViews:xe}=(0,Q.useMemo)(()=>{let e=W.slice(0,N),n=W.slice(N),r=n.findIndex(e=>e.id===t);if(r===-1)return{visibleViews:e,overflowViews:n};let i=n[r],a=e.length>0?[...e.slice(0,-1),i]:[i],o=e.length>0?e[e.length-1]:null,s=n.filter((e,t)=>t!==r);return o&&s.unshift(o),{visibleViews:a,overflowViews:s}},[W,N,t]),Se=it(qe(Xe,{activationConstraint:{distance:Ht}}),qe(rt)),we=(0,Q.useCallback)(e=>{let{active:t,over:n}=e;if(!n||t.id===n.id||!h)return;let r=W.findIndex(e=>e.id===t.id),i=W.findIndex(e=>e.id===n.id);r===-1||i===-1||h(Ze(W,r,i).map(e=>e.id))},[W,h]),Y=Pe,Oe=(0,Q.useCallback)(e=>{if(!ue||e===0)return!1;let t=be[e-1],n=be[e],r=e=>e.visibility===`private`;return r(t)&&!r(n)},[ue,be]),ke=(e,i)=>{let a=e.id===t,p=r[e.type]||Y,w=I===e.id,E=se&&(e.hasActiveFilters||e.hasActiveSort),D=Oe(i),O=!!e.readonly,te=(e=>ue?e.visibility===`private`?(0,$.jsx)(P,{"data-testid":`view-tab-visibility-${e.id}`,className:`h-3 w-3 text-muted-foreground shrink-0`}):e.visibility?(0,$.jsx)(Re,{"data-testid":`view-tab-visibility-${e.id}`,className:`h-3 w-3 text-muted-foreground shrink-0`}):null:null)(e),re=t=>(0,$.jsxs)(`div`,{"data-testid":`view-tab-${e.id}`,role:`tab`,tabIndex:0,"aria-selected":a,onClick:()=>!w&&n(e.id),onDoubleClick:()=>V(e.id),onKeyDown:t=>{!w&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e.id))},...t?.listeners??{},...t?.attributes??{},className:q(`group/tab inline-flex items-center gap-1.5 px-3 py-2 text-sm font-medium border-b-2 transition-colors whitespace-nowrap relative outline-none focus-visible:ring-2 focus-visible:ring-ring`,t?.isDragging?`cursor-grabbing`:`cursor-pointer`,a?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground hover:border-border`),children:[ae&&h&&(0,$.jsx)(`span`,{"data-testid":`view-tab-drag-handle-${e.id}`,"aria-hidden":`true`,className:q(`text-muted-foreground transition-opacity pointer-events-none`,`opacity-0 group-hover/tab:opacity-100`,t?.isDragging&&`opacity-100`),children:(0,$.jsx)(Ce,{className:`h-3 w-3`})}),le&&e.isPinned&&(0,$.jsx)(M,{"data-testid":`view-tab-pin-indicator-${e.id}`,className:`h-3 w-3 text-primary shrink-0`}),te,(0,$.jsx)(p,{className:`h-3.5 w-3.5`}),w?(0,$.jsx)(X,{ref:B,"data-testid":`view-tab-rename-input-${e.id}`,value:de,onChange:e=>R(e.target.value),onBlur:me,onKeyDown:e=>{e.key===`Enter`&&me(),e.key===`Escape`&&U()},className:`h-5 w-24 px-1 py-0 text-sm border-none focus-visible:ring-1`,onClick:e=>e.stopPropagation()}):(0,$.jsx)(`span`,{children:e.label}),O&&!he&&(0,$.jsxs)(oe,{children:[(0,$.jsx)(k,{asChild:!0,children:(0,$.jsx)(P,{"data-testid":`view-tab-readonly-${e.id}`,"aria-label":F(`view.readonlyAriaLabel`,`Read-only view`),className:`h-3 w-3 text-muted-foreground shrink-0`})}),(0,$.jsx)(b,{side:`bottom`,className:`text-xs`,children:e.readonlyReason||F(`view.readonlyTooltip`,`System view — defined in code, read-only.`)})]}),E&&(0,$.jsxs)(oe,{children:[(0,$.jsx)(k,{asChild:!0,children:(0,$.jsxs)(`span`,{"data-testid":`view-tab-indicator-${e.id}`,className:`ml-1 inline-flex items-center gap-0.5 h-4 px-1 rounded-full bg-primary/10 text-primary shrink-0`,children:[e.hasActiveFilters&&(0,$.jsx)(Ve,{className:`h-2.5 w-2.5`}),e.hasActiveSort&&(0,$.jsx)(ge,{className:`h-2.5 w-2.5`})]})}),(0,$.jsx)(b,{side:`bottom`,className:`text-xs`,children:[e.hasActiveFilters&&`Active filters`,e.hasActiveSort&&`Active sort`].filter(Boolean).join(`, `)})]}),e.isDefault&&(0,$.jsx)(ve,{className:`h-3 w-3 text-amber-500 fill-amber-500 shrink-0`}),a&&(y||o||s||c)&&(0,$.jsxs)(G,{children:[(0,$.jsx)(He,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"data-testid":`view-tab-actions-${e.id}`,className:`ml-0.5 h-4 w-4 flex items-center justify-center rounded hover:bg-accent shrink-0 opacity-70 hover:opacity-100 transition-opacity`,onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),"aria-label":F(`view.tabActionsFor`,`View actions for ${e.label}`,{name:e.label}),children:(0,$.jsx)(C,{className:`h-3 w-3`})})}),(0,$.jsxs)(Ae,{align:`start`,className:`min-w-[180px]`,onClick:e=>e.stopPropagation(),children:[y&&!O&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-config-${e.id}`,onClick:()=>y(e.id),children:[(0,$.jsx)(_,{className:`h-4 w-4 mr-2`}),` `,F(`view.editViewConfig`,`Edit view config`)]}),o&&!O&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-rename-${e.id}`,onClick:()=>V(e.id),children:[(0,$.jsx)(De,{className:`h-4 w-4 mr-2`}),` `,F(`view.rename`,`Rename`)]}),s&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-duplicate-${e.id}`,onClick:()=>s(e.id),children:[(0,$.jsx)(ye,{className:`h-4 w-4 mr-2`}),` `,F(`view.duplicateView`,`Duplicate view`)]}),d&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-share-${e.id}`,onClick:()=>d(e.id),children:[(0,$.jsx)(ze,{className:`h-4 w-4 mr-2`}),` `,F(`view.shareView`,`Share view`)]}),l&&!O&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-default-${e.id}`,onClick:()=>l(e.id),children:[(0,$.jsx)(ve,{className:`h-4 w-4 mr-2`}),` `,F(`view.setAsDefault`,`Set as default`)]}),m&&!O&&(0,$.jsx)(K,{"data-testid":`view-tab-menu-pin-${e.id}`,onClick:()=>m(e.id,!e.isPinned),children:e.isPinned?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(u,{className:`h-4 w-4 mr-2`}),` `,F(`view.unpinView`,`Unpin view`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(M,{className:`h-4 w-4 mr-2`}),` `,F(`view.pinView`,`Pin view`)]})}),v&&!O&&T&&T.length>0&&(0,$.jsxs)(Le,{children:[(0,$.jsxs)(_e,{"data-testid":`view-tab-menu-change-type-${e.id}`,children:[(0,$.jsx)(fe,{className:`h-4 w-4 mr-2`}),` `,F(`view.changeViewType`,`Change view type`)]}),(0,$.jsx)(Ue,{children:T.map(t=>{let n=r[t.type]||Y;return(0,$.jsxs)(K,{"data-testid":`view-tab-menu-type-${e.id}-${t.type}`,disabled:t.type===e.type,onClick:()=>v(e.id,t.type),children:[(0,$.jsx)(n,{className:`h-4 w-4 mr-2`}),(0,$.jsx)(`span`,{children:t.label})]},t.type)})})]}),c&&!O&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{}),(0,$.jsxs)(K,{"data-testid":`view-tab-menu-delete-${e.id}`,onClick:()=>c(e.id),className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Me,{className:`h-4 w-4 mr-2`}),` `,F(`view.deleteView`,`Delete view`)]})]}),x&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{}),(0,$.jsxs)(K,{"data-testid":`view-tab-menu-manage-${e.id}`,onClick:x,children:[(0,$.jsx)(S,{className:`h-4 w-4 mr-2`}),` `,F(`view.manageAllViews`,`Manage all views…`)]})]})]})]})]}),N=t=>!ie||w?t:(0,$.jsxs)(g,{children:[(0,$.jsx)(j,{asChild:!0,children:t}),(0,$.jsxs)(A,{children:[o&&!O&&(0,$.jsxs)(J,{"data-testid":`context-menu-rename-${e.id}`,onClick:()=>V(e.id),children:[(0,$.jsx)(De,{className:`h-4 w-4 mr-2`}),` `,F(`view.rename`,`Rename`)]}),s&&(0,$.jsxs)(J,{"data-testid":`context-menu-duplicate-${e.id}`,onClick:()=>s(e.id),children:[(0,$.jsx)(ye,{className:`h-4 w-4 mr-2`}),` `,F(`view.duplicateView`,`Duplicate view`)]}),d&&(0,$.jsxs)(J,{"data-testid":`context-menu-share-${e.id}`,onClick:()=>d(e.id),children:[(0,$.jsx)(ze,{className:`h-4 w-4 mr-2`}),` `,F(`view.shareView`,`Share view`)]}),l&&!O&&(0,$.jsxs)(J,{"data-testid":`context-menu-default-${e.id}`,onClick:()=>l(e.id),children:[(0,$.jsx)(ve,{className:`h-4 w-4 mr-2`}),` `,F(`view.setAsDefault`,`Set as default`)]}),m&&!O&&(0,$.jsx)(J,{"data-testid":`context-menu-pin-${e.id}`,onClick:()=>m(e.id,!e.isPinned),children:e.isPinned?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(u,{className:`h-4 w-4 mr-2`}),` `,F(`view.unpinView`,`Unpin view`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(M,{className:`h-4 w-4 mr-2`}),` `,F(`view.pinView`,`Pin view`)]})}),v&&!O&&T&&T.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(f,{}),(0,$.jsxs)(Ee,{children:[(0,$.jsxs)(ne,{"data-testid":`context-menu-change-type-${e.id}`,children:[(0,$.jsx)(fe,{className:`h-4 w-4 mr-2`}),` `,F(`view.changeViewType`,`Change view type`)]}),(0,$.jsx)(ee,{"data-testid":`context-menu-type-submenu-${e.id}`,children:T.map(t=>{let n=r[t.type]||Y;return(0,$.jsxs)(J,{"data-testid":`context-menu-type-${e.id}-${t.type}`,disabled:t.type===e.type,onClick:()=>v(e.id,t.type),children:[(0,$.jsx)(n,{className:`h-4 w-4 mr-2`}),(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`span`,{children:t.label}),t.description&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.description})]})]},t.type)})})]})]}),c&&!O&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(f,{}),(0,$.jsxs)(J,{"data-testid":`context-menu-delete-${e.id}`,onClick:()=>c(e.id),className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Me,{className:`h-4 w-4 mr-2`}),` `,F(`view.deleteView`,`Delete view`)]})]}),x&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(f,{}),(0,$.jsxs)(J,{"data-testid":`context-menu-manage-${e.id}`,onClick:x,children:[(0,$.jsx)(S,{className:`h-4 w-4 mr-2`}),` `,F(`view.manageAllViews`,`Manage all views…`)]})]})]})]});return ae&&h?(0,$.jsxs)(Q.Fragment,{children:[D&&(0,$.jsx)(`div`,{"data-testid":`view-tab-visibility-separator`,className:`w-px h-5 bg-border mx-1 self-center shrink-0`}),(0,$.jsx)(Ut,{id:e.id,children:({setNodeRef:e,style:t,listeners:n,attributes:r,isDragging:i})=>(0,$.jsx)(`div`,{ref:e,style:t,className:q(`flex`,i&&`z-10`),children:N(re({listeners:n,attributes:r,isDragging:i}))})})]},e.id):(0,$.jsxs)(Q.Fragment,{children:[D&&(0,$.jsx)(`div`,{"data-testid":`view-tab-visibility-separator`,className:`w-px h-5 bg-border mx-1 self-center shrink-0`}),N(re())]},e.id)},je=(0,$.jsx)($.Fragment,{children:be.map((e,t)=>ke(e,t))});return(0,$.jsx)(w,{children:(0,$.jsxs)(`div`,{"data-testid":`view-tab-bar`,className:q(`flex items-center gap-0.5 -mb-px`,O),children:[ae&&h?(0,$.jsx)(Ye,{sensors:Se,collisionDetection:$e,onDragEnd:we,children:(0,$.jsx)(nt,{items:be.map(e=>e.id),strategy:et,children:(0,$.jsx)(`div`,{"data-testid":`view-tab-sortable-container`,className:`flex items-center gap-0.5`,children:je})})}):je,xe.length>0&&(0,$.jsxs)(G,{children:[(0,$.jsx)(He,{asChild:!0,children:(0,$.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:[(0,$.jsx)(z,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs`,children:F(`view.moreViews`,`${xe.length} more`,{count:xe.length})})]})}),(0,$.jsxs)(Ae,{align:`end`,children:[x&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(K,{"data-testid":`view-tab-overflow-manage`,onClick:x,className:`font-medium`,children:[(0,$.jsx)(S,{className:`h-4 w-4 mr-2`}),` `,F(`view.manageAllViews`,`Manage all views…`)]}),(0,$.jsx)(H,{})]}),xe.map(e=>{let t=r[e.type]||Y;return(0,$.jsxs)(K,{"data-testid":`view-tab-overflow-${e.id}`,onClick:()=>n(e.id),children:[e.isPinned&&(0,$.jsx)(M,{className:`h-3 w-3 mr-1 text-primary shrink-0`}),(0,$.jsx)(t,{className:`h-4 w-4 mr-2`}),e.label,se&&(e.hasActiveFilters||e.hasActiveSort)&&(0,$.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-0.5 h-4 px-1 rounded-full bg-primary/10 text-primary`,children:[e.hasActiveFilters&&(0,$.jsx)(Ve,{className:`h-2.5 w-2.5`}),e.hasActiveSort&&(0,$.jsx)(ge,{className:`h-2.5 w-2.5`})]})]},e.id)})]})]}),te&&a&&(0,$.jsxs)(oe,{children:[(0,$.jsx)(k,{asChild:!0,children:(0,$.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:(0,$.jsx)(pe,{className:`h-4 w-4`})})}),(0,$.jsx)(b,{children:`Add View`})]}),ce&&E&&(0,$.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:[(0,$.jsx)(Te,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Unsaved changes`}),p&&(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,"data-testid":`view-tab-save-as-btn`,className:`h-6 px-2 text-xs`,onClick:p,children:`Save as View`}),D&&(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,"data-testid":`view-tab-reset-btn`,className:`h-6 px-2 text-xs`,onClick:D,children:`Reset`})]})]})})};function Gt(){try{let{t:e}=o();return(t,n,r)=>{let i=e(t,r);return!i||i===t?n:i}}catch{return(e,t)=>t}}var Kt=Pe,qt=({view:e,isActive:t,Icon:n,isRenaming:r,onStartRename:i,onCommitRename:a,onCancelRename:o,onRowClick:s,onDelete:c,onDuplicate:l,onSetDefault:d,onSetPinned:f,onConfigView:p})=>{let m=Gt(),{attributes:h,listeners:g,setNodeRef:_,transform:v,transition:y,isDragging:x}=Qe({id:e.id}),S={transform:at.Transform.toString(v),transition:y,opacity:x?.5:1},C=(0,Q.useRef)(null),[T,E]=(0,Q.useState)(e.label),D=!!e.readonly;(0,Q.useEffect)(()=>{r&&(E(e.label),requestAnimationFrame(()=>{C.current?.focus(),C.current?.select()}))},[r,e.label]);let O=(0,Q.useCallback)(()=>{let t=T.trim();t&&t!==e.label?a(e.id,t):o()},[T,e.id,e.label,a,o]);return(0,$.jsxs)(`li`,{ref:_,style:S,"data-testid":`manage-views-row-${e.id}`,className:q(`group/row flex items-center gap-2 px-2 py-2 rounded-md border border-transparent`,`hover:bg-accent/50 transition-colors`,t&&`bg-accent/40 border-border`,x&&`shadow-md bg-background border-border z-10`),children:[(0,$.jsx)(`button`,{type:`button`,...h,...g,"aria-label":m(`view.dragToReorder`,`Drag to reorder`),"data-testid":`manage-views-drag-${e.id}`,className:`shrink-0 h-6 w-5 flex items-center justify-center text-muted-foreground/40 hover:text-muted-foreground cursor-grab active:cursor-grabbing rounded hover:bg-accent`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Ce,{className:`h-4 w-4`})}),(0,$.jsx)(n,{className:`shrink-0 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,onClick:()=>{r||s?.(e.id)},children:r?(0,$.jsx)(X,{ref:C,value:T,onChange:e=>E(e.target.value),onBlur:O,onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),O()):e.key===`Escape`&&(e.preventDefault(),o())},onClick:e=>e.stopPropagation(),className:`h-7 text-sm`,"data-testid":`manage-views-rename-input-${e.id}`}):(0,$.jsxs)(`button`,{type:`button`,className:`w-full text-left text-sm font-medium truncate cursor-pointer flex items-center gap-1.5`,onDoubleClick:t=>{t.stopPropagation(),D||i(e.id)},title:e.label,children:[(0,$.jsx)(`span`,{className:`truncate`,children:e.label}),D&&(0,$.jsx)(P,{"aria-label":m(`view.readonlyAriaLabel`,`Read-only view`),"data-testid":`manage-views-readonly-${e.id}`,className:`h-3 w-3 text-muted-foreground shrink-0`}),e.isDefault&&(0,$.jsxs)(`span`,{className:`ml-1 inline-flex items-center text-[10px] uppercase tracking-wide text-muted-foreground`,title:m(`view.defaultView`,`Default view`),children:[(0,$.jsx)(ve,{className:`h-3 w-3 mr-0.5 fill-current`}),` `,m(`view.defaultBadge`,`default`)]})]})}),f&&!r&&!D&&(0,$.jsx)(w,{delayDuration:300,children:(0,$.jsxs)(oe,{children:[(0,$.jsx)(k,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":e.isPinned?m(`view.unpinView`,`Unpin View`):m(`view.pinView`,`Pin View`),"data-testid":`manage-views-pin-${e.id}`,onClick:t=>{t.stopPropagation(),f(e.id,!e.isPinned)},className:q(`shrink-0 h-7 w-7 inline-flex items-center justify-center rounded hover:bg-accent transition-colors`,e.isPinned?`text-amber-500`:`text-muted-foreground/40 opacity-0 group-hover/row:opacity-100`),children:e.isPinned?(0,$.jsx)(M,{className:`h-4 w-4 fill-current`}):(0,$.jsx)(M,{className:`h-4 w-4`})})}),(0,$.jsx)(b,{side:`top`,children:e.isPinned?m(`view.unpinView`,`Unpin View`):m(`view.pinView`,`Pin View`)})]})}),d&&!r&&!e.isDefault&&!D&&(0,$.jsx)(w,{delayDuration:300,children:(0,$.jsxs)(oe,{children:[(0,$.jsx)(k,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":m(`view.setAsDefault`,`Set as Default`),"data-testid":`manage-views-default-${e.id}`,onClick:t=>{t.stopPropagation(),d(e.id)},className:`shrink-0 h-7 w-7 inline-flex items-center justify-center rounded hover:bg-accent text-muted-foreground/40 hover:text-foreground opacity-0 group-hover/row:opacity-100 transition-colors`,children:(0,$.jsx)(ve,{className:`h-4 w-4`})})}),(0,$.jsx)(b,{side:`top`,children:m(`view.setAsDefault`,`Set as Default`)})]})}),!r&&(c||l||p||d)&&(0,$.jsxs)(G,{children:[(0,$.jsx)(He,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":m(`view.tabActionsFor`,`View actions for ${e.label}`,{name:e.label}),"data-testid":`manage-views-actions-${e.id}`,onClick:e=>e.stopPropagation(),className:`shrink-0 h-7 w-7 inline-flex items-center justify-center rounded hover:bg-accent text-muted-foreground opacity-60 group-hover/row:opacity-100 transition-opacity`,children:(0,$.jsx)(z,{className:`h-4 w-4`})})}),(0,$.jsxs)(Ae,{align:`end`,className:`min-w-[180px]`,children:[!D&&(0,$.jsxs)(K,{"data-testid":`manage-views-action-rename-${e.id}`,onClick:()=>i(e.id),children:[(0,$.jsx)(De,{className:`h-4 w-4 mr-2`}),` `,m(`view.rename`,`Rename`)]}),l&&(0,$.jsxs)(K,{"data-testid":`manage-views-action-duplicate-${e.id}`,onClick:()=>l(e.id),children:[(0,$.jsx)(ye,{className:`h-4 w-4 mr-2`}),` `,m(`view.duplicateView`,`Duplicate View`)]}),p&&!D&&(0,$.jsxs)(K,{"data-testid":`manage-views-action-config-${e.id}`,onClick:()=>p(e.id),children:[(0,$.jsx)(De,{className:`h-4 w-4 mr-2`}),` `,m(`view.editViewConfig`,`Edit view config`)]}),d&&!e.isDefault&&!D&&(0,$.jsxs)(K,{"data-testid":`manage-views-action-default-${e.id}`,onClick:()=>d(e.id),children:[(0,$.jsx)(ve,{className:`h-4 w-4 mr-2`}),` `,m(`view.setAsDefault`,`Set as Default`)]}),f&&!D&&(0,$.jsx)(K,{"data-testid":`manage-views-action-pin-${e.id}`,onClick:()=>f(e.id,!e.isPinned),children:e.isPinned?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(u,{className:`h-4 w-4 mr-2`}),` `,m(`view.unpinView`,`Unpin View`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(M,{className:`h-4 w-4 mr-2`}),` `,m(`view.pinView`,`Pin View`)]})}),c&&!D&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{}),(0,$.jsxs)(K,{"data-testid":`manage-views-action-delete-${e.id}`,onClick:()=>c(e.id),className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(Me,{className:`h-4 w-4 mr-2`}),` `,m(`view.deleteView`,`Delete View`)]})]})]})]}),r&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":m(`common.save`,`Save`),onMouseDown:e=>e.preventDefault(),onClick:O,className:`h-7 w-7 inline-flex items-center justify-center rounded hover:bg-accent text-emerald-600`,children:(0,$.jsx)(F,{className:`h-4 w-4`})}),(0,$.jsx)(`button`,{type:`button`,"aria-label":m(`common.cancel`,`Cancel`),onMouseDown:e=>e.preventDefault(),onClick:o,className:`h-7 w-7 inline-flex items-center justify-center rounded hover:bg-accent text-muted-foreground`,children:(0,$.jsx)(ae,{className:`h-4 w-4`})})]})]})},Jt=({open:e,onOpenChange:t,views:n,activeViewId:r,viewTypeIcons:i={},onRename:a,onDelete:o,onDuplicate:s,onSetDefault:c,onSetPinned:l,onReorder:u,onAddView:d,onConfigView:f})=>{let p=Gt(),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(()=>n.map(e=>e.id));(0,Q.useEffect)(()=>{y(n.map(e=>e.id))},[n]),(0,Q.useEffect)(()=>{e||(_(null),h(``))},[e]);let b=(0,Q.useMemo)(()=>{let e=new Map(n.map(e=>[e.id,e]));return v.map(t=>e.get(t)).filter(Boolean)},[v,n]),S=(0,Q.useMemo)(()=>{if(!m.trim())return b;let e=m.toLowerCase();return b.filter(t=>t.label.toLowerCase().includes(e))},[b,m]),C=it(qe(Xe,{activationConstraint:{distance:5}}),qe(rt,{coordinateGetter:Je})),w=e=>{let{active:t,over:n}=e;if(!n||t.id===n.id)return;let r=v.indexOf(String(t.id)),i=v.indexOf(String(n.id));if(r<0||i<0)return;let a=Ze(v,r,i);y(a),u?.(a)},E=e=>{t(!1),requestAnimationFrame(()=>f?.(e))};return(0,$.jsx)(ue,{open:e,onOpenChange:t,children:(0,$.jsxs)(de,{className:`sm:max-w-[560px] p-0 gap-0 overflow-hidden`,"data-testid":`manage-views-dialog`,children:[(0,$.jsxs)(je,{className:`px-5 pt-5 pb-3`,children:[(0,$.jsx)(T,{className:`text-base`,children:p(`view.manageViews`,`Manage views`)}),(0,$.jsx)(x,{className:`text-xs`,children:p(`view.manageViewsDescription`,`Reorder, rename, pin, or delete every view in this object.`)})]}),(0,$.jsx)(`div`,{className:`px-5 pb-3`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(ie,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none`}),(0,$.jsx)(X,{value:m,onChange:e=>h(e.target.value),placeholder:p(`view.searchViews`,`Search views`),className:`pl-8 h-9`,"data-testid":`manage-views-search`})]})}),(0,$.jsx)(`div`,{className:`px-3 pb-3 max-h-[55vh] overflow-y-auto`,"data-testid":`manage-views-list`,children:S.length===0?(0,$.jsx)(`div`,{className:`text-center text-sm text-muted-foreground py-10`,children:p(`view.noViewsFound`,`No views match your search.`)}):(0,$.jsx)(Ye,{sensors:C,collisionDetection:$e,onDragEnd:w,children:(0,$.jsx)(nt,{items:S.map(e=>e.id),strategy:tt,children:(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:S.map(e=>{let t=i[e.type]||Kt;return(0,$.jsx)(qt,{view:e,Icon:t,isActive:e.id===r,isRenaming:g===e.id,onStartRename:e=>_(e),onCancelRename:()=>_(null),onCommitRename:(e,t)=>{_(null),a?.(e,t)},onDelete:o,onDuplicate:s,onSetDefault:c,onSetPinned:l,onConfigView:f?E:void 0},e.id)})})})})}),(0,$.jsxs)(D,{className:`border-t bg-muted/30 px-5 py-3 flex sm:justify-between gap-2`,children:[d?(0,$.jsxs)(Z,{variant:`ghost`,size:`sm`,onClick:()=>{t(!1),requestAnimationFrame(()=>d())},"data-testid":`manage-views-add`,className:`text-sm`,children:[(0,$.jsx)(pe,{className:`h-4 w-4 mr-1.5`}),` `,p(`view.addNewView`,`Add new view`)]}):(0,$.jsx)(`span`,{}),(0,$.jsx)(Z,{size:`sm`,onClick:()=>t(!1),"data-testid":`manage-views-done`,children:p(`view.done`,`Done`)})]})]})})};function Yt(e){let t=(e||``).toLowerCase();return[`integer`,`int`,`float`,`double`,`number`,`currency`,`money`,`percent`,`rating`].includes(t)?`number`:[`date`,`datetime`,`datetime_tz`,`timestamp`,`time`].includes(t)?`date`:[`boolean`,`bool`,`checkbox`,`switch`].includes(t)?`boolean`:[`select`,`picklist`,`single_select`,`multi_select`,`enum`,`status`,`lookup`,`master_detail`,`user`,`owner`].includes(t)?`select`:`text`}function Xt(e){return e.fields?Object.entries(e.fields).filter(([e,t])=>!(e.startsWith(`_`)||t?.hidden)).map(([e,t])=>({value:e,label:t.label||e,type:Yt(t.type),options:t.options,rawType:t.type,rawName:e})):[]}var Zt=new Set([`image`,`image_url`,`photo`,`picture`,`avatar`,`file`,`attachment`,`attachments`,`media`,`url`,`link`]),Qt=[`image`,`photo`,`picture`,`avatar`,`thumbnail`,`thumb`,`logo`,`cover`,`banner`,`icon`,`attachment`];function $t(e){if(!e)return!1;let t=(e.rawType||e.type||``).toLowerCase();if(Zt.has(t))return!0;let n=(e.rawName||e.name||e.key||e.value||``).toLowerCase();return n?Qt.some(e=>n.includes(e)):!1}var en=new Set([`geolocation`,`geo`,`geo_point`,`geopoint`,`location`,`latlng`,`lnglat`]);function tn(e,t){if(!e)return!1;let n=(e.rawType||e.type||``).toLowerCase();if(en.has(n))return!0;let r=(e.rawName||e.name||e.key||e.value||``).toLowerCase();return r?t===`latitude`?/(^|[_-])lat([^a-z]|itude)?($|[_-])/.test(r)||r===`lat`:/(^|[_-])(lng|lon|long)([^a-z]|gitude)?($|[_-])/.test(r)||r===`lng`||r===`lon`:!1}function nn(e,t){if(e.length!==0){for(let n of t){let t=e.find(e=>e.value.toLowerCase().includes(n));if(t)return t.value}return e[0]?.value}}var rn=[`status`,`stage`,`state`,`priority`,`category`,`type`],an=[`start_date`,`startdate`,`due_date`,`duedate`,`event_date`,`date`,`created_at`,`createdat`,`created`],on=[`end_date`,`enddate`,`finish_date`,`completion_date`,`closed_at`],sn=s,cn=({schema:e})=>(0,$.jsx)(Dt,{schema:e,dataSource:(0,Q.useContext)(sn)?.dataSource??null});r.register(`object-view`,cn,{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}}),r.register(`view`,cn,{namespace:`plugin-view`,label:`View`,category:`view`}),r.register(`view-switcher`,xt,{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`}}]}}),r.register(`filter-ui`,jt,{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`}]}}),r.register(`sort-ui`,It,{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`}]}}),r.register(`shared-view-link`,zt,{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`}}),r.register(`view:simple`,({schema:e,className:t,children:n,dataSource:r,...i})=>(0,$.jsx)(`div`,{className:t,style:e.props?.columns?{display:`grid`,gridTemplateColumns:`repeat(${e.props.columns}, 1fr)`,gap:`1rem`}:void 0,...i,children:n}),{namespace:`plugin-view`,label:`Simple View`,category:`view`});export{tn as a,Jt as c,wt as d,Xt as i,Wt as l,rn as n,$t as o,an as r,nn as s,on as t,Dt as u};