@objectstack/console 11.1.0 → 11.2.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.
- package/dist/assets/{AdapterProvider-BTAMdG2T.js → AdapterProvider-BPgD5wI1.js} +1 -1
- package/dist/assets/{AiPendingActionsPage-BtiQFQw8.js → AiPendingActionsPage-Cojy8a-z.js} +1 -1
- package/dist/assets/{ApiConsolePage-CQJbzAsw.js → ApiConsolePage-o44winom.js} +1 -1
- package/dist/assets/{AppDocsIndex-CbHC6KGX.js → AppDocsIndex-CnVwFuo5.js} +1 -1
- package/dist/assets/{AppManagementPage-DOoQrTPO.js → AppManagementPage-Dzv2LTfe.js} +1 -1
- package/dist/assets/{ApprovalsInboxPage-D6eWYxCu.js → ApprovalsInboxPage-CbMAm2Z1.js} +1 -1
- package/dist/assets/{AuditLogPage-F85cQBBY.js → AuditLogPage-Ckb7Ei0l.js} +1 -1
- package/dist/assets/{ComponentNavView-g9qw3mhW.js → ComponentNavView-C1ZKriwP.js} +1 -1
- package/dist/assets/ConsoleFloatingChatbot-DqrmAZNg.js +1 -0
- package/dist/assets/{DashboardView-mIWO-jW_.js → DashboardView-PNh3ds7Y.js} +1 -1
- package/dist/assets/{DashboardWidgetInspector-DOnyBhGN.js → DashboardWidgetInspector-BqmZ8NCC.js} +1 -1
- package/dist/assets/{DeveloperHubPage-Ci0wA8GZ.js → DeveloperHubPage-YHIc76u2.js} +1 -1
- package/dist/assets/{ExpressionProvider-NqLS0ljf.js → ExpressionProvider-CMntDoz9.js} +1 -1
- package/dist/assets/{FlowRunsPage-CNz2_VFK.js → FlowRunsPage-daH77deA.js} +1 -1
- package/dist/assets/{IntegrationsPage-CAZ3nsKJ.js → IntegrationsPage-FpPdGLBF.js} +1 -1
- package/dist/assets/{InterfaceListPage-D1BbH0Iy.js → InterfaceListPage-Npe_tn_H.js} +1 -1
- package/dist/assets/{ManagedByBadge-6DwSVsdr.js → ManagedByBadge-CLEdt1ik.js} +1 -1
- package/dist/assets/{MarketplaceAccessDenied-Cyx7lSjy.js → MarketplaceAccessDenied-DiK0S3Vq.js} +1 -1
- package/dist/assets/{MarketplaceInstalledPage-C41H1YlB.js → MarketplaceInstalledPage-ytCNj-9Y.js} +1 -1
- package/dist/assets/{MarketplacePackagePage-Bihb2q1b.js → MarketplacePackagePage-CAsMrnZF.js} +1 -1
- package/dist/assets/{MarketplacePage-C2B6TMNM.js → MarketplacePage-Ct4PVYqJ.js} +1 -1
- package/dist/assets/{MetadataInspector-COEBMw6y.js → MetadataInspector-B3LWAl8X.js} +1 -1
- package/dist/assets/{MetadataProvider-D234gTjV.js → MetadataProvider-BRGGbotZ.js} +1 -1
- package/dist/assets/{PageView-DuiaqvzN.js → PageView-VljnDnGh.js} +1 -1
- package/dist/assets/{ProfilePage-B1oCou0F.js → ProfilePage-D6bk--bm.js} +1 -1
- package/dist/assets/{PublicFormsPage-C2prdsH6.js → PublicFormsPage-gyZqil7Y.js} +1 -1
- package/dist/assets/{RecordDetailView-B-AuOKPI.js → RecordDetailView-ClJoPCbl.js} +2 -2
- package/dist/assets/{RecordFormPage-CpKMoOCj.js → RecordFormPage-SzhX0SxR.js} +1 -1
- package/dist/assets/{ReportDefaultInspector-DxP-Ac7I.js → ReportDefaultInspector-BIOfFevD.js} +2 -2
- package/dist/assets/{ReportView-Cw9Ompki.js → ReportView-Bbmeyhqd.js} +1 -1
- package/dist/assets/{SearchResultsPage-CZ038ncU.js → SearchResultsPage-JwPvnRco.js} +1 -1
- package/dist/assets/{SettingsHub-BXe-fVlJ.js → SettingsHub-BbH3HtvN.js} +1 -1
- package/dist/assets/{SettingsView-DxPgTnlF.js → SettingsView-R0t6xrOR.js} +1 -1
- package/dist/assets/{SystemHubPage-CJq_1ITt.js → SystemHubPage-DW-xYOhx.js} +1 -1
- package/dist/assets/{data-adapter-02g96tfY.js → data-adapter-BwlZo45L.js} +1 -1
- package/dist/assets/{framework-h98DIM1k.js → framework-CakMZS2A.js} +7 -7
- package/dist/assets/{highlighted-body-OFNGDK62-DO9p_wSr.js → highlighted-body-OFNGDK62-BGuZxdtV.js} +1 -1
- package/dist/assets/{index-BQhiWf8_.js → index-Bc8lMePA.js} +1 -1
- package/dist/assets/index-CKUQ3pPE.css +2 -0
- package/dist/assets/mermaid-GHXKKRXX-BjC9P-Az.js +1 -0
- package/dist/assets/{metadata-admin-DStYGsRM.js → metadata-admin-CmNQ3PCe.js} +4 -4
- package/dist/assets/{plugin-calendar-BYmYEyQk.js → plugin-calendar-D1hSxakw.js} +1 -1
- package/dist/assets/{plugin-charts-BDFf0TCn.js → plugin-charts-DUJQWrQu.js} +1 -1
- package/dist/assets/{plugin-chatbot-CnuZn8AC.js → plugin-chatbot-xCaZPNnP.js} +4 -4
- package/dist/assets/{plugin-dashboard-CuwYQhsg.js → plugin-dashboard-C5-M_XlX.js} +1 -1
- package/dist/assets/{plugin-form-CH8ruD9E.js → plugin-form-C7Hglo5P.js} +1 -1
- package/dist/assets/{plugin-gantt-BB8ZeREv.js → plugin-gantt-C_CBI9Ze.js} +1 -1
- package/dist/assets/{plugin-grid-D414NLNP.js → plugin-grid-DxUHFaSG.js} +1 -1
- package/dist/assets/{plugin-kanban-BRFJEEAA.js → plugin-kanban-fK0Hn7gr.js} +1 -1
- package/dist/assets/{plugin-map-rEWoyyKa.js → plugin-map-CFUHBBgY.js} +1 -1
- package/dist/assets/{plugin-markdown-BgV76qm3.js → plugin-markdown-D2JDzxOb.js} +1 -1
- package/dist/assets/{plugin-report-C-YPOtvZ.js → plugin-report-C_gu6Sl0.js} +1 -1
- package/dist/assets/{plugin-timeline-CC91-fmI.js → plugin-timeline-JAVlYIZG.js} +1 -1
- package/dist/assets/{plugin-tree-D2QWz1x1.js → plugin-tree-ckWxLNeS.js} +1 -1
- package/dist/assets/{plugin-view-C6iEzx93.js → plugin-view-CYd_0MnO.js} +1 -1
- package/dist/assets/{plugins-views-CcoNygsH.js → plugins-views-CpVdFGRz.js} +2 -2
- package/dist/assets/{skeletons-BQ5aRDUn.js → skeletons-CTmAPzFj.js} +1 -1
- package/dist/assets/{src-C4OnKiir.js → src-CMNhRk8x.js} +1 -1
- package/dist/assets/src-DZhiMT1j.js +2 -0
- package/dist/assets/{types-BUZu4QOP.js → types-5UGg6DKH.js} +1 -1
- package/dist/assets/ui-components-BXvcyYmR.js +42 -0
- package/dist/assets/{ui-layout-BwokMuBv.js → ui-layout-DAe4Nna8.js} +1 -1
- package/dist/assets/{useActionModal-ChUaxcEW.js → useActionModal-B6_KUPqx.js} +1 -1
- package/dist/assets/{useOpenRecordList-BkSEs2q6.js → useOpenRecordList-yTGpfA54.js} +1 -1
- package/dist/assets/{useReconcileOnError-FPUCNTHc.js → useReconcileOnError-oxCJ7_s6.js} +1 -1
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/dist/assets/ConsoleFloatingChatbot-Cy-Ny_TS.js +0 -1
- package/dist/assets/index-WhD62Q-7.css +0 -2
- package/dist/assets/mermaid-GHXKKRXX-DEmtnxCC.js +0 -1
- package/dist/assets/src-CKHT6scJ.js +0 -2
- package/dist/assets/ui-components-C9egdVxV.js +0 -42
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e,r as t,t as n}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as r,g as i,t as a}from"./vendor-react-ClIa1CJA.js";import{$ as o,Dt as s,N as c,P as l,V as u,Y as d,Z as f,at as p,b as m,ct as h,dt as g,et as _,ft as v,i as y,it as b,kt as x,lt as S,m as C,mt as w,n as T,nt as E,ot as D,pt as ee,st as O,t as k,tt as A,ut as j}from"./framework-h98DIM1k.js";import{$ as M,$n as te,A as N,Ac as P,Bt as F,Cc as I,Ei as ne,F as re,Fc as ie,Gr as L,Ht as ae,I as oe,Jn as R,L as z,Lt as B,Mc as se,Ns as V,Oc as H,Or as ce,Pc as U,R as le,Ta as ue,Un as W,Ut as G,Vi as K,Wn as q,Xs as de,Y as J,Zo as fe,_ as pe,_c as Y,a as X,di as me,er as he,et as ge,f as _e,ho as ve,ji as ye,nr as be,nt as xe,o as Se,qn as Ce,rr as we,u as Te,vc as Ee,xr as De,za as Oe,zt as ke}from"./ui-components-C9egdVxV.js";import{o as Ae,t as je}from"./vendor-ui-utils-C92Fl7BT.js";import{_ as Me,c as Ne,d as Pe,g as Fe,h as Ie,i as Le,n as Re,o as ze,p as Be,s as Ve,t as He}from"./vendor-dndkit-CJ-mJJuO.js";var Z=e(r(),1),Ue=e(i(),1),Q=a();function We(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&e.provider===`object`}function Ge(e,t){if(t==null||e==null||typeof e!=`number`||!Number.isFinite(e)||typeof t!=`number`||!Number.isFinite(t))return null;if(t===0)return e===0?{value:0,direction:`neutral`}:{value:100,direction:e>0?`up`:`down`};let n=e-t;if(n===0)return{value:0,direction:`neutral`};let r=Math.round(n/Math.abs(t)*100);return{value:Math.abs(r),direction:r>0?`up`:`down`}}var Ke=new Set([`id`,`organization_id`,`tenant_id`,`created_at`,`updated_at`,`created_by`,`updated_by`,`deleted_at`,`deleted_by`,`version`,`_id`,`__typename`]);function qe(e,t){return t&&(t.isSystem===!0||t.system===!0)?!0:Ke.has(e)}var Je=new Set([`select`,`picklist`,`dropdown`,`status`]),Ye=new Set([`currency`,`money`,`number`,`integer`,`decimal`,`float`,`percent`,`percentage`]);function Xe(e){let t={},n=e?.fields;if(!n)return t;if(Array.isArray(n))for(let e of n)e?.name&&(t[e.name]=e);else for(let[e,r]of Object.entries(n))t[e]={name:e,...r};return t}function Ze(e){let{accessorKey:t,label:n,def:r,objectName:i,fieldOptionLabel:a,overrides:o={}}=e,s=o.referenceTo??r?.referenceTo??(typeof r?.reference==`string`?r.reference:r?.reference?.to)??r?.target,c=o.options??r?.options;return i&&c&&a&&Je.has(r?.type)&&(c=c.map(e=>{if(e==null)return e;let n=typeof e==`object`?e.value:e,r=typeof e==`object`&&e.label||String(n);return{value:n,label:a(i,t,String(n),r),color:typeof e==`object`?e.color:void 0}})),{name:t,label:n,type:o.type??r?.type,options:c,referenceTo:s,format:o.format??r?.format,currency:o.currency??r?.currency??r?.defaultCurrency,decimals:o.decimals??r?.decimals??r?.precision??r?.scale}}function Qe(e){return Ye.has(e.type)||typeof e.format==`string`&&/^[\$¥€£]|%$|0/.test(e.format)}function $e(e,t,n){if(e==null||e===``)return``;let r=t.format;if(typeof r==`string`&&/^\$|¥|€|£/.test(r)&&typeof e==`number`){let i={$:`USD`,"¥":`JPY`,"€":`EUR`,"£":`GBP`}[r[0]];return X(e,t.currency||i||n)}if(typeof r==`string`&&/%/.test(r)&&typeof e==`number`){let t=(r.match(/0\.(0+)%/)||[,``])[1].length;return Te((e>1?e/100:e)*100,t)}return typeof r==`string`&&/[YMDHms]/.test(r)?Se(e,r):(0,Q.jsx)(_e(pe(t)),{value:e,field:t})}var et=[`name`,`title`,`label`,`subject`,`display_name`,`full_name`];function tt(e,t){if(t&&t.trim())return t;for(let t of et){let n=e[t];if(typeof n==`string`&&n.trim())return n}let n=e.id??e._id;return n==null?`Record`:String(n)}var nt=({record:e,objectName:t,objectSchema:n,fields:r,title:i,target:a=`drawer`,onClose:o})=>{let{fieldLabel:s,fieldOptionLabel:c}=ie(),{currency:l}=se(),u=(0,Z.useMemo)(()=>{if(!e)return[];let i=Xe(n),a;return a=r&&r.length>0?r:Object.keys(i).length>0?Object.keys(i).filter(e=>!qe(e,i[e])):Object.keys(e).filter(e=>!e.startsWith(`_`)&&!qe(e)),a.map(n=>{let r=i[n],a=n.charAt(0).toUpperCase()+n.slice(1).replace(/([A-Z])/g,` $1`).replace(/_/g,` `),o=t?s(t,n,a):a,u=Ze({accessorKey:n,label:o,def:r,objectName:t,fieldOptionLabel:c});return{key:n,label:o,node:$e(e[n],u,l),numeric:Qe(u)}})},[e,n,t,r,s,c,l]);if(!e)return null;let d=tt(e,i),f=(0,Q.jsx)(`dl`,{className:`divide-y divide-border/60`,"data-testid":`record-detail-body`,children:u.map(e=>(0,Q.jsxs)(`div`,{className:`grid grid-cols-3 gap-3 py-2.5`,children:[(0,Q.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground self-center`,children:e.label}),(0,Q.jsx)(`dd`,{className:`col-span-2 text-sm break-words ${e.numeric?`tabular-nums`:``}`,children:e.node===``||e.node==null?(0,Q.jsx)(`span`,{className:`text-muted-foreground/60`,children:`—`}):e.node})]},e.key))});return a===`dialog`?(0,Q.jsx)(W,{open:!0,onOpenChange:e=>!e&&o(),children:(0,Q.jsxs)(q,{className:`max-w-2xl`,children:[(0,Q.jsx)(Ce,{children:(0,Q.jsx)(R,{children:d})}),(0,Q.jsx)(`div`,{className:`max-h-[70vh] overflow-auto`,children:f})]})}):(0,Q.jsx)(ke,{open:!0,onOpenChange:e=>!e&&o(),children:(0,Q.jsxs)(F,{side:`right`,className:`w-full sm:max-w-md md:max-w-lg flex flex-col`,children:[(0,Q.jsx)(ae,{children:(0,Q.jsx)(G,{children:d})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-auto mt-2 pr-1`,children:f})]})})};function rt(e){return e.map(e=>typeof e==`string`?{header:e.replace(/_/g,` `).replace(/([A-Z])/g,` $1`).trim().replace(/\b\w/g,e=>e.toUpperCase()),accessorKey:e}:e)}function it(e,t){if(!t?.fields)return[];let n={};if(Array.isArray(t.fields))for(let e of t.fields)e?.name&&(n[e.name]=e);else for(let[e,r]of Object.entries(t.fields))n[e]={name:e,...r};let r=e=>e===`lookup`||e===`reference`||e===`master_detail`||e===`user`||e===`owner`,i=Array.isArray(e.columns)?e.columns:[],a=new Set;if(i.length>0){let e=i.map(e=>typeof e==`string`?e:e.accessorKey||e.name).filter(Boolean);for(let t of e){let e=n[t];e&&r(e.type)&&a.add(t)}}else for(let[e,t]of Object.entries(n))r(t?.type)&&a.add(e);return Array.from(a)}var at=({schema:e,dataSource:t,className:n})=>{let{currency:r}=se(),i=(0,Z.useContext)(d),a=t||i?.dataSource,o=f(e.bind),{fieldLabel:c,fieldOptionLabel:l}=ie(),p=`No data available`,m=`No data source available for`;try{let{t:e}=y(),t=e(`dashboard.noDataAvailable`);t&&t!==`dashboard.noDataAvailable`&&(p=t);let n=e(`dashboard.noDataSourceFor`);n&&n!==`dashboard.noDataSourceFor`&&(m=n)}catch{}let[h,_]=(0,Z.useState)([]),[v,b]=(0,Z.useState)(null),[x,S]=(0,Z.useState)(()=>!(Array.isArray(e.data)&&e.data.length>0)&&!!e.objectName),[C,w]=(0,Z.useState)(null),T=e.drillDown,E=ee(T)&&(T?.mode??`record`)===`record`,[D,O]=(0,Z.useState)(null),k=(0,Z.useCallback)(e=>{O(e??null)},[]);(0,Z.useEffect)(()=>{let t=!0;return e.objectName&&!o&&(!e.data||e.data.length===0)?(async()=>{if(!a||!e.objectName){t&&S(!1);return}t&&(S(!0),w(null));try{let n;if(typeof a.find==`function`){let t=it(e,v),r={$filter:g(e.filter)};t.length&&(r.$expand=t),n=s(await a.find(e.objectName,r))}else return;t&&_(n)}catch(e){console.error(`[ObjectDataTable] Fetch error:`,e),t&&w(e instanceof Error?e.message:`Failed to load data`)}finally{t&&S(!1)}})():t&&S(!1),()=>{t=!1}},[e.objectName,a,o,e.data,e.filter,v]),(0,Z.useEffect)(()=>{let t=!0;if(!(!a||!e.objectName||typeof a.getObjectSchema!=`function`))return a.getObjectSchema(e.objectName).then(e=>{t&&b(e)}).catch(()=>{}),()=>{t=!1}},[e.objectName,a]);let A=o||e.data||h,j=Array.isArray(A)?A:[],M=(0,Z.useMemo)(()=>{let t=e.objectName,n={};if(v?.fields){let e=v.fields;if(Array.isArray(e))for(let t of e)t?.name&&(n[t.name]=t);else for(let[t,r]of Object.entries(e))n[t]={name:t,...r}}let i=e=>{let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/([A-Z])/g,` $1`);return t?c(t,e,n):n},a=e=>{let i=Ze({accessorKey:e.accessorKey,label:e.header,def:n[e.accessorKey],objectName:t,fieldOptionLabel:l,overrides:{type:e.type,format:e.format,options:e.options,referenceTo:e.referenceTo,currency:e.currency,decimals:e.decimals}}),a=e.align??(Qe(i)?`right`:void 0);if(typeof e.cell==`function`)return{...e,...i,align:a};let o=e=>$e(e,i,r);return{...e,...i,align:a,cell:o}};if(e.columns&&e.columns.length>0){let n=rt(e.columns);return(t?n.map(e=>({...e,header:c(t,e.accessorKey,e.header)})):n).map(a)}return j.length===0?[]:(Object.keys(n).length>0?Object.keys(n).filter(e=>!qe(e,n[e])):Object.keys(j[0]).filter(e=>!e.startsWith(`_`)&&!qe(e))).map(e=>a({header:i(e),accessorKey:e}))},[e.columns,e.objectName,j,v,c,l,r]);if(x&&j.length===0)return(0,Q.jsx)(`div`,{className:H(`overflow-auto`,n),"data-testid":`table-loading`,children:(0,Q.jsxs)(`div`,{className:`space-y-2 p-2`,children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(B,{className:`h-6 w-1/4`}),(0,Q.jsx)(B,{className:`h-6 w-1/4`}),(0,Q.jsx)(B,{className:`h-6 w-1/4`}),(0,Q.jsx)(B,{className:`h-6 w-1/4`})]}),[1,2,3,4].map(e=>(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(B,{className:`h-5 w-1/4`}),(0,Q.jsx)(B,{className:`h-5 w-1/4`}),(0,Q.jsx)(B,{className:`h-5 w-1/4`}),(0,Q.jsx)(B,{className:`h-5 w-1/4`})]},e))]})});if(C)return(0,Q.jsx)(`div`,{className:H(`overflow-auto`,n),"data-testid":`table-error`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-destructive`,"data-testid":`table-error-message`,children:[(0,Q.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,className:`h-8 w-8 mb-2 opacity-60`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,Q.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]}),(0,Q.jsx)(`p`,{className:`text-xs`,children:C})]})});if(!a&&e.objectName&&j.length===0)return(0,Q.jsx)(`div`,{className:H(`overflow-auto`,n),children:(0,Q.jsx)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:(0,Q.jsxs)(`p`,{className:`text-xs`,children:[m,` “`,e.objectName,`”`]})})});if(j.length===0)return(0,Q.jsx)(`div`,{className:H(`overflow-auto`,n),"data-testid":`table-empty-state`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,Q.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,className:`h-8 w-8 mb-2 opacity-40`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,Q.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),(0,Q.jsx)(`line`,{x1:`3`,y1:`9`,x2:`21`,y2:`9`}),(0,Q.jsx)(`line`,{x1:`9`,y1:`21`,x2:`9`,y2:`9`})]}),(0,Q.jsx)(`p`,{className:`text-xs`,children:p})]})});let te={...e,type:`data-table`,data:j,columns:M,onRowClick:e.onRowClick??(E?k:void 0)},N=T?.title&&!T.title.includes("${")?T.title:void 0;return(0,Q.jsxs)(`div`,{className:H(`relative`,n),children:[(0,Q.jsx)(oe,{active:x&&j.length>0}),(0,Q.jsx)(u,{schema:te,className:n}),E&&(0,Q.jsx)(nt,{record:D,objectName:e.objectName,objectSchema:v,fields:T?.columns,title:N,target:T?.target===`dialog`?`dialog`:`drawer`,onClose:()=>O(null)})]})},ot=({objectName:e,filter:t,onNavigate:n,className:r})=>{let{openRecordList:i}=m(),a=T();return!i||!e?null:(0,Q.jsxs)(De,{type:`button`,variant:`ghost`,size:`sm`,className:r,"data-testid":`drill-open-in-list`,onClick:()=>{i(e,t),n?.()},children:[a(`dashboard.openInList`,`Open in list`),(0,Q.jsx)(Ee,{className:`ml-1 h-3.5 w-3.5`})]})},st=({open:e,onClose:t,title:n,target:r=`drawer`,objectName:i,filter:a,dataSource:o,columns:s,maxRows:c,className:l,report:d})=>{let{openRecordList:f}=m(),p=d&&typeof d==`object`&&(Array.isArray(d.columns)||`objectName`in d),h=r===`navigate`&&!!f&&!p&&!!i;if(Z.useEffect(()=>{e&&h&&(f(i,a),t())},[e,h]),h)return null;let g=p?null:(0,Q.jsx)(ot,{objectName:i,filter:a,onNavigate:t}),_=(0,Q.jsx)(`div`,{className:H(`overflow-auto`,l),"data-testid":`drill-down-body`,children:p?(()=>{let e=d.filter,t=e?a?{$and:[e,a]}:e:a;return(0,Q.jsx)(u,{schema:{...d,type:`spec-report`,report:{...d,filter:t},filter:t}})})():(0,Q.jsx)(at,{schema:{type:`object-data-table`,objectName:i,filter:a,columns:s?.map(e=>({accessorKey:e,header:e})),pagination:!0,searchable:!1,pageSize:c,drillDown:{enabled:!0,mode:`record`,target:`dialog`}},dataSource:o})});return r===`dialog`?(0,Q.jsx)(W,{open:e,onOpenChange:e=>!e&&t(),children:(0,Q.jsxs)(q,{className:`max-w-5xl`,children:[(0,Q.jsxs)(Ce,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,Q.jsx)(R,{children:n}),g]}),_]})}):(0,Q.jsx)(ke,{open:e,onOpenChange:e=>!e&&t(),children:(0,Q.jsxs)(F,{side:`right`,className:`w-full sm:max-w-2xl md:max-w-3xl lg:max-w-4xl flex flex-col`,children:[(0,Q.jsxs)(ae,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,Q.jsx)(G,{children:n}),g]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-hidden mt-2`,children:_})]})})},ct=o;function lt(e,t,n){let r=[],i=[],a=new Set,o=new Set,s=new Map;return e.forEach((e,c)=>{let l=t.map(t=>String(e[t]??`∅`)).join(``),u=String(e[n]??`∅`);a.has(l)||(a.add(l),r.push({id:l,labels:t.map(t=>A(e[t]))})),o.has(u)||(o.add(u),i.push({id:u,label:A(e[n])})),s.set(`${l} ${u}`,c)}),{rowHeaders:r,colHeaders:i,cellIndex:s}}function ut(e){if(e==null)return``;let t=String(e);return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}function dt(e){return e.map(e=>e.map(ut).join(`,`)).join(`\r
|
|
1
|
+
import{o as e,r as t,t as n}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as r,g as i,t as a}from"./vendor-react-ClIa1CJA.js";import{$ as o,Dt as s,N as c,P as l,V as u,Y as d,Z as f,at as p,b as m,ct as h,dt as g,et as _,ft as v,i as y,it as b,kt as x,lt as S,m as C,mt as w,n as T,nt as E,ot as D,pt as ee,st as O,t as k,tt as A,ut as j}from"./framework-CakMZS2A.js";import{$ as M,$n as te,A as N,Ac as P,Bt as F,Cc as I,Ei as ne,F as re,Fc as ie,Gr as L,Ht as ae,I as oe,Jn as R,L as z,Lt as B,Mc as se,Ns as V,Oc as H,Or as ce,Pc as U,R as le,Ta as ue,Un as W,Ut as G,Vi as K,Wn as q,Xs as de,Y as J,Zo as fe,_ as pe,_c as Y,a as X,di as me,er as he,et as ge,f as _e,ho as ve,ji as ye,nr as be,nt as xe,o as Se,qn as Ce,rr as we,u as Te,vc as Ee,xr as De,za as Oe,zt as ke}from"./ui-components-BXvcyYmR.js";import{o as Ae,t as je}from"./vendor-ui-utils-C92Fl7BT.js";import{_ as Me,c as Ne,d as Pe,g as Fe,h as Ie,i as Le,n as Re,o as ze,p as Be,s as Ve,t as He}from"./vendor-dndkit-CJ-mJJuO.js";var Z=e(r(),1),Ue=e(i(),1),Q=a();function We(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&e.provider===`object`}function Ge(e,t){if(t==null||e==null||typeof e!=`number`||!Number.isFinite(e)||typeof t!=`number`||!Number.isFinite(t))return null;if(t===0)return e===0?{value:0,direction:`neutral`}:{value:100,direction:e>0?`up`:`down`};let n=e-t;if(n===0)return{value:0,direction:`neutral`};let r=Math.round(n/Math.abs(t)*100);return{value:Math.abs(r),direction:r>0?`up`:`down`}}var Ke=new Set([`id`,`organization_id`,`tenant_id`,`created_at`,`updated_at`,`created_by`,`updated_by`,`deleted_at`,`deleted_by`,`version`,`_id`,`__typename`]);function qe(e,t){return t&&(t.isSystem===!0||t.system===!0)?!0:Ke.has(e)}var Je=new Set([`select`,`picklist`,`dropdown`,`status`]),Ye=new Set([`currency`,`money`,`number`,`integer`,`decimal`,`float`,`percent`,`percentage`]);function Xe(e){let t={},n=e?.fields;if(!n)return t;if(Array.isArray(n))for(let e of n)e?.name&&(t[e.name]=e);else for(let[e,r]of Object.entries(n))t[e]={name:e,...r};return t}function Ze(e){let{accessorKey:t,label:n,def:r,objectName:i,fieldOptionLabel:a,overrides:o={}}=e,s=o.referenceTo??r?.referenceTo??(typeof r?.reference==`string`?r.reference:r?.reference?.to)??r?.target,c=o.options??r?.options;return i&&c&&a&&Je.has(r?.type)&&(c=c.map(e=>{if(e==null)return e;let n=typeof e==`object`?e.value:e,r=typeof e==`object`&&e.label||String(n);return{value:n,label:a(i,t,String(n),r),color:typeof e==`object`?e.color:void 0}})),{name:t,label:n,type:o.type??r?.type,options:c,referenceTo:s,format:o.format??r?.format,currency:o.currency??r?.currency??r?.defaultCurrency,decimals:o.decimals??r?.decimals??r?.precision??r?.scale}}function Qe(e){return Ye.has(e.type)||typeof e.format==`string`&&/^[\$¥€£]|%$|0/.test(e.format)}function $e(e,t,n){if(e==null||e===``)return``;let r=t.format;if(typeof r==`string`&&/^\$|¥|€|£/.test(r)&&typeof e==`number`){let i={$:`USD`,"¥":`JPY`,"€":`EUR`,"£":`GBP`}[r[0]];return X(e,t.currency||i||n)}if(typeof r==`string`&&/%/.test(r)&&typeof e==`number`){let t=(r.match(/0\.(0+)%/)||[,``])[1].length;return Te((e>1?e/100:e)*100,t)}return typeof r==`string`&&/[YMDHms]/.test(r)?Se(e,r):(0,Q.jsx)(_e(pe(t)),{value:e,field:t})}var et=[`name`,`title`,`label`,`subject`,`display_name`,`full_name`];function tt(e,t){if(t&&t.trim())return t;for(let t of et){let n=e[t];if(typeof n==`string`&&n.trim())return n}let n=e.id??e._id;return n==null?`Record`:String(n)}var nt=({record:e,objectName:t,objectSchema:n,fields:r,title:i,target:a=`drawer`,onClose:o})=>{let{fieldLabel:s,fieldOptionLabel:c}=ie(),{currency:l}=se(),u=(0,Z.useMemo)(()=>{if(!e)return[];let i=Xe(n),a;return a=r&&r.length>0?r:Object.keys(i).length>0?Object.keys(i).filter(e=>!qe(e,i[e])):Object.keys(e).filter(e=>!e.startsWith(`_`)&&!qe(e)),a.map(n=>{let r=i[n],a=n.charAt(0).toUpperCase()+n.slice(1).replace(/([A-Z])/g,` $1`).replace(/_/g,` `),o=t?s(t,n,a):a,u=Ze({accessorKey:n,label:o,def:r,objectName:t,fieldOptionLabel:c});return{key:n,label:o,node:$e(e[n],u,l),numeric:Qe(u)}})},[e,n,t,r,s,c,l]);if(!e)return null;let d=tt(e,i),f=(0,Q.jsx)(`dl`,{className:`divide-y divide-border/60`,"data-testid":`record-detail-body`,children:u.map(e=>(0,Q.jsxs)(`div`,{className:`grid grid-cols-3 gap-3 py-2.5`,children:[(0,Q.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground self-center`,children:e.label}),(0,Q.jsx)(`dd`,{className:`col-span-2 text-sm break-words ${e.numeric?`tabular-nums`:``}`,children:e.node===``||e.node==null?(0,Q.jsx)(`span`,{className:`text-muted-foreground/60`,children:`—`}):e.node})]},e.key))});return a===`dialog`?(0,Q.jsx)(W,{open:!0,onOpenChange:e=>!e&&o(),children:(0,Q.jsxs)(q,{className:`max-w-2xl`,children:[(0,Q.jsx)(Ce,{children:(0,Q.jsx)(R,{children:d})}),(0,Q.jsx)(`div`,{className:`max-h-[70vh] overflow-auto`,children:f})]})}):(0,Q.jsx)(ke,{open:!0,onOpenChange:e=>!e&&o(),children:(0,Q.jsxs)(F,{side:`right`,className:`w-full sm:max-w-md md:max-w-lg flex flex-col`,children:[(0,Q.jsx)(ae,{children:(0,Q.jsx)(G,{children:d})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-auto mt-2 pr-1`,children:f})]})})};function rt(e){return e.map(e=>typeof e==`string`?{header:e.replace(/_/g,` `).replace(/([A-Z])/g,` $1`).trim().replace(/\b\w/g,e=>e.toUpperCase()),accessorKey:e}:e)}function it(e,t){if(!t?.fields)return[];let n={};if(Array.isArray(t.fields))for(let e of t.fields)e?.name&&(n[e.name]=e);else for(let[e,r]of Object.entries(t.fields))n[e]={name:e,...r};let r=e=>e===`lookup`||e===`reference`||e===`master_detail`||e===`user`||e===`owner`,i=Array.isArray(e.columns)?e.columns:[],a=new Set;if(i.length>0){let e=i.map(e=>typeof e==`string`?e:e.accessorKey||e.name).filter(Boolean);for(let t of e){let e=n[t];e&&r(e.type)&&a.add(t)}}else for(let[e,t]of Object.entries(n))r(t?.type)&&a.add(e);return Array.from(a)}var at=({schema:e,dataSource:t,className:n})=>{let{currency:r}=se(),i=(0,Z.useContext)(d),a=t||i?.dataSource,o=f(e.bind),{fieldLabel:c,fieldOptionLabel:l}=ie(),p=`No data available`,m=`No data source available for`;try{let{t:e}=y(),t=e(`dashboard.noDataAvailable`);t&&t!==`dashboard.noDataAvailable`&&(p=t);let n=e(`dashboard.noDataSourceFor`);n&&n!==`dashboard.noDataSourceFor`&&(m=n)}catch{}let[h,_]=(0,Z.useState)([]),[v,b]=(0,Z.useState)(null),[x,S]=(0,Z.useState)(()=>!(Array.isArray(e.data)&&e.data.length>0)&&!!e.objectName),[C,w]=(0,Z.useState)(null),T=e.drillDown,E=ee(T)&&(T?.mode??`record`)===`record`,[D,O]=(0,Z.useState)(null),k=(0,Z.useCallback)(e=>{O(e??null)},[]);(0,Z.useEffect)(()=>{let t=!0;return e.objectName&&!o&&(!e.data||e.data.length===0)?(async()=>{if(!a||!e.objectName){t&&S(!1);return}t&&(S(!0),w(null));try{let n;if(typeof a.find==`function`){let t=it(e,v),r={$filter:g(e.filter)};t.length&&(r.$expand=t),n=s(await a.find(e.objectName,r))}else return;t&&_(n)}catch(e){console.error(`[ObjectDataTable] Fetch error:`,e),t&&w(e instanceof Error?e.message:`Failed to load data`)}finally{t&&S(!1)}})():t&&S(!1),()=>{t=!1}},[e.objectName,a,o,e.data,e.filter,v]),(0,Z.useEffect)(()=>{let t=!0;if(!(!a||!e.objectName||typeof a.getObjectSchema!=`function`))return a.getObjectSchema(e.objectName).then(e=>{t&&b(e)}).catch(()=>{}),()=>{t=!1}},[e.objectName,a]);let A=o||e.data||h,j=Array.isArray(A)?A:[],M=(0,Z.useMemo)(()=>{let t=e.objectName,n={};if(v?.fields){let e=v.fields;if(Array.isArray(e))for(let t of e)t?.name&&(n[t.name]=t);else for(let[t,r]of Object.entries(e))n[t]={name:t,...r}}let i=e=>{let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/([A-Z])/g,` $1`);return t?c(t,e,n):n},a=e=>{let i=Ze({accessorKey:e.accessorKey,label:e.header,def:n[e.accessorKey],objectName:t,fieldOptionLabel:l,overrides:{type:e.type,format:e.format,options:e.options,referenceTo:e.referenceTo,currency:e.currency,decimals:e.decimals}}),a=e.align??(Qe(i)?`right`:void 0);if(typeof e.cell==`function`)return{...e,...i,align:a};let o=e=>$e(e,i,r);return{...e,...i,align:a,cell:o}};if(e.columns&&e.columns.length>0){let n=rt(e.columns);return(t?n.map(e=>({...e,header:c(t,e.accessorKey,e.header)})):n).map(a)}return j.length===0?[]:(Object.keys(n).length>0?Object.keys(n).filter(e=>!qe(e,n[e])):Object.keys(j[0]).filter(e=>!e.startsWith(`_`)&&!qe(e))).map(e=>a({header:i(e),accessorKey:e}))},[e.columns,e.objectName,j,v,c,l,r]);if(x&&j.length===0)return(0,Q.jsx)(`div`,{className:H(`overflow-auto`,n),"data-testid":`table-loading`,children:(0,Q.jsxs)(`div`,{className:`space-y-2 p-2`,children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(B,{className:`h-6 w-1/4`}),(0,Q.jsx)(B,{className:`h-6 w-1/4`}),(0,Q.jsx)(B,{className:`h-6 w-1/4`}),(0,Q.jsx)(B,{className:`h-6 w-1/4`})]}),[1,2,3,4].map(e=>(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(B,{className:`h-5 w-1/4`}),(0,Q.jsx)(B,{className:`h-5 w-1/4`}),(0,Q.jsx)(B,{className:`h-5 w-1/4`}),(0,Q.jsx)(B,{className:`h-5 w-1/4`})]},e))]})});if(C)return(0,Q.jsx)(`div`,{className:H(`overflow-auto`,n),"data-testid":`table-error`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-destructive`,"data-testid":`table-error-message`,children:[(0,Q.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,className:`h-8 w-8 mb-2 opacity-60`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,Q.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]}),(0,Q.jsx)(`p`,{className:`text-xs`,children:C})]})});if(!a&&e.objectName&&j.length===0)return(0,Q.jsx)(`div`,{className:H(`overflow-auto`,n),children:(0,Q.jsx)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:(0,Q.jsxs)(`p`,{className:`text-xs`,children:[m,` “`,e.objectName,`”`]})})});if(j.length===0)return(0,Q.jsx)(`div`,{className:H(`overflow-auto`,n),"data-testid":`table-empty-state`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,Q.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,className:`h-8 w-8 mb-2 opacity-40`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,Q.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),(0,Q.jsx)(`line`,{x1:`3`,y1:`9`,x2:`21`,y2:`9`}),(0,Q.jsx)(`line`,{x1:`9`,y1:`21`,x2:`9`,y2:`9`})]}),(0,Q.jsx)(`p`,{className:`text-xs`,children:p})]})});let te={...e,type:`data-table`,data:j,columns:M,onRowClick:e.onRowClick??(E?k:void 0)},N=T?.title&&!T.title.includes("${")?T.title:void 0;return(0,Q.jsxs)(`div`,{className:H(`relative`,n),children:[(0,Q.jsx)(oe,{active:x&&j.length>0}),(0,Q.jsx)(u,{schema:te,className:n}),E&&(0,Q.jsx)(nt,{record:D,objectName:e.objectName,objectSchema:v,fields:T?.columns,title:N,target:T?.target===`dialog`?`dialog`:`drawer`,onClose:()=>O(null)})]})},ot=({objectName:e,filter:t,onNavigate:n,className:r})=>{let{openRecordList:i}=m(),a=T();return!i||!e?null:(0,Q.jsxs)(De,{type:`button`,variant:`ghost`,size:`sm`,className:r,"data-testid":`drill-open-in-list`,onClick:()=>{i(e,t),n?.()},children:[a(`dashboard.openInList`,`Open in list`),(0,Q.jsx)(Ee,{className:`ml-1 h-3.5 w-3.5`})]})},st=({open:e,onClose:t,title:n,target:r=`drawer`,objectName:i,filter:a,dataSource:o,columns:s,maxRows:c,className:l,report:d})=>{let{openRecordList:f}=m(),p=d&&typeof d==`object`&&(Array.isArray(d.columns)||`objectName`in d),h=r===`navigate`&&!!f&&!p&&!!i;if(Z.useEffect(()=>{e&&h&&(f(i,a),t())},[e,h]),h)return null;let g=p?null:(0,Q.jsx)(ot,{objectName:i,filter:a,onNavigate:t}),_=(0,Q.jsx)(`div`,{className:H(`overflow-auto`,l),"data-testid":`drill-down-body`,children:p?(()=>{let e=d.filter,t=e?a?{$and:[e,a]}:e:a;return(0,Q.jsx)(u,{schema:{...d,type:`spec-report`,report:{...d,filter:t},filter:t}})})():(0,Q.jsx)(at,{schema:{type:`object-data-table`,objectName:i,filter:a,columns:s?.map(e=>({accessorKey:e,header:e})),pagination:!0,searchable:!1,pageSize:c,drillDown:{enabled:!0,mode:`record`,target:`dialog`}},dataSource:o})});return r===`dialog`?(0,Q.jsx)(W,{open:e,onOpenChange:e=>!e&&t(),children:(0,Q.jsxs)(q,{className:`max-w-5xl`,children:[(0,Q.jsxs)(Ce,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,Q.jsx)(R,{children:n}),g]}),_]})}):(0,Q.jsx)(ke,{open:e,onOpenChange:e=>!e&&t(),children:(0,Q.jsxs)(F,{side:`right`,className:`w-full sm:max-w-2xl md:max-w-3xl lg:max-w-4xl flex flex-col`,children:[(0,Q.jsxs)(ae,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,Q.jsx)(G,{children:n}),g]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-hidden mt-2`,children:_})]})})},ct=o;function lt(e,t,n){let r=[],i=[],a=new Set,o=new Set,s=new Map;return e.forEach((e,c)=>{let l=t.map(t=>String(e[t]??`∅`)).join(``),u=String(e[n]??`∅`);a.has(l)||(a.add(l),r.push({id:l,labels:t.map(t=>A(e[t]))})),o.has(u)||(o.add(u),i.push({id:u,label:A(e[n])})),s.set(`${l} ${u}`,c)}),{rowHeaders:r,colHeaders:i,cellIndex:s}}function ut(e){if(e==null)return``;let t=String(e);return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}function dt(e){return e.map(e=>e.map(ut).join(`,`)).join(`\r
|
|
2
2
|
`)}function ft(e,t){if(typeof document>`u`)return;let n=e&&e.trim()?e.trim():`export`,r=new Blob([`${dt(t)}`],{type:`text/csv;charset=utf-8;`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=n.endsWith(`.csv`)?n:`${n}.csv`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}var pt=new Set([`metric`,`kpi`,`gauge`,`solid-gauge`,`bullet`]),mt={bar:`bar`,column:`column`,"horizontal-bar":`horizontal-bar`,"grouped-bar":`bar`,"stacked-bar":`bar`,"bi-polar-bar":`bar`,line:`line`,spline:`line`,"step-line":`line`,area:`area`,"stacked-area":`area`,pie:`pie`,donut:`donut`,funnel:`funnel`,pyramid:`funnel`,scatter:`scatter`,bubble:`scatter`,radar:`radar`,treemap:`treemap`,sankey:`sankey`};function ht({widget:e,dataSource:t}){let n=String(e?.dataset??``),r=(0,Z.useMemo)(()=>Array.isArray(e?.dimensions)?e.dimensions.filter(Boolean):[],[e]),i=(0,Z.useMemo)(()=>Array.isArray(e?.values)?e.values.filter(Boolean):[],[e]),a=e?.compareTo&&typeof e.compareTo==`object`?e.compareTo:void 0,o=String(e?.type??``),s=pt.has(o)||r.length===0,c=o===`table`||o===`pivot`,l=o===`pivot`&&r.length>=2,d=l?r.slice(0,-1):[],f=l?r[r.length-1]:``,m=l?[d,[f],[]]:void 0,v=T(),{fieldLabel:y}=ie(),x=e?.filter,S=(0,Z.useMemo)(()=>x&&typeof x==`object`&&Object.keys(x).length>0?g(x):void 0,[x]),[C,w]=(0,Z.useState)({status:`idle`,rows:[]}),[ee,k]=(0,Z.useState)(null),[j,M]=(0,Z.useState)(null),[te,N]=(0,Z.useState)(null);if((0,Z.useEffect)(()=>{let e=t;if(!e||typeof e.queryDataset!=`function`){w({status:`error`,rows:[],error:v(`dashboard.datasetUnsupported`,`This data source does not support dataset queries.`)});return}if(i.length===0){w({status:`idle`,rows:[]});return}let o=!1;return w({status:`loading`,rows:[]}),e.queryDataset(n,{dimensions:r,measures:i,...S?{runtimeFilter:S}:{},...a?{compareTo:a}:{},...m?{totals:{groupings:m}}:{}}).then(e=>{o||w({status:`ok`,rows:Array.isArray(e?.rows)?e.rows:[],fields:Array.isArray(e?.fields)?e.fields:[],object:e?.object,dimensionFields:e?.dimensionFields,drillRawRows:Array.isArray(e?.drillRawRows)?e.drillRawRows:void 0,totals:Array.isArray(e?.totals)?e.totals:void 0})}).catch(e=>{o||w({status:`error`,rows:[],error:String(e?.message??e)})}),()=>{o=!0}},[`${o}|${n}|${r.join(`,`)}|${i.join(`,`)}|${JSON.stringify(x??null)}|${JSON.stringify(a??null)}`]),(0,Z.useEffect)(()=>{if(s||c){M(null),N(null);return}let e=C.object;if(!e||r.length===0){M(null),N(null);return}let t=e=>C.dimensionFields&&C.dimensionFields[e]||e,n=!1;return(async()=>{try{let i=await(await fetch(`/api/v1/meta/object/${encodeURIComponent(e)}`,{headers:{accept:`application/json`},credentials:`include`})).json().catch(()=>null),a=i?.item??i?.data??i,o=D(a?.fields?.[t(r[0])]?.options),s={};for(let e of r){let n=p(a?.fields?.[t(e)]?.options);n&&(s[e]=n)}n||(M(o),N(Object.keys(s).length>0?s:null))}catch{n||(M(null),N(null))}})(),()=>{n=!0}},[C.object,C.dimensionFields,r,s,c]),i.length===0)return(0,Q.jsx)(`div`,{className:`flex h-full w-full items-center justify-center rounded border border-dashed bg-muted/20 p-4 text-xs text-muted-foreground`,children:v(`dashboard.pickMeasures`,`Pick measures (values) for this dataset widget.`)});if(C.status===`loading`||C.status===`idle`)return(0,Q.jsxs)(`div`,{className:`h-full w-full p-2`,"data-testid":`dataset-loading`,role:`status`,"aria-busy":`true`,"aria-live":`polite`,children:[(0,Q.jsx)(`span`,{className:`sr-only`,children:v(`dashboard.loading`,`Loading…`)}),s?(0,Q.jsxs)(`div`,{className:`flex h-full w-full flex-col items-start justify-center gap-2 p-2`,children:[(0,Q.jsx)(B,{className:`h-8 w-32 rounded`}),(0,Q.jsx)(B,{className:`h-3 w-20 rounded`})]}):c?(0,Q.jsx)(le,{className:`h-full`,rows:5,columns:Math.max(2,r.length+i.length)}):(0,Q.jsx)(z,{className:`h-full`})]});if(C.status===`error`)return(0,Q.jsxs)(`div`,{role:`alert`,className:`flex h-full w-full items-start gap-2 rounded border border-destructive/40 bg-destructive/5 p-3 text-xs text-destructive`,children:[(0,Q.jsx)(L,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`break-words`,children:C.error})]});if(C.rows.length===0&&!s)return(0,Q.jsxs)(`div`,{className:`flex h-full w-full items-center justify-center rounded border border-dashed bg-muted/20 p-4 text-xs text-muted-foreground`,children:[(0,Q.jsx)(de,{className:`mr-2 h-4 w-4`}),v(`dashboard.noRows`,`No rows`)]});let{measureField:P,headerLabel:F}=_(C.fields,C.object,y),{object:I,dimensionFields:ne,drillRawRows:re}=C,ae=ne?r.filter(e=>e in ne):[],oe=!!I&&ae.length>0,R=(t,n)=>{!I||!ne||k({filter:ct(re?.[t],ae,ne,S),title:n||String(e?.title??``)})},se=ee&&I?(0,Q.jsx)(st,{open:!0,onClose:()=>k(null),title:ee.title||String(e?.title??v(`dashboard.details`,`Details`)),objectName:I,filter:ee.filter,dataSource:t}):null;if(s){let e=P(i[0]);return(0,Q.jsxs)(`div`,{className:`flex h-full w-full flex-col items-start justify-center gap-1 p-2`,children:[(0,Q.jsx)(`span`,{className:`text-2xl font-semibold tabular-nums`,children:E(C.rows[0]?.[i[0]]??0,e?.format,e?.currency)}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:F(i[0])})]})}if(c){let t=[...r,...i],a=(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ft(String(e?.title??n??`export`),[t.map(e=>F(e)),...C.rows.map(e=>t.map(t=>{let n=e[t];return n==null?``:typeof n==`number`?n:String(n)}))]),"data-testid":`dataset-export`,title:v(`dashboard.exportCsv`,`Export CSV`),"aria-label":v(`dashboard.exportCsv`,`Export CSV`),className:`absolute right-1 top-1 z-10 rounded p-1 text-muted-foreground opacity-70 hover:bg-accent/50 hover:text-foreground hover:opacity-100`,children:(0,Q.jsx)(fe,{className:`h-3.5 w-3.5`})});if(l){let e=lt(C.rows,d,f),t=e.colHeaders.flatMap(e=>i.map(t=>({col:e,measure:t,header:i.length===1?e.label:`${e.label} · ${F(t)}`}))),n=(e,t)=>E(e,P(t)?.format,P(t)?.currency),r=e=>C.totals?.find(t=>Array.isArray(t.dimensions)&&t.dimensions.join(`,`)===e.join(`,`))?.rows,o=new Map;for(let e of r(d)??[])o.set(d.map(t=>String(e[t]??`∅`)).join(``),e);let s=new Map;for(let e of r([f])??[])s.set(String(e[f]??`∅`),e);let c=r([])?.[0],l=o.size>0,u=s.size>0,p=v(`dashboard.total`,`Total`);return(0,Q.jsxs)(`div`,{className:`relative h-full w-full overflow-auto p-1`,"data-testid":`dataset-matrix`,children:[a,(0,Q.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Q.jsx)(`thead`,{className:`bg-muted/40`,children:(0,Q.jsxs)(`tr`,{children:[d.map(e=>(0,Q.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:F(e)},e)),t.map(e=>(0,Q.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,children:e.header},`${e.col.id}-${e.measure}`)),l&&i.map(e=>(0,Q.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,"data-testid":`matrix-total-col-header`,children:i.length===1?p:`${p} · ${F(e)}`},`total-${e}`))]})}),(0,Q.jsxs)(`tbody`,{children:[e.rowHeaders.map(r=>(0,Q.jsxs)(`tr`,{className:`border-t`,children:[r.labels.map((e,t)=>(0,Q.jsx)(`td`,{className:`px-2 py-1 whitespace-nowrap font-medium`,children:e},t)),t.map(t=>{let i=e.cellIndex.get(`${r.id} ${t.col.id}`),a=i==null?void 0:C.rows[i],o=oe&&i!=null,s=[...r.labels,t.col.label].filter(Boolean).join(` / `);return(0,Q.jsx)(`td`,{className:H(`px-2 py-1 text-right tabular-nums whitespace-nowrap`,o&&`cursor-pointer hover:bg-accent/40`),"data-testid":o?`dataset-drill-cell`:void 0,onClick:o?()=>R(i,s):void 0,children:a?n(a[t.measure],t.measure):`—`},`${t.col.id}-${t.measure}`)}),l&&i.map(e=>(0,Q.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap font-medium`,"data-testid":`matrix-row-total`,children:n(o.get(r.id)?.[e],e)},`total-${e}`))]},r.id)),u&&(0,Q.jsxs)(`tr`,{className:`border-t bg-muted/30 font-medium`,"data-testid":`matrix-total-row`,children:[d.length>0&&(0,Q.jsx)(`td`,{colSpan:d.length,className:`px-2 py-1 whitespace-nowrap`,children:p}),t.map(e=>(0,Q.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,children:n(s.get(e.col.id)?.[e.measure],e.measure)},`${e.col.id}-${e.measure}`)),l&&i.map(e=>(0,Q.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,"data-testid":`matrix-grand-total`,children:n(c?.[e],e)},`grand-${e}`))]})]})]}),se]})}let o=[...r,...i];return(0,Q.jsxs)(`div`,{className:`relative h-full w-full overflow-auto p-1`,children:[a,(0,Q.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Q.jsx)(`thead`,{className:`bg-muted/40`,children:(0,Q.jsx)(`tr`,{children:o.map(e=>(0,Q.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:F(e)},e))})}),(0,Q.jsx)(`tbody`,{children:C.rows.map((e,t)=>(0,Q.jsx)(`tr`,{className:H(`border-t`,oe&&`cursor-pointer hover:bg-accent/40`),"data-testid":oe?`dataset-drill-row`:void 0,onClick:oe?()=>R(t,ae.map(t=>A(e[t])).filter(Boolean).join(` / `)):void 0,children:o.map(t=>(0,Q.jsx)(`td`,{className:`px-2 py-1 whitespace-nowrap tabular-nums`,children:i.includes(t)?E(e[t],P(t)?.format,P(t)?.currency):A(e[t])},t))},t))})]}),se]})}let V=mt[o]??`bar`,ce=h(C.rows,te),{data:U,xAxisKey:ue,series:W}=b(ce,r,i,C.fields),G=oe?e=>{let t=O(ce,r,i,e?.category,e?.series);if(t<0)return;let n=r.length>=2&&i.length===1;R(t,[e?.category,n?e?.series:void 0].filter(Boolean).map(String).join(` / `))}:void 0;return(0,Q.jsxs)(`div`,{className:H(`relative h-full w-full min-h-[220px]`),children:[(0,Q.jsx)(u,{schema:{type:`chart`,chartType:V,data:U,xAxisKey:ue,series:W,...j?{categoryColors:j}:{}},onChartClick:G,onSegmentClick:G}),se]})}function gt({id:e,disabled:t,gridSpan:n,className:r,children:i}){let{attributes:a,listeners:o,setNodeRef:s,transform:c,transition:l,isDragging:u,isOver:d}=ze({id:e,disabled:t});return(0,Q.jsx)(`div`,{ref:s,style:{transform:Me.Transform.toString(c),transition:l,opacity:u?.4:1,...n?{gridColumn:`span ${n.w}`,gridRow:`span ${n.h}`}:{}},className:H(`h-full w-full`,r,!t&&`cursor-grab active:cursor-grabbing`,d&&!u&&`ring-2 ring-primary ring-offset-2 rounded-lg`),"data-sortable-widget-id":e,...a,...o,children:i})}function _t(e){return e?xe(e):null}function vt(e){if(e!=null)return typeof e==`string`?e:e.defaultValue||e.key}var yt=[`hsl(var(--chart-1))`,`hsl(var(--chart-2))`,`hsl(var(--chart-3))`,`hsl(var(--chart-4))`,`hsl(var(--chart-5))`],bt={column:`bar`,"stacked-bar":`bar`,"grouped-bar":`bar`,"bi-polar-bar":`bar`,spline:`line`,"step-line":`line`,"stacked-area":`area`,pyramid:`funnel`,bubble:`scatter`},xt=new Set([`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`scatter`,`funnel`,`radar`,`treemap`,`sankey`]),St=new Set([`gauge`,`solid-gauge`,`kpi`,`bullet`]),Ct=new Set([`sunburst`,`word-cloud`,`choropleth`,`bubble-map`,`gl-map`,`heatmap`,`waterfall`,`box-plot`,`violin`,`candlestick`,`stock`]),wt=new Set([`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`funnel`,`scatter`,`treemap`,`sankey`]);function Tt(e){return wt.has(e)?{enabled:!0}:void 0}var Et=(0,Z.forwardRef)(({schema:e,className:t,dataSource:n,onRefresh:r,recordCount:i,userActions:a,designMode:o,selectedWidgetId:s,onWidgetClick:c,onWidgetsReorder:l,modalHandler:d,scriptHandlers:f,hideHeaderText:p,...m},h)=>{let g=(()=>{if(e.columns!=null)return e.columns;let t=e.widgets??[],n=0;for(let e of t){let t=(e.layout?.x??0)+(e.layout?.w??0);t>n&&(n=t),(e.layout?.w??0)>n&&(n=e.layout.w)}return n>4?12:4})(),_=g,v=e.gap||4,b=e.columns!=null||g!==4,[x,S]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(!1),E=(0,Z.useRef)(null),{executeAction:D,engine:ee}=C({actions:(0,Z.useMemo)(()=>(e.header?.actions??[]).map(e=>({name:e.actionUrl||e.label,type:e.actionType||`url`,target:e.actionUrl,label:e.label})),[e.header?.actions])}),{dashboardLabel:O,dashboardDescription:k,dashboardActionLabel:A,widgetTitle:j,widgetDescription:M,fieldLabel:N}=U(),{t:P}=y(),F=(0,Z.useCallback)((e,t,n)=>n&&(!t||t===`value`||t===`count`||n===`count`)?P(`report.aggregate.${n}`,{defaultValue:n}):e?N(e,t,t):t,[P,N]),I=e.name,ne=(0,Z.useCallback)(e=>I?A(I,e.actionUrl||e.label,e.label):e.label,[I,A]),re=(0,Z.useCallback)(e=>{let t=vt(e.title);return!I||!e.id||t===void 0?t:j(I,e.id,t)},[I,j]),ie=(0,Z.useCallback)(e=>{let t=vt(e.description);return!I||!e.id?t:M(I,e.id,t)},[I,M]);(0,Z.useEffect)(()=>{let e=ee.getRunner();if(d&&e.setModalHandler(d),f)for(let[t,n]of Object.entries(f))e.registerScript(t,n)},[ee,d,f]),(0,Z.useEffect)(()=>{let e=()=>T(window.innerWidth<768);return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let L=(0,Z.useCallback)(()=>{r&&(S(!0),r(),setTimeout(()=>S(!1),600))},[r]);(0,Z.useEffect)(()=>{if(!(!e.refreshInterval||e.refreshInterval<=0||!r))return E.current=setInterval(L,e.refreshInterval*1e3),()=>{E.current&&clearInterval(E.current)}},[e.refreshInterval,r,L]);let ae=(0,Z.useCallback)((e,t)=>{!o||!c||!t||(e.stopPropagation(),c(t))},[o,c]),oe=(0,Z.useCallback)((t,n,r)=>{if(!o||!c)return;let i=e.widgets||[];if(t.key===`Enter`||t.key===` `)t.preventDefault(),c(n??null);else if(t.key===`ArrowRight`||t.key===`ArrowDown`){t.preventDefault();let e=r+1<i.length?i[r+1]:null;e?.id&&c(e.id)}else if(t.key===`ArrowLeft`||t.key===`ArrowUp`){t.preventDefault();let e=r-1>=0?i[r-1]:null;e?.id&&c(e.id)}else t.key===`Escape`&&(t.preventDefault(),c(null))},[o,c,e.widgets]),R=(0,Z.useCallback)(e=>{!o||!c||e.target===e.currentTarget&&c(null)},[o,c]),z=!!(o&&l),B=Fe(Ie(Pe,{activationConstraint:{distance:5}})),se=(0,Z.useCallback)(t=>{if(!z)return;let{active:n,over:r}=t;if(!r||n.id===r.id)return;let i=e.widgets??[],a=i.findIndex(e=>e.id===n.id),o=i.findIndex(e=>e.id===r.id);a<0||o<0||l?.(Re(i,a,o))},[z,e.widgets,l]),V=(e,t,r)=>{let i=e.type===`metric`||St.has(e.type||``),a=b?{w:Math.min(i?3:6,_),h:i?2:4}:void 0,c=e.layout??a,l=c?{...c,w:Math.min(c.w,_)}:void 0,d=!!e.dataset,f=(()=>{if(e.component)return e.component;let t=e.type,n=e.options||{};if(t===`metric`&&e.object){let t=n.data,r=We(t)&&t.aggregate?{field:e.valueField||t.aggregate.field,function:e.aggregate||t.aggregate.function,groupBy:e.categoryField??t.aggregate.groupBy??`_all`}:e.aggregate?{field:e.valueField||`value`,function:e.aggregate,groupBy:e.categoryField||`_all`}:void 0;return{type:`object-metric`,objectName:e.object||(We(t)?t.object:void 0),aggregate:r,filter:(We(t)?t.filter:void 0)||e.filter,label:n.label||re(e)||``,fallbackValue:n.value,trend:n.trend,icon:n.icon,description:n.description,colorVariant:e.colorVariant,format:n.format,currency:n.currency,prefix:n.prefix,suffix:n.suffix,drillDown:n.drillDown??{enabled:!0},title:n.label||re(e)||``,compareTo:e.compareTo}}if(St.has(t||``)&&e.object){let t=e.aggregate?{field:e.valueField||`value`,function:e.aggregate,groupBy:e.categoryField||`_all`}:void 0;return{type:`object-metric`,objectName:e.object,aggregate:t,filter:e.filter,label:n.label||re(e)||``,fallbackValue:n.fallbackValue??n.value,icon:n.icon,description:n.description,colorVariant:e.colorVariant,format:n.format,currency:n.currency,prefix:n.prefix,suffix:n.suffix,invert:n.invert,compareTo:e.compareTo}}let r=t&&bt[t]||t;if(r&&xt.has(r)){let t=e.data||n.data,i=e.categoryField||n.xField||`name`,a=e.valueField||n.yField||`value`;if(We(t)){let o=t.aggregate,s=(()=>{let t=e.categoryField||o?.groupBy;if(t)return e.categoryGranularity&&typeof t==`string`?{field:t,dateGranularity:e.categoryGranularity}:t})(),c=o?{field:e.valueField||o.field,function:e.aggregate||o.function,groupBy:s}:void 0,l=c?.field||a,u=e.object||t.object;return{type:`object-chart`,chartType:r,objectName:u,aggregate:c,filter:t.filter||e.filter,xAxisKey:i,series:[{dataKey:l,label:F(u,l,c?.function)}],colors:yt,drillDown:n.drillDown??Tt(r),compareTo:e.compareTo,className:`h-[200px] sm:h-[250px] md:h-[300px]`}}if(!t&&e.object){let t=e.categoryField||`name`,a=e.categoryGranularity?{field:t,dateGranularity:e.categoryGranularity}:t,o=e.aggregate?{field:e.valueField||`value`,function:e.aggregate,groupBy:a}:void 0,s=e.valueField||`value`;return{type:`object-chart`,chartType:r,objectName:e.object,aggregate:o,filter:e.filter,xAxisKey:i,series:[{dataKey:s,label:F(e.object,s,e.aggregate)}],colors:yt,drillDown:n.drillDown??Tt(r),compareTo:e.compareTo,className:`h-[200px] sm:h-[250px] md:h-[300px]`}}return{type:`chart`,chartType:r,data:Array.isArray(t)?t:t?.items||[],xAxisKey:i,series:[{dataKey:a,label:F(e.object,a,e.aggregate)}],colors:yt,className:`h-[200px] sm:h-[250px] md:h-[300px]`}}if(t===`table`){let t=e.data||n.data,r=We(t)||!t&&e.object?n.drillDown??{enabled:!0,mode:`record`}:void 0;if(We(t)){let{data:i,...a}=n;return{type:`object-data-table`,...a,objectName:e.object||t.object,dataProvider:t,filter:t.filter||e.filter,searchable:e.searchable??!1,pagination:e.pagination??!1,drillDown:r,className:`border-0`}}return!t&&e.object?{type:`object-data-table`,...n,objectName:e.object,filter:e.filter,searchable:e.searchable??!1,pagination:e.pagination??!1,drillDown:r,className:`border-0`}:{type:`data-table`,...n,data:t?.items||[],searchable:!1,pagination:!1,className:`border-0`}}if(t===`pivot`){let t=e.data||n.data,r=e,i={rowField:r.rowField??n.rowField,columnField:r.columnField??n.columnField,valueField:r.valueField??n.valueField,aggregation:r.aggregation??n.aggregation??`sum`,showRowTotals:r.showRowTotals??n.showRowTotals,showColumnTotals:r.showColumnTotals??n.showColumnTotals,format:r.format??n.format},a=(We(t)||!t&&e.object)&&n.drillDown===void 0?{...n,drillDown:{enabled:!0}}:n;if(We(t)){let{data:n,...r}=a;return{type:`object-pivot`,...r,...i,objectName:e.object||t.object,dataProvider:t,filter:t.filter||e.filter}}return!t&&e.object?{type:`object-pivot`,...a,...i,objectName:e.object,filter:e.filter}:{type:`pivot`,...n,...i,data:Array.isArray(t)?t:t?.items||[]}}if(t===`list`){let t=e.data||n.data,r=We(t)||!t&&e.object?n.drillDown??{enabled:!0,mode:`record`}:void 0;if(We(t)){let{data:i,...a}=n;return{type:`object-data-table`,...a,objectName:e.object||t.object,dataProvider:t,filter:t.filter||e.filter,searchable:!1,pagination:!1,drillDown:r,className:`border-0`}}return!t&&e.object?{type:`object-data-table`,...n,objectName:e.object,filter:e.filter,searchable:!1,pagination:!1,drillDown:r,className:`border-0`}:{type:`data-table`,...n,data:Array.isArray(t)?t:t?.items||[],searchable:!1,pagination:!1,className:`border-0`}}return t===`custom`?{type:`text`,value:"Custom widget — set `component` to a UIComponent schema.",variant:`caption`,align:`center`,className:`flex h-full w-full items-center justify-center rounded border border-dashed bg-muted/20 p-4 text-muted-foreground`}:t&&Ct.has(t)?{type:`text`,value:`「${t}」chart type is not supported yet`,variant:`caption`,align:`center`,className:`flex h-full w-full items-center justify-center rounded border border-dashed bg-muted/20 p-4 text-muted-foreground`}:{...e,...n}})(),p=e.type===`metric`&&!d,m=re(e),h=ie(e),g=e.id||m||`widget-${t}`,v=o&&s===e.id,y=o?{"data-testid":`dashboard-preview-widget-${e.id}`,"data-widget-id":e.id,role:`button`,tabIndex:0,"aria-selected":v,"aria-label":`Widget: ${m||`Widget ${t+1}`}`,onClick:t=>ae(t,e.id),onKeyDown:n=>oe(n,e.id,t)}:{},x=o?H(`cursor-pointer rounded-lg transition-all outline-none`,`focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,v?`ring-2 ring-primary shadow-md bg-primary/5 dark:bg-primary/10`:`hover:ring-2 hover:ring-primary/40 hover:shadow-sm`):void 0,S=!w&&l&&!z?{gridColumn:`span ${l.w}`,gridRow:`span ${l.h}`}:void 0,C=p?(0,Q.jsxs)(`div`,{className:H(`h-full w-full`,o&&`relative`,x),style:S,...y,children:[d?(0,Q.jsx)(`div`,{className:H(`h-full w-full`,o&&`pointer-events-none`),children:(0,Q.jsx)(ht,{widget:e,dataSource:n})}):(0,Q.jsx)(u,{schema:f,className:H(`h-full w-full`,o&&`pointer-events-none`),dataSource:n}),o&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-10`,"aria-hidden":`true`,"data-testid":`widget-click-overlay`})]}):(0,Q.jsxs)(te,{className:H(`overflow-hidden border-border/50 shadow-sm transition-all hover:shadow-md`,`bg-card/50 backdrop-blur-sm`,r&&`w-full`,o&&`relative`,x),style:S,...y,children:[m&&(0,Q.jsxs)(be,{className:`pb-2 border-b border-border/40 bg-muted/20 px-3 sm:px-6`,children:[(0,Q.jsx)(we,{className:`text-sm sm:text-base font-medium tracking-tight truncate`,title:m,children:m}),h&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5 line-clamp-2`,children:h})]}),(0,Q.jsx)(he,{className:`p-0`,children:(0,Q.jsx)(`div`,{className:H(`h-full w-full`,`p-3 sm:p-4 md:p-6`,o&&`pointer-events-none`),children:d?(0,Q.jsx)(ht,{widget:e,dataSource:n}):(0,Q.jsx)(u,{schema:f,dataSource:n})})}),o&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-10`,"aria-hidden":`true`,"data-testid":`widget-click-overlay`})]});return z&&e.id?(0,Q.jsx)(gt,{id:e.id,gridSpan:!w&&l?{w:l.w,h:l.h}:void 0,children:C},g):(0,Q.jsx)(Z.Fragment,{children:C},g)},ce=e.header&&(0,Q.jsxs)(`div`,{className:`col-span-full mb-4`,children:[!p&&e.header.showTitle!==!1&&e.title&&(0,Q.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:I?O({name:I,label:vt(e.title)}):vt(e.title)}),!p&&e.header.showDescription!==!1&&e.description&&(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:I?k({name:I,description:vt(e.description)}):vt(e.description)}),e.header.actions&&e.header.actions.length>0&&(0,Q.jsx)(`div`,{className:`flex gap-2 mt-3`,children:e.header.actions.map((e,t)=>{let n=_t(e.icon);return(0,Q.jsxs)(De,{variant:`outline`,size:`sm`,onClick:async()=>{let{actionType:t,actionUrl:n,label:r}=e;if(!t||!n){console.warn(`[DashboardRenderer] Header action missing actionType/actionUrl:`,e);return}if(t===`url`){/^https?:\/\//.test(n)||n.startsWith(`//`)?window.location.assign(n):(window.history.pushState({},``,n),window.dispatchEvent(new PopStateEvent(`popstate`)));return}if(t===`modal`||t===`script`){let e=await D(n||r);e?.success||console.warn(`[DashboardRenderer] action failed`,e?.error);return}console.warn(`[DashboardRenderer] Unknown header actionType="${t}" for "${r}"`)},children:[n&&(0,Q.jsx)(n,{className:`w-4 h-4 mr-1.5`}),ne(e)]},t)})})]}),le=i!==void 0&&(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[i.toLocaleString(),` records`]}),ue=a?JSON.stringify(a):void 0,W=r&&(0,Q.jsxs)(`div`,{className:H(`flex items-center justify-end gap-3 mb-2`,!w&&`col-span-full`),children:[le,(0,Q.jsxs)(De,{variant:`outline`,size:`sm`,onClick:L,disabled:x,"aria-label":`Refresh dashboard`,children:[(0,Q.jsx)(K,{className:H(`h-4 w-4 mr-2`,x&&`animate-spin`)}),x?`Refreshing…`:`Refresh All`]})]}),G=(0,Z.useMemo)(()=>(e.widgets??[]).map(e=>e.id).filter(e=>!!e),[e.widgets]),q=(0,Z.useMemo)(()=>(e.widgets??[]).filter(e=>e.type===`metric`).map(e=>e.id).filter(e=>!!e),[e.widgets]),de=(0,Z.useMemo)(()=>(e.widgets??[]).filter(e=>e.type!==`metric`).map(e=>e.id).filter(e=>!!e),[e.widgets]);if(w){let n=e.widgets?.filter(e=>e.type===`metric`)||[],r=e.widgets?.filter(e=>e.type!==`metric`)||[],i=(0,Q.jsxs)(`div`,{ref:h,className:H(`flex flex-col gap-4 px-4`,t),"data-user-actions":ue,onClick:R,...m,children:[ce,W,n.length>0&&(0,Q.jsx)(`div`,{className:`grid grid-cols-2 gap-3`,onClick:R,children:(0,Q.jsx)(He,{items:q,strategy:Le,disabled:!z,children:n.map((e,t)=>V(e,t))})}),r.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-col gap-4`,onClick:R,children:(0,Q.jsx)(He,{items:de,strategy:Ve,disabled:!z,children:r.map((e,t)=>V(e,t,!0))})})]});return z?(0,Q.jsx)(Ne,{sensors:B,collisionDetection:Be,onDragEnd:se,children:i}):i}let J=(0,Q.jsxs)(`div`,{ref:h,className:H(`grid`,!b&&`auto-rows-min grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,t),style:{...b&&{gridTemplateColumns:`repeat(${_}, minmax(0, 1fr))`,gridAutoRows:`minmax(5rem, auto)`},gap:`${v*.25}rem`},"data-user-actions":ue,onClick:R,...m,children:[ce,W,(0,Q.jsx)(He,{items:G,strategy:Le,disabled:!z,children:e.widgets?.map((e,t)=>V(e,t))})]});return z?(0,Q.jsx)(Ne,{sensors:B,collisionDetection:Be,onDragEnd:se,children:J}):J});function Dt(e){let{margin:t,containerPadding:n,containerWidth:r,cols:i}=e;return(r-t[0]*(i-1)-n[0]*2)/i}function Ot(e,t,n){return Number.isFinite(e)?Math.round(t*e+Math.max(0,e-1)*n):e}function kt(e,t,n,r,i,a,o){let{margin:s,containerPadding:c,rowHeight:l}=e,u=Dt(e),d,f,p,m;if(o?(d=Math.round(o.width),f=Math.round(o.height)):(d=Ot(r,u,s[0]),f=Ot(i,l,s[1])),a?(p=Math.round(a.top),m=Math.round(a.left)):o?(p=Math.round(o.top),m=Math.round(o.left)):(p=Math.round((l+s[1])*n+c[1]),m=Math.round((u+s[0])*t+c[0])),!a&&!o){if(Number.isFinite(r)){let e=Math.round((u+s[0])*(t+r)+c[0])-m-d;e!==s[0]&&(d+=e-s[0])}if(Number.isFinite(i)){let e=Math.round((l+s[1])*(n+i)+c[1])-p-f;e!==s[1]&&(f+=e-s[1])}}return{top:p,left:m,width:d,height:f}}function At(e,t,n,r,i){let{margin:a,containerPadding:o,cols:s,rowHeight:c,maxRows:l}=e,u=Dt(e),d=Math.round((n-o[0])/(u+a[0])),f=Math.round((t-o[1])/(c+a[1]));return d=Nt(d,0,s-r),f=Nt(f,0,l-i),{x:d,y:f}}function jt(e,t,n){let{margin:r,containerPadding:i,rowHeight:a}=e,o=Dt(e);return{x:Math.round((n-i[0])/(o+r[0])),y:Math.round((t-i[1])/(a+r[1]))}}function Mt(e,t,n){let{margin:r,rowHeight:i}=e,a=Dt(e);return{w:Math.max(1,Math.round((t+r[0])/(a+r[0]))),h:Math.max(1,Math.round((n+r[1])/(i+r[1])))}}function Nt(e,t,n){return Math.max(Math.min(e,n),t)}function Pt(e,t){return!(e.i===t.i||e.x+e.w<=t.x||e.x>=t.x+t.w||e.y+e.h<=t.y||e.y>=t.y+t.h)}function Ft(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0&&Pt(r,t))return r}}function It(e,t){return e.filter(e=>Pt(e,t))}function Lt(e,t){return t===`horizontal`?zt(e):t===`vertical`||t===`wrap`?Rt(e):[...e]}function Rt(e){return[...e].sort((e,t)=>e.y===t.y?e.x-t.x:e.y-t.y)}function zt(e){return[...e].sort((e,t)=>e.x===t.x?e.y-t.y:e.x-t.x)}function Bt(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0){let e=r.y+r.h;e>t&&(t=e)}}return t}function Vt(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(r!==void 0&&r.i===t)return r}}function Ht(e){return e.filter(e=>e.static===!0)}function Ut(e){return{i:e.i,x:e.x,y:e.y,w:e.w,h:e.h,minW:e.minW,maxW:e.maxW,minH:e.minH,maxH:e.maxH,moved:!!e.moved,static:!!e.static,isDraggable:e.isDraggable,isResizable:e.isResizable,resizeHandles:e.resizeHandles,constraints:e.constraints,isBounded:e.isBounded}}function Wt(e){let t=Array(e.length);for(let n=0;n<e.length;n++){let r=e[n];r!==void 0&&(t[n]=Ut(r))}return t}function Gt(e,t){let n=Array(e.length);for(let r=0;r<e.length;r++){let i=e[r];i!==void 0&&(t.i===i.i?n[r]=t:n[r]=i)}return n}function Kt(e,t,n){let r=Vt(e,t);return r?(r=n(Ut(r)),[Gt(e,r),r]):[[...e],null]}function qt(e,t){let n=Ht(e);for(let r=0;r<e.length;r++){let i=e[r];if(i!==void 0)if(i.x+i.w>t.cols&&(i.x=t.cols-i.w),i.x<0&&(i.x=0,i.w=t.cols),!i.static)n.push(i);else for(;Ft(n,i);)i.y++}return e}function Jt(e,t,n,r,i,a,o,s,c){if(t.static&&t.isDraggable!==!0||t.y===r&&t.x===n)return[...e];let l=t.x,u=t.y;typeof n==`number`&&(t.x=n),typeof r==`number`&&(t.y=r),t.moved=!0;let d=Lt(e,o);(o===`vertical`&&typeof r==`number`?u>=r:o===`horizontal`&&typeof n==`number`&&l>=n)&&(d=d.reverse());let f=It(d,t),p=f.length>0;if(p&&c)return Wt(e);if(p&&a)return t.x=l,t.y=u,t.moved=!1,e;let m=[...e];for(let e=0;e<f.length;e++){let n=f[e];n!==void 0&&(n.moved||(m=n.static?Yt(m,n,t,i,o):Yt(m,t,n,i,o)))}return m}function Yt(e,t,n,r,i,a){let o=i===`horizontal`,s=i===`vertical`,c=t.static;if(r){r=!1;let a={x:o?Math.max(t.x-n.w,0):n.x,y:s?Math.max(t.y-n.h,0):n.y,w:n.w,h:n.h,i:`-1`},l=Ft(e,a),u=l!==void 0&&l.y+l.h>t.y,d=l!==void 0&&t.x+t.w>l.x;if(!l)return Jt(e,n,o?a.x:void 0,s?a.y:void 0,r,c,i);if(u&&s)return Jt(e,n,void 0,n.y+1,r,c,i);if(u&&i===null)return t.y=n.y,n.y+=n.h,[...e];if(d&&o)return Jt(e,t,n.x,void 0,r,c,i)}let l=o?n.x+1:void 0,u=s?n.y+1:void 0;return l===void 0&&u===void 0?[...e]:Jt(e,n,l,u,r,c,i)}function Xt(e,t,n){return Math.max(t,Math.min(n,e))}var Zt=[{name:`gridBounds`,constrainPosition(e,t,n,{cols:r,maxRows:i}){return{x:Xt(t,0,Math.max(0,r-e.w)),y:Xt(n,0,Math.max(0,i-e.h))}},constrainSize(e,t,n,r,{cols:i,maxRows:a}){let o=r===`w`||r===`nw`||r===`sw`?e.x+e.w:i-e.x,s=r===`n`||r===`nw`||r===`ne`?e.y+e.h:a-e.y;return{w:Xt(t,1,Math.max(1,o)),h:Xt(n,1,Math.max(1,s))}}},{name:`minMaxSize`,constrainSize(e,t,n){return{w:Xt(t,e.minW??1,e.maxW??1/0),h:Xt(n,e.minH??1,e.maxH??1/0)}}}];function Qt(e,t,n,r,i){let a={x:n,y:r};for(let n of e)n.constrainPosition&&(a=n.constrainPosition(t,a.x,a.y,i));if(t.constraints)for(let e of t.constraints)e.constrainPosition&&(a=e.constrainPosition(t,a.x,a.y,i));return a}function $t(e,t,n,r,i,a){let o={w:n,h:r};for(let n of e)n.constrainSize&&(o=n.constrainSize(t,o.w,o.h,i,a));if(t.constraints)for(let e of t.constraints)e.constrainSize&&(o=e.constrainSize(t,o.w,o.h,i,a));return o}function en({top:e,left:t,width:n,height:r}){let i=`translate(${t}px,${e}px)`;return{transform:i,WebkitTransform:i,MozTransform:i,msTransform:i,OTransform:i,width:`${n}px`,height:`${r}px`,position:`absolute`}}function tn({top:e,left:t,width:n,height:r}){return{top:`${e}px`,left:`${t}px`,width:`${n}px`,height:`${r}px`,position:`absolute`}}function nn(e){return e*100+`%`}function rn(e,t,n,r){return e+n>r?t:n}function an(e,t,n){return e<0?t:n}function on(e){return Math.max(0,e)}function sn(e){return Math.max(0,e)}var cn=(e,t,n)=>{let{left:r,height:i,width:a}=t,o=e.top-(i-e.height);return{left:r,width:a,height:an(o,e.height,i),top:sn(o)}},ln=(e,t,n)=>{let{top:r,left:i,height:a,width:o}=t;return{top:r,height:a,width:rn(e.left,e.width,o,n),left:on(i)}},un=(e,t,n)=>{let{top:r,height:i,width:a}=t,o=e.left+e.width-a;return o<0?{height:i,width:e.left+e.width,top:sn(r),left:0}:{height:i,width:a,top:sn(r),left:o}},dn=(e,t,n)=>{let{top:r,left:i,height:a,width:o}=t;return{width:o,left:i,height:an(r,e.height,a),top:sn(r)}},fn={n:cn,ne:(e,t,n)=>cn(e,ln(e,t,n)),e:ln,se:(e,t,n)=>dn(e,ln(e,t,n)),s:dn,sw:(e,t,n)=>dn(e,un(e,t)),w:un,nw:(e,t,n)=>cn(e,un(e,t))};function pn(e,t,n,r){let i=fn[e];return i?i(t,{...t,...n},r):n}var mn={type:`transform`,scale:1,calcStyle(e){return en(e)}},hn={cols:12,rowHeight:150,margin:[10,10],containerPadding:null,maxRows:1/0},gn={enabled:!0,bounded:!1,threshold:3},_n={enabled:!0,handles:[`se`]},vn={enabled:!1,defaultItem:{w:1,h:1}};function yn(e,t,n,r,i){let a=r===`x`?`w`:`h`;t[r]+=1;let o=e.findIndex(e=>e.i===t.i),s=i??Ht(e).length>0;for(let i=o+1;i<e.length;i++){let o=e[i];if(o!==void 0&&!o.static){if(!s&&o.y>t.y+t.h)break;Pt(t,o)&&yn(e,o,n+t[a],r,s)}}t[r]=n}function bn(e,t,n,r){for(t.x=Math.max(t.x,0),t.y=Math.max(t.y,0),t.y=Math.min(r,t.y);t.y>0&&!Ft(e,t);)t.y--;let i;for(;(i=Ft(e,t))!==void 0;)yn(n,t,i.y+i.h,`y`);return t.y=Math.max(t.y,0),t}function xn(e,t,n,r){for(t.x=Math.max(t.x,0),t.y=Math.max(t.y,0);t.x>0&&!Ft(e,t);)t.x--;let i;for(;(i=Ft(e,t))!==void 0;)if(yn(r,t,i.x+i.w,`x`),t.x+t.w>n)for(t.x=n-t.w,t.y++;t.x>0&&!Ft(e,t);)t.x--;return t.x=Math.max(t.x,0),t}var Sn={type:`vertical`,allowOverlap:!1,compact(e,t){let n=Ht(e),r=Bt(n),i=Rt(e),a=Array(e.length);for(let t=0;t<i.length;t++){let o=i[t];if(o===void 0)continue;let s=Ut(o);s.static||(s=bn(n,s,i,r),r=Math.max(r,s.y+s.h),n.push(s));let c=e.indexOf(o);a[c]=s,s.moved=!1}return a}},Cn={type:`horizontal`,allowOverlap:!1,compact(e,t){let n=Ht(e),r=zt(e),i=Array(e.length);for(let a=0;a<r.length;a++){let o=r[a];if(o===void 0)continue;let s=Ut(o);s.static||(s=xn(n,s,t,r),n.push(s));let c=e.indexOf(o);i[c]=s,s.moved=!1}return i}},wn={type:null,allowOverlap:!1,compact(e,t){return Wt(e)}},Tn={...Sn,allowOverlap:!0,compact(e,t){return Wt(e)}},En={...Cn,allowOverlap:!0,compact(e,t){return Wt(e)}},Dn={...wn,allowOverlap:!0};function On(e,t=!1,n=!1){let r;return r=t?e===`vertical`?Tn:e===`horizontal`?En:Dn:e===`vertical`?Sn:e===`horizontal`?Cn:wn,n?{...r,preventCollision:n}:r}function kn(e){return Object.keys(e).sort((t,n)=>e[t]-e[n])}function An(e,t){let n=kn(e),r=n[0];if(r===void 0)throw Error(`No breakpoints defined`);for(let i=1;i<n.length;i++){let a=n[i];a!==void 0&&t>e[a]&&(r=a)}return r}function jn(e,t){let n=t[e];if(n===void 0)throw Error(`ResponsiveReactGridLayout: \`cols\` entry for breakpoint ${String(e)} is missing!`);return n}function Mn(e,t,n,r,i,a){let o=e[n];if(o)return Wt(o);let s=e[r],c=kn(t),l=c.slice(c.indexOf(n));for(let t=0;t<l.length;t++){let n=l[t];if(n===void 0)continue;let r=e[n];if(r){s=r;break}}let u=qt(Wt(s||[]),{cols:i});return(typeof a==`object`&&a?a:On(a)).compact(u,i)}function Nn(e,t){if(Array.isArray(e))return e;let n=e,r=n[t];if(r!==void 0)return r;let i=Object.keys(n);for(let e of i){let t=n[e];if(t!==void 0)return t}return[10,10]}var Pn=n(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?r(e):typeof define==`function`&&define.amd?define([`exports`],r):(n=typeof globalThis<`u`?globalThis:n||self,r(n[`fast-equals`]={}))})(e,(function(e){function t(e){return function(t,n,r,i,a,o,s){return e(t,n,s)}}function n(e){return function(t,n,r,i){if(!t||!n||typeof t!=`object`||typeof n!=`object`)return e(t,n,r,i);var a=i.get(t),o=i.get(n);if(a&&o)return a===n&&o===t;i.set(t,n),i.set(n,t);var s=e(t,n,r,i);return i.delete(t),i.delete(n),s}}function r(e,t){var n={};for(var r in e)n[r]=e[r];for(var r in t)n[r]=t[r];return n}function i(e){return e.constructor===Object||e.constructor==null}function a(e){return typeof e.then==`function`}function o(e,t){return e===t||e!==e&&t!==t}var s=`[object Arguments]`,c=`[object Boolean]`,l=`[object Date]`,u=`[object RegExp]`,d=`[object Map]`,f=`[object Number]`,p=`[object Object]`,m=`[object Set]`,h=`[object String]`,g=Object.prototype.toString;function _(e){var t=e.areArraysEqual,n=e.areDatesEqual,r=e.areMapsEqual,_=e.areObjectsEqual,v=e.areRegExpsEqual,y=e.areSetsEqual,b=e.createIsNestedEqual,x=b(S);function S(e,b,S){if(e===b)return!0;if(!e||!b||typeof e!=`object`||typeof b!=`object`)return e!==e&&b!==b;if(i(e)&&i(b))return _(e,b,x,S);var C=Array.isArray(e),w=Array.isArray(b);if(C||w)return C===w&&t(e,b,x,S);var T=g.call(e);return T===g.call(b)?T===l?n(e,b,x,S):T===u?v(e,b,x,S):T===d?r(e,b,x,S):T===m?y(e,b,x,S):T===p||T===s?a(e)||a(b)?!1:_(e,b,x,S):T===c||T===f||T===h?o(e.valueOf(),b.valueOf()):!1:!1}return S}function v(e,t,n,r){var i=e.length;if(t.length!==i)return!1;for(;i-- >0;)if(!n(e[i],t[i],i,i,e,t,r))return!1;return!0}var y=n(v);function b(e,t){return o(e.valueOf(),t.valueOf())}function x(e,t,n,r){var i=e.size===t.size;if(!i)return!1;if(!e.size)return!0;var a={},o=0;return e.forEach(function(s,c){if(i){var l=!1,u=0;t.forEach(function(i,d){!l&&!a[u]&&(l=n(c,d,o,u,e,t,r)&&n(s,i,c,d,e,t,r))&&(a[u]=!0),u++}),o++,i=l}}),i}var S=n(x),C=`_owner`,w=Object.prototype.hasOwnProperty;function T(e,t,n,r){var i=Object.keys(e),a=i.length;if(Object.keys(t).length!==a)return!1;for(var o;a-- >0;){if(o=i[a],o===C){var s=!!e.$$typeof,c=!!t.$$typeof;if((s||c)&&s!==c)return!1}if(!w.call(t,o)||!n(e[o],t[o],o,o,e,t,r))return!1}return!0}var E=n(T);function D(e,t){return e.source===t.source&&e.flags===t.flags}function ee(e,t,n,r){var i=e.size===t.size;if(!i)return!1;if(!e.size)return!0;var a={};return e.forEach(function(o,s){if(i){var c=!1,l=0;t.forEach(function(i,u){!c&&!a[l]&&(c=n(o,i,s,u,e,t,r))&&(a[l]=!0),l++}),i=c}}),i}var O=n(ee),k=Object.freeze({areArraysEqual:v,areDatesEqual:b,areMapsEqual:x,areObjectsEqual:T,areRegExpsEqual:D,areSetsEqual:ee,createIsNestedEqual:t}),A=Object.freeze({areArraysEqual:y,areDatesEqual:b,areMapsEqual:S,areObjectsEqual:E,areRegExpsEqual:D,areSetsEqual:O,createIsNestedEqual:t}),j=_(k);function M(e,t){return j(e,t,void 0)}var te=_(r(k,{createIsNestedEqual:function(){return o}}));function N(e,t){return te(e,t,void 0)}var P=_(A);function F(e,t){return P(e,t,new WeakMap)}var I=_(r(A,{createIsNestedEqual:function(){return o}}));function ne(e,t){return I(e,t,new WeakMap)}function re(e){return _(r(k,e(k)))}function ie(e){var t=_(r(A,e(A)));return(function(e,n,r){return r===void 0&&(r=new WeakMap),t(e,n,r)})}e.circularDeepEqual=F,e.circularShallowEqual=ne,e.createCustomCircularEqual=ie,e.createCustomEqual=re,e.deepEqual=M,e.sameValueZeroEqual=o,e.shallowEqual=N,Object.defineProperty(e,"__esModule",{value:!0})}))}));function Fn(e={}){let{measureBeforeMount:t=!1,initialWidth:n=1280}=e,[r,i]=(0,Z.useState)(n),[a,o]=(0,Z.useState)(!t),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useCallback)(()=>{let e=s.current;if(e){let t=e.offsetWidth;i(t),a||o(!0)}},[a]);return(0,Z.useEffect)(()=>{let e=s.current;if(e){if(l(),typeof ResizeObserver<`u`){let t=null;return c.current=new ResizeObserver(e=>{let n=e[0];if(n){let e=n.contentRect.width;t!==null&&cancelAnimationFrame(t),t=requestAnimationFrame(()=>{i(e),t=null})}}),c.current.observe(e),()=>{t!==null&&cancelAnimationFrame(t),c.current&&=(c.current.disconnect(),null)}}return()=>{c.current&&=(c.current.disconnect(),null)}}},[l]),{width:r,mounted:a,containerRef:s,measureWidth:l}}var In=n(((e,t)=>{t.exports=`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`})),Ln=n(((e,t)=>{var n=In();function r(){}function i(){}i.resetWarningCache=r,t.exports=function(){function e(e,t,r,i,a,o){if(o!==n){var s=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name=`Invariant Violation`,s}}e.isRequired=e;function t(){return e}var a={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:r};return a.PropTypes=a,a}})),Rn=n(((e,t)=>{t.exports=Ln()()})),$=e(Rn(),1);function zn(e,t){for(let n=0,r=e.length;n<r;n++)if(t.apply(t,[e[n],n,e]))return e[n]}function Bn(e){return typeof e==`function`||Object.prototype.toString.call(e)===`[object Function]`}function Vn(e){return typeof e==`number`&&!isNaN(e)}function Hn(e){return parseInt(e,10)}function Un(e,t,n){if(e[t])return Error(`Invalid prop ${t} passed to ${n} - do not set this, set it on the child.`)}var Wn=[`Moz`,`Webkit`,`O`,`ms`];function Gn(e=`transform`){if(typeof window>`u`)return``;let t=window.document?.documentElement?.style;if(!t||e in t)return``;for(let n=0;n<Wn.length;n++)if(Kn(e,Wn[n])in t)return Wn[n];return``}function Kn(e,t){return t?`${t}${qn(e)}`:e}function qn(e){let t=``,n=!0;for(let r=0;r<e.length;r++)n?(t+=e[r].toUpperCase(),n=!1):e[r]===`-`?n=!0:t+=e[r];return t}var Jn=Gn(),Yn=``;function Xn(e,t){Yn||=zn([`matches`,`webkitMatchesSelector`,`mozMatchesSelector`,`msMatchesSelector`,`oMatchesSelector`],function(t){return Bn(e[t])})??``;let n=e[Yn];return Bn(n)?!!n.call(e,t):!1}function Zn(e,t,n){let r=e;do{if(Xn(r,t))return!0;if(r===n)return!1;r=r.parentNode}while(r);return!1}function Qn(e,t,n,r){if(!e)return;let i={capture:!0,...r},a=n;e.addEventListener?e.addEventListener(t,a,i):e.attachEvent?e.attachEvent(`on`+t,a):e[`on`+t]=a}function $n(e,t,n,r){if(!e)return;let i={capture:!0,...r},a=n;e.removeEventListener?e.removeEventListener(t,a,i):e.detachEvent?e.detachEvent(`on`+t,a):e[`on`+t]=null}function er(e){let t=e.clientHeight,n=e.ownerDocument.defaultView.getComputedStyle(e);return t+=Hn(n.borderTopWidth),t+=Hn(n.borderBottomWidth),t}function tr(e){let t=e.clientWidth,n=e.ownerDocument.defaultView.getComputedStyle(e);return t+=Hn(n.borderLeftWidth),t+=Hn(n.borderRightWidth),t}function nr(e){let t=e.clientHeight,n=e.ownerDocument.defaultView.getComputedStyle(e);return t-=Hn(n.paddingTop),t-=Hn(n.paddingBottom),t}function rr(e){let t=e.clientWidth,n=e.ownerDocument.defaultView.getComputedStyle(e);return t-=Hn(n.paddingLeft),t-=Hn(n.paddingRight),t}function ir(e,t,n){let r=t===t.ownerDocument.body?{left:0,top:0}:t.getBoundingClientRect();return{x:(e.clientX+t.scrollLeft-r.left)/n,y:(e.clientY+t.scrollTop-r.top)/n}}function ar(e,t){let n=sr(e,t,`px`);return{[Kn(`transform`,Jn)]:n}}function or(e,t){return sr(e,t,``)}function sr({x:e,y:t},n,r){let i=`translate(${e}${r},${t}${r})`;return n&&(i=`translate(${`${typeof n.x==`string`?n.x:n.x+r}`}, ${`${typeof n.y==`string`?n.y:n.y+r}`})`+i),i}function cr(e,t){return e.targetTouches&&zn(e.targetTouches,e=>t===e.identifier)||e.changedTouches&&zn(e.changedTouches,e=>t===e.identifier)}function lr(e){if(e.targetTouches&&e.targetTouches[0])return e.targetTouches[0].identifier;if(e.changedTouches&&e.changedTouches[0])return e.changedTouches[0].identifier}function ur(){return typeof __webpack_nonce__<`u`?__webpack_nonce__:void 0}function dr(e,t){if(!e)return;let n=e.getElementById(`react-draggable-style-el`);if(!n){n=e.createElement(`style`),n.type=`text/css`,n.id=`react-draggable-style-el`;let r=t??ur();r&&n.setAttribute(`nonce`,r),n.innerHTML=`.react-draggable-transparent-selection *::-moz-selection {all: inherit;}
|
|
3
3
|
`,n.innerHTML+=`.react-draggable-transparent-selection *::selection {all: inherit;}
|
|
4
4
|
`,e.getElementsByTagName(`head`)[0].appendChild(n)}e.body&&mr(e.body,`react-draggable-transparent-selection`)}function fr(e){window.requestAnimationFrame?window.requestAnimationFrame(()=>{pr(e)}):pr(e)}function pr(e){if(e)try{e.body&&hr(e.body,`react-draggable-transparent-selection`);let t=e.selection;if(t)t.empty();else{let t=(e.defaultView||window).getSelection();t&&t.type!==`Caret`&&t.removeAllRanges()}}catch{}}function mr(e,t){e.classList?e.classList.add(t):e.className.match(RegExp(`(?:^|\\s)${t}(?!\\S)`))||(e.className+=` ${t}`)}function hr(e,t){e.classList?e.classList.remove(t):e.className=e.className.replace(RegExp(`(?:^|\\s)${t}(?!\\S)`,`g`),``)}function gr(e,t,n){if(!e.props.bounds)return[t,n];let{bounds:r}=e.props;r=typeof r==`string`?r:Cr(r);let i=wr(e);if(typeof r==`string`){let{ownerDocument:e}=i,t=e.defaultView;if(!t)throw Error(`Cannot resolve the owner window of the draggable node.`);let n;if(n=r===`parent`?i.parentNode:i.getRootNode().querySelector(r),!(n instanceof t.HTMLElement))throw Error(`Bounds selector "`+r+`" could not find an element.`);let a=n,o=t.getComputedStyle(i),s=t.getComputedStyle(a);r={left:-i.offsetLeft+Hn(s.paddingLeft)+Hn(o.marginLeft),top:-i.offsetTop+Hn(s.paddingTop)+Hn(o.marginTop),right:rr(a)-tr(i)-i.offsetLeft+Hn(s.paddingRight)-Hn(o.marginRight),bottom:nr(a)-er(i)-i.offsetTop+Hn(s.paddingBottom)-Hn(o.marginBottom)}}return Vn(r.right)&&(t=Math.min(t,r.right)),Vn(r.bottom)&&(n=Math.min(n,r.bottom)),Vn(r.left)&&(t=Math.max(t,r.left)),Vn(r.top)&&(n=Math.max(n,r.top)),[t,n]}function _r(e,t,n){return[Math.round(t/e[0])*e[0],Math.round(n/e[1])*e[1]]}function vr(e){return e.props.axis===`both`||e.props.axis===`x`}function yr(e){return e.props.axis===`both`||e.props.axis===`y`}function br(e,t,n){let r=typeof t==`number`?cr(e,t):null;if(typeof t==`number`&&!r)return null;let i=wr(n),a=n.props.offsetParent||i.offsetParent||i.ownerDocument.body;return ir(r||e,a,n.props.scale)}function xr(e,t,n){let r=!Vn(e.lastX),i=wr(e);return r?{node:i,deltaX:0,deltaY:0,lastX:t,lastY:n,x:t,y:n}:{node:i,deltaX:t-e.lastX,deltaY:n-e.lastY,lastX:e.lastX,lastY:e.lastY,x:t,y:n}}function Sr(e,t){let n=e.props.scale;return{node:t.node,x:e.state.x+t.deltaX/n,y:e.state.y+t.deltaY/n,deltaX:t.deltaX/n,deltaY:t.deltaY/n,lastX:e.state.x,lastY:e.state.y}}function Cr(e){return{left:e.left,top:e.top,right:e.right,bottom:e.bottom}}function wr(e){let t=e.findDOMNode();if(!t)throw Error(`<DraggableCore>: Unmounted during event!`);return t}function Tr(...e){({}).DRAGGABLE_DEBUG&&console.log(...e)}var Er={touch:{start:`touchstart`,move:`touchmove`,stop:`touchend`},mouse:{start:`mousedown`,move:`mousemove`,stop:`mouseup`}},Dr=Er.mouse,Or=class extends Z.Component{constructor(){super(...arguments),this.dragging=!1,this.lastX=NaN,this.lastY=NaN,this.touchIdentifier=null,this.mounted=!1,this.handleDragStart=e=>{if(this.props.onMouseDown(e),!this.props.allowAnyClick&&(typeof e.button==`number`&&e.button!==0||e.ctrlKey))return!1;let t=this.findDOMNode();if(!t||!t.ownerDocument||!t.ownerDocument.body)throw Error(`<DraggableCore> not mounted on DragStart!`);let{ownerDocument:n}=t;if(this.props.disabled||!(e.target instanceof n.defaultView.Node)||this.props.handle&&!Zn(e.target,this.props.handle,t)||this.props.cancel&&Zn(e.target,this.props.cancel,t))return;e.type===`touchstart`&&!this.props.allowMobileScroll&&e.preventDefault();let r=lr(e);this.touchIdentifier=r;let i=br(e,r,this);if(i==null)return;let{x:a,y:o}=i,s=xr(this,a,o);Tr(`DraggableCore: handleDragStart: %j`,s),Tr(`calling`,this.props.onStart),!(this.props.onStart(e,s)===!1||this.mounted===!1)&&(this.props.enableUserSelectHack&&dr(n,this.props.nonce),this.dragging=!0,this.lastX=a,this.lastY=o,Qn(n,Dr.move,this.handleDrag),Qn(n,Dr.stop,this.handleDragStop))},this.handleDrag=e=>{let t=br(e,this.touchIdentifier,this);if(t==null)return;let{x:n,y:r}=t;if(Array.isArray(this.props.grid)){let e=n-this.lastX,t=r-this.lastY;if([e,t]=_r(this.props.grid,e,t),!e&&!t)return;n=this.lastX+e,r=this.lastY+t}let i=xr(this,n,r);if(Tr(`DraggableCore: handleDrag: %j`,i),this.props.onDrag(e,i)===!1||this.mounted===!1){try{this.handleDragStop(new MouseEvent(`mouseup`))}catch{let e=document.createEvent(`MouseEvents`);e.initMouseEvent(`mouseup`,!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),this.handleDragStop(e)}return}this.lastX=n,this.lastY=r},this.handleDragStop=e=>{if(!this.dragging)return;let t=br(e,this.touchIdentifier,this);if(t==null)return;let{x:n,y:r}=t;if(Array.isArray(this.props.grid)){let e=n-this.lastX||0,t=r-this.lastY||0;[e,t]=_r(this.props.grid,e,t),n=this.lastX+e,r=this.lastY+t}let i=xr(this,n,r);if(this.props.onStop(e,i)===!1||this.mounted===!1)return!1;let a=this.findDOMNode();a&&this.props.enableUserSelectHack&&fr(a.ownerDocument),Tr(`DraggableCore: handleDragStop: %j`,i),this.dragging=!1,this.lastX=NaN,this.lastY=NaN,a&&(Tr(`DraggableCore: Removing handlers`),$n(a.ownerDocument,Dr.move,this.handleDrag),$n(a.ownerDocument,Dr.stop,this.handleDragStop))},this.onMouseDown=e=>(Dr=Er.mouse,this.handleDragStart(e)),this.onMouseUp=e=>(Dr=Er.mouse,this.handleDragStop(e)),this.onTouchStart=e=>(Dr=Er.touch,this.handleDragStart(e)),this.onTouchEnd=e=>(Dr=Er.touch,this.handleDragStop(e))}componentDidMount(){this.mounted=!0;let e=this.findDOMNode();e&&Qn(e,Er.touch.start,this.onTouchStart,{passive:!1})}componentWillUnmount(){this.mounted=!1;let e=this.findDOMNode();if(e){let{ownerDocument:t}=e;$n(t,Er.mouse.move,this.handleDrag),$n(t,Er.touch.move,this.handleDrag),$n(t,Er.mouse.stop,this.handleDragStop),$n(t,Er.touch.stop,this.handleDragStop),$n(e,Er.touch.start,this.onTouchStart,{passive:!1}),this.props.enableUserSelectHack&&fr(t)}}findDOMNode(){if(this.props?.nodeRef)return this.props.nodeRef.current;let e=Ue.default;return typeof e.findDOMNode==`function`?e.findDOMNode(this):(Tr(`react-draggable: ReactDOM.findDOMNode is not available in React 19+. You must provide a nodeRef prop. See: https://github.com/react-grid-layout/react-draggable#noderef`),null)}render(){return Z.cloneElement(Z.Children.only(this.props.children),{onMouseDown:this.onMouseDown,onMouseUp:this.onMouseUp,onTouchEnd:this.onTouchEnd})}};Or.displayName=`DraggableCore`,Or.propTypes={allowAnyClick:$.default.bool,allowMobileScroll:$.default.bool,children:$.default.node.isRequired,disabled:$.default.bool,enableUserSelectHack:$.default.bool,offsetParent:function(e,t){if(e[t]&&e[t].nodeType!==1)throw Error(`Draggable's offsetParent must be a DOM Node.`)},grid:$.default.arrayOf($.default.number),handle:$.default.string,cancel:$.default.string,nodeRef:$.default.object,nonce:$.default.string,onStart:$.default.func,onDrag:$.default.func,onStop:$.default.func,onMouseDown:$.default.func,scale:$.default.number,className:Un,style:Un,transform:Un},Or.defaultProps={allowAnyClick:!1,allowMobileScroll:!1,disabled:!1,enableUserSelectHack:!0,onStart:function(){},onDrag:function(){},onStop:function(){},onMouseDown:function(){},scale:1};var kr=class extends Z.Component{constructor(e){super(e),this.onDragStart=(e,t)=>{if(Tr(`Draggable: onDragStart: %j`,t),this.props.onStart(e,Sr(this,t))===!1)return!1;this.setState({dragging:!0,dragged:!0})},this.onDrag=(e,t)=>{if(!this.state.dragging)return!1;Tr(`Draggable: onDrag: %j`,t);let n=Sr(this,t),r={x:n.x,y:n.y,slackX:0,slackY:0};if(this.props.bounds){let{x:e,y:t}=r;r.x+=this.state.slackX,r.y+=this.state.slackY;let[i,a]=gr(this,r.x,r.y);r.x=i,r.y=a,r.slackX=this.state.slackX+(e-r.x),r.slackY=this.state.slackY+(t-r.y),n.x=r.x,n.y=r.y,n.deltaX=r.x-this.state.x,n.deltaY=r.y-this.state.y}if(this.props.onDrag(e,n)===!1)return!1;this.setState(r)},this.onDragStop=(e,t)=>{if(!this.state.dragging||this.props.onStop(e,Sr(this,t))===!1)return!1;Tr(`Draggable: onDragStop: %j`,t);let n={dragging:!1,slackX:0,slackY:0};if(this.props.position){let{x:e,y:t}=this.props.position;n.x=e,n.y=t}this.setState(n)},this.state={dragging:!1,dragged:!1,x:e.position?e.position.x:e.defaultPosition.x,y:e.position?e.position.y:e.defaultPosition.y,prevPropsPosition:{...e.position},slackX:0,slackY:0,isElementSVG:!1},e.position&&!(e.onDrag||e.onStop)&&console.warn("A `position` was applied to this <Draggable>, without drag handlers. This will make this component effectively undraggable. Please attach `onDrag` or `onStop` handlers so you can adjust the `position` of this element.")}static getDerivedStateFromProps({position:e},{prevPropsPosition:t}){return e&&(!t||e.x!==t.x||e.y!==t.y)?(Tr(`Draggable: getDerivedStateFromProps %j`,{position:e,prevPropsPosition:t}),{x:e.x,y:e.y,prevPropsPosition:{...e}}):null}componentDidMount(){window.SVGElement!==void 0&&this.findDOMNode()instanceof window.SVGElement&&this.setState({isElementSVG:!0})}componentWillUnmount(){this.state.dragging&&this.setState({dragging:!1})}findDOMNode(){if(this.props?.nodeRef)return this.props.nodeRef.current;let e=Ue.default;return typeof e.findDOMNode==`function`?e.findDOMNode(this):null}render(){let{axis:e,bounds:t,children:n,defaultPosition:r,defaultClassName:i,defaultClassNameDragging:a,defaultClassNameDragged:o,position:s,positionOffset:c,scale:l,...u}=this.props,d={},f=null,p=!s||this.state.dragging,m=s||r,h={x:vr(this)&&p?this.state.x:m.x,y:yr(this)&&p?this.state.y:m.y};this.state.isElementSVG?f=or(h,c):d=ar(h,c);let g=Z.Children.only(n),_=Ae(g.props.className||``,i,{[a]:this.state.dragging,[o]:this.state.dragged});return Z.createElement(Or,{...u,onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop},Z.cloneElement(g,{className:_,style:{...g.props.style,...d},transform:f}))}};kr.displayName=`Draggable`,kr.propTypes={...Or.propTypes,axis:$.default.oneOf([`both`,`x`,`y`,`none`]),bounds:$.default.oneOfType([$.default.shape({left:$.default.number,right:$.default.number,top:$.default.number,bottom:$.default.number}),$.default.string,$.default.oneOf([!1])]),defaultClassName:$.default.string,defaultClassNameDragging:$.default.string,defaultClassNameDragged:$.default.string,defaultPosition:$.default.shape({x:$.default.number,y:$.default.number}),positionOffset:$.default.shape({x:$.default.oneOfType([$.default.number,$.default.string]),y:$.default.oneOfType([$.default.number,$.default.string])}),position:$.default.shape({x:$.default.number,y:$.default.number}),className:Un,style:Un,transform:Un},kr.defaultProps={...Or.defaultProps,axis:`both`,bounds:!1,defaultClassName:`react-draggable`,defaultClassNameDragging:`react-draggable-dragging`,defaultClassNameDragged:`react-draggable-dragged`,defaultPosition:{x:0,y:0},scale:1};var Ar=n(((e,t)=>{var n=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},d=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let i of s(t))!l.call(e,i)&&i!==n&&a(e,i,{get:()=>t[i],enumerable:!(r=o(t,i))||r.enumerable});return e},f=(e,t,r)=>(r=e==null?{}:n(c(e)),d(t||!e||!e.__esModule?a(r,`default`,{value:e,enumerable:!0}):r,e)),p=e=>d(a({},`__esModule`,{value:!0}),e),m={};u(m,{DraggableCore:()=>me,default:()=>he}),t.exports=p(m);var h=f(r()),g=f(Rn()),_=f(i()),v=je();function y(e,t){for(let n=0,r=e.length;n<r;n++)if(t.apply(t,[e[n],n,e]))return e[n]}function b(e){return typeof e==`function`||Object.prototype.toString.call(e)===`[object Function]`}function x(e){return typeof e==`number`&&!isNaN(e)}function S(e){return parseInt(e,10)}function C(e,t,n){if(e[t])return Error(`Invalid prop ${t} passed to ${n} - do not set this, set it on the child.`)}var w=[`Moz`,`Webkit`,`O`,`ms`];function T(e=`transform`){if(typeof window>`u`)return``;let t=window.document?.documentElement?.style;if(!t||e in t)return``;for(let n=0;n<w.length;n++)if(E(e,w[n])in t)return w[n];return``}function E(e,t){return t?`${t}${D(e)}`:e}function D(e){let t=``,n=!0;for(let r=0;r<e.length;r++)n?(t+=e[r].toUpperCase(),n=!1):e[r]===`-`?n=!0:t+=e[r];return t}var ee=T(),O=``;function k(e,t){O||=y([`matches`,`webkitMatchesSelector`,`mozMatchesSelector`,`msMatchesSelector`,`oMatchesSelector`],function(t){return b(e[t])})??``;let n=e[O];return b(n)?!!n.call(e,t):!1}function A(e,t,n){let r=e;do{if(k(r,t))return!0;if(r===n)return!1;r=r.parentNode}while(r);return!1}function j(e,t,n,r){if(!e)return;let i={capture:!0,...r},a=n;e.addEventListener?e.addEventListener(t,a,i):e.attachEvent?e.attachEvent(`on`+t,a):e[`on`+t]=a}function M(e,t,n,r){if(!e)return;let i={capture:!0,...r},a=n;e.removeEventListener?e.removeEventListener(t,a,i):e.detachEvent?e.detachEvent(`on`+t,a):e[`on`+t]=null}function te(e){let t=e.clientHeight,n=e.ownerDocument.defaultView.getComputedStyle(e);return t+=S(n.borderTopWidth),t+=S(n.borderBottomWidth),t}function N(e){let t=e.clientWidth,n=e.ownerDocument.defaultView.getComputedStyle(e);return t+=S(n.borderLeftWidth),t+=S(n.borderRightWidth),t}function P(e){let t=e.clientHeight,n=e.ownerDocument.defaultView.getComputedStyle(e);return t-=S(n.paddingTop),t-=S(n.paddingBottom),t}function F(e){let t=e.clientWidth,n=e.ownerDocument.defaultView.getComputedStyle(e);return t-=S(n.paddingLeft),t-=S(n.paddingRight),t}function I(e,t,n){let r=t===t.ownerDocument.body?{left:0,top:0}:t.getBoundingClientRect();return{x:(e.clientX+t.scrollLeft-r.left)/n,y:(e.clientY+t.scrollTop-r.top)/n}}function ne(e,t){let n=ie(e,t,`px`);return{[E(`transform`,ee)]:n}}function re(e,t){return ie(e,t,``)}function ie({x:e,y:t},n,r){let i=`translate(${e}${r},${t}${r})`;return n&&(i=`translate(${`${typeof n.x==`string`?n.x:n.x+r}`}, ${`${typeof n.y==`string`?n.y:n.y+r}`})`+i),i}function L(e,t){return e.targetTouches&&y(e.targetTouches,e=>t===e.identifier)||e.changedTouches&&y(e.changedTouches,e=>t===e.identifier)}function ae(e){if(e.targetTouches&&e.targetTouches[0])return e.targetTouches[0].identifier;if(e.changedTouches&&e.changedTouches[0])return e.changedTouches[0].identifier}function oe(){return typeof __webpack_nonce__<`u`?__webpack_nonce__:void 0}function R(e,t){if(!e)return;let n=e.getElementById(`react-draggable-style-el`);if(!n){n=e.createElement(`style`),n.type=`text/css`,n.id=`react-draggable-style-el`;let r=t??oe();r&&n.setAttribute(`nonce`,r),n.innerHTML=`.react-draggable-transparent-selection *::-moz-selection {all: inherit;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n}from"./vendor-react-ClIa1CJA.js";import{n as r}from"./infrastructure-B1z73d-r.js";import{E as i,Q as a,R as o,V as s,Y as c,kt as l,t as u}from"./framework-h98DIM1k.js";import{$n as d,$t as f,As as p,Bs as m,Bt as h,Fc as g,Gn as _,Hs as v,Ht as y,Jn as b,Lt as x,Oc as S,P as C,Qt as w,Ra as T,Rt as E,Si as D,Un as O,Ut as k,Vs as A,Vt as j,_r as M,c as N,ct as P,en as F,er as I,fr as L,g as R,gr as ee,hr as z,lt as te,mr as ne,nr as B,pr as re,qn as ie,r as V,rr as H,st as ae,t as oe,tr as U,ut as se,v as W,vr as ce,xr as G,yr as le,za as ue,zs as K,zt as de}from"./ui-components-C9egdVxV.js";import{r as q}from"./vendor-ui-utils-C92Fl7BT.js";var J=e(t(),1);function fe(e){try{return typeof window>`u`?!1:new URL(e,window.location.href).origin===window.location.origin}catch{return!1}}function Y(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 fe(r)?r:null}var X=n(),pe=({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,J.useState)(r),f={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)},m=c??!!e,h=e||t?(0,X.jsxs)(`div`,{className:S(`flex items-start gap-2`,!m&&`mb-4`,n&&`cursor-pointer select-none`),onClick:p,role:n?`button`:void 0,"aria-expanded":n?!l:void 0,children:[n&&(0,X.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:l?(0,X.jsx)(K,{className:`h-4 w-4`}):(0,X.jsx)(A,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,X.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),t&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:t})]})]}):null,g=l?null:(0,X.jsx)(`div`,{className:S(`grid gap-4`,s||f[i]),children:a});return m?(0,X.jsxs)(d,{className:S(`form-section`,o),children:[h&&(0,X.jsxs)(B,{className:`pb-3`,children:[e&&(0,X.jsx)(H,{className:`text-base`,children:e}),t&&(0,X.jsx)(U,{children:t}),n&&(0,X.jsx)(`button`,{type:`button`,className:`absolute right-4 top-4 text-muted-foreground`,onClick:p,"aria-expanded":!l,"aria-label":l?`Expand section`:`Collapse section`,children:l?(0,X.jsx)(K,{className:`h-4 w-4`}):(0,X.jsx)(A,{className:`h-4 w-4`})})]}),g&&(0,X.jsx)(I,{children:g})]}):(0,X.jsxs)(`div`,{className:S(`form-section`,o),children:[h,g]})};function Z(e,t){return typeof t==`string`&&t.trim()?{...e,visible:e=>V(t,e)}:e}function Q(e,t){let n=t.objectSchema?.fields?.[e];return n?{name:e,label:t.fieldLabel(t.objectName,e,n.label||e),type:R(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}:{name:e,label:e,type:`input`}}function me(e,t){if(typeof e==`string`){let n=t.objectSchema?.fields?.[e];return Z(Q(e,t),n?.visible_on??n?.visibleOn)}let n=e;if(typeof n.field!=`string`)return Z(n,n.visibleOn);let r=n.field,i=Q(r,t);return n.type!=null&&(i.type=R(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.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),Z(i,n.visibleOn)}function he(e,t){return(e.fields??[]).map(e=>me(e,t))}var ge=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=g(),[i,a]=(0,J.useState)(null),[o,c]=(0,J.useState)({}),[l,u]=(0,J.useState)(!0),[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`);J.useEffect(()=>{(async()=>{if(!t){u(!1);return}try{a(await t.getObjectSchema(e.objectName))}catch(e){f(e)}})()},[e.objectName,t]),J.useEffect(()=>{(i||!t)&&(async()=>{if(e.mode===`create`||!e.recordId||!t){c(e.initialData||e.initialValues||{}),u(!1);return}try{c(await t.findOne(e.objectName,e.recordId)||{})}catch(e){f(e)}finally{u(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let h=(0,J.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]),_=(0,J.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]),v=(0,J.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),y=(e,t)=>e.name||e.label||`tab-${t}`;if(d)return(0,X.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,X.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,X.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:d.message})]});if(l)return(0,X.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,X.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,X.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let b={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:_,onCancel:v},x=e.tabPosition===`left`||e.tabPosition===`right`;return(0,X.jsx)(`div`,{className:S(`w-full`,n,e.className),children:(0,X.jsxs)(ae,{value:p,onValueChange:m,orientation:x?`vertical`:`horizontal`,className:S(x&&`flex gap-4`),children:[(0,X.jsx)(te,{className:S(x?`flex-col h-auto`:``,e.tabPosition===`bottom`&&`order-last`,e.tabPosition===`right`&&`order-last`),children:e.sections.map((e,t)=>(0,X.jsx)(se,{value:y(e,t),className:x?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},y(e,t)))}),(0,X.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,X.jsx)(P,{value:y(t,n),className:`mt-0`,children:(0,X.jsx)(pe,{description:t.description,columns:t.columns||1,children:(0,X.jsx)(s,{schema:{...b,fields:h(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},y(t,n)))})]})})},_e=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=g(),[i,a]=(0,J.useState)(null),[o,c]=(0,J.useState)({}),[l,u]=(0,J.useState)(!0),[d,f]=(0,J.useState)(null),[p,h]=(0,J.useState)(0),[_,y]=(0,J.useState)(new Set),[b,x]=(0,J.useState)(!1),C=J.useId(),[w,T]=(0,J.useState)(0),E=J.useRef(!1),D=e.sections.length,O=p===0,k=p===D-1;J.useEffect(()=>{(async()=>{if(!t){u(!1);return}try{a(await t.getObjectSchema(e.objectName))}catch(e){f(e)}})()},[e.objectName,t]),J.useEffect(()=>{(i||!t)&&(async()=>{if(e.mode===`create`||!e.recordId||!t){E.current||=(c(e.initialData||e.initialValues||{}),!0),u(!1);return}try{c(await t.findOne(e.objectName,e.recordId)||{})}catch(e){f(e)}finally{u(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let A=(0,J.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]),j=(0,J.useMemo)(()=>p>=0&&p<D?A(e.sections[p]):[],[p,D,e.sections,A]),M=(0,J.useCallback)(async n=>{let r={...o,...n};if(c(r),y(e=>new Set(e).add(p)),k){x(!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{let t=Y(e.navigateOnSuccess,n);if(t)return window.location.assign(t),n;q.success(e.successMessage||(e.mode===`create`?`Created`:`Saved`)),e.resetOnSuccess&&e.mode===`create`&&(c({}),y(new Set),h(0),T(e=>e+1))}return n}catch(t){throw e.onError&&e.onError(t),t}finally{x(!1)}}else N(p+1)},[o,p,k,e,t]),N=(0,J.useCallback)(t=>{t>=0&&t<D&&(h(t),e.onStepChange&&e.onStepChange(t))},[D,e]),P=(0,J.useCallback)(()=>{N(p-1)},[p,N]),F=(0,J.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),I=(0,J.useCallback)(t=>{(e.allowSkip||_.has(t)||t<=p)&&N(t)},[e.allowSkip,_,p,N]);if(d)return(0,X.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,X.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,X.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:d.message})]});if(l)return(0,X.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,X.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,X.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let L=e.sections[p];return(0,X.jsxs)(`div`,{className:S(`w-full`,n,e.className),children:[e.showStepIndicator!==!1&&(0,X.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,X.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===p,i=_.has(n),a=e.allowSkip||i||n<=p;return(0,X.jsxs)(`li`,{className:S(`relative flex-1`,n!==D-1&&`pr-8 sm:pr-12`),children:[n!==D-1&&(0,X.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,X.jsx)(`div`,{className:S(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,X.jsxs)(`button`,{type:`button`,className:S(`group relative flex items-center`,a?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>I(n),disabled:!a,children:[(0,X.jsx)(`span`,{className:S(`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,X.jsx)(v,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,X.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,X.jsx)(`span`,{className:S(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,X.jsx)(`div`,{className:`min-h-[200px]`,children:L&&(0,X.jsx)(pe,{label:L.label,description:L.description,columns:L.columns||1,children:j.length>0?(0,X.jsx)(s,{schema:{type:`form`,objectName:e.objectName,id:C,fields:j,layout:`vertical`,defaultValues:o,showSubmit:!1,showCancel:!1,onSubmit:M}},w):(0,X.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,X.jsx)(`div`,{children:e.showCancel!==!1&&(0,X.jsx)(G,{variant:`ghost`,onClick:F,children:e.cancelText||`Cancel`})}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,p+1,` of `,D]}),!O&&(0,X.jsxs)(G,{variant:`outline`,onClick:P,children:[(0,X.jsx)(m,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),k?(0,X.jsxs)(G,{type:`submit`,form:C,disabled:b||e.mode===`view`,children:[b&&(0,X.jsx)(ue,{className:`mr-2 h-4 w-4 animate-spin`,"aria-hidden":!0}),b?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)]}):(0,X.jsxs)(G,{type:`submit`,form:C,children:[e.nextText||`Next`,(0,X.jsx)(K,{className:`h-4 w-4 ml-1`})]})]})]})]})},ve=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=g(),[i,a]=(0,J.useState)(null),[o,c]=(0,J.useState)({}),[l,u]=(0,J.useState)(!0),[d,p]=(0,J.useState)(null);(0,J.useEffect)(()=>{(async()=>{if(!t){u(!1);return}try{a(await t.getObjectSchema(e.objectName))}catch(e){p(e),u(!1)}})()},[e.objectName,t]),(0,J.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{c(await t.findOne(e.objectName,e.recordId)||{})}catch(e){p(e)}finally{u(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let m=(0,J.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,J.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,J.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),v=(0,J.useMemo)(()=>e.sections.slice(0,1),[e.sections]),y=(0,J.useMemo)(()=>e.sections.slice(1),[e.sections]);(0,J.useMemo)(()=>e.sections.flatMap(e=>m(e)),[e.sections,m]);let b=e.splitDirection||`horizontal`,x=e.splitSize||50;if(d)return(0,X.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,X.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,X.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:d.message})]});if(l)return(0,X.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,X.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,X.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:_},T=(t,n)=>(0,X.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,r)=>(0,X.jsx)(pe,{label:t.label,description:t.description,columns:t.columns||1,children:(0,X.jsx)(s,{schema:{...C,fields:m(t),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,X.jsx)(`div`,{className:S(`w-full`,n,e.className),children:(0,X.jsxs)(F,{orientation:b,className:`min-h-[300px] rounded-lg border`,children:[(0,X.jsx)(f,{defaultSize:x,minSize:20,children:T(v,y.length===0)}),y.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(w,{withHandle:e.splitResizable!==!1}),(0,X.jsx)(f,{defaultSize:100-x,minSize:20,children:T(y,!0)})]})]})})},$=e=>e==null?void 0:e.id??e._id??e.recordId,ye=new Set([`id`,`_id`,`recordId`]);function be(e,t){return e?Object.entries(e).every(([e,n])=>e===t||ye.has(e)?!0:n==null||n===``):!0}function xe(e,t,n){let r=[{object:e,action:`create`,data:t}];for(let e of n)for(let t of e.rows)be(t,e.relationshipField)||r.push({object:e.childObject,action:`create`,data:{...t,[e.relationshipField]:{$ref:0}}});return r}function Se(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}=Ce(e.original||[],n);for(let t of r){if(be(t,e.relationshipField))continue;let{id:n,_id:r,recordId:a,...o}=t;i.push({object:e.childObject,action:`create`,data:o})}for(let t of a)i.push({object:e.childObject,action:`update`,id:$(t),data:t});for(let t of o)i.push({object:e.childObject,action:`delete`,id:t})}return i}function Ce(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 we(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 Te(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 Ee(e,t,n){return n.length===0?[]:typeof e.bulk==`function`?Te(await e.bulk(t,`create`,n)):Te(await Promise.all(n.map(n=>e.create(t,n))))}async function De(e,t,n,r){let i=[],a=r.rows.filter(e=>$(e)||!be(e,r.relationshipField)).map(e=>({...e,[r.relationshipField]:n}));if(r.original!==void 0){let{toCreate:t,toUpdate:n,toDelete:o}=Ce(r.original,a),s=await Ee(e,r.childObject,t);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),t))),await Promise.all(o.map(t=>e.delete(r.childObject,t)))}else{let t=await Ee(e,r.childObject,a);for(let e of t){let t=$(e);t&&i.push({object:r.childObject,id:t})}}if(r.totalField){let i=we(r.rows,r.amountField||`amount`);await e.update(t,n,{[r.totalField]:i})}return{created:i}}var Oe=new Set([`id`,`_id`,`recordId`,`created_at`,`updated_at`,`created_by`,`updated_by`,`createdAt`,`updatedAt`,`createdBy`,`updatedBy`,`organization_id`,`tenant_id`,`space`,`owner`]),ke=new Set([`position`,`sort_order`,`sequence`,`line_no`,`line_number`,`sort`]),Ae=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`,`file`,`image`,`avatar`,`json`,`object`,`grid`,`table`,`location`,`vector`,`html`,`markdown`,`richtext`]);function je(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 Me(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 Ne(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 Pe=[`name`,`title`,`subject`,`label`,`full_name`,`display_name`,`code`],Fe={select:0,currency:1,number:1,lookup:2,date:3,text:4};function Ie(e,t){if(t<=0||e.length<=t)return e;let n=new Set,r=e.find(e=>Pe.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)=>(Fe[e.c.type]??5)-(Fe[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 Le(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(Oe.has(e)||r.has(e)||ke.has(e)||n?.system||n?.readonly||n?.hidden||Ae.has(n?.type))continue;let a={field:e,label:n?.label||e,type:je(n?.type),required:!!n?.required},o=Me(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 Ie(i,t.maxColumns??6)}var Re=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`]);function ze(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;Oe.has(e)||r.has(e)||ke.has(e)||n?.system||n?.hidden||Re.has(n?.type)||i.push(e)}return i}var Be=new Set([`textarea`,`richtext`,`html`,`markdown`,`rich-text`,`file`,`image`,`avatar`,`attachment`,`json`,`location`,`address`]);function Ve(e,t,n={}){if(t===`grid`||t===`form`)return t;let r=e?.fields??{},i=ze(e,{relationshipField:n.relationshipField});return i.some(e=>Be.has(r[e]?.type))||i.length>8?`form`:`grid`}var He=[`amount`,`total`,`subtotal`,`line_total`,`line_amount`,`net_amount`];function Ue(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=>He.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 We(e,t,n,r={}){let i=r.relationshipField||Ne(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?r.columns:Le(t,{relationshipField:i}),o=r.amountField||Ue(a);return{childObject:e,relationshipField:i,columns:a,formFields:ze(t,{relationshipField:i}),mode:Ve(t,r.inlineEdit??(t?.fields)?.[i]?.inlineEdit,{relationshipField:i}),amountField:o,sortField:Object.keys(t?.fields??{}).find(e=>ke.has(e))}}function Ge(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 Ke=({details:e,state:t,setRows:n,formHostRef:r,taxRateField:i,formKey:a,onRowExpand:o,onAddViaForm:s})=>{let[c,l]=(0,J.useState)({}),u=(0,J.useRef)(``);(0,J.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{let t=Ge(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+we(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,X.jsxs)(X.Fragment,{children:[e.map((e,r)=>(0,X.jsxs)(`section`,{className:`space-y-2`,children:[(0,X.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:e.title||`Line Items`}),e.columns?.length?(0,X.jsx)(W,{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,X.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`Loading columns…`})]},`${e.childObject}-${r}`)),m&&(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsxs)(`dl`,{className:`w-64 space-y-1.5 text-sm`,"data-testid":`md-totals`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:`Subtotal`}),(0,X.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-subtotal`,children:v(p)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`dt`,{className:`text-muted-foreground`,children:[`Tax (`,h,`%)`]}),(0,X.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-tax`,children:v(g)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-t border-border pt-1.5 text-base font-semibold`,children:[(0,X.jsx)(`dt`,{children:`Total`}),(0,X.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-grand-total`,children:v(_)})]})]})})]})},qe=({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),[o,s]=(0,J.useState)(a?null:r),c=o??r;(0,J.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=>{if(n.relationshipField&&n.columns?.length)return n;try{let r=await t.getObjectSchema(n.childObject),i=We(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,J.useState)(()=>r.map(()=>({rows:[],original:[]}))),f=(0,J.useRef)(l);f.current=l;let[p,m]=(0,J.useState)(0),[h,g]=(0,J.useState)(!1),_=(0,J.useRef)(!1),v=(0,J.useRef)(null),y=(0,J.useCallback)(()=>{_.current=!1,g(!1),v.current&&=(clearTimeout(v.current),null)},[]);(0,J.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 b=(0,J.useCallback)((e,t)=>{u(n=>n.map((n,r)=>r===e?{...n,rows:t}:n))},[]),x=e.taxRateField||`tax_rate`,[C,w]=(0,J.useState)(null),T=C?l[C.detailIdx]?.rows?.[C.rowIdx]:void 0,E=C?c[C.detailIdx]:void 0,D=(0,J.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,J.useCallback)(e=>{u(t=>{let n=t.map((t,n)=>n===e?{...t,rows:[...t.rows,{}]}:t);return w({detailIdx:e,rowIdx:n[e].rows.length-1,isNew:!0}),n})},[]),k=(0,J.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,J.useCallback)(async t=>{y(),q.success(i?e.title?`${e.title} saved`:`Saved`:`Created`),i||(u(c.map(()=>({rows:[],original:[]}))),m(e=>e+1)),await e.onSuccess?.(t)},[i,e.onSuccess,e.title,c.length,y]),j=(0,J.useCallback)(t=>{y(),q.error(t?.message||`Save failed`),e.onError?.(t)},[e,y]),M=(0,J.useCallback)(async n=>{let r=[];for(let a=0;a<c.length;a++){let o=c[a],{rows:s,original:l}=f.current[a];if(!o.relationshipField)continue;let{created:u}=await De(t,e.objectName,n,{childObject:o.childObject,relationshipField:o.relationshipField,rows:s,original:i?l:void 0,amountField:o.amountField,totalField:o.totalField});r.push(...u)}return r},[c,i,t,e.objectName]),N=(0,J.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,J.useCallback)(async n=>{let r=t,a={...n};c.forEach((e,t)=>{e.totalField&&(a[e.totalField]=we(f.current[t]?.rows??[],e.amountField||`amount`))});let o=i?Se(e.objectName,e.recordId,a,c.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:f.current[t]?.rows??[],original:f.current[t]?.original??[]}))):xe(e.objectName,a,c.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:f.current[t]?.rows??[]})));return(await r.batchTransaction(o))?.results?.[0]??{...a,id:e.recordId}},[t,c,e.objectName,e.recordId,i]),L=(0,J.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,J.useRef)(null),ee=e.submitText??(i?`Save`:`Create`),z=(0,J.useCallback)(()=>{_.current||R.current?.querySelector(`form`)&&(_.current=!0,g(!0),setTimeout(()=>{(R.current?.querySelector(`form`))?.requestSubmit()},0),v.current=setTimeout(()=>y(),1500))},[y]);return(0,J.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]),(0,X.jsxs)(`div`,{className:S(`space-y-6`,n,e.className),children:[(0,X.jsx)(`div`,{ref:R,children:(0,X.jsx)(vt,{schema:L,dataSource:t},p)}),(0,X.jsx)(Ke,{details:c,state:l,setRows:b,formHostRef:R,taxRateField:x,formKey:p,onRowExpand:(e,t)=>w({detailIdx:e,rowIdx:t}),onAddViaForm:O}),C&&E&&(0,X.jsxs)(d,{className:`border-primary/40 shadow-none ring-1 ring-primary/10`,"data-testid":`md-row-form`,children:[(0,X.jsxs)(B,{className:`pb-2 flex flex-row items-center justify-between gap-2 space-y-0`,children:[(0,X.jsxs)(H,{className:`text-sm font-medium`,children:[E.title||`Line item`,` — row `,C.rowIdx+1]}),(0,X.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 text-xs text-muted-foreground`,onClick:k,children:`Close`})]}),(0,X.jsx)(I,{children:(0,X.jsx)(vt,{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,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-border pt-4`,children:[e.onCancel&&(0,X.jsx)(G,{type:`button`,variant:`outline`,onClick:e.onCancel,disabled:h,"data-testid":`md-form-cancel`,children:`Cancel`}),(0,X.jsx)(G,{type:`button`,onClick:z,disabled:h||a&&!o,"data-testid":`md-form-submit`,children:h?`Saving…`:ee})]})]})},Je=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),Ye=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),Xe=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function Ze(e){return Ye.has(e)}function Qe(e){return Xe.has(e)}function $e(e){return e<=3?1:2}function et(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&Ze(e.type)?{...e,colSpan:t}:e)}var tt=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 nt(e,t){return e.filter(e=>{if(tt.has(e.name))return!1;let n=t?.fields?.[e.name];return!(n?.hidden===!0||n?.readonly===!0)})}function rt(e,t){return e.filter(e=>{if(e.type&&Je.has(e.type))return!1;let n=t?.fields?.[e.name];return n?!Qe(n.type):!0})}function it(e){return e<=1?`default`:e===2?`xl`:`full`}function at(e,t,n,r){let i=[...e];if(i=nt(i,t),r===`create`&&(i=rt(i,t)),n!==void 0)return i=et(i,n),{fields:i,columns:n};let a=$e(i.length);return i=et(i,a),{fields:i,columns:a}}var ot=new Set([`id`,`_id`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`organization_id`,`organizationId`]),st=new Set([`formula`,`rollup`,`lookup_value`,`auto_number`,`autonumber`,`computed`]);function ct(e,t){if(!e||typeof e!=`object`)return e;let n={},r=t?.fields;for(let[t,i]of Object.entries(e))if(!ot.has(t)){if(r){let e=r[t];if(!e)continue;let n=String(e.type||``).toLowerCase();if(st.has(n)||e.computed===!0||e.formula||e.readOnly===!0||e.readonly===!0)continue}n[t]=i}return n}var lt={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`},ut=u({"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`),dt=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=g(),{t:i}=ut(),a=o(),[c,l]=(0,J.useState)(null),[u,d]=(0,J.useState)([]),[f,p]=(0,J.useState)({}),[m,_]=(0,J.useState)(!0),[v,b]=(0,J.useState)(null),[x,C]=(0,J.useState)(!1),[w,T]=(0,J.useState)(!1),[E,D]=(0,J.useState)(!1),O=(0,J.useRef)(!1),A=e.confirmOnDiscard!==!1,N=e.open!==!1,P=e.drawerSide||`right`,F=(0,J.useId)(),[I,te]=(0,J.useState)(()=>{let t={};return e.sections?.forEach((e,n)=>{let r=e.name||String(n);e.collapsed&&(t[r]=!0)}),t});(0,J.useEffect)(()=>{(async()=>{if(!t){_(!1);return}try{l(await t.getObjectSchema(e.objectName))}catch(e){b(e),_(!1)}})()},[e.objectName,t]),(0,J.useEffect)(()=>{(c||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){p(e.initialData||e.initialValues||{}),_(!1);return}if(!t){p(e.initialData||e.initialValues||{}),_(!1);return}try{p(await t.findOne(e.objectName,e.recordId)||{})}catch(e){b(e)}finally{_(!1)}})()},[c,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let B=(0,J.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,J.useEffect)(()=>{if(!c&&t)return;if(e.customFields?.length){d(e.customFields),_(!1);return}if(e.sections?.length){_(!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:R(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),_(!1)},[c,e.fields,e.customFields,e.sections,e.readOnly,e.mode,t]);let ie=(0,J.useCallback)(async n=>{D(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(n),e.onOpenChange?.(!1),n;let r,i=ct(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{D(!1)}},[e,t,c]),V=(0,J.useCallback)(()=>{T(!1),O.current&&(O.current=!1,e.onCancel?.()),e.onOpenChange?.(!1)},[e]),H=(0,J.useCallback)(e=>{O.current=e,A&&x?T(!0):V()},[A,x,V]),ae=(0,J.useCallback)(()=>{O.current=!0,V()},[V]),U=(0,J.useMemo)(()=>{if(e.drawerWidth)return P===`left`||P===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,P]),se=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,W=e.showSubmit!==!1&&e.mode!==`view`,K=e.showCancel!==!1,q=e.submitText||(e.mode===`create`?`Create`:`Update`),fe=e.cancelText||`Cancel`,Y={type:`form`,objectName:e.objectName,layout:se,defaultValues:f,submitLabel:q,cancelLabel:fe,showSubmit:W,showCancel:K,onSubmit:ie,onCancel:ae,onDirtyChange:C,showActions:!1,id:F},pe=()=>{if(v)return(0,X.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,X.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,X.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:v.message})]});if(m)return(0,X.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,X.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,X.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?()=>te(e=>({...e,[r]:!i})):void 0});let a=B(e);i?t.push(...a.map(e=>({...e,hidden:!0}))):t.push(...a)}),(0,X.jsx)(s,{schema:{...Y,fields:t}})}let t=at(u,c,e.columns,e.mode),n=lt[t.columns||1];return(0,X.jsx)(s,{schema:{...Y,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},Z=e.subforms,Q=Z?.length&&e.mode!==`view`?(0,X.jsx)(qe,{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,details:Z,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:t}):pe();return a?(0,X.jsxs)(`div`,{className:`@container rounded-md border bg-card p-4`,children:[(e.title||e.description)&&(0,X.jsxs)(`div`,{className:`mb-3 space-y-0.5`,children:[e.title&&(0,X.jsx)(`div`,{className:`text-sm font-semibold`,children:e.title}),e.description&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),Q]}):(0,X.jsx)(de,{open:N,onOpenChange:t=>{if(t){e.onOpenChange?.(!0);return}H(!1)},children:(0,X.jsxs)(h,{side:P,className:S(`overflow-y-auto`,n,e.className),style:U,children:[(e.title||e.description)&&(0,X.jsxs)(y,{children:[e.title&&(0,X.jsx)(k,{children:e.title}),e.description?(0,X.jsx)(j,{children:e.description}):(0,X.jsx)(j,{className:`sr-only`,children:`Complete the form fields, then submit or cancel.`})]}),(0,X.jsx)(`div`,{className:`@container py-4`,children:Q}),!v&&!m&&!(Z?.length&&e.mode!==`view`)&&(W||K)&&(0,X.jsx)(`div`,{className:`shrink-0 border-t px-4 py-3 bg-background`,"data-testid":`drawer-form-footer`,children:(0,X.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[K&&(0,X.jsx)(G,{type:`button`,variant:`outline`,onClick:ae,disabled:E,className:`w-full sm:w-auto`,children:fe}),W&&(0,X.jsxs)(G,{type:`submit`,form:F,disabled:E,className:`w-full sm:w-auto`,children:[E&&(0,X.jsx)(ue,{className:`mr-2 h-4 w-4 animate-spin`}),q]})]})}),(0,X.jsx)(L,{open:w,onOpenChange:T,children:(0,X.jsxs)(z,{children:[(0,X.jsxs)(ce,{children:[(0,X.jsx)(le,{children:i(`form.discardTitle`)}),(0,X.jsx)(ee,{children:i(`form.discardMessage`)})]}),(0,X.jsxs)(M,{children:[(0,X.jsx)(ne,{onClick:()=>{O.current=!1},children:i(`form.keepEditing`)}),(0,X.jsx)(re,{onClick:V,children:i(`form.discard`)})]})]})})]})})},ft=u({"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`),pt={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`},mt={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`},ht=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:i}=g(),{t:a}=ft(),c=o(),l=r(),u=(0,J.useCallback)(t=>{if(!l?.isLoaded)return t;let n=[];for(let r of t){if(!r?.name){n.push(r);continue}l.checkField(e.objectName,r.name,`read`)&&(!l.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0}):n.push(r))}return n},[l,e.objectName,e.mode]),[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)([]),[h,v]=(0,J.useState)({}),[y,w]=(0,J.useState)(!0),[T,E]=(0,J.useState)(null),[D,k]=(0,J.useState)(!1),[A,j]=(0,J.useState)(!1),[N,F]=(0,J.useState)(!1),I=(0,J.useRef)(!1),B=e.confirmOnDiscard!==!1,V=e.open!==!1,H=(0,J.useId)(),U=(0,J.useMemo)(()=>e.sections?.length||e.customFields?.length?null:at(p,d,e.columns,e.mode),[p,d,e.columns,e.mode,e.sections,e.customFields]),W=pt[(0,J.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(U?.columns&&U.columns>1)return it(U.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return it(t)}return`default`},[e.modalSize,U,e.sections])]||pt.default;(0,J.useEffect)(()=>{(async()=>{if(!t){w(!1);return}try{f(await t.getObjectSchema(e.objectName))}catch(e){E(e),w(!1)}})()},[e.objectName,t]),(0,J.useEffect)(()=>{(d||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){v(e.initialData||e.initialValues||{}),w(!1);return}if(!t){v(e.initialData||e.initialValues||{}),w(!1);return}try{v(await t.findOne(e.objectName,e.recordId)||{})}catch(e){E(e)}finally{w(!1)}})()},[d,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let K=(0,J.useCallback)(t=>he(t,{objectSchema:d,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:i}),[d,e.readOnly,e.mode,e.objectName,i]);(0,J.useEffect)(()=>{if(!d&&t)return;if(e.customFields?.length){m(e.customFields),w(!1);return}if(e.sections?.length){w(!1);return}if(!d)return;let n=e.fields||Object.keys(d.fields||{}),r=[];for(let t of n){let n=typeof t==`string`?t:t.name;if(!n)continue;let a=d.fields?.[n];a&&r.push({name:n,label:i(e.objectName,n,a.label||n),type:R(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})}m(r),w(!1)},[d,e.fields,e.customFields,e.sections,e.readOnly,e.mode,t]);let de=(0,J.useCallback)(async n=>{k(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(n),e.onOpenChange?.(!1),n;let r,i=ct(n,d);if(l?.isLoaded){let t={};for(let n of Object.keys(i))l.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,d,l]),q=(0,J.useCallback)(()=>{F(!1),I.current&&(I.current=!1,e.onCancel?.()),e.onOpenChange?.(!1)},[e]),fe=(0,J.useCallback)(e=>{I.current=e,B&&A?F(!0):q()},[B,A,q]),Y=(0,J.useCallback)(()=>{I.current=!0,q()},[q]),Z=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,Q=e.showSubmit!==!1&&e.mode!==`view`,me=e.showCancel!==!1,ge=e.submitText||(e.mode===`create`?`Create`:`Update`),_e=e.cancelText||`Cancel`,ve={type:`form`,objectName:e.objectName,layout:Z,defaultValues:h,submitLabel:ge,cancelLabel:_e,showSubmit:Q,showCancel:me,onSubmit:de,onCancel:Y,onDirtyChange:j,showActions:!1,id:H},$=()=>{if(T)return(0,X.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,X.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,X.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:T.message})]});if(y)return(0,X.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(x,{className:`h-4 w-24`}),(0,X.jsx)(x,{className:`h-10 w-full`})]},e))});if(e.sections?.length){let t=e.sections,n=(e,t)=>e.name||e.label||String(t),r=e=>(0,X.jsx)(s,{schema:{...ve,fields:u(K(e))}});return e.contentLayout===`tabbed`&&t.length>1?(0,X.jsxs)(ae,{defaultValue:n(t[0],0),className:`w-full`,children:[(0,X.jsx)(te,{className:`mb-4`,children:t.map((e,t)=>(0,X.jsx)(se,{value:n(e,t),children:e.label||`Section ${t+1}`},n(e,t)))}),t.map((e,t)=>(0,X.jsx)(P,{value:n(e,t),children:(0,X.jsx)(pe,{description:e.description,columns:e.columns||1,gridClassName:mt[e.columns||1],children:r(e)})},n(e,t)))]}):(0,X.jsx)(`div`,{className:`space-y-6`,children:t.map((e,t)=>(0,X.jsx)(pe,{label:e.label,description:e.description,columns:e.columns||1,gridClassName:mt[e.columns||1],children:r(e)},n(e,t)))})}let t=U??at(p,d,e.columns,e.mode),n=mt[t.columns||1];return(0,X.jsx)(s,{schema:{...ve,fields:u(t.fields),columns:t.columns,...n?{fieldContainerClass:n}:{}}})},ye=e.subforms;if(c)return(0,X.jsxs)(`div`,{className:`@container rounded-md border bg-card p-4`,children:[(e.title||e.description)&&(0,X.jsxs)(`div`,{className:`mb-3 space-y-0.5`,children:[e.title&&(0,X.jsx)(`div`,{className:`text-sm font-semibold`,children:e.title}),e.description&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),$()]});if(ye?.length&&e.mode!==`view`)return(0,X.jsx)(O,{open:V,onOpenChange:e.onOpenChange,children:(0,X.jsxs)(C,{className:S(W,`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,X.jsxs)(ie,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,X.jsx)(b,{children:e.title}),e.description?(0,X.jsx)(_,{children:e.description}):(0,X.jsx)(_,{className:`sr-only`,children:`Enter the record and its line items, then save.`})]}),(0,X.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:(0,X.jsx)(qe,{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:ge,details:ye,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:t})})]})});let be=!y&&!T&&(Q||me);return(0,X.jsx)(O,{open:V,onOpenChange:t=>{if(t){e.onOpenChange?.(!0);return}fe(!1)},children:(0,X.jsxs)(C,{className:S(W,`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,X.jsxs)(ie,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,X.jsx)(b,{children:e.title}),e.description?(0,X.jsx)(_,{children:e.description}):(0,X.jsx)(_,{className:`sr-only`,children:`Complete the form fields, then submit or cancel.`})]}),(0,X.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:$()}),be&&(0,X.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,X.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[me&&(0,X.jsx)(G,{type:`button`,variant:`outline`,onClick:Y,disabled:D,className:`w-full sm:w-auto`,children:_e}),Q&&(0,X.jsxs)(G,{type:`submit`,form:H,disabled:D,className:`w-full sm:w-auto`,children:[D&&(0,X.jsx)(ue,{className:`mr-2 h-4 w-4 animate-spin`}),ge]})]})}),(0,X.jsx)(L,{open:N,onOpenChange:F,children:(0,X.jsxs)(z,{children:[(0,X.jsxs)(ce,{children:[(0,X.jsx)(le,{children:a(`form.discardTitle`)}),(0,X.jsx)(ee,{children:a(`form.discardMessage`)})]}),(0,X.jsxs)(M,{children:[(0,X.jsx)(ne,{onClick:()=>{I.current=!1},children:a(`form.keepEditing`)}),(0,X.jsx)(re,{onClick:q,children:a(`form.discard`)})]})]})})]})})};function gt(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`).map(e=>({key:typeof e.key==`string`?e.key:``,label:typeof e.label==`string`?e.label:void 0,collapsible:typeof e.collapsible==`boolean`?e.collapsible:void 0,collapsed:typeof e.collapsed==`boolean`?e.collapsed:void 0})).filter(e=>e.key):[]}function _t(e,t){let n=gt(t);if(n.length===0)return null;let r=new Set(n.map(e=>e.key)),i=e=>{let t=e.group;return typeof t==`string`&&r.has(t)?t:null};if(!e.some(e=>i(e)!==null))return null;let a=new Map;for(let e of n)a.set(e.key,[]);let o=[];for(let t of e){let e=i(t);e?a.get(e).push(t):o.push(t)}let s=[];for(let e of n){let t=a.get(e.key);t.length!==0&&s.push({name:e.key,label:e.label??e.key,fields:t.map(e=>e.name),...e.collapsible===void 0?{}:{collapsible:e.collapsible},...e.collapsed===void 0?{}:{collapsed:e.collapsed}})}return o.length>0&&s.push({fields:o.map(e=>e.name)}),s}var vt=({schema:e,dataSource:t})=>{let n=r(),i=(0,J.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}=g(),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,X.jsx)(qe,{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,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,X.jsx)(ge,{schema:{...i,formType:`tabbed`,sections:i.sections.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields})),defaultTab:i.defaultTab,tabPosition:i.tabPosition},dataSource:t,className:i.className});if(i.formType===`wizard`&&i.sections?.length)return(0,X.jsx)(_e,{schema:{...i,formType:`wizard`,sections:i.sections.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields})),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,X.jsx)(ve,{schema:{...i,formType:`split`,sections:i.sections.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields})),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,X.jsx)(dt,{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})),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,X.jsx)(ht,{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})),open:i.open,onOpenChange:i.onOpenChange,modalSize:i.modalSize,modalCloseButton:i.modalCloseButton},dataSource:t,className:i.className})}return(0,X.jsx)(yt,{schema:i,dataSource:t})},yt=({schema:e,dataSource:t})=>{let{fieldLabel:n,sectionLabel:i}=g(),a=E(),o=r(),c=(0,J.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,J.useState)(null),[d,f]=(0,J.useState)([]),[p,m]=(0,J.useState)(null),[h,_]=(0,J.useState)(!0),[v,y]=(0,J.useState)(null),b=e.customFields&&e.customFields.length>0;(0,J.useEffect)(()=>{b&&(m(e.initialData||e.initialValues||{}),_(!1))},[b,e.initialData,e.initialValues]),(0,J.useEffect)(()=>{b?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){y(e),_(!1)}})():b||_(!1)},[e.objectName,t,b]),(0,J.useEffect)(()=>{l&&!b&&(async()=>{if(!e.recordId||e.mode===`create`){m(e.initialData||e.initialValues||{}),_(!1);return}if(!b){if(!t){y(Error(`DataSource is required for fetching record data (inline data not provided)`)),_(!1);return}_(!0);try{m(await t.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),y(e)}finally{_(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,t,l,b]);let x=(0,J.useCallback)(e=>{if(!e||typeof e.visible==`function`)return e;let t=e.visibleOn;return typeof t==`string`&&t.trim()?{...e,visible:e=>V(t,e)}:e},[]);(0,J.useEffect)(()=>{if(b&&e.customFields){f(e.customFields.map(x)),_(!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&&!b)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(x(s));else if(a){let o={name:i,label:n(e.objectName,i,a.label||t),type:R(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: ${N(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.visible=e=>V(a.visible_on,e)),r.push(o)}}),f(r),!b&&e.recordId&&e.mode!==`create`&&t||_(!1)},[l,e.fields,e.customFields,e.readOnly,e.mode,b,e.recordId,t]);let S=(0,J.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={})),b&&!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=n;if(o?.isLoaded&&n&&typeof n==`object`){i={};for(let t of Object.keys(n))o.checkField(e.objectName,t,`write`)&&(i[t]=n[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){let t=Y(e.navigateOnSuccess,n);if(t)return window.location.assign(t),n;q.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,b,o]),C=(0,J.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),w={...J.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},T=J.useMemo(()=>e.sections?.length?null:_t(d,l?.fieldGroups),[e.sections,d,l]),D=e.sections?.length?e.sections:T,[O,k]=(0,J.useState)({});if(v)return(0,X.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,X.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,X.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:v.message})]});if(h)return(0,X.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,X.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,X.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let A=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(D?.length&&(!e.formType||e.formType===`simple`)){let t=[];return D.forEach((n,r)=>{let a=n.fields.map(e=>typeof e==`string`?e:e.field??e.name),o=c(d.filter(e=>a.includes(e.name)));if(o.length===0)return;let s=n.name||n.label||String(r),l=n.name?i(e.objectName,n.name,n.label||n.name):n.label,u=O[s]??n.collapsed??!1;l&&t.push({name:`__section_${s}`,label:l,type:`section-divider`,colSpan:4,collapsible:n.collapsible,collapsed:u,onToggle:n.collapsible?()=>k(e=>({...e,[s]:!u})):void 0}),l&&u?t.push(...o.map(e=>({...e,hidden:!0}))):t.push(...o)}),(0,X.jsx)(`div`,{className:`w-full`,children:(0,X.jsx)(s,{schema:{type:`form`,objectName:e.objectName,fields:t,layout:A,defaultValues:w,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,onSubmit:S,onCancel:C}})})}let j=e.sections?.length,M=c(d),P=j?{fields:M,columns:e.columns}:at(M,l,e.columns,e.mode),F=e.mobile,I=F?.fullscreenLongText?P.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}):P.fields,L=F?.stepper,ee=F?.stepperMinFields??8,z=Math.max(1,F?.stepperFieldsPerStep??1);if(!e.formType&&!j&&I.length>=2&&(L===!0||L===`auto`&&a&&I.length>=ee)){let n=I,r=[];for(let e=0;e<n.length;e+=z){let t=n.slice(e,e+z);r.push({name:`step-${Math.floor(e/z)+1}`,label:t[0]?.label||t[0]?.name||`Step ${Math.floor(e/z)+1}`,fields:t})}return(0,X.jsx)(_e,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:t,className:e.className})}let te={type:`form`,objectName:e.objectName,fields:I,layout:A,columns:P.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.resetOnSuccess&&e.mode===`create`,defaultValues:w,onSubmit:S,onCancel:C,className:e.className,mobileStickyActions:!!F?.stickyActions};return(0,X.jsx)(`div`,{className:F?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":F?`true`:void 0,children:(0,X.jsx)(s,{schema:te})})},bt={text:200,email:254,url:2048,phone:32,textarea:5e3,markdown:5e3,html:5e3},xt=`_company_website_2`,St=1500;function Ct(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 wt(e){return e&&e.map(e=>{let t=bt[String(e.type||``).toLowerCase()];return!t||(e.maxLength??e.max_length)?e:{...e,maxLength:t}})}var Tt=({config:e,dataSource:t,prefillParams:n,className:r})=>{let[i,a]=(0,J.useState)(!1),[o,s]=(0,J.useState)(!1),[c,l]=(0,J.useState)(null),[u,d]=(0,J.useState)(!(e.consent?.required??!!e.consent)),[f,m]=(0,J.useState)(null),h=(0,J.useRef)(null),g=(0,J.useRef)(0);(0,J.useEffect)(()=>{i||(g.current=Date.now())},[i]);let _=e.honeypot===!1?null:e.honeypot||xt,v=e.minFillTime??St,y=(0,J.useMemo)(()=>wt(e.customFields),[e.customFields]),b=(0,J.useMemo)(()=>{if(!t||y&&y.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,y,e.fields]),x=(0,J.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]),S=(0,J.useCallback)(async n=>{if(e.consent?.required&&!u){m(e.texts?.consentRequired??`Please accept the privacy policy to continue.`);return}if(m(null),_&&h.current?.value){a(!0);return}if(v>0&&Date.now()-g.current<v){l(e.texts?.rateLimited??`Please take a moment to review your answers before submitting.`);return}let r={...n};_&&delete r[_],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(Ct(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,_,v]),C=(0,J.useCallback)(()=>{a(!1),l(null)},[]),w=(0,J.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,X.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,X.jsxs)(`div`,{className:`max-w-md w-full bg-card border rounded-xl shadow-sm p-8 text-center space-y-4`,children:[(0,X.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,X.jsx)(p,{className:`h-8 w-8`,"aria-hidden":`true`})}),(0,X.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||n.thankYouTitle||`Thank You!`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t?.message||n.thankYouMessage||`Your submission has been received successfully.`}),e.allowMultiple&&(0,X.jsx)(G,{variant:`outline`,size:`sm`,onClick:C,className:`mt-2`,children:n.submitAnother??`Submit Another Response`}),t?.redirectUrl&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a})]})})}let E=e.texts??{},O=!!e.consent?.required,k=`${e.formId}-consent`;return(0,X.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,X.jsxs)(`div`,{className:`max-w-2xl w-full bg-card border rounded-xl shadow-sm overflow-hidden`,children:[e.branding?.coverImage&&(0,X.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,X.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,X.jsx)(`img`,{src:e.branding.logo,alt:``,className:`h-8 mb-4`}),e.title&&(0,X.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground`,children:e.title}),e.description&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 leading-relaxed`,children:e.description}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 mt-3`,"aria-hidden":`true`,children:E.requiredHint??`* Required field`})]}),(0,X.jsxs)(`div`,{className:`relative px-6 sm:px-8 py-6`,children:[c&&(0,X.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,X.jsx)(vt,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:y,initialData:x,onSuccess:S,submitText:o?E.submitting??`Submitting...`:E.submit??`Submit`},dataSource:b}),_&&(0,X.jsxs)(`div`,{"aria-hidden":`true`,className:`absolute left-[-10000px] top-auto h-px w-px overflow-hidden`,children:[(0,X.jsx)(`label`,{htmlFor:`${e.formId}-${_}`,children:`Do not fill this field`}),(0,X.jsx)(`input`,{ref:h,id:`${e.formId}-${_}`,type:`text`,name:_,tabIndex:-1,autoComplete:`off`,defaultValue:``})]}),e.consent&&(0,X.jsxs)(`div`,{className:`mt-4`,children:[(0,X.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-foreground cursor-pointer select-none`,children:[(0,X.jsx)(`input`,{type:`checkbox`,id:k,checked:u,onChange:e=>{d(e.target.checked),e.target.checked&&m(null)},"aria-required":O||void 0,"aria-invalid":f?`true`:void 0,"aria-describedby":f?`${k}-error`:void 0,className:`mt-0.5 h-4 w-4 rounded border-input accent-primary`}),(0,X.jsxs)(`span`,{className:`leading-relaxed`,children:[e.consent.label??E.consentLabelDefault??`I agree to the privacy policy.`,O&&(0,X.jsx)(`span`,{"aria-hidden":`true`,className:`text-destructive ml-0.5`,children:`*`}),e.consent.privacyUrl&&(0,X.jsxs)(X.Fragment,{children:[` `,(0,X.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,X.jsx)(`p`,{id:`${k}-error`,role:`alert`,className:`mt-1.5 text-xs text-destructive`,children:f})]}),o&&(0,X.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,X.jsx)(ue,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{children:E.submitting??`Submitting…`})]})]}),(0,X.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,X.jsxs)(`p`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,X.jsx)(T,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{children:E.secureNotice??`Your information is transmitted securely and only used to respond to your request.`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground/80`,children:[e.privacyPolicyUrl&&(0,X.jsxs)(`a`,{href:e.privacyPolicyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 underline hover:text-foreground`,children:[(0,X.jsx)(D,{className:`h-3 w-3`,"aria-hidden":`true`}),E.consentLink??`Privacy policy`]}),(0,X.jsx)(`span`,{children:E.poweredBy??`Powered by ObjectStack`})]})]})]})})};function Et(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 Dt=({formId:e,formTitle:t,metrics:n,className:r})=>{let i=(0,J.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,J.useMemo)(()=>n.dailySubmissions?.length?Math.max(...n.dailySubmissions.map(e=>e.count),1):1,[n.dailySubmissions]);return(0,X.jsxs)(`div`,{className:`space-y-4 ${r||``}`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:t||`Form Analytics`}),(0,X.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,X.jsx)(d,{children:(0,X.jsxs)(B,{className:`pb-2`,children:[(0,X.jsx)(U,{children:`Total Submissions`}),(0,X.jsx)(H,{className:`text-2xl`,children:n.totalSubmissions.toLocaleString()})]})}),(0,X.jsxs)(d,{children:[(0,X.jsxs)(B,{className:`pb-2`,children:[(0,X.jsx)(U,{children:`Fill Rate`}),(0,X.jsxs)(H,{className:`text-2xl`,children:[i,`%`]})]}),(0,X.jsx)(I,{children:(0,X.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,X.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${i}%`}})})})]}),(0,X.jsx)(d,{children:(0,X.jsxs)(B,{className:`pb-2`,children:[(0,X.jsx)(U,{children:`Avg. Completion Time`}),(0,X.jsx)(H,{className:`text-2xl`,children:n.avgCompletionTime?Et(n.avgCompletionTime):`—`})]})})]}),n.dailySubmissions&&n.dailySubmissions.length>0&&(0,X.jsxs)(d,{children:[(0,X.jsx)(B,{children:(0,X.jsx)(H,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,X.jsx)(I,{children:(0,X.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:n.dailySubmissions.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,X.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,X.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,X.jsxs)(d,{children:[(0,X.jsxs)(B,{children:[(0,X.jsx)(H,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,X.jsx)(U,{children:`Percentage of users who completed each field`})]}),(0,X.jsx)(I,{children:(0,X.jsx)(`div`,{className:`space-y-3`,children:n.fieldDropOff.map((e,t)=>(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,X.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,X.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,X.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))})})]})]})},Ot=({schema:e})=>{let t=a()?.dataSource,n=i(),r=e.parentObject||n?.objectName,o=e.parentId||e.recordId||n?.recordId,[s,c]=(0,J.useState)([]),[l,u]=(0,J.useState)([]),[f,p]=(0,J.useState)(!0),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(!1),[v,y]=(0,J.useState)(null),b=(0,J.useCallback)(async()=>{if(!t||!o){p(!1);return}p(!0);try{let n=(await t.find(e.childObject,{$filter:{[e.relationshipField]:o},$top:500}))?.data??[];c(n.map(e=>({...e}))),u(n.map(e=>({...e}))),_(!1)}catch(e){y(e?.message||`Failed to load line items`)}finally{p(!1)}},[t,o,e.childObject,e.relationshipField]);(0,J.useEffect)(()=>{b()},[b]);let x=(0,J.useCallback)(e=>{c(e),_(!0)},[]),C=(0,J.useCallback)(async()=>{if(!(!t||!o)){h(!0),y(null);try{await De(t,r||e.childObject,o,{childObject:e.childObject,relationshipField:e.relationshipField,rows:s,original:l,amountField:e.amountField,totalField:r?e.totalField:void 0}),await b()}catch(e){y(e?.message||`Failed to save line items`)}finally{h(!1)}}},[t,o,s,l,e,r,b]),w=(0,J.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,X.jsxs)(d,{className:S(`shadow-none`),children:[(0,X.jsxs)(B,{className:`flex-row items-center justify-between gap-2 pb-2`,children:[(0,X.jsx)(H,{className:`text-sm font-medium`,children:e.title||`Line Items`}),!e.readonly&&(0,X.jsx)(G,{type:`button`,size:`sm`,onClick:C,disabled:m||f||!g||!o,children:m?`Saving…`:`Save`})]}),(0,X.jsxs)(I,{children:[v&&(0,X.jsx)(`p`,{className:`mb-2 text-sm text-destructive`,children:v}),f?(0,X.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Loading…`}):o?(0,X.jsx)(W,{value:s,onChange:x,field:w,readonly:e.readonly}):(0,X.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Save the record first to add line items.`})]})]})},kt=({schema:e})=>(0,X.jsx)(vt,{schema:e,dataSource:(0,J.useContext)(c)?.dataSource??void 0});l.register(`object-form`,kt,{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`]}]}),l.register(`form`,kt,{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`]}]}),l.register(`embeddable-form`,({schema:e})=>(0,X.jsx)(Tt,{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`}]}),l.register(`form-analytics`,({schema:e})=>(0,X.jsx)(Dt,{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`}]}),l.register(`object-master-detail-form`,({schema:e})=>(0,X.jsx)(qe,{schema:e,dataSource:(0,J.useContext)(c)?.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}]}),l.register(`line_items`,({schema:e})=>(0,X.jsx)(Ot,{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{Ve as i,ht as n,dt as r,vt as t};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n}from"./vendor-react-ClIa1CJA.js";import{n as r}from"./infrastructure-B1z73d-r.js";import{E as i,Q as a,R as o,V as s,Y as c,kt as l,t as u}from"./framework-CakMZS2A.js";import{$n as d,$t as f,As as p,Bs as m,Bt as h,Fc as g,Gn as _,Hs as v,Ht as y,Jn as b,Lt as x,Oc as S,P as C,Qt as w,Ra as T,Rt as E,Si as D,Un as O,Ut as k,Vs as A,Vt as j,_r as M,c as N,ct as P,en as F,er as I,fr as L,g as R,gr as ee,hr as z,lt as te,mr as ne,nr as B,pr as re,qn as ie,r as V,rr as H,st as ae,t as oe,tr as U,ut as se,v as W,vr as ce,xr as G,yr as le,za as ue,zs as K,zt as de}from"./ui-components-BXvcyYmR.js";import{r as q}from"./vendor-ui-utils-C92Fl7BT.js";var J=e(t(),1);function fe(e){try{return typeof window>`u`?!1:new URL(e,window.location.href).origin===window.location.origin}catch{return!1}}function Y(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 fe(r)?r:null}var X=n(),pe=({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,J.useState)(r),f={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)},m=c??!!e,h=e||t?(0,X.jsxs)(`div`,{className:S(`flex items-start gap-2`,!m&&`mb-4`,n&&`cursor-pointer select-none`),onClick:p,role:n?`button`:void 0,"aria-expanded":n?!l:void 0,children:[n&&(0,X.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:l?(0,X.jsx)(K,{className:`h-4 w-4`}):(0,X.jsx)(A,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,X.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),t&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:t})]})]}):null,g=l?null:(0,X.jsx)(`div`,{className:S(`grid gap-4`,s||f[i]),children:a});return m?(0,X.jsxs)(d,{className:S(`form-section`,o),children:[h&&(0,X.jsxs)(B,{className:`pb-3`,children:[e&&(0,X.jsx)(H,{className:`text-base`,children:e}),t&&(0,X.jsx)(U,{children:t}),n&&(0,X.jsx)(`button`,{type:`button`,className:`absolute right-4 top-4 text-muted-foreground`,onClick:p,"aria-expanded":!l,"aria-label":l?`Expand section`:`Collapse section`,children:l?(0,X.jsx)(K,{className:`h-4 w-4`}):(0,X.jsx)(A,{className:`h-4 w-4`})})]}),g&&(0,X.jsx)(I,{children:g})]}):(0,X.jsxs)(`div`,{className:S(`form-section`,o),children:[h,g]})};function Z(e,t){return typeof t==`string`&&t.trim()?{...e,visible:e=>V(t,e)}:e}function Q(e,t){let n=t.objectSchema?.fields?.[e];return n?{name:e,label:t.fieldLabel(t.objectName,e,n.label||e),type:R(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}:{name:e,label:e,type:`input`}}function me(e,t){if(typeof e==`string`){let n=t.objectSchema?.fields?.[e];return Z(Q(e,t),n?.visible_on??n?.visibleOn)}let n=e;if(typeof n.field!=`string`)return Z(n,n.visibleOn);let r=n.field,i=Q(r,t);return n.type!=null&&(i.type=R(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.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),Z(i,n.visibleOn)}function he(e,t){return(e.fields??[]).map(e=>me(e,t))}var ge=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=g(),[i,a]=(0,J.useState)(null),[o,c]=(0,J.useState)({}),[l,u]=(0,J.useState)(!0),[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`);J.useEffect(()=>{(async()=>{if(!t){u(!1);return}try{a(await t.getObjectSchema(e.objectName))}catch(e){f(e)}})()},[e.objectName,t]),J.useEffect(()=>{(i||!t)&&(async()=>{if(e.mode===`create`||!e.recordId||!t){c(e.initialData||e.initialValues||{}),u(!1);return}try{c(await t.findOne(e.objectName,e.recordId)||{})}catch(e){f(e)}finally{u(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let h=(0,J.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]),_=(0,J.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]),v=(0,J.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),y=(e,t)=>e.name||e.label||`tab-${t}`;if(d)return(0,X.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,X.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,X.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:d.message})]});if(l)return(0,X.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,X.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,X.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let b={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:_,onCancel:v},x=e.tabPosition===`left`||e.tabPosition===`right`;return(0,X.jsx)(`div`,{className:S(`w-full`,n,e.className),children:(0,X.jsxs)(ae,{value:p,onValueChange:m,orientation:x?`vertical`:`horizontal`,className:S(x&&`flex gap-4`),children:[(0,X.jsx)(te,{className:S(x?`flex-col h-auto`:``,e.tabPosition===`bottom`&&`order-last`,e.tabPosition===`right`&&`order-last`),children:e.sections.map((e,t)=>(0,X.jsx)(se,{value:y(e,t),className:x?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},y(e,t)))}),(0,X.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,X.jsx)(P,{value:y(t,n),className:`mt-0`,children:(0,X.jsx)(pe,{description:t.description,columns:t.columns||1,children:(0,X.jsx)(s,{schema:{...b,fields:h(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},y(t,n)))})]})})},_e=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=g(),[i,a]=(0,J.useState)(null),[o,c]=(0,J.useState)({}),[l,u]=(0,J.useState)(!0),[d,f]=(0,J.useState)(null),[p,h]=(0,J.useState)(0),[_,y]=(0,J.useState)(new Set),[b,x]=(0,J.useState)(!1),C=J.useId(),[w,T]=(0,J.useState)(0),E=J.useRef(!1),D=e.sections.length,O=p===0,k=p===D-1;J.useEffect(()=>{(async()=>{if(!t){u(!1);return}try{a(await t.getObjectSchema(e.objectName))}catch(e){f(e)}})()},[e.objectName,t]),J.useEffect(()=>{(i||!t)&&(async()=>{if(e.mode===`create`||!e.recordId||!t){E.current||=(c(e.initialData||e.initialValues||{}),!0),u(!1);return}try{c(await t.findOne(e.objectName,e.recordId)||{})}catch(e){f(e)}finally{u(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let A=(0,J.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]),j=(0,J.useMemo)(()=>p>=0&&p<D?A(e.sections[p]):[],[p,D,e.sections,A]),M=(0,J.useCallback)(async n=>{let r={...o,...n};if(c(r),y(e=>new Set(e).add(p)),k){x(!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{let t=Y(e.navigateOnSuccess,n);if(t)return window.location.assign(t),n;q.success(e.successMessage||(e.mode===`create`?`Created`:`Saved`)),e.resetOnSuccess&&e.mode===`create`&&(c({}),y(new Set),h(0),T(e=>e+1))}return n}catch(t){throw e.onError&&e.onError(t),t}finally{x(!1)}}else N(p+1)},[o,p,k,e,t]),N=(0,J.useCallback)(t=>{t>=0&&t<D&&(h(t),e.onStepChange&&e.onStepChange(t))},[D,e]),P=(0,J.useCallback)(()=>{N(p-1)},[p,N]),F=(0,J.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),I=(0,J.useCallback)(t=>{(e.allowSkip||_.has(t)||t<=p)&&N(t)},[e.allowSkip,_,p,N]);if(d)return(0,X.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,X.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,X.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:d.message})]});if(l)return(0,X.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,X.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,X.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let L=e.sections[p];return(0,X.jsxs)(`div`,{className:S(`w-full`,n,e.className),children:[e.showStepIndicator!==!1&&(0,X.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,X.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===p,i=_.has(n),a=e.allowSkip||i||n<=p;return(0,X.jsxs)(`li`,{className:S(`relative flex-1`,n!==D-1&&`pr-8 sm:pr-12`),children:[n!==D-1&&(0,X.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,X.jsx)(`div`,{className:S(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,X.jsxs)(`button`,{type:`button`,className:S(`group relative flex items-center`,a?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>I(n),disabled:!a,children:[(0,X.jsx)(`span`,{className:S(`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,X.jsx)(v,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,X.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,X.jsx)(`span`,{className:S(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,X.jsx)(`div`,{className:`min-h-[200px]`,children:L&&(0,X.jsx)(pe,{label:L.label,description:L.description,columns:L.columns||1,children:j.length>0?(0,X.jsx)(s,{schema:{type:`form`,objectName:e.objectName,id:C,fields:j,layout:`vertical`,defaultValues:o,showSubmit:!1,showCancel:!1,onSubmit:M}},w):(0,X.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,X.jsx)(`div`,{children:e.showCancel!==!1&&(0,X.jsx)(G,{variant:`ghost`,onClick:F,children:e.cancelText||`Cancel`})}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,p+1,` of `,D]}),!O&&(0,X.jsxs)(G,{variant:`outline`,onClick:P,children:[(0,X.jsx)(m,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),k?(0,X.jsxs)(G,{type:`submit`,form:C,disabled:b||e.mode===`view`,children:[b&&(0,X.jsx)(ue,{className:`mr-2 h-4 w-4 animate-spin`,"aria-hidden":!0}),b?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)]}):(0,X.jsxs)(G,{type:`submit`,form:C,children:[e.nextText||`Next`,(0,X.jsx)(K,{className:`h-4 w-4 ml-1`})]})]})]})]})},ve=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=g(),[i,a]=(0,J.useState)(null),[o,c]=(0,J.useState)({}),[l,u]=(0,J.useState)(!0),[d,p]=(0,J.useState)(null);(0,J.useEffect)(()=>{(async()=>{if(!t){u(!1);return}try{a(await t.getObjectSchema(e.objectName))}catch(e){p(e),u(!1)}})()},[e.objectName,t]),(0,J.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{c(await t.findOne(e.objectName,e.recordId)||{})}catch(e){p(e)}finally{u(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let m=(0,J.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,J.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,J.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),v=(0,J.useMemo)(()=>e.sections.slice(0,1),[e.sections]),y=(0,J.useMemo)(()=>e.sections.slice(1),[e.sections]);(0,J.useMemo)(()=>e.sections.flatMap(e=>m(e)),[e.sections,m]);let b=e.splitDirection||`horizontal`,x=e.splitSize||50;if(d)return(0,X.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,X.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,X.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:d.message})]});if(l)return(0,X.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,X.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,X.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:_},T=(t,n)=>(0,X.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,r)=>(0,X.jsx)(pe,{label:t.label,description:t.description,columns:t.columns||1,children:(0,X.jsx)(s,{schema:{...C,fields:m(t),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,X.jsx)(`div`,{className:S(`w-full`,n,e.className),children:(0,X.jsxs)(F,{orientation:b,className:`min-h-[300px] rounded-lg border`,children:[(0,X.jsx)(f,{defaultSize:x,minSize:20,children:T(v,y.length===0)}),y.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(w,{withHandle:e.splitResizable!==!1}),(0,X.jsx)(f,{defaultSize:100-x,minSize:20,children:T(y,!0)})]})]})})},$=e=>e==null?void 0:e.id??e._id??e.recordId,ye=new Set([`id`,`_id`,`recordId`]);function be(e,t){return e?Object.entries(e).every(([e,n])=>e===t||ye.has(e)?!0:n==null||n===``):!0}function xe(e,t,n){let r=[{object:e,action:`create`,data:t}];for(let e of n)for(let t of e.rows)be(t,e.relationshipField)||r.push({object:e.childObject,action:`create`,data:{...t,[e.relationshipField]:{$ref:0}}});return r}function Se(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}=Ce(e.original||[],n);for(let t of r){if(be(t,e.relationshipField))continue;let{id:n,_id:r,recordId:a,...o}=t;i.push({object:e.childObject,action:`create`,data:o})}for(let t of a)i.push({object:e.childObject,action:`update`,id:$(t),data:t});for(let t of o)i.push({object:e.childObject,action:`delete`,id:t})}return i}function Ce(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 we(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 Te(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 Ee(e,t,n){return n.length===0?[]:typeof e.bulk==`function`?Te(await e.bulk(t,`create`,n)):Te(await Promise.all(n.map(n=>e.create(t,n))))}async function De(e,t,n,r){let i=[],a=r.rows.filter(e=>$(e)||!be(e,r.relationshipField)).map(e=>({...e,[r.relationshipField]:n}));if(r.original!==void 0){let{toCreate:t,toUpdate:n,toDelete:o}=Ce(r.original,a),s=await Ee(e,r.childObject,t);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),t))),await Promise.all(o.map(t=>e.delete(r.childObject,t)))}else{let t=await Ee(e,r.childObject,a);for(let e of t){let t=$(e);t&&i.push({object:r.childObject,id:t})}}if(r.totalField){let i=we(r.rows,r.amountField||`amount`);await e.update(t,n,{[r.totalField]:i})}return{created:i}}var Oe=new Set([`id`,`_id`,`recordId`,`created_at`,`updated_at`,`created_by`,`updated_by`,`createdAt`,`updatedAt`,`createdBy`,`updatedBy`,`organization_id`,`tenant_id`,`space`,`owner`]),ke=new Set([`position`,`sort_order`,`sequence`,`line_no`,`line_number`,`sort`]),Ae=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`,`file`,`image`,`avatar`,`json`,`object`,`grid`,`table`,`location`,`vector`,`html`,`markdown`,`richtext`]);function je(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 Me(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 Ne(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 Pe=[`name`,`title`,`subject`,`label`,`full_name`,`display_name`,`code`],Fe={select:0,currency:1,number:1,lookup:2,date:3,text:4};function Ie(e,t){if(t<=0||e.length<=t)return e;let n=new Set,r=e.find(e=>Pe.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)=>(Fe[e.c.type]??5)-(Fe[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 Le(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(Oe.has(e)||r.has(e)||ke.has(e)||n?.system||n?.readonly||n?.hidden||Ae.has(n?.type))continue;let a={field:e,label:n?.label||e,type:je(n?.type),required:!!n?.required},o=Me(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 Ie(i,t.maxColumns??6)}var Re=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`]);function ze(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;Oe.has(e)||r.has(e)||ke.has(e)||n?.system||n?.hidden||Re.has(n?.type)||i.push(e)}return i}var Be=new Set([`textarea`,`richtext`,`html`,`markdown`,`rich-text`,`file`,`image`,`avatar`,`attachment`,`json`,`location`,`address`]);function Ve(e,t,n={}){if(t===`grid`||t===`form`)return t;let r=e?.fields??{},i=ze(e,{relationshipField:n.relationshipField});return i.some(e=>Be.has(r[e]?.type))||i.length>8?`form`:`grid`}var He=[`amount`,`total`,`subtotal`,`line_total`,`line_amount`,`net_amount`];function Ue(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=>He.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 We(e,t,n,r={}){let i=r.relationshipField||Ne(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?r.columns:Le(t,{relationshipField:i}),o=r.amountField||Ue(a);return{childObject:e,relationshipField:i,columns:a,formFields:ze(t,{relationshipField:i}),mode:Ve(t,r.inlineEdit??(t?.fields)?.[i]?.inlineEdit,{relationshipField:i}),amountField:o,sortField:Object.keys(t?.fields??{}).find(e=>ke.has(e))}}function Ge(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 Ke=({details:e,state:t,setRows:n,formHostRef:r,taxRateField:i,formKey:a,onRowExpand:o,onAddViaForm:s})=>{let[c,l]=(0,J.useState)({}),u=(0,J.useRef)(``);(0,J.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{let t=Ge(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+we(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,X.jsxs)(X.Fragment,{children:[e.map((e,r)=>(0,X.jsxs)(`section`,{className:`space-y-2`,children:[(0,X.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:e.title||`Line Items`}),e.columns?.length?(0,X.jsx)(W,{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,X.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`Loading columns…`})]},`${e.childObject}-${r}`)),m&&(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsxs)(`dl`,{className:`w-64 space-y-1.5 text-sm`,"data-testid":`md-totals`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:`Subtotal`}),(0,X.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-subtotal`,children:v(p)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`dt`,{className:`text-muted-foreground`,children:[`Tax (`,h,`%)`]}),(0,X.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-tax`,children:v(g)})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-t border-border pt-1.5 text-base font-semibold`,children:[(0,X.jsx)(`dt`,{children:`Total`}),(0,X.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-grand-total`,children:v(_)})]})]})})]})},qe=({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),[o,s]=(0,J.useState)(a?null:r),c=o??r;(0,J.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=>{if(n.relationshipField&&n.columns?.length)return n;try{let r=await t.getObjectSchema(n.childObject),i=We(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,J.useState)(()=>r.map(()=>({rows:[],original:[]}))),f=(0,J.useRef)(l);f.current=l;let[p,m]=(0,J.useState)(0),[h,g]=(0,J.useState)(!1),_=(0,J.useRef)(!1),v=(0,J.useRef)(null),y=(0,J.useCallback)(()=>{_.current=!1,g(!1),v.current&&=(clearTimeout(v.current),null)},[]);(0,J.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 b=(0,J.useCallback)((e,t)=>{u(n=>n.map((n,r)=>r===e?{...n,rows:t}:n))},[]),x=e.taxRateField||`tax_rate`,[C,w]=(0,J.useState)(null),T=C?l[C.detailIdx]?.rows?.[C.rowIdx]:void 0,E=C?c[C.detailIdx]:void 0,D=(0,J.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,J.useCallback)(e=>{u(t=>{let n=t.map((t,n)=>n===e?{...t,rows:[...t.rows,{}]}:t);return w({detailIdx:e,rowIdx:n[e].rows.length-1,isNew:!0}),n})},[]),k=(0,J.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,J.useCallback)(async t=>{y(),q.success(i?e.title?`${e.title} saved`:`Saved`:`Created`),i||(u(c.map(()=>({rows:[],original:[]}))),m(e=>e+1)),await e.onSuccess?.(t)},[i,e.onSuccess,e.title,c.length,y]),j=(0,J.useCallback)(t=>{y(),q.error(t?.message||`Save failed`),e.onError?.(t)},[e,y]),M=(0,J.useCallback)(async n=>{let r=[];for(let a=0;a<c.length;a++){let o=c[a],{rows:s,original:l}=f.current[a];if(!o.relationshipField)continue;let{created:u}=await De(t,e.objectName,n,{childObject:o.childObject,relationshipField:o.relationshipField,rows:s,original:i?l:void 0,amountField:o.amountField,totalField:o.totalField});r.push(...u)}return r},[c,i,t,e.objectName]),N=(0,J.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,J.useCallback)(async n=>{let r=t,a={...n};c.forEach((e,t)=>{e.totalField&&(a[e.totalField]=we(f.current[t]?.rows??[],e.amountField||`amount`))});let o=i?Se(e.objectName,e.recordId,a,c.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:f.current[t]?.rows??[],original:f.current[t]?.original??[]}))):xe(e.objectName,a,c.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:f.current[t]?.rows??[]})));return(await r.batchTransaction(o))?.results?.[0]??{...a,id:e.recordId}},[t,c,e.objectName,e.recordId,i]),L=(0,J.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,J.useRef)(null),ee=e.submitText??(i?`Save`:`Create`),z=(0,J.useCallback)(()=>{_.current||R.current?.querySelector(`form`)&&(_.current=!0,g(!0),setTimeout(()=>{(R.current?.querySelector(`form`))?.requestSubmit()},0),v.current=setTimeout(()=>y(),1500))},[y]);return(0,J.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]),(0,X.jsxs)(`div`,{className:S(`space-y-6`,n,e.className),children:[(0,X.jsx)(`div`,{ref:R,children:(0,X.jsx)(vt,{schema:L,dataSource:t},p)}),(0,X.jsx)(Ke,{details:c,state:l,setRows:b,formHostRef:R,taxRateField:x,formKey:p,onRowExpand:(e,t)=>w({detailIdx:e,rowIdx:t}),onAddViaForm:O}),C&&E&&(0,X.jsxs)(d,{className:`border-primary/40 shadow-none ring-1 ring-primary/10`,"data-testid":`md-row-form`,children:[(0,X.jsxs)(B,{className:`pb-2 flex flex-row items-center justify-between gap-2 space-y-0`,children:[(0,X.jsxs)(H,{className:`text-sm font-medium`,children:[E.title||`Line item`,` — row `,C.rowIdx+1]}),(0,X.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 text-xs text-muted-foreground`,onClick:k,children:`Close`})]}),(0,X.jsx)(I,{children:(0,X.jsx)(vt,{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,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-border pt-4`,children:[e.onCancel&&(0,X.jsx)(G,{type:`button`,variant:`outline`,onClick:e.onCancel,disabled:h,"data-testid":`md-form-cancel`,children:`Cancel`}),(0,X.jsx)(G,{type:`button`,onClick:z,disabled:h||a&&!o,"data-testid":`md-form-submit`,children:h?`Saving…`:ee})]})]})},Je=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),Ye=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),Xe=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function Ze(e){return Ye.has(e)}function Qe(e){return Xe.has(e)}function $e(e){return e<=3?1:2}function et(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&Ze(e.type)?{...e,colSpan:t}:e)}var tt=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 nt(e,t){return e.filter(e=>{if(tt.has(e.name))return!1;let n=t?.fields?.[e.name];return!(n?.hidden===!0||n?.readonly===!0)})}function rt(e,t){return e.filter(e=>{if(e.type&&Je.has(e.type))return!1;let n=t?.fields?.[e.name];return n?!Qe(n.type):!0})}function it(e){return e<=1?`default`:e===2?`xl`:`full`}function at(e,t,n,r){let i=[...e];if(i=nt(i,t),r===`create`&&(i=rt(i,t)),n!==void 0)return i=et(i,n),{fields:i,columns:n};let a=$e(i.length);return i=et(i,a),{fields:i,columns:a}}var ot=new Set([`id`,`_id`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`organization_id`,`organizationId`]),st=new Set([`formula`,`rollup`,`lookup_value`,`auto_number`,`autonumber`,`computed`]);function ct(e,t){if(!e||typeof e!=`object`)return e;let n={},r=t?.fields;for(let[t,i]of Object.entries(e))if(!ot.has(t)){if(r){let e=r[t];if(!e)continue;let n=String(e.type||``).toLowerCase();if(st.has(n)||e.computed===!0||e.formula||e.readOnly===!0||e.readonly===!0)continue}n[t]=i}return n}var lt={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`},ut=u({"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`),dt=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:r}=g(),{t:i}=ut(),a=o(),[c,l]=(0,J.useState)(null),[u,d]=(0,J.useState)([]),[f,p]=(0,J.useState)({}),[m,_]=(0,J.useState)(!0),[v,b]=(0,J.useState)(null),[x,C]=(0,J.useState)(!1),[w,T]=(0,J.useState)(!1),[E,D]=(0,J.useState)(!1),O=(0,J.useRef)(!1),A=e.confirmOnDiscard!==!1,N=e.open!==!1,P=e.drawerSide||`right`,F=(0,J.useId)(),[I,te]=(0,J.useState)(()=>{let t={};return e.sections?.forEach((e,n)=>{let r=e.name||String(n);e.collapsed&&(t[r]=!0)}),t});(0,J.useEffect)(()=>{(async()=>{if(!t){_(!1);return}try{l(await t.getObjectSchema(e.objectName))}catch(e){b(e),_(!1)}})()},[e.objectName,t]),(0,J.useEffect)(()=>{(c||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){p(e.initialData||e.initialValues||{}),_(!1);return}if(!t){p(e.initialData||e.initialValues||{}),_(!1);return}try{p(await t.findOne(e.objectName,e.recordId)||{})}catch(e){b(e)}finally{_(!1)}})()},[c,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let B=(0,J.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,J.useEffect)(()=>{if(!c&&t)return;if(e.customFields?.length){d(e.customFields),_(!1);return}if(e.sections?.length){_(!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:R(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),_(!1)},[c,e.fields,e.customFields,e.sections,e.readOnly,e.mode,t]);let ie=(0,J.useCallback)(async n=>{D(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(n),e.onOpenChange?.(!1),n;let r,i=ct(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{D(!1)}},[e,t,c]),V=(0,J.useCallback)(()=>{T(!1),O.current&&(O.current=!1,e.onCancel?.()),e.onOpenChange?.(!1)},[e]),H=(0,J.useCallback)(e=>{O.current=e,A&&x?T(!0):V()},[A,x,V]),ae=(0,J.useCallback)(()=>{O.current=!0,V()},[V]),U=(0,J.useMemo)(()=>{if(e.drawerWidth)return P===`left`||P===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,P]),se=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,W=e.showSubmit!==!1&&e.mode!==`view`,K=e.showCancel!==!1,q=e.submitText||(e.mode===`create`?`Create`:`Update`),fe=e.cancelText||`Cancel`,Y={type:`form`,objectName:e.objectName,layout:se,defaultValues:f,submitLabel:q,cancelLabel:fe,showSubmit:W,showCancel:K,onSubmit:ie,onCancel:ae,onDirtyChange:C,showActions:!1,id:F},pe=()=>{if(v)return(0,X.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,X.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,X.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:v.message})]});if(m)return(0,X.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,X.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,X.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?()=>te(e=>({...e,[r]:!i})):void 0});let a=B(e);i?t.push(...a.map(e=>({...e,hidden:!0}))):t.push(...a)}),(0,X.jsx)(s,{schema:{...Y,fields:t}})}let t=at(u,c,e.columns,e.mode),n=lt[t.columns||1];return(0,X.jsx)(s,{schema:{...Y,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},Z=e.subforms,Q=Z?.length&&e.mode!==`view`?(0,X.jsx)(qe,{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,details:Z,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:t}):pe();return a?(0,X.jsxs)(`div`,{className:`@container rounded-md border bg-card p-4`,children:[(e.title||e.description)&&(0,X.jsxs)(`div`,{className:`mb-3 space-y-0.5`,children:[e.title&&(0,X.jsx)(`div`,{className:`text-sm font-semibold`,children:e.title}),e.description&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),Q]}):(0,X.jsx)(de,{open:N,onOpenChange:t=>{if(t){e.onOpenChange?.(!0);return}H(!1)},children:(0,X.jsxs)(h,{side:P,className:S(`overflow-y-auto`,n,e.className),style:U,children:[(e.title||e.description)&&(0,X.jsxs)(y,{children:[e.title&&(0,X.jsx)(k,{children:e.title}),e.description?(0,X.jsx)(j,{children:e.description}):(0,X.jsx)(j,{className:`sr-only`,children:`Complete the form fields, then submit or cancel.`})]}),(0,X.jsx)(`div`,{className:`@container py-4`,children:Q}),!v&&!m&&!(Z?.length&&e.mode!==`view`)&&(W||K)&&(0,X.jsx)(`div`,{className:`shrink-0 border-t px-4 py-3 bg-background`,"data-testid":`drawer-form-footer`,children:(0,X.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[K&&(0,X.jsx)(G,{type:`button`,variant:`outline`,onClick:ae,disabled:E,className:`w-full sm:w-auto`,children:fe}),W&&(0,X.jsxs)(G,{type:`submit`,form:F,disabled:E,className:`w-full sm:w-auto`,children:[E&&(0,X.jsx)(ue,{className:`mr-2 h-4 w-4 animate-spin`}),q]})]})}),(0,X.jsx)(L,{open:w,onOpenChange:T,children:(0,X.jsxs)(z,{children:[(0,X.jsxs)(ce,{children:[(0,X.jsx)(le,{children:i(`form.discardTitle`)}),(0,X.jsx)(ee,{children:i(`form.discardMessage`)})]}),(0,X.jsxs)(M,{children:[(0,X.jsx)(ne,{onClick:()=>{O.current=!1},children:i(`form.keepEditing`)}),(0,X.jsx)(re,{onClick:V,children:i(`form.discard`)})]})]})})]})})},ft=u({"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`),pt={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`},mt={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`},ht=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:i}=g(),{t:a}=ft(),c=o(),l=r(),u=(0,J.useCallback)(t=>{if(!l?.isLoaded)return t;let n=[];for(let r of t){if(!r?.name){n.push(r);continue}l.checkField(e.objectName,r.name,`read`)&&(!l.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0}):n.push(r))}return n},[l,e.objectName,e.mode]),[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)([]),[h,v]=(0,J.useState)({}),[y,w]=(0,J.useState)(!0),[T,E]=(0,J.useState)(null),[D,k]=(0,J.useState)(!1),[A,j]=(0,J.useState)(!1),[N,F]=(0,J.useState)(!1),I=(0,J.useRef)(!1),B=e.confirmOnDiscard!==!1,V=e.open!==!1,H=(0,J.useId)(),U=(0,J.useMemo)(()=>e.sections?.length||e.customFields?.length?null:at(p,d,e.columns,e.mode),[p,d,e.columns,e.mode,e.sections,e.customFields]),W=pt[(0,J.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(U?.columns&&U.columns>1)return it(U.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return it(t)}return`default`},[e.modalSize,U,e.sections])]||pt.default;(0,J.useEffect)(()=>{(async()=>{if(!t){w(!1);return}try{f(await t.getObjectSchema(e.objectName))}catch(e){E(e),w(!1)}})()},[e.objectName,t]),(0,J.useEffect)(()=>{(d||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){v(e.initialData||e.initialValues||{}),w(!1);return}if(!t){v(e.initialData||e.initialValues||{}),w(!1);return}try{v(await t.findOne(e.objectName,e.recordId)||{})}catch(e){E(e)}finally{w(!1)}})()},[d,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let K=(0,J.useCallback)(t=>he(t,{objectSchema:d,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:i}),[d,e.readOnly,e.mode,e.objectName,i]);(0,J.useEffect)(()=>{if(!d&&t)return;if(e.customFields?.length){m(e.customFields),w(!1);return}if(e.sections?.length){w(!1);return}if(!d)return;let n=e.fields||Object.keys(d.fields||{}),r=[];for(let t of n){let n=typeof t==`string`?t:t.name;if(!n)continue;let a=d.fields?.[n];a&&r.push({name:n,label:i(e.objectName,n,a.label||n),type:R(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})}m(r),w(!1)},[d,e.fields,e.customFields,e.sections,e.readOnly,e.mode,t]);let de=(0,J.useCallback)(async n=>{k(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(n),e.onOpenChange?.(!1),n;let r,i=ct(n,d);if(l?.isLoaded){let t={};for(let n of Object.keys(i))l.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,d,l]),q=(0,J.useCallback)(()=>{F(!1),I.current&&(I.current=!1,e.onCancel?.()),e.onOpenChange?.(!1)},[e]),fe=(0,J.useCallback)(e=>{I.current=e,B&&A?F(!0):q()},[B,A,q]),Y=(0,J.useCallback)(()=>{I.current=!0,q()},[q]),Z=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,Q=e.showSubmit!==!1&&e.mode!==`view`,me=e.showCancel!==!1,ge=e.submitText||(e.mode===`create`?`Create`:`Update`),_e=e.cancelText||`Cancel`,ve={type:`form`,objectName:e.objectName,layout:Z,defaultValues:h,submitLabel:ge,cancelLabel:_e,showSubmit:Q,showCancel:me,onSubmit:de,onCancel:Y,onDirtyChange:j,showActions:!1,id:H},$=()=>{if(T)return(0,X.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,X.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,X.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:T.message})]});if(y)return(0,X.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(x,{className:`h-4 w-24`}),(0,X.jsx)(x,{className:`h-10 w-full`})]},e))});if(e.sections?.length){let t=e.sections,n=(e,t)=>e.name||e.label||String(t),r=e=>(0,X.jsx)(s,{schema:{...ve,fields:u(K(e))}});return e.contentLayout===`tabbed`&&t.length>1?(0,X.jsxs)(ae,{defaultValue:n(t[0],0),className:`w-full`,children:[(0,X.jsx)(te,{className:`mb-4`,children:t.map((e,t)=>(0,X.jsx)(se,{value:n(e,t),children:e.label||`Section ${t+1}`},n(e,t)))}),t.map((e,t)=>(0,X.jsx)(P,{value:n(e,t),children:(0,X.jsx)(pe,{description:e.description,columns:e.columns||1,gridClassName:mt[e.columns||1],children:r(e)})},n(e,t)))]}):(0,X.jsx)(`div`,{className:`space-y-6`,children:t.map((e,t)=>(0,X.jsx)(pe,{label:e.label,description:e.description,columns:e.columns||1,gridClassName:mt[e.columns||1],children:r(e)},n(e,t)))})}let t=U??at(p,d,e.columns,e.mode),n=mt[t.columns||1];return(0,X.jsx)(s,{schema:{...ve,fields:u(t.fields),columns:t.columns,...n?{fieldContainerClass:n}:{}}})},ye=e.subforms;if(c)return(0,X.jsxs)(`div`,{className:`@container rounded-md border bg-card p-4`,children:[(e.title||e.description)&&(0,X.jsxs)(`div`,{className:`mb-3 space-y-0.5`,children:[e.title&&(0,X.jsx)(`div`,{className:`text-sm font-semibold`,children:e.title}),e.description&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),$()]});if(ye?.length&&e.mode!==`view`)return(0,X.jsx)(O,{open:V,onOpenChange:e.onOpenChange,children:(0,X.jsxs)(C,{className:S(W,`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,X.jsxs)(ie,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,X.jsx)(b,{children:e.title}),e.description?(0,X.jsx)(_,{children:e.description}):(0,X.jsx)(_,{className:`sr-only`,children:`Enter the record and its line items, then save.`})]}),(0,X.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:(0,X.jsx)(qe,{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:ge,details:ye,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:t})})]})});let be=!y&&!T&&(Q||me);return(0,X.jsx)(O,{open:V,onOpenChange:t=>{if(t){e.onOpenChange?.(!0);return}fe(!1)},children:(0,X.jsxs)(C,{className:S(W,`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,X.jsxs)(ie,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,X.jsx)(b,{children:e.title}),e.description?(0,X.jsx)(_,{children:e.description}):(0,X.jsx)(_,{className:`sr-only`,children:`Complete the form fields, then submit or cancel.`})]}),(0,X.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:$()}),be&&(0,X.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,X.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[me&&(0,X.jsx)(G,{type:`button`,variant:`outline`,onClick:Y,disabled:D,className:`w-full sm:w-auto`,children:_e}),Q&&(0,X.jsxs)(G,{type:`submit`,form:H,disabled:D,className:`w-full sm:w-auto`,children:[D&&(0,X.jsx)(ue,{className:`mr-2 h-4 w-4 animate-spin`}),ge]})]})}),(0,X.jsx)(L,{open:N,onOpenChange:F,children:(0,X.jsxs)(z,{children:[(0,X.jsxs)(ce,{children:[(0,X.jsx)(le,{children:a(`form.discardTitle`)}),(0,X.jsx)(ee,{children:a(`form.discardMessage`)})]}),(0,X.jsxs)(M,{children:[(0,X.jsx)(ne,{onClick:()=>{I.current=!1},children:a(`form.keepEditing`)}),(0,X.jsx)(re,{onClick:q,children:a(`form.discard`)})]})]})})]})})};function gt(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`).map(e=>({key:typeof e.key==`string`?e.key:``,label:typeof e.label==`string`?e.label:void 0,collapsible:typeof e.collapsible==`boolean`?e.collapsible:void 0,collapsed:typeof e.collapsed==`boolean`?e.collapsed:void 0})).filter(e=>e.key):[]}function _t(e,t){let n=gt(t);if(n.length===0)return null;let r=new Set(n.map(e=>e.key)),i=e=>{let t=e.group;return typeof t==`string`&&r.has(t)?t:null};if(!e.some(e=>i(e)!==null))return null;let a=new Map;for(let e of n)a.set(e.key,[]);let o=[];for(let t of e){let e=i(t);e?a.get(e).push(t):o.push(t)}let s=[];for(let e of n){let t=a.get(e.key);t.length!==0&&s.push({name:e.key,label:e.label??e.key,fields:t.map(e=>e.name),...e.collapsible===void 0?{}:{collapsible:e.collapsible},...e.collapsed===void 0?{}:{collapsed:e.collapsed}})}return o.length>0&&s.push({fields:o.map(e=>e.name)}),s}var vt=({schema:e,dataSource:t})=>{let n=r(),i=(0,J.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}=g(),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,X.jsx)(qe,{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,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,X.jsx)(ge,{schema:{...i,formType:`tabbed`,sections:i.sections.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields})),defaultTab:i.defaultTab,tabPosition:i.tabPosition},dataSource:t,className:i.className});if(i.formType===`wizard`&&i.sections?.length)return(0,X.jsx)(_e,{schema:{...i,formType:`wizard`,sections:i.sections.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields})),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,X.jsx)(ve,{schema:{...i,formType:`split`,sections:i.sections.map(e=>({name:e.name,label:o(e),description:e.description,columns:e.columns,fields:e.fields})),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,X.jsx)(dt,{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})),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,X.jsx)(ht,{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})),open:i.open,onOpenChange:i.onOpenChange,modalSize:i.modalSize,modalCloseButton:i.modalCloseButton},dataSource:t,className:i.className})}return(0,X.jsx)(yt,{schema:i,dataSource:t})},yt=({schema:e,dataSource:t})=>{let{fieldLabel:n,sectionLabel:i}=g(),a=E(),o=r(),c=(0,J.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,J.useState)(null),[d,f]=(0,J.useState)([]),[p,m]=(0,J.useState)(null),[h,_]=(0,J.useState)(!0),[v,y]=(0,J.useState)(null),b=e.customFields&&e.customFields.length>0;(0,J.useEffect)(()=>{b&&(m(e.initialData||e.initialValues||{}),_(!1))},[b,e.initialData,e.initialValues]),(0,J.useEffect)(()=>{b?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){y(e),_(!1)}})():b||_(!1)},[e.objectName,t,b]),(0,J.useEffect)(()=>{l&&!b&&(async()=>{if(!e.recordId||e.mode===`create`){m(e.initialData||e.initialValues||{}),_(!1);return}if(!b){if(!t){y(Error(`DataSource is required for fetching record data (inline data not provided)`)),_(!1);return}_(!0);try{m(await t.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),y(e)}finally{_(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,t,l,b]);let x=(0,J.useCallback)(e=>{if(!e||typeof e.visible==`function`)return e;let t=e.visibleOn;return typeof t==`string`&&t.trim()?{...e,visible:e=>V(t,e)}:e},[]);(0,J.useEffect)(()=>{if(b&&e.customFields){f(e.customFields.map(x)),_(!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&&!b)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(x(s));else if(a){let o={name:i,label:n(e.objectName,i,a.label||t),type:R(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: ${N(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.visible=e=>V(a.visible_on,e)),r.push(o)}}),f(r),!b&&e.recordId&&e.mode!==`create`&&t||_(!1)},[l,e.fields,e.customFields,e.readOnly,e.mode,b,e.recordId,t]);let S=(0,J.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={})),b&&!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=n;if(o?.isLoaded&&n&&typeof n==`object`){i={};for(let t of Object.keys(n))o.checkField(e.objectName,t,`write`)&&(i[t]=n[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){let t=Y(e.navigateOnSuccess,n);if(t)return window.location.assign(t),n;q.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,b,o]),C=(0,J.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),w={...J.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},T=J.useMemo(()=>e.sections?.length?null:_t(d,l?.fieldGroups),[e.sections,d,l]),D=e.sections?.length?e.sections:T,[O,k]=(0,J.useState)({});if(v)return(0,X.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,X.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,X.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:v.message})]});if(h)return(0,X.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,X.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,X.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let A=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(D?.length&&(!e.formType||e.formType===`simple`)){let t=[];return D.forEach((n,r)=>{let a=n.fields.map(e=>typeof e==`string`?e:e.field??e.name),o=c(d.filter(e=>a.includes(e.name)));if(o.length===0)return;let s=n.name||n.label||String(r),l=n.name?i(e.objectName,n.name,n.label||n.name):n.label,u=O[s]??n.collapsed??!1;l&&t.push({name:`__section_${s}`,label:l,type:`section-divider`,colSpan:4,collapsible:n.collapsible,collapsed:u,onToggle:n.collapsible?()=>k(e=>({...e,[s]:!u})):void 0}),l&&u?t.push(...o.map(e=>({...e,hidden:!0}))):t.push(...o)}),(0,X.jsx)(`div`,{className:`w-full`,children:(0,X.jsx)(s,{schema:{type:`form`,objectName:e.objectName,fields:t,layout:A,defaultValues:w,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,onSubmit:S,onCancel:C}})})}let j=e.sections?.length,M=c(d),P=j?{fields:M,columns:e.columns}:at(M,l,e.columns,e.mode),F=e.mobile,I=F?.fullscreenLongText?P.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}):P.fields,L=F?.stepper,ee=F?.stepperMinFields??8,z=Math.max(1,F?.stepperFieldsPerStep??1);if(!e.formType&&!j&&I.length>=2&&(L===!0||L===`auto`&&a&&I.length>=ee)){let n=I,r=[];for(let e=0;e<n.length;e+=z){let t=n.slice(e,e+z);r.push({name:`step-${Math.floor(e/z)+1}`,label:t[0]?.label||t[0]?.name||`Step ${Math.floor(e/z)+1}`,fields:t})}return(0,X.jsx)(_e,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:t,className:e.className})}let te={type:`form`,objectName:e.objectName,fields:I,layout:A,columns:P.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.resetOnSuccess&&e.mode===`create`,defaultValues:w,onSubmit:S,onCancel:C,className:e.className,mobileStickyActions:!!F?.stickyActions};return(0,X.jsx)(`div`,{className:F?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":F?`true`:void 0,children:(0,X.jsx)(s,{schema:te})})},bt={text:200,email:254,url:2048,phone:32,textarea:5e3,markdown:5e3,html:5e3},xt=`_company_website_2`,St=1500;function Ct(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 wt(e){return e&&e.map(e=>{let t=bt[String(e.type||``).toLowerCase()];return!t||(e.maxLength??e.max_length)?e:{...e,maxLength:t}})}var Tt=({config:e,dataSource:t,prefillParams:n,className:r})=>{let[i,a]=(0,J.useState)(!1),[o,s]=(0,J.useState)(!1),[c,l]=(0,J.useState)(null),[u,d]=(0,J.useState)(!(e.consent?.required??!!e.consent)),[f,m]=(0,J.useState)(null),h=(0,J.useRef)(null),g=(0,J.useRef)(0);(0,J.useEffect)(()=>{i||(g.current=Date.now())},[i]);let _=e.honeypot===!1?null:e.honeypot||xt,v=e.minFillTime??St,y=(0,J.useMemo)(()=>wt(e.customFields),[e.customFields]),b=(0,J.useMemo)(()=>{if(!t||y&&y.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,y,e.fields]),x=(0,J.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]),S=(0,J.useCallback)(async n=>{if(e.consent?.required&&!u){m(e.texts?.consentRequired??`Please accept the privacy policy to continue.`);return}if(m(null),_&&h.current?.value){a(!0);return}if(v>0&&Date.now()-g.current<v){l(e.texts?.rateLimited??`Please take a moment to review your answers before submitting.`);return}let r={...n};_&&delete r[_],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(Ct(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,_,v]),C=(0,J.useCallback)(()=>{a(!1),l(null)},[]),w=(0,J.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,X.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,X.jsxs)(`div`,{className:`max-w-md w-full bg-card border rounded-xl shadow-sm p-8 text-center space-y-4`,children:[(0,X.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,X.jsx)(p,{className:`h-8 w-8`,"aria-hidden":`true`})}),(0,X.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||n.thankYouTitle||`Thank You!`}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t?.message||n.thankYouMessage||`Your submission has been received successfully.`}),e.allowMultiple&&(0,X.jsx)(G,{variant:`outline`,size:`sm`,onClick:C,className:`mt-2`,children:n.submitAnother??`Submit Another Response`}),t?.redirectUrl&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a})]})})}let E=e.texts??{},O=!!e.consent?.required,k=`${e.formId}-consent`;return(0,X.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,X.jsxs)(`div`,{className:`max-w-2xl w-full bg-card border rounded-xl shadow-sm overflow-hidden`,children:[e.branding?.coverImage&&(0,X.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,X.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,X.jsx)(`img`,{src:e.branding.logo,alt:``,className:`h-8 mb-4`}),e.title&&(0,X.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground`,children:e.title}),e.description&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 leading-relaxed`,children:e.description}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 mt-3`,"aria-hidden":`true`,children:E.requiredHint??`* Required field`})]}),(0,X.jsxs)(`div`,{className:`relative px-6 sm:px-8 py-6`,children:[c&&(0,X.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,X.jsx)(vt,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:y,initialData:x,onSuccess:S,submitText:o?E.submitting??`Submitting...`:E.submit??`Submit`},dataSource:b}),_&&(0,X.jsxs)(`div`,{"aria-hidden":`true`,className:`absolute left-[-10000px] top-auto h-px w-px overflow-hidden`,children:[(0,X.jsx)(`label`,{htmlFor:`${e.formId}-${_}`,children:`Do not fill this field`}),(0,X.jsx)(`input`,{ref:h,id:`${e.formId}-${_}`,type:`text`,name:_,tabIndex:-1,autoComplete:`off`,defaultValue:``})]}),e.consent&&(0,X.jsxs)(`div`,{className:`mt-4`,children:[(0,X.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-foreground cursor-pointer select-none`,children:[(0,X.jsx)(`input`,{type:`checkbox`,id:k,checked:u,onChange:e=>{d(e.target.checked),e.target.checked&&m(null)},"aria-required":O||void 0,"aria-invalid":f?`true`:void 0,"aria-describedby":f?`${k}-error`:void 0,className:`mt-0.5 h-4 w-4 rounded border-input accent-primary`}),(0,X.jsxs)(`span`,{className:`leading-relaxed`,children:[e.consent.label??E.consentLabelDefault??`I agree to the privacy policy.`,O&&(0,X.jsx)(`span`,{"aria-hidden":`true`,className:`text-destructive ml-0.5`,children:`*`}),e.consent.privacyUrl&&(0,X.jsxs)(X.Fragment,{children:[` `,(0,X.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,X.jsx)(`p`,{id:`${k}-error`,role:`alert`,className:`mt-1.5 text-xs text-destructive`,children:f})]}),o&&(0,X.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,X.jsx)(ue,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{children:E.submitting??`Submitting…`})]})]}),(0,X.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,X.jsxs)(`p`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,X.jsx)(T,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{children:E.secureNotice??`Your information is transmitted securely and only used to respond to your request.`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground/80`,children:[e.privacyPolicyUrl&&(0,X.jsxs)(`a`,{href:e.privacyPolicyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 underline hover:text-foreground`,children:[(0,X.jsx)(D,{className:`h-3 w-3`,"aria-hidden":`true`}),E.consentLink??`Privacy policy`]}),(0,X.jsx)(`span`,{children:E.poweredBy??`Powered by ObjectStack`})]})]})]})})};function Et(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 Dt=({formId:e,formTitle:t,metrics:n,className:r})=>{let i=(0,J.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,J.useMemo)(()=>n.dailySubmissions?.length?Math.max(...n.dailySubmissions.map(e=>e.count),1):1,[n.dailySubmissions]);return(0,X.jsxs)(`div`,{className:`space-y-4 ${r||``}`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:t||`Form Analytics`}),(0,X.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,X.jsx)(d,{children:(0,X.jsxs)(B,{className:`pb-2`,children:[(0,X.jsx)(U,{children:`Total Submissions`}),(0,X.jsx)(H,{className:`text-2xl`,children:n.totalSubmissions.toLocaleString()})]})}),(0,X.jsxs)(d,{children:[(0,X.jsxs)(B,{className:`pb-2`,children:[(0,X.jsx)(U,{children:`Fill Rate`}),(0,X.jsxs)(H,{className:`text-2xl`,children:[i,`%`]})]}),(0,X.jsx)(I,{children:(0,X.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,X.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${i}%`}})})})]}),(0,X.jsx)(d,{children:(0,X.jsxs)(B,{className:`pb-2`,children:[(0,X.jsx)(U,{children:`Avg. Completion Time`}),(0,X.jsx)(H,{className:`text-2xl`,children:n.avgCompletionTime?Et(n.avgCompletionTime):`—`})]})})]}),n.dailySubmissions&&n.dailySubmissions.length>0&&(0,X.jsxs)(d,{children:[(0,X.jsx)(B,{children:(0,X.jsx)(H,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,X.jsx)(I,{children:(0,X.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:n.dailySubmissions.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,X.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,X.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,X.jsxs)(d,{children:[(0,X.jsxs)(B,{children:[(0,X.jsx)(H,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,X.jsx)(U,{children:`Percentage of users who completed each field`})]}),(0,X.jsx)(I,{children:(0,X.jsx)(`div`,{className:`space-y-3`,children:n.fieldDropOff.map((e,t)=>(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,X.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,X.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,X.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))})})]})]})},Ot=({schema:e})=>{let t=a()?.dataSource,n=i(),r=e.parentObject||n?.objectName,o=e.parentId||e.recordId||n?.recordId,[s,c]=(0,J.useState)([]),[l,u]=(0,J.useState)([]),[f,p]=(0,J.useState)(!0),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(!1),[v,y]=(0,J.useState)(null),b=(0,J.useCallback)(async()=>{if(!t||!o){p(!1);return}p(!0);try{let n=(await t.find(e.childObject,{$filter:{[e.relationshipField]:o},$top:500}))?.data??[];c(n.map(e=>({...e}))),u(n.map(e=>({...e}))),_(!1)}catch(e){y(e?.message||`Failed to load line items`)}finally{p(!1)}},[t,o,e.childObject,e.relationshipField]);(0,J.useEffect)(()=>{b()},[b]);let x=(0,J.useCallback)(e=>{c(e),_(!0)},[]),C=(0,J.useCallback)(async()=>{if(!(!t||!o)){h(!0),y(null);try{await De(t,r||e.childObject,o,{childObject:e.childObject,relationshipField:e.relationshipField,rows:s,original:l,amountField:e.amountField,totalField:r?e.totalField:void 0}),await b()}catch(e){y(e?.message||`Failed to save line items`)}finally{h(!1)}}},[t,o,s,l,e,r,b]),w=(0,J.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,X.jsxs)(d,{className:S(`shadow-none`),children:[(0,X.jsxs)(B,{className:`flex-row items-center justify-between gap-2 pb-2`,children:[(0,X.jsx)(H,{className:`text-sm font-medium`,children:e.title||`Line Items`}),!e.readonly&&(0,X.jsx)(G,{type:`button`,size:`sm`,onClick:C,disabled:m||f||!g||!o,children:m?`Saving…`:`Save`})]}),(0,X.jsxs)(I,{children:[v&&(0,X.jsx)(`p`,{className:`mb-2 text-sm text-destructive`,children:v}),f?(0,X.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Loading…`}):o?(0,X.jsx)(W,{value:s,onChange:x,field:w,readonly:e.readonly}):(0,X.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Save the record first to add line items.`})]})]})},kt=({schema:e})=>(0,X.jsx)(vt,{schema:e,dataSource:(0,J.useContext)(c)?.dataSource??void 0});l.register(`object-form`,kt,{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`]}]}),l.register(`form`,kt,{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`]}]}),l.register(`embeddable-form`,({schema:e})=>(0,X.jsx)(Tt,{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`}]}),l.register(`form-analytics`,({schema:e})=>(0,X.jsx)(Dt,{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`}]}),l.register(`object-master-detail-form`,({schema:e})=>(0,X.jsx)(qe,{schema:e,dataSource:(0,J.useContext)(c)?.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}]}),l.register(`line_items`,({schema:e})=>(0,X.jsx)(Ot,{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{Ve as i,ht as n,dt as r,vt as t};
|