@object-ui/plugin-dashboard 17.3.0 → 17.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +1445 -0
  2. package/README.md +199 -33
  3. package/dist/DashboardConfigPanel.d.ts +3 -0
  4. package/dist/DashboardConfigPanel.d.ts.map +1 -1
  5. package/dist/DashboardFilterBar.d.ts.map +1 -1
  6. package/dist/DashboardGridLayout.d.ts +27 -0
  7. package/dist/DashboardGridLayout.d.ts.map +1 -1
  8. package/dist/DashboardRenderer.d.ts +46 -4
  9. package/dist/DashboardRenderer.d.ts.map +1 -1
  10. package/dist/DashboardWithConfig.d.ts.map +1 -1
  11. package/dist/DatasetWidget.d.ts +70 -6
  12. package/dist/DatasetWidget.d.ts.map +1 -1
  13. package/dist/MetricCard.d.ts +29 -10
  14. package/dist/MetricCard.d.ts.map +1 -1
  15. package/dist/MetricWidget.d.ts +82 -17
  16. package/dist/MetricWidget.d.ts.map +1 -1
  17. package/dist/ObjectDataTable.d.ts +68 -3
  18. package/dist/ObjectDataTable.d.ts.map +1 -1
  19. package/dist/ObjectMetricWidget.d.ts +41 -27
  20. package/dist/ObjectMetricWidget.d.ts.map +1 -1
  21. package/dist/ObjectPivotTable.d.ts.map +1 -1
  22. package/dist/PivotTable.d.ts.map +1 -1
  23. package/dist/RecordDetailDrawer.d.ts.map +1 -1
  24. package/dist/WidgetConfigPanel.d.ts +28 -0
  25. package/dist/WidgetConfigPanel.d.ts.map +1 -1
  26. package/dist/colorVariants.d.ts +56 -0
  27. package/dist/colorVariants.d.ts.map +1 -0
  28. package/dist/domPassthroughPins.d.ts +9 -0
  29. package/dist/domPassthroughPins.d.ts.map +1 -0
  30. package/dist/index.d.ts +16 -11
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +2087 -1564
  33. package/dist/index.umd.cjs +2 -2
  34. package/dist/legacyRetiredWidget.d.ts +41 -0
  35. package/dist/legacyRetiredWidget.d.ts.map +1 -0
  36. package/dist/recordFields.d.ts +41 -2
  37. package/dist/recordFields.d.ts.map +1 -1
  38. package/dist/schemaHostProps.d.ts +80 -0
  39. package/dist/schemaHostProps.d.ts.map +1 -0
  40. package/dist/useConfigPanelTranslation.d.ts +35 -0
  41. package/dist/useConfigPanelTranslation.d.ts.map +1 -0
  42. package/dist/utils.d.ts +34 -0
  43. package/dist/utils.d.ts.map +1 -1
  44. package/package.json +14 -12
@@ -1,2 +1,2 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@object-ui/core"),require("@object-ui/react"),require("@object-ui/i18n"),require("@object-ui/components"),require("react"),require("lucide-react"),require("@dnd-kit/core"),require("@dnd-kit/sortable"),require("@dnd-kit/utilities"),require("@object-ui/fields"),require("react/jsx-runtime"),require("react-grid-layout"),require("react-grid-layout/css/styles.css")):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`@object-ui/react`,`@object-ui/i18n`,`@object-ui/components`,`react`,`lucide-react`,`@dnd-kit/core`,`@dnd-kit/sortable`,`@dnd-kit/utilities`,`@object-ui/fields`,`react/jsx-runtime`,`react-grid-layout`,`react-grid-layout/css/styles.css`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginDashboard={},e.ObjectUICore,e.ObjectUIReact,e.ObjectUII18n,e.ObjectUIComponents,e.React,e.lucide_react,e._dnd_kit_core,e._dnd_kit_sortable,e._dnd_kit_utilities,e.ObjectUIFields,e.react_jsx_runtime,e.ReactGridLayout,e.react_grid_layout_css_styles_css))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var m=Object.create,h=Object.defineProperty,g=Object.getOwnPropertyDescriptor,_=Object.getOwnPropertyNames,v=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty,b=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=_(t),a=0,o=i.length,s;a<o;a++)s=i[a],!y.call(e,s)&&s!==n&&h(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=g(t,s))||r.enumerable});return e};a=((e,t,n)=>(n=e==null?{}:m(v(e)),b(t||!e||!e.__esModule||!y.call(e,`default`)?h(n,`default`,{value:e,enumerable:!0}):n,e)))(a,1);function x(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&e.provider===`object`}function S(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 C={column:`bar`,"stacked-bar":`bar`,"grouped-bar":`bar`,"bi-polar-bar":`bar`,spline:`line`,"step-line":`line`,"stacked-area":`area`,pyramid:`funnel`,bubble:`scatter`},w=new Set([`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`scatter`,`funnel`,`radar`,`treemap`,`sankey`,`combo`]),T=new Set([`metric`,`gauge`,`solid-gauge`,`kpi`,`bullet`]),E=new Set([`table`,`list`]),D=new Set([`sunburst`,`word-cloud`,`choropleth`,`bubble-map`,`gl-map`,`heatmap`,`waterfall`,`box-plot`,`violin`,`candlestick`,`stock`]);function O(e){if(!e)return{family:`passthrough`};let t=C[e]??e;return w.has(t)?{family:`series`,chartType:t}:T.has(e)?{family:`metric`}:E.has(e)?{family:`table`}:e===`pivot`?{family:`pivot`}:e===`custom`?{family:`custom`}:D.has(e)?{family:`unsupported`}:{family:`passthrough`}}var k=new Set([`id`,`organization_id`,`tenant_id`,`created_at`,`updated_at`,`created_by`,`updated_by`,`deleted_at`,`deleted_by`,`version`,`_id`,`__typename`]);function A(e,t){return t&&(t.isSystem===!0||t.system===!0)?!0:k.has(e)}var j=new Set([`select`,`picklist`,`dropdown`,`status`]),M=new Set([`currency`,`money`,`number`,`integer`,`decimal`,`float`,`percent`,`percentage`]);function N(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 P(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&&j.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?.scale}}function F(e){return M.has(e.type)||typeof e.format==`string`&&/^[$¥€£]|%$|0/.test(e.format)}function I(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(0,u.formatCurrency)(e,t.currency||i||n)}if(typeof r==`string`&&/%/.test(r)&&typeof e==`number`){let t=(r.match(/0\.(0+)%/)||[void 0,``])[1].length,n=e>1?e/100:e;return(0,u.formatPercent)(n*100,t)}if(typeof r==`string`&&/[YMDHms]/.test(r))return(0,u.formatDate)(e,r);let i=(0,u.getCellRenderer)((0,u.resolveCellRendererType)(t));return(0,d.jsx)(i,{value:e,field:t})}var L=[`name`,`title`,`label`,`subject`,`display_name`,`full_name`];function R(e,t){if(t&&t.trim())return t;for(let t of L){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 ee=({record:e,objectName:t,objectSchema:n,fields:o,title:s,target:c=`drawer`,onClose:l})=>{let{fieldLabel:u,fieldOptionLabel:f}=(0,r.useSafeFieldLabel)(),{currency:p}=(0,r.useLocalization)(),m=(0,a.useMemo)(()=>{if(!e)return[];let r=N(n),i;return i=o&&o.length>0?o:Object.keys(r).length>0?Object.keys(r).filter(e=>!A(e,r[e])):Object.keys(e).filter(e=>!e.startsWith(`_`)&&!A(e)),i.map(n=>{let i=r[n],a=n.charAt(0).toUpperCase()+n.slice(1).replace(/([A-Z])/g,` $1`).replace(/_/g,` `),o=t?u(t,n,a):a,s=P({accessorKey:n,label:o,def:i,objectName:t,fieldOptionLabel:f});return{key:n,label:o,node:I(e[n],s,p),numeric:F(s)}})},[e,n,t,o,u,f,p]);if(!e)return null;let h=R(e,s),g=(0,d.jsx)(`dl`,{className:`divide-y divide-border/60`,"data-testid":`record-detail-body`,children:m.map(e=>(0,d.jsxs)(`div`,{className:`grid grid-cols-3 gap-3 py-2.5`,children:[(0,d.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground self-center`,children:e.label}),(0,d.jsx)(`dd`,{className:`col-span-2 text-sm break-words ${e.numeric?`tabular-nums`:``}`,children:e.node===``||e.node==null?(0,d.jsx)(`span`,{className:`text-muted-foreground/60`,children:`—`}):e.node})]},e.key))});return c===`dialog`?(0,d.jsx)(i.Dialog,{open:!0,onOpenChange:e=>!e&&l(),children:(0,d.jsxs)(i.DialogContent,{className:`max-w-2xl`,children:[(0,d.jsx)(i.DialogHeader,{children:(0,d.jsx)(i.DialogTitle,{children:h})}),(0,d.jsx)(`div`,{className:`max-h-[70vh] overflow-auto`,children:g})]})}):(0,d.jsx)(i.Sheet,{open:!0,onOpenChange:e=>!e&&l(),children:(0,d.jsxs)(i.SheetContent,{side:`right`,className:`w-full sm:max-w-md md:max-w-lg flex flex-col`,children:[(0,d.jsx)(i.SheetHeader,{children:(0,d.jsx)(i.SheetTitle,{children:h})}),(0,d.jsx)(`div`,{className:`flex-1 overflow-auto mt-2 pr-1`,children:g})]})})};function z(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 te(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 B=({schema:e,dataSource:o,className:s})=>{let{currency:c}=(0,r.useLocalization)(),l=(0,a.useContext)(n.SchemaRendererContext),u=o||l?.dataSource,f=(0,n.useDataScope)(e.bind),{fieldLabel:p,fieldOptionLabel:m}=(0,r.useSafeFieldLabel)(),h=`No data available`,g=`No data source available for`,{t:_}=(0,r.useObjectTranslation)(),v=_(`dashboard.noDataAvailable`);v&&v!==`dashboard.noDataAvailable`&&(h=v);let y=_(`dashboard.noDataSourceFor`);y&&y!==`dashboard.noDataSourceFor`&&(g=y);let[b,x]=(0,a.useState)([]),[S,C]=(0,a.useState)(null),[w,T]=(0,a.useState)(()=>!(Array.isArray(e.data)&&e.data.length>0)&&!!e.objectName),[E,D]=(0,a.useState)(null),O=e.drillDown,k=(0,t.isDrillEnabled)(O)&&(O?.mode??`record`)===`record`,[j,M]=(0,a.useState)(null),N=(0,a.useCallback)(e=>{M(e??null)},[]),L=(0,n.useFilterScope)();(0,a.useEffect)(()=>{let n=!0;return e.objectName&&!f&&(!e.data||e.data.length===0)?(async()=>{if(!u||!e.objectName){n&&T(!1);return}n&&(T(!0),D(null));try{let r;if(typeof u.find==`function`){let n=te(e,S),i={$filter:(0,t.resolveFilterPlaceholders)(e.filter,L)};n.length&&(i.$expand=n);let a=await u.find(e.objectName,i);r=(0,t.extractRecords)(a)}else return;n&&x(r)}catch(e){console.error(`[ObjectDataTable] Fetch error:`,e),n&&D(e instanceof Error?e.message:`Failed to load data`)}finally{n&&T(!1)}})():n&&T(!1),()=>{n=!1}},[e.objectName,u,f,e.data,e.filter,S,L]),(0,a.useEffect)(()=>{let t=!0;if(!(!u||!e.objectName||typeof u.getObjectSchema!=`function`))return u.getObjectSchema(e.objectName).then(e=>{t&&C(e)}).catch(()=>{}),()=>{t=!1}},[e.objectName,u]);let R=f||e.data||b,B=Array.isArray(R)?R:[],V=(0,a.useMemo)(()=>{let t=e.objectName,n={};if(S?.fields){let e=S.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 r=e=>{let n=e.charAt(0).toUpperCase()+e.slice(1).replace(/([A-Z])/g,` $1`);return t?p(t,e,n):n},i=e=>{let r=P({accessorKey:e.accessorKey,label:e.header,def:n[e.accessorKey],objectName:t,fieldOptionLabel:m,overrides:{type:e.type,format:e.format,options:e.options,referenceTo:e.referenceTo,currency:e.currency,decimals:e.decimals}}),i=e.align??(F(r)?`right`:void 0);if(typeof e.cell==`function`)return{...e,...r,align:i};let a=e=>I(e,r,c);return{...e,...r,align:i,cell:a}};if(e.columns&&e.columns.length>0){let n=z(e.columns);return(t?n.map(e=>({...e,header:p(t,e.accessorKey,e.header)})):n).map(i)}return B.length===0?[]:(Object.keys(n).length>0?Object.keys(n).filter(e=>!A(e,n[e])):Object.keys(B[0]).filter(e=>!e.startsWith(`_`)&&!A(e))).map(e=>i({header:r(e),accessorKey:e}))},[e.columns,e.objectName,B,S,p,m,c]);if(w&&B.length===0)return(0,d.jsx)(`div`,{className:(0,i.cn)(`overflow-auto`,s),"data-testid":`table-loading`,children:(0,d.jsxs)(`div`,{className:`space-y-2 p-2`,children:[(0,d.jsxs)(`div`,{className:`flex gap-2`,children:[(0,d.jsx)(i.Skeleton,{className:`h-6 w-1/4`}),(0,d.jsx)(i.Skeleton,{className:`h-6 w-1/4`}),(0,d.jsx)(i.Skeleton,{className:`h-6 w-1/4`}),(0,d.jsx)(i.Skeleton,{className:`h-6 w-1/4`})]}),[1,2,3,4].map(e=>(0,d.jsxs)(`div`,{className:`flex gap-2`,children:[(0,d.jsx)(i.Skeleton,{className:`h-5 w-1/4`}),(0,d.jsx)(i.Skeleton,{className:`h-5 w-1/4`}),(0,d.jsx)(i.Skeleton,{className:`h-5 w-1/4`}),(0,d.jsx)(i.Skeleton,{className:`h-5 w-1/4`})]},e))]})});if(E)return(0,d.jsx)(`div`,{className:(0,i.cn)(`overflow-auto`,s),"data-testid":`table-error`,children:(0,d.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-destructive`,"data-testid":`table-error-message`,children:[(0,d.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,d.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,d.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,d.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]}),(0,d.jsx)(`p`,{className:`text-xs`,children:E})]})});if(!u&&e.objectName&&B.length===0)return(0,d.jsx)(`div`,{className:(0,i.cn)(`overflow-auto`,s),children:(0,d.jsx)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:(0,d.jsxs)(`p`,{className:`text-xs`,children:[g,` “`,e.objectName,`”`]})})});if(B.length===0)return(0,d.jsx)(`div`,{className:(0,i.cn)(`overflow-auto`,s),"data-testid":`table-empty-state`,children:(0,d.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,d.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,d.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),(0,d.jsx)(`line`,{x1:`3`,y1:`9`,x2:`21`,y2:`9`}),(0,d.jsx)(`line`,{x1:`9`,y1:`21`,x2:`9`,y2:`9`})]}),(0,d.jsx)(`p`,{className:`text-xs`,children:h})]})});let ne={...e,type:`data-table`,data:B,columns:V,onRowClick:e.onRowClick??(k?N:void 0)},re=O?.title&&!O.title.includes("${")?O.title:void 0;return(0,d.jsxs)(`div`,{className:(0,i.cn)(`relative`,s),children:[(0,d.jsx)(i.RefreshIndicator,{active:w&&B.length>0}),(0,d.jsx)(n.SchemaRenderer,{schema:ne,className:s}),k&&(0,d.jsx)(ee,{record:j,objectName:e.objectName,objectSchema:S,fields:O?.columns,title:re,target:O?.target===`dialog`?`dialog`:`drawer`,onClose:()=>M(null)})]})},V=({objectName:e,filter:t,onNavigate:a,className:s})=>{let{openRecordList:c}=(0,n.useDrillNavigation)(),l=(0,r.useSafeTranslate)();return!c||!e?null:(0,d.jsxs)(i.Button,{type:`button`,variant:`ghost`,size:`sm`,className:s,"data-testid":`drill-open-in-list`,onClick:()=>{c(e,t),a?.()},children:[l(`dashboard.openInList`,`Open in list`),(0,d.jsx)(o.ArrowUpRight,{className:`ml-1 h-3.5 w-3.5`})]})},ne=({open:e,onClose:t,title:r,target:o=`drawer`,objectName:s,filter:c,dataSource:l,columns:u,maxRows:f,className:p,report:m})=>{let{openRecordList:h}=(0,n.useDrillNavigation)(),g=m&&typeof m==`object`&&(Array.isArray(m.columns)||`objectName`in m),_=o===`navigate`&&!!h&&!g&&!!s;if(a.default.useEffect(()=>{e&&_&&(h(s,c),t())},[e,_]),_)return null;let v=g?null:(0,d.jsx)(V,{objectName:s,filter:c,onNavigate:t}),y=(0,d.jsx)(`div`,{className:(0,i.cn)(`overflow-auto`,p),"data-testid":`drill-down-body`,children:g?(()=>{let e=m.filter,t=e?c?{$and:[e,c]}:e:c,r={...m,type:`spec-report`,report:{...m,filter:t},filter:t};return(0,d.jsx)(n.SchemaRenderer,{schema:r})})():(0,d.jsx)(B,{schema:{type:`object-data-table`,objectName:s,filter:c,columns:u?.map(e=>({accessorKey:e,header:e})),pagination:!0,searchable:!1,pageSize:f,drillDown:{enabled:!0,mode:`record`,target:`dialog`}},dataSource:l})});return o===`dialog`?(0,d.jsx)(i.Dialog,{open:e,onOpenChange:e=>!e&&t(),children:(0,d.jsxs)(i.DialogContent,{className:`max-w-5xl`,children:[(0,d.jsxs)(i.DialogHeader,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,d.jsx)(i.DialogTitle,{children:r}),v]}),y]})}):(0,d.jsx)(i.Sheet,{open:e,onOpenChange:e=>!e&&t(),children:(0,d.jsxs)(i.SheetContent,{side:`right`,className:`w-full sm:max-w-2xl md:max-w-3xl lg:max-w-4xl flex flex-col`,children:[(0,d.jsxs)(i.SheetHeader,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,d.jsx)(i.SheetTitle,{children:r}),v]}),(0,d.jsx)(`div`,{className:`flex-1 overflow-hidden mt-2`,children:y})]})})},re=t.buildDatasetDrillFilter;function ie(e,n,r){let i=[],a=[],o=new Set,s=new Set,c=new Map;return e.forEach((e,l)=>{let u=(0,t.pivotBucketId)(n.map(t=>String(e[t]??`∅`))),d=String(e[r]??`∅`);o.has(u)||(o.add(u),i.push({id:u,labels:n.map(n=>(0,t.formatDimensionValue)(e[n]))})),s.has(d)||(s.add(d),a.push({id:d,label:(0,t.formatDimensionValue)(e[r])})),c.set((0,t.pivotCellKey)(u,d),l)}),{rowHeaders:i,colHeaders:a,cellIndex:c}}function H(e){if(e==null)return``;let t=String(e);return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}function U(e){return e.map(e=>e.map(H).join(`,`)).join(`\r
2
- `)}function W(e,t){if(typeof document>`u`)return;let n=e&&e.trim()?e.trim():`export`,r=new Blob([`\uFEFF${U(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 ae=new Set([`metric`,`kpi`,`gauge`,`solid-gauge`,`bullet`]),G={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 oe({widget:e,dataSource:s}){let c=String(e?.dataset??``),l=(0,a.useMemo)(()=>Array.isArray(e?.dimensions)?e.dimensions.filter(Boolean):[],[e]),u=(0,a.useMemo)(()=>Array.isArray(e?.values)?e.values.filter(Boolean):[],[e]),f=e?.compareTo&&typeof e.compareTo==`object`?e.compareTo:void 0,p=String(e?.type??``),m=ae.has(p)||l.length===0,h=p===`table`||p===`pivot`,g=p===`pivot`&&l.length>=2,_=g?l.slice(0,-1):[],v=g?l[l.length-1]:``,y=g?[_,[v],[]]:void 0,b=e?.options&&typeof e.options==`object`&&!Array.isArray(e.options)?e.options:{},x=typeof b.dateGranularity==`string`?b.dateGranularity:void 0,S=typeof b.sortBy==`string`&&b.sortBy?b.sortBy:void 0,C=S&&(l.includes(S)||u.includes(S))?S:void 0,w=C?{[C]:b.sortOrder===`desc`?`desc`:`asc`}:void 0,T=typeof b.limit==`number`&&Number.isFinite(b.limit)&&b.limit>0?Math.floor(b.limit):void 0,E=(0,r.useSafeTranslate)(),{fieldLabel:D}=(0,r.useSafeFieldLabel)(),O=(0,n.useFilterScope)(),k=e?.filter,A=(0,a.useMemo)(()=>k&&typeof k==`object`&&Object.keys(k).length>0?(0,t.resolveFilterPlaceholders)(k,O):void 0,[k,O]),[j,M]=(0,a.useState)({status:`idle`,rows:[]}),[N,P]=(0,a.useState)(null),[F,I]=(0,a.useState)(null),[L,R]=(0,a.useState)(null),[ee,z]=(0,a.useState)(null),te=`${p}|${c}|${l.join(`,`)}|${u.join(`,`)}|${JSON.stringify(k??null)}|${JSON.stringify(f??null)}|${x??``}|${JSON.stringify(w??null)}|${T??``}`;if((0,a.useEffect)(()=>{let e=s;if(!e||typeof e.queryDataset!=`function`){M({status:`error`,rows:[],error:E(`dashboard.datasetUnsupported`,`This data source does not support dataset queries.`)});return}if(u.length===0){M({status:`idle`,rows:[]});return}let t=!1;return M({status:`loading`,rows:[]}),e.queryDataset(c,{dimensions:l,measures:u,...A?{runtimeFilter:A}:{},...f?{compareTo:f}:{},...y?{totals:{groupings:y}}:{},...x?{dateGranularity:x}:{},...w?{order:w}:{},...T==null?{}:{limit:T}}).then(e=>{t||M({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,drillRanges:Array.isArray(e?.drillRanges)?e.drillRanges:void 0,totals:Array.isArray(e?.totals)?e.totals:void 0})}).catch(e=>{t||M({status:`error`,rows:[],error:String(e?.message??e)})}),()=>{t=!0}},[te]),(0,a.useEffect)(()=>{if(m||h){I(null),R(null),z(null);return}let e=j.object;if(!e||l.length===0){I(null),R(null),z(null);return}let n=e=>j.dimensionFields&&j.dimensionFields[e]||e,r=!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=a?.fields?.[n(l[0])]?.options,s=(0,t.buildOptionColorMap)(o),c={};for(let e of l){let r=(0,t.buildDimensionLabelMap)(a?.fields?.[n(e)]?.options);r&&(c[e]=r)}r||(I(s),R(Object.keys(c).length>0?c:null),z((0,t.buildCategoryOrder)(o)))}catch{r||(I(null),R(null),z(null))}})(),()=>{r=!0}},[j.object,j.dimensionFields,l,m,h]),u.length===0)return(0,d.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:E(`dashboard.pickMeasures`,`Pick measures (values) for this dataset widget.`)});if(j.status===`loading`||j.status===`idle`)return(0,d.jsxs)(`div`,{className:`h-full w-full p-2`,"data-testid":`dataset-loading`,role:`status`,"aria-busy":`true`,"aria-live":`polite`,children:[(0,d.jsx)(`span`,{className:`sr-only`,children:E(`dashboard.loading`,`Loading…`)}),m?(0,d.jsxs)(`div`,{className:`flex h-full w-full flex-col items-start justify-center gap-2 p-2`,children:[(0,d.jsx)(i.Skeleton,{className:`h-8 w-32 rounded`}),(0,d.jsx)(i.Skeleton,{className:`h-3 w-20 rounded`})]}):h?(0,d.jsx)(i.GridSkeleton,{className:`h-full`,rows:5,columns:Math.max(2,l.length+u.length)}):(0,d.jsx)(i.ChartSkeleton,{className:`h-full`})]});if(j.status===`error`)return(0,d.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,d.jsx)(o.AlertTriangle,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,d.jsx)(`span`,{className:`break-words`,children:j.error})]});if(j.rows.length===0&&!m)return(0,d.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,d.jsx)(o.BarChart3,{className:`mr-2 h-4 w-4`}),E(`dashboard.noRows`,`No rows`)]});let{measureField:B,headerLabel:V}=(0,t.buildDatasetFieldHelpers)(j.fields,j.object,D),{object:H,dimensionFields:U,drillRawRows:oe,drillRanges:K}=j,q=U?l.filter(e=>e in U):[],J=!!H&&(q.length>0||!!K?.length),Y=(t,n)=>{if(!H)return;let r=re(oe?.[t],q,U??{},A,K?.[t]);P({filter:r,title:n||String(e?.title??``)})},X=N&&H?(0,d.jsx)(ne,{open:!0,onClose:()=>P(null),title:N.title||String(e?.title??E(`dashboard.details`,`Details`)),objectName:H,filter:N.filter,dataSource:s}):null;if(m){let e=B(u[0]),n=j.rows[0]?.[u[0]]??0;return(0,d.jsxs)(`div`,{className:`flex h-full w-full flex-col items-start justify-center gap-1 p-2`,children:[(0,d.jsx)(`span`,{className:`text-2xl font-semibold tabular-nums`,children:(0,t.formatMeasure)(n,e?.format,e?.currency,e?.percentScale)}),(0,d.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:V(u[0])})]})}if(h){let n=[...l,...u],r=(0,d.jsx)(`button`,{type:`button`,onClick:()=>W(String(e?.title??c??`export`),[n.map(e=>V(e)),...j.rows.map(e=>n.map(t=>{let n=e[t];return n==null?``:typeof n==`number`?n:String(n)}))]),"data-testid":`dataset-export`,title:E(`dashboard.exportCsv`,`Export CSV`),"aria-label":E(`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,d.jsx)(o.Download,{className:`h-3.5 w-3.5`})});if(g){let e=ie(j.rows,_,v),n=e.colHeaders.flatMap(e=>u.map(t=>({col:e,measure:t,header:u.length===1?e.label:`${e.label} · ${V(t)}`}))),a=(e,n)=>(0,t.formatMeasure)(e,B(n)?.format,B(n)?.currency,B(n)?.percentScale),o=e=>j.totals?.find(t=>Array.isArray(t.dimensions)&&t.dimensions.join(`,`)===e.join(`,`))?.rows,s=new Map;for(let e of o(_)??[])s.set((0,t.pivotBucketId)(_.map(t=>String(e[t]??`∅`))),e);let c=new Map;for(let e of o([v])??[])c.set(String(e[v]??`∅`),e);let l=o([])?.[0],f=s.size>0,p=c.size>0,m=E(`dashboard.total`,`Total`);return(0,d.jsxs)(`div`,{className:`relative h-full w-full overflow-auto p-1`,"data-testid":`dataset-matrix`,children:[r,(0,d.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,d.jsx)(`thead`,{className:`bg-muted/40`,children:(0,d.jsxs)(`tr`,{children:[_.map(e=>(0,d.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:V(e)},e)),n.map(e=>(0,d.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,children:e.header},`${e.col.id}-${e.measure}`)),f&&u.map(e=>(0,d.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,"data-testid":`matrix-total-col-header`,children:u.length===1?m:`${m} · ${V(e)}`},`total-${e}`))]})}),(0,d.jsxs)(`tbody`,{children:[e.rowHeaders.map(r=>(0,d.jsxs)(`tr`,{className:`border-t`,children:[r.labels.map((e,t)=>(0,d.jsx)(`td`,{className:`px-2 py-1 whitespace-nowrap font-medium`,children:e},t)),n.map(n=>{let o=e.cellIndex.get((0,t.pivotCellKey)(r.id,n.col.id)),s=o==null?void 0:j.rows[o],c=J&&o!=null,l=[...r.labels,n.col.label].filter(Boolean).join(` / `);return(0,d.jsx)(`td`,{className:(0,i.cn)(`px-2 py-1 text-right tabular-nums whitespace-nowrap`,c&&`cursor-pointer hover:bg-accent/40`),"data-testid":c?`dataset-drill-cell`:void 0,onClick:c?()=>Y(o,l):void 0,children:s?a(s[n.measure],n.measure):`—`},`${n.col.id}-${n.measure}`)}),f&&u.map(e=>(0,d.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap font-medium`,"data-testid":`matrix-row-total`,children:a(s.get(r.id)?.[e],e)},`total-${e}`))]},r.id)),p&&(0,d.jsxs)(`tr`,{className:`border-t bg-muted/30 font-medium`,"data-testid":`matrix-total-row`,children:[_.length>0&&(0,d.jsx)(`td`,{colSpan:_.length,className:`px-2 py-1 whitespace-nowrap`,children:m}),n.map(e=>(0,d.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,children:a(c.get(e.col.id)?.[e.measure],e.measure)},`${e.col.id}-${e.measure}`)),f&&u.map(e=>(0,d.jsx)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,"data-testid":`matrix-grand-total`,children:a(l?.[e],e)},`grand-${e}`))]})]})]}),X]})}let a=[...l,...u];return(0,d.jsxs)(`div`,{className:`relative h-full w-full overflow-auto p-1`,children:[r,(0,d.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,d.jsx)(`thead`,{className:`bg-muted/40`,children:(0,d.jsx)(`tr`,{children:a.map(e=>(0,d.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:V(e)},e))})}),(0,d.jsx)(`tbody`,{children:j.rows.map((e,n)=>(0,d.jsx)(`tr`,{className:(0,i.cn)(`border-t`,J&&`cursor-pointer hover:bg-accent/40`),"data-testid":J?`dataset-drill-row`:void 0,onClick:J?()=>Y(n,q.map(n=>(0,t.formatDimensionValue)(e[n])).filter(Boolean).join(` / `)):void 0,children:a.map(n=>(0,d.jsx)(`td`,{className:`px-2 py-1 whitespace-nowrap tabular-nums`,children:u.includes(n)?(0,t.formatMeasure)(e[n],B(n)?.format,B(n)?.currency,B(n)?.percentScale):(0,t.formatDimensionValue)(e[n])},n))},n))})]}),X]})}let se=G[p]??`bar`,Z=(0,t.relabelDimensions)(j.rows,L),{data:ce,xAxisKey:le,series:ue}=(0,t.buildChartSeries)(Z,l,u,j.fields),Q=(Array.isArray(b.stageOrder)?b.stageOrder:void 0)?.flatMap(e=>{let t=String(e),n=L?.[l[0]]?.[t];return n&&n!==t?[t,n]:[t]}),de=Q?.length?Q:ee,$=e?.chartConfig&&typeof e.chartConfig==`object`&&!Array.isArray(e.chartConfig)?e.chartConfig:{},fe=typeof $.showLegend==`boolean`?$.showLegend:void 0,pe=J?e=>{let n=(0,t.findChartSeriesRow)(Z,l,u,e?.category,e?.series);if(n<0)return;let r=l.length>=2&&u.length===1,i=[e?.category,r?e?.series:void 0].filter(Boolean).map(String).join(` / `);Y(n,i)}:void 0;return(0,d.jsxs)(`div`,{className:(0,i.cn)(`relative h-full w-full min-h-[220px]`),children:[(0,d.jsx)(n.SchemaRenderer,{schema:{type:`chart`,chartType:se,data:ce,xAxisKey:le,series:ue,isAnimationActive:!1,...fe==null?{}:{showLegend:fe},...F?{categoryColors:F}:{},...de?{categoryOrder:de}:{}},onChartClick:pe,onSegmentClick:pe}),X]})}var K=`__all__`,q=`__custom__`;function J(e,t){if(e){if(e.preset)return t(e.preset);if(e.from||e.to)return`${e.from??`…`} – ${e.to??`…`}`}}function Y(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function X({def:e,value:n,onChange:s}){let c=(0,r.useSafeTranslate)(),[l,u]=(0,a.useState)(!1),f=e.allowCustomRange!==!1,p=e=>c(`dashboard.filters.range.${e}`,e.replace(/_/g,` `)),m=n?.preset??(n?.from||n?.to?q:K);return(0,d.jsxs)(`div`,{className:`flex items-center gap-1`,"data-testid":`dashboard-filter-${e.name}`,children:[(0,d.jsxs)(i.Select,{value:m,onValueChange:e=>{e===K?s(void 0):e===q?u(!0):s({preset:e})},children:[(0,d.jsxs)(i.SelectTrigger,{className:`h-8 w-auto min-w-36 gap-1`,"aria-label":e.label||c(`dashboard.filters.dateRange`,`Date range`),children:[(0,d.jsx)(o.CalendarIcon,{className:`size-3.5 opacity-60`}),(0,d.jsx)(i.SelectValue,{placeholder:c(`dashboard.filters.dateRange`,`Date range`),children:J(n,p)??c(`dashboard.filters.allTime`,`All time`)})]}),(0,d.jsxs)(i.SelectContent,{children:[(0,d.jsx)(i.SelectItem,{value:K,children:c(`dashboard.filters.allTime`,`All time`)}),t.DATE_RANGE_PRESETS.map(e=>(0,d.jsx)(i.SelectItem,{value:e,children:p(e)},e)),f&&(0,d.jsx)(i.SelectItem,{value:q,children:c(`dashboard.filters.custom`,`Custom…`)})]})]}),f&&(0,d.jsxs)(i.Popover,{open:l,onOpenChange:u,children:[(0,d.jsx)(i.PopoverTrigger,{asChild:!0,children:(0,d.jsx)(`span`,{"aria-hidden":!0,className:`size-0`})}),(0,d.jsx)(i.PopoverContent,{className:`w-auto p-0`,align:`start`,children:(0,d.jsx)(i.Calendar,{mode:`range`,numberOfMonths:2,selected:{from:n?.from&&!n.from.startsWith(`{`)?new Date(n.from):void 0,to:n?.to&&!n.to.startsWith(`{`)?new Date(n.to):void 0},onSelect:e=>{if(!e?.from&&!e?.to){s(void 0);return}s({...e?.from?{from:Y(e.from)}:{},...e?.to?{to:Y(e.to)}:{}})}})})]})]})}function se({def:e,value:t,onChange:n,dataSource:o}){let s=(0,r.useSafeTranslate)(),[c,l]=(0,a.useState)(null),u=e.optionsFrom;(0,a.useEffect)(()=>{if(!u||!o)return;let e=!1,t=()=>{if(typeof o.find!=`function`){e||l([]);return}o.find(u.object,{fields:[u.valueField,...u.labelField?[u.labelField]:[]],...u.filter?{$filter:u.filter}:{},top:200}).then(t=>{if(e)return;let n=Array.isArray(t)?t:t?.items??[],r=new Map;for(let e of n){let t=e?.[u.valueField];if(t==null||t===``)continue;let n=String(t);r.has(n)||r.set(n,String(u.labelField?e?.[u.labelField]??n:n))}l(Array.from(r,([e,t])=>({value:e,label:t})))}).catch(()=>{e||l([])})};if(typeof o.queryDataset==`function`){let n=[{name:u.valueField,field:u.valueField}];u.labelField&&u.labelField!==u.valueField&&n.push({name:u.labelField,field:u.labelField}),o.queryDataset({name:`dashboard_filter_options`,label:`Dashboard filter options`,object:u.object,dimensions:n,measures:[{name:`option_count`,aggregate:`count`}]},{dimensions:n.map(e=>e.name),measures:[`option_count`],...u.filter?{runtimeFilter:u.filter}:{},order:{[u.valueField]:`asc`},limit:1e3}).then(t=>{if(e)return;let n=Array.isArray(t?.rows)?t.rows:[],r=new Map;for(let e of n){let t=e?.[u.valueField];if(t==null||t===``)continue;let n=String(t);r.has(n)||r.set(n,String(u.labelField?e?.[u.labelField]??n:n))}l(Array.from(r,([e,t])=>({value:e,label:t})))}).catch(()=>{e||t()})}else t();return()=>{e=!0}},[u?.object,u?.valueField,u?.labelField,o]);let f=(0,a.useMemo)(()=>e.options?.length?e.options:c??[],[e.options,c]),p=e.label||e.name,m=t?f.find(e=>e.value===String(t))?.label??String(t):void 0;return(0,d.jsxs)(i.Select,{value:t?String(t):K,onValueChange:e=>n(e===K?void 0:e),children:[(0,d.jsx)(i.SelectTrigger,{className:`h-8 w-auto min-w-32`,"aria-label":p,"data-testid":`dashboard-filter-${e.name}`,children:(0,d.jsx)(i.SelectValue,{children:m??`${p}: ${s(`dashboard.filters.all`,`All`)}`})}),(0,d.jsxs)(i.SelectContent,{children:[(0,d.jsx)(i.SelectItem,{value:K,children:s(`dashboard.filters.all`,`All`)}),f.map(e=>(0,d.jsx)(i.SelectItem,{value:e.value,children:e.label},e.value))]})]})}function Z({def:e,value:t,onChange:n}){let[r,o]=(0,a.useState)(t==null?``:String(t));(0,a.useEffect)(()=>{o(t==null?``:String(t))},[t]);let s=()=>{let t=r.trim();if(t===``){n(void 0);return}n(e.type===`number`?Number(t):t)};return(0,d.jsx)(i.Input,{className:`h-8 w-36`,type:e.type===`number`?`number`:`text`,placeholder:e.label||e.name,value:r,onChange:e=>o(e.target.value),onBlur:s,onKeyDown:e=>{e.key===`Enter`&&s()},"aria-label":e.label||e.name,"data-testid":`dashboard-filter-${e.name}`})}function ce({defs:e,values:t,onChange:n,onReset:a,dataSource:s,className:c}){let l=(0,r.useSafeTranslate)();if(e.length===0)return null;let u=e=>e==null||e===``||typeof e==`object`&&Object.keys(e).length===0,f=e.some(e=>{let n=t[e.name],r=e.defaultValue;return u(n)&&u(r)?!1:JSON.stringify(n??null)!==JSON.stringify(r??null)});return(0,d.jsxs)(`div`,{className:(0,i.cn)(`col-span-full flex flex-wrap items-center gap-2`,c),"data-testid":`dashboard-filter-bar`,role:`group`,"aria-label":l(`dashboard.filters.label`,`Dashboard filters`),children:[e.map(e=>{let r=t[e.name],i=t=>n(e.name,t);return e.type===`dateRange`||e.type===`date`?(0,d.jsx)(X,{def:e,value:r,onChange:i},e.name):e.type===`select`||e.type===`lookup`?(0,d.jsx)(se,{def:e,value:r,onChange:i,dataSource:s},e.name):(0,d.jsx)(Z,{def:e,value:r,onChange:i},e.name)}),a&&f&&(0,d.jsxs)(i.Button,{variant:`ghost`,size:`sm`,onClick:a,className:`text-muted-foreground`,children:[(0,d.jsx)(o.RotateCcw,{className:`size-3.5`}),l(`dashboard.filters.reset`,`Reset`)]})]})}function le({id:e,disabled:t,gridSpan:n,className:r,children:a}){let{attributes:o,listeners:s,setNodeRef:u,transform:f,transition:p,isDragging:m,isOver:h}=(0,c.useSortable)({id:e,disabled:t}),g={transform:l.CSS.Transform.toString(f),transition:p,opacity:m?.4:1,...n?{gridColumn:`span ${n.w}`,gridRow:`span ${n.h}`}:{}};return(0,d.jsx)(`div`,{ref:u,style:g,className:(0,i.cn)(`h-full w-full`,r,!t&&`cursor-grab active:cursor-grabbing`,h&&!m&&`ring-2 ring-primary ring-offset-2 rounded-lg`),"data-sortable-widget-id":e,...o,...s,children:a})}function ue(e){return e?(0,i.getLazyIcon)(e):null}function Q(e){if(e!=null)return typeof e==`string`?e:e.defaultValue||e.key}var de=[`hsl(var(--chart-1))`,`hsl(var(--chart-2))`,`hsl(var(--chart-3))`,`hsl(var(--chart-4))`,`hsl(var(--chart-5))`],$=new Set([`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`funnel`,`scatter`,`treemap`,`sankey`]);function fe(e){return $.has(e)?{enabled:!0}:void 0}var pe=new Set([`object-chart`,`object-metric`,`object-data-table`]),me={type:`text`,value:`This widget uses a retired data format. Edit it to bind a dataset.`,variant:`caption`,align:`center`,className:`flex h-full w-full items-center justify-center rounded border border-dashed border-destructive/40 bg-destructive/5 p-4 text-center text-destructive`},he=(0,a.forwardRef)(({schema:e,className:l,dataSource:u,onRefresh:f,recordCount:p,userActions:m,designMode:h,selectedWidgetId:g,onWidgetClick:_,onWidgetsReorder:v,modalHandler:y,scriptHandlers:b,hideHeaderText:S,...C},w)=>{let E=(()=>{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})(),D=E,k=e.gap||4,A=e.columns!=null||E!==4,[j,M]=(0,a.useState)(!1),[N,P]=(0,a.useState)(!1),F=(0,a.useRef)(null),I=(0,a.useMemo)(()=>(0,t.resolveDashboardFilterDefs)(e),[e.globalFilters,e.dateRange]),{variables:L,setVariable:R,resetVariables:ee}=(0,n.usePageVariables)(),z=(0,a.useMemo)(()=>(e.header?.actions??[]).map(e=>({name:e.actionUrl||e.label,type:e.actionType||`url`,target:e.actionUrl,label:e.label})),[e.header?.actions]),{executeAction:te,engine:B}=(0,n.useActionEngine)({actions:z}),{dashboardLabel:V,dashboardDescription:ne,dashboardActionLabel:re,widgetTitle:ie,widgetDescription:H,fieldLabel:U}=(0,n.useObjectLabel)(),{t:W}=(0,r.useObjectTranslation)(),ae=(0,a.useCallback)((e,t,n)=>n&&(!t||t===`value`||t===`count`||n===`count`)?W(`report.aggregate.${n}`,{defaultValue:n}):e?U(e,t,t):t,[W,U]),G=e.name,K=(0,a.useCallback)(e=>{if(!G)return e.label;let t=e.actionUrl||e.label;return re(G,t,e.label)},[G,re]),q=(0,a.useCallback)(e=>{let t=Q(e.title);return!G||!e.id||t===void 0?t:ie(G,e.id,t)},[G,ie]),J=(0,a.useCallback)(e=>{let t=Q(e.description);return!G||!e.id?t:H(G,e.id,t)},[G,H]);(0,a.useEffect)(()=>{let e=B.getRunner();if(y&&e.setModalHandler(y),b)for(let[t,n]of Object.entries(b))e.registerScript(t,n)},[B,y,b]),(0,a.useEffect)(()=>{let e=()=>P(window.innerWidth<768);return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let Y=(0,a.useCallback)(()=>{f&&(M(!0),f(),setTimeout(()=>M(!1),600))},[f]);(0,a.useEffect)(()=>{if(!(!e.refreshInterval||e.refreshInterval<=0||!f))return F.current=setInterval(Y,e.refreshInterval*1e3),()=>{F.current&&clearInterval(F.current)}},[e.refreshInterval,f,Y]);let X=(0,a.useCallback)((e,t)=>{!h||!_||!t||(e.stopPropagation(),_(t))},[h,_]),se=(0,a.useCallback)((t,n,r)=>{if(!h||!_)return;let i=e.widgets||[];if(t.key===`Enter`||t.key===` `)t.preventDefault(),_(n??null);else if(t.key===`ArrowRight`||t.key===`ArrowDown`){t.preventDefault();let e=r+1<i.length?i[r+1]:null;e?.id&&_(e.id)}else if(t.key===`ArrowLeft`||t.key===`ArrowUp`){t.preventDefault();let e=r-1>=0?i[r-1]:null;e?.id&&_(e.id)}else t.key===`Escape`&&(t.preventDefault(),_(null))},[h,_,e.widgets]),Z=(0,a.useCallback)(e=>{!h||!_||e.target===e.currentTarget&&_(null)},[h,_]),$=!!(h&&v),he=(0,s.useSensors)((0,s.useSensor)(s.PointerSensor,{activationConstraint:{distance:5}})),ge=(0,a.useCallback)(t=>{if(!$)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||v?.((0,c.arrayMove)(i,a,o))},[$,e.widgets,v]),_e=(e,r,o)=>{let s=e.type===`metric`||T.has(e.type||``),c=A?{w:Math.min(s?3:6,D),h:s?2:4}:void 0,l=e.layout??c,f=l?{...l,w:Math.min(l.w,D)}:void 0,p=!!e.dataset,m=()=>{if(e.component)return e.component;let t=e.type,n=e.options||{},r=e.data||n.data;if(!r&&e.object)return me;let i=O(t),a=i.chartType??t;if(i.family===`series`&&i.chartType){let t=n.xField||`name`,o=n.yField||`value`;if(x(r)){let s=r.aggregate,c=s?{field:s.field,function:s.function,groupBy:s.groupBy}:void 0,l=c?.field||o;return{type:`object-chart`,chartType:a,objectName:r.object,aggregate:c,filter:r.filter||e.filter,xAxisKey:t,series:[{dataKey:l,label:ae(r.object,l,c?.function)}],colors:de,isAnimationActive:!1,drillDown:n.drillDown??fe(i.chartType),compareTo:e.compareTo,className:`h-[200px] sm:h-[250px] md:h-[300px]`}}return{type:`chart`,chartType:a,data:Array.isArray(r)?r:r?.items||[],xAxisKey:t,series:[{dataKey:o,label:ae(void 0,o,void 0)}],colors:de,isAnimationActive:!1,className:`h-[200px] sm:h-[250px] md:h-[300px]`}}if(i.family===`metric`){let i=Q(e.title)||t;if(x(r)){let t=r.aggregate;return{type:`object-metric`,...n,objectName:r.object,label:i,aggregate:t?{field:t.field,function:t.function,groupBy:t.groupBy}:void 0,filter:r.filter||e.filter}}let a=Array.isArray(r)?r:r?.items||[],o=n.yField||`value`;return{type:`metric`,...n,label:i,value:n.value??a[0]?.[o]??`—`}}if(i.family===`table`){let i=t===`list`;if(x(r)){let{data:t,...a}=n;return{type:`object-data-table`,...a,objectName:r.object,dataProvider:r,filter:r.filter||e.filter,searchable:i?!1:e.searchable??!1,pagination:i?!1:e.pagination??!1,drillDown:n.drillDown??{enabled:!0,mode:`record`},className:`border-0`}}return{type:`data-table`,...n,data:Array.isArray(r)?r:r?.items||[],searchable:!1,pagination:!1,className:`border-0`}}return i.family===`pivot`?me:i.family===`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`}:i.family===`unsupported`?{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}},_=I.length>0?(0,t.buildWidgetScopedFilter)(e,I,L):void 0,v=(()=>{let e=m();return _&&e&&pe.has(e.type)?{...e,filter:(0,t.mergeFilters)(e.filter,_)}:e})(),y=_&&p?{...e,filter:(0,t.mergeFilters)(e.filter,_)}:e,b=e.type===`metric`&&!p,S=q(e),C=J(e),w=e.id||S||`widget-${r}`,E=h&&g===e.id,k=h?{"data-testid":`dashboard-preview-widget-${e.id}`,"data-widget-id":e.id,role:`button`,tabIndex:0,"aria-selected":E,"aria-label":`Widget: ${S||`Widget ${r+1}`}`,onClick:t=>X(t,e.id),onKeyDown:t=>se(t,e.id,r)}:{},j=h?(0,i.cn)(`cursor-pointer rounded-lg transition-all outline-none`,`focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,E?`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,M=!N&&f&&!$?{gridColumn:`span ${f.w}`,gridRow:`span ${f.h}`}:void 0,P=b?(0,d.jsxs)(`div`,{className:(0,i.cn)(`h-full w-full`,h&&`relative`,j),style:M,...k,children:[p?(0,d.jsx)(`div`,{className:(0,i.cn)(`h-full w-full`,h&&`pointer-events-none`),children:(0,d.jsx)(oe,{widget:y,dataSource:u})}):(0,d.jsx)(n.SchemaRenderer,{schema:v,className:(0,i.cn)(`h-full w-full`,h&&`pointer-events-none`),dataSource:u}),h&&(0,d.jsx)(`div`,{className:`absolute inset-0 z-10`,"aria-hidden":`true`,"data-testid":`widget-click-overlay`})]}):(0,d.jsxs)(i.Card,{className:(0,i.cn)(`overflow-hidden border-border/50 shadow-sm transition-all hover:shadow-md`,`bg-card/50 backdrop-blur-sm`,o&&`w-full`,h&&`relative`,j),style:M,...k,children:[S&&(0,d.jsxs)(i.CardHeader,{className:`pb-2 border-b border-border/40 bg-muted/20 px-3 sm:px-6`,children:[(0,d.jsx)(i.CardTitle,{className:`text-sm sm:text-base font-medium tracking-tight truncate`,title:S,children:S}),C&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5 line-clamp-2`,children:C})]}),(0,d.jsx)(i.CardContent,{className:`p-0`,children:(0,d.jsx)(`div`,{className:(0,i.cn)(`h-full w-full`,`p-3 sm:p-4 md:p-6`,h&&`pointer-events-none`),children:p?(0,d.jsx)(oe,{widget:y,dataSource:u}):(0,d.jsx)(n.SchemaRenderer,{schema:v,dataSource:u})})}),h&&(0,d.jsx)(`div`,{className:`absolute inset-0 z-10`,"aria-hidden":`true`,"data-testid":`widget-click-overlay`})]});return $&&e.id?(0,d.jsx)(le,{id:e.id,gridSpan:!N&&f?{w:f.w,h:f.h}:void 0,children:P},w):(0,d.jsx)(a.Fragment,{children:P},w)},ve=e.title||e.label,ye=e.header&&(0,d.jsxs)(`div`,{className:`col-span-full mb-4`,children:[!S&&e.header.showTitle!==!1&&ve&&(0,d.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:G?V({name:G,label:Q(ve)}):Q(ve)}),!S&&e.header.showDescription!==!1&&e.description&&(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:G?ne({name:G,description:Q(e.description)}):Q(e.description)}),e.header.actions&&e.header.actions.length>0&&(0,d.jsx)(`div`,{className:`flex gap-2 mt-3`,children:e.header.actions.map((e,t)=>{let n=ue(e.icon);return(0,d.jsxs)(i.Button,{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}let i=await te(n||r);i?.success||console.warn(`[DashboardRenderer] action failed`,i?.error)},children:[n&&(0,d.jsx)(n,{className:`w-4 h-4 mr-1.5`}),K(e)]},t)})})]}),be=I.length>0&&(0,d.jsx)(ce,{defs:I,values:L,onChange:R,onReset:ee,dataSource:u,className:`mb-2`}),xe=p!==void 0&&(0,d.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[p.toLocaleString(),` records`]}),Se=m?JSON.stringify(m):void 0,Ce=f&&(0,d.jsxs)(`div`,{className:(0,i.cn)(`flex items-center justify-end gap-3 mb-2`,!N&&`col-span-full`),children:[xe,(0,d.jsxs)(i.Button,{variant:`outline`,size:`sm`,onClick:Y,disabled:j,"aria-label":`Refresh dashboard`,children:[(0,d.jsx)(o.RefreshCw,{className:(0,i.cn)(`h-4 w-4 mr-2`,j&&`animate-spin`)}),j?`Refreshing…`:`Refresh All`]})]}),we=(0,a.useMemo)(()=>(e.widgets??[]).map(e=>e.id).filter(e=>!!e),[e.widgets]),Te=(0,a.useMemo)(()=>(e.widgets??[]).filter(e=>e.type===`metric`).map(e=>e.id).filter(e=>!!e),[e.widgets]),Ee=(0,a.useMemo)(()=>(e.widgets??[]).filter(e=>e.type!==`metric`).map(e=>e.id).filter(e=>!!e),[e.widgets]);if(N){let t=e.widgets?.filter(e=>e.type===`metric`)||[],n=e.widgets?.filter(e=>e.type!==`metric`)||[],r=(0,d.jsxs)(`div`,{ref:w,className:(0,i.cn)(`flex flex-col gap-4 px-4`,l),"data-user-actions":Se,onClick:Z,...C,children:[ye,be,Ce,t.length>0&&(0,d.jsx)(`div`,{className:`grid grid-cols-2 gap-3`,onClick:Z,children:(0,d.jsx)(c.SortableContext,{items:Te,strategy:c.rectSortingStrategy,disabled:!$,children:t.map((e,t)=>_e(e,t))})}),n.length>0&&(0,d.jsx)(`div`,{className:`flex flex-col gap-4`,onClick:Z,children:(0,d.jsx)(c.SortableContext,{items:Ee,strategy:c.verticalListSortingStrategy,disabled:!$,children:n.map((e,t)=>_e(e,t,!0))})})]});return $?(0,d.jsx)(s.DndContext,{sensors:he,collisionDetection:s.closestCenter,onDragEnd:ge,children:r}):r}let De=(0,d.jsxs)(`div`,{ref:w,className:(0,i.cn)(`grid`,!A&&`auto-rows-min grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,l),style:{...A&&{gridTemplateColumns:`repeat(${D}, minmax(0, 1fr))`,gridAutoRows:`minmax(5rem, auto)`},gap:`${k*.25}rem`},"data-user-actions":Se,onClick:Z,...C,children:[ye,be,Ce,(0,d.jsx)(c.SortableContext,{items:we,strategy:c.rectSortingStrategy,disabled:!$,children:e.widgets?.map((e,t)=>_e(e,t))})]});return $?(0,d.jsx)(s.DndContext,{sensors:he,collisionDetection:s.closestCenter,onDragEnd:ge,children:De}):De});he.displayName=`DashboardRendererInner`;var ge=(0,a.forwardRef)((e,r)=>{let{schema:i}=e,o=(0,a.useMemo)(()=>(0,t.resolveDashboardFilterDefs)(i),[i.globalFilters,i.dateRange]);return o.length===0?(0,d.jsx)(he,{ref:r,...e}):(0,d.jsx)(n.PageVariablesProvider,{definitions:(0,t.dashboardFilterVariableDefs)(o),children:(0,d.jsx)(he,{ref:r,...e})})});ge.displayName=`DashboardRenderer`;function _e({editMode:e}){let t=(0,n.useDnd)();return a.useEffect(()=>{if(e)return t.startDrag({id:`dashboard-layout`,type:`dashboard-widget`,data:{}}),()=>{t.endDrag()};t.endDrag(`dashboard`)},[e,t]),null}var ve=[`hsl(var(--chart-1))`,`hsl(var(--chart-2))`,`hsl(var(--chart-3))`,`hsl(var(--chart-4))`,`hsl(var(--chart-5))`];function ye(e,t){if(!e.widgets?.length)return e;let n=new Map(t.map(e=>[e.i,e])),r=e.widgets.map((e,t)=>{let r=e.id||`widget-${t}`,i=n.get(r);return i?{...e,layout:{x:i.x,y:i.y,w:i.w,h:i.h}}:e});return{...e,widgets:r}}function be(e){return{lg:e.widgets?.map((e,t)=>({i:e.id||`widget-${t}`,x:e.layout?.x??t%4*3,y:e.layout?.y??Math.floor(t/4)*4,w:e.layout?.w??3,h:e.layout?.h??4}))||[]}}var xe=({schema:e,className:t,onLayoutChange:r,onSchemaChange:s,onRefresh:c})=>{let{width:l,containerRef:u,mounted:p}=(0,f.useContainerWidth)(),[m,h]=a.useState(!1),[g,_]=a.useState(!1),v=(0,n.useHasDndProvider)(),y=a.useRef(null),b=a.useCallback(()=>{c&&(_(!0),c(),setTimeout(()=>_(!1),600))},[c]);a.useEffect(()=>{if(!(!e.refreshInterval||e.refreshInterval<=0||!c))return y.current=setInterval(b,e.refreshInterval*1e3),()=>{y.current&&clearInterval(y.current)}},[e.refreshInterval,c,b]);let[S,C]=a.useState(()=>be(e)),w=a.useMemo(()=>JSON.stringify(e.widgets?.map((e,t)=>({i:e.id||`widget-${t}`,x:e.layout?.x,y:e.layout?.y,w:e.layout?.w,h:e.layout?.h}))??[]),[e.widgets]);a.useEffect(()=>{C(be(e))},[w]);let T=a.useCallback((e,t)=>{C(t),r?.(e)},[r]),E=a.useCallback(()=>{s?s(ye(e,S.lg)):globalThis.process?.env?.NODE_ENV!==`production`&&console.warn("[DashboardGridLayout] Layout edits are in-memory only. Wire `onSchemaChange` to persist via your data adapter."),h(!1)},[s,e,S]),D=a.useCallback(()=>{C(be(e))},[e]),k=a.useCallback(e=>{if(e.component)return e.component;let t=e.type,n=e.options||{},r=O(t);if(r.family===`series`&&r.chartType){let t=e.data||n.data,i=n.xField||`name`,a=n.yField||`value`;if(x(t)){let e=t.aggregate,n=e?{field:e.field,function:e.function,groupBy:e.groupBy}:void 0,o=n?.field||a;return{type:`object-chart`,chartType:r.chartType,objectName:t.object,aggregate:n,xAxisKey:i,series:[{dataKey:o}],colors:ve,isAnimationActive:!1,className:`h-full`}}let o=Array.isArray(t)?t:t?.items||[];return{type:`chart`,chartType:r.chartType,data:o,xAxisKey:i,series:[{dataKey:a}],colors:ve,isAnimationActive:!1,className:`h-full`}}if(r.family===`metric`){let r=e.data||n.data,i=e.title||t;if(x(r)){let t=r.aggregate;return{type:`object-metric`,...n,objectName:r.object,label:i,aggregate:t?{field:t.field,function:t.function,groupBy:t.groupBy}:void 0,filter:r.filter||e.filter}}let a=Array.isArray(r)?r:r?.items||[],o=n.yField||`value`;return{type:`metric`,...n,label:i,value:n.value??a[0]?.[o]??`—`}}if(r.family===`table`){let t=e.data||n.data;if(x(t)){let{data:e,...r}=n;return{type:`data-table`,...r,objectName:t.object,dataProvider:t,data:[],searchable:!1,pagination:!1,className:`border-0`}}return{type:`data-table`,...n,data:t?.items||[],searchable:!1,pagination:!1,className:`border-0`}}if(r.family===`pivot`){let t=e.data||n.data;if(x(t)){let{data:e,...r}=n;return{type:`pivot`,...r,objectName:t.object,dataProvider:t,data:[]}}return{type:`pivot`,...n,data:Array.isArray(t)?t:t?.items||[]}}return r.family===`unsupported`?{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}},[]);return(0,d.jsxs)(`div`,{ref:u,className:(0,i.cn)(`w-full`,t),"data-testid":`grid-layout`,children:[v&&(0,d.jsx)(_e,{editMode:m}),(0,d.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,d.jsx)(`h2`,{className:`text-2xl font-bold`,children:e.title||e.label||`Dashboard`}),(0,d.jsx)(`div`,{className:`flex gap-2`,children:m?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(i.Button,{onClick:E,size:`sm`,variant:`default`,children:[(0,d.jsx)(o.Save,{className:`h-4 w-4 mr-2`}),`Save Layout`]}),(0,d.jsxs)(i.Button,{onClick:D,size:`sm`,variant:`outline`,children:[(0,d.jsx)(o.X,{className:`h-4 w-4 mr-2`}),`Reset`]}),(0,d.jsx)(i.Button,{onClick:()=>h(!1),size:`sm`,variant:`ghost`,children:`Cancel`})]}):(0,d.jsxs)(d.Fragment,{children:[c&&(0,d.jsxs)(i.Button,{onClick:b,size:`sm`,variant:`outline`,disabled:g,"aria-label":`Refresh dashboard`,children:[(0,d.jsx)(o.RefreshCw,{className:(0,i.cn)(`h-4 w-4 mr-2`,g&&`animate-spin`)}),g?`Refreshing…`:`Refresh All`]}),(0,d.jsxs)(i.Button,{onClick:()=>h(!0),size:`sm`,variant:`outline`,children:[(0,d.jsx)(o.Edit,{className:`h-4 w-4 mr-2`}),`Edit Layout`]})]})})]}),p&&(0,d.jsx)(f.ResponsiveGridLayout,{className:`layout`,width:l,layouts:S,breakpoints:{lg:1200,md:996,sm:768,xs:480,xxs:0},cols:{lg:12,md:10,sm:6,xs:4,xxs:2},rowHeight:60,dragConfig:{enabled:m,handle:`.drag-handle`},resizeConfig:{enabled:m},onLayoutChange:T,children:e.widgets?.map((e,t)=>{let r=e.id||`widget-${t}`,a=k(e),s=e.type===`metric`;return(0,d.jsx)(`div`,{className:`h-full`,children:s?(0,d.jsxs)(`div`,{className:`h-full w-full relative`,children:[m&&(0,d.jsx)(`div`,{className:`drag-handle absolute top-2 right-2 z-10 cursor-move p-1 bg-background/80 rounded border border-border`,children:(0,d.jsx)(o.GripVertical,{className:`h-4 w-4`})}),(0,d.jsx)(n.SchemaRenderer,{schema:a,className:`h-full w-full`})]}):(0,d.jsxs)(i.Card,{className:(0,i.cn)(`h-full overflow-hidden border-border/50 shadow-sm transition-all`,`bg-card/50 backdrop-blur-sm`,m&&`ring-2 ring-primary/20`),children:[e.title&&(0,d.jsxs)(i.CardHeader,{className:`pb-2 border-b border-border/40 bg-muted/20 flex flex-row items-center justify-between`,children:[(0,d.jsx)(i.CardTitle,{className:`text-base font-medium tracking-tight truncate`,title:e.title,children:e.title}),m&&(0,d.jsx)(`div`,{className:`drag-handle cursor-move p-1 hover:bg-muted/40 rounded`,children:(0,d.jsx)(o.GripVertical,{className:`h-4 w-4`})})]}),(0,d.jsx)(i.CardContent,{className:`p-0 h-full`,children:(0,d.jsx)(`div`,{className:(0,i.cn)(`h-full w-full overflow-auto p-4`),children:(0,d.jsx)(n.SchemaRenderer,{schema:a})})})]})},r)})})]})},Se=(0,r.createSafeTranslation)({"dashboard.trend.vsLastQuarter":`vs last quarter`,"dashboard.trend.vsLastMonth":`vs last month`,"dashboard.trend.vsLastWeek":`vs last week`,"dashboard.trend.vsLastYear":`vs last year`,"dashboard.trend.vsYesterday":`vs yesterday`,"dashboard.trend.vsPreviousPeriod":`vs previous period`},`dashboard.trend.vsLastQuarter`);function Ce(e){switch(e.trim().toLowerCase().replace(/\s+/g,` `)){case`vs last quarter`:case`vs previous quarter`:return`dashboard.trend.vsLastQuarter`;case`vs last month`:case`vs previous month`:return`dashboard.trend.vsLastMonth`;case`vs last week`:case`vs previous week`:return`dashboard.trend.vsLastWeek`;case`vs last year`:case`vs previous year`:return`dashboard.trend.vsLastYear`;case`vs yesterday`:return`dashboard.trend.vsYesterday`;case`vs previous period`:case`vs prior period`:return`dashboard.trend.vsPreviousPeriod`;default:return}}function we(e,t,n){if(e==null)return``;if(typeof e==`string`){let r=Number(e);return!isFinite(r)||e.trim()===``?e:we(r,t,n)}if(!isFinite(e))return String(e);let r={$:`USD`,"¥":`JPY`,"€":`EUR`,"£":`GBP`},i=(t||``).trim(),a=!!n||i.length>0&&r[i[0]]!==void 0,o=i.endsWith(`%`),s=i.match(/0\.(0+)/),c=s?s[1].length:0;if(/a/i.test(i)){let t={notation:`compact`,maximumFractionDigits:c||1};a&&(t.style=`currency`,t.currency=n||r[i[0]]||`USD`);try{return new Intl.NumberFormat(`en-US`,t).format(e)}catch{}}if(a){let t=n||r[i[0]]||`USD`;try{return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:t,minimumFractionDigits:c,maximumFractionDigits:c}).format(e)}catch{return`${t} ${e.toFixed(c)}`}}return o?`${(e>1?e:e*100).toFixed(c)}%`:new Intl.NumberFormat(`en-US`,{minimumFractionDigits:c,maximumFractionDigits:c}).format(e)}function Te(e){if(e!=null)return typeof e==`string`?e:e.defaultValue||e.key}var Ee={default:`bg-muted text-muted-foreground`,blue:`bg-blue-500/10 text-blue-600 dark:text-blue-400`,teal:`bg-teal-500/10 text-teal-600 dark:text-teal-400`,orange:`bg-orange-500/10 text-orange-600 dark:text-orange-400`,purple:`bg-purple-500/10 text-purple-600 dark:text-purple-400`,success:`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`,warning:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,danger:`bg-rose-500/10 text-rose-600 dark:text-rose-400`},De={default:`text-foreground`,blue:`text-blue-600 dark:text-blue-400`,teal:`text-teal-600 dark:text-teal-400`,orange:`text-orange-600 dark:text-orange-400`,purple:`text-purple-600 dark:text-purple-400`,success:`text-emerald-600 dark:text-emerald-400`,warning:`text-amber-600 dark:text-amber-400`,danger:`text-rose-600 dark:text-rose-400`},Oe=({label:e,value:t,trend:n,icon:r,className:s,description:c,loading:l,error:u,colorVariant:f=`default`,format:p,currency:m,prefix:h,suffix:g,onClick:_,variant:v=`card`,...y})=>{let b=Ee[f]||Ee.default,{t:x}=Se(),S=(0,a.useMemo)(()=>{let e=Te(c)||Te(n?.label);if(!e)return e;let t=Ce(e);return t?x(t):e},[c,n?.label,x]),C=(0,a.useMemo)(()=>{let e=typeof t==`number`||typeof t==`string`&&t.trim()!==``&&isFinite(Number(t))?we(t,p,m):t??``,n=String(e);return`${h&&n.startsWith(h)?``:h??``}${n}${g&&n.endsWith(g)?``:g??``}`},[t,p,m,h,g]),w=(0,a.useMemo)(()=>{if(typeof r==`string`){let e=(0,i.getLazyIcon)(r);return e?(0,d.jsx)(e,{className:`h-4 w-4`}):null}return r},[r]);if(v===`bare`){let t=De[f]||De.default;return(0,d.jsx)(`div`,{className:(0,i.cn)(`flex flex-col gap-1 min-w-0`,_&&`cursor-pointer`,s),onClick:_,role:_?`button`:void 0,tabIndex:_?0:void 0,onKeyDown:_?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),_())}:void 0,children:l?(0,d.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,"data-testid":`metric-loading`,children:[(0,d.jsx)(o.Loader2,{className:`h-4 w-4 animate-spin`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Loading…`})]}):u?(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,"data-testid":`metric-error`,role:`alert`,children:[(0,d.jsx)(o.AlertCircle,{className:`h-4 w-4 text-destructive shrink-0`}),(0,d.jsx)(`span`,{className:`text-xs text-destructive truncate`,children:u})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{className:(0,i.cn)(`text-[2rem] leading-none font-extrabold tabular-nums tracking-tight truncate`,t),children:C}),(0,d.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground truncate`,children:Te(e)})]})})}return(0,d.jsxs)(i.Card,{className:(0,i.cn)(`h-full overflow-hidden`,_&&`cursor-pointer transition-colors hover:bg-accent/40 focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none`,s),onClick:_,role:_?`button`:void 0,tabIndex:_?0:void 0,onKeyDown:_?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),_())}:void 0,...y,children:[(0,d.jsxs)(i.CardHeader,{className:`flex flex-row items-center justify-between space-y-0 pb-2`,children:[(0,d.jsx)(i.CardTitle,{className:`text-sm font-medium truncate`,children:Te(e)}),w&&(0,d.jsx)(`div`,{className:(0,i.cn)(`flex h-8 w-8 items-center justify-center rounded-md shrink-0`,b),children:w})]}),(0,d.jsx)(i.CardContent,{children:l?(0,d.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,"data-testid":`metric-loading`,children:[(0,d.jsx)(o.Loader2,{className:`h-4 w-4 animate-spin`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Loading…`})]}):u?(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,"data-testid":`metric-error`,role:`alert`,children:[(0,d.jsx)(o.AlertCircle,{className:`h-4 w-4 text-destructive shrink-0`}),(0,d.jsx)(`span`,{className:`text-xs text-destructive truncate`,children:u})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{className:`text-2xl font-bold tabular-nums tracking-tight truncate`,children:C}),(n||c)&&(0,d.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 min-w-0`,children:[n&&(0,d.jsxs)(`span`,{className:(0,i.cn)(`flex items-center shrink-0 font-medium`,n.direction===`up`&&`text-emerald-600 dark:text-emerald-400`,n.direction===`down`&&`text-rose-600 dark:text-rose-400`,n.direction===`neutral`&&`text-muted-foreground`),children:[n.direction===`up`&&(0,d.jsx)(o.ArrowUpIcon,{className:`h-3 w-3 mr-1`}),n.direction===`down`&&(0,d.jsx)(o.ArrowDownIcon,{className:`h-3 w-3 mr-1`}),n.direction===`neutral`&&(0,d.jsx)(o.MinusIcon,{className:`h-3 w-3 mr-1`}),n.value,`%`]}),(0,d.jsx)(`span`,{className:`truncate min-w-0`,children:S})]})]})})]})};function ke(e){if(e!=null)return typeof e==`string`?e:e.defaultValue||e.key}var Ae=({title:e,value:t,icon:n,trend:r,trendValue:a,description:s,className:c,loading:l,error:u,...f})=>{let p=n?(0,i.getLazyIcon)(n):null;return(0,d.jsxs)(i.Card,{className:(0,i.cn)(`h-full`,c),...f,children:[(0,d.jsxs)(i.CardHeader,{className:`flex flex-row items-center justify-between space-y-0 pb-2`,children:[(0,d.jsx)(i.CardTitle,{className:`text-sm font-medium`,children:ke(e)}),p&&(0,d.jsx)(p,{className:`h-4 w-4 text-muted-foreground`})]}),(0,d.jsx)(i.CardContent,{children:l?(0,d.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,"data-testid":`metric-card-loading`,children:[(0,d.jsx)(o.Loader2,{className:`h-4 w-4 animate-spin`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Loading…`})]}):u?(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,"data-testid":`metric-card-error`,role:`alert`,children:[(0,d.jsx)(o.AlertCircle,{className:`h-4 w-4 text-destructive shrink-0`}),(0,d.jsx)(`span`,{className:`text-xs text-destructive truncate`,children:u})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{className:`text-2xl font-bold`,children:t}),(r||a||s)&&(0,d.jsxs)(`p`,{className:`text-xs text-muted-foreground flex items-center mt-1`,children:[r&&a&&(0,d.jsxs)(`span`,{className:(0,i.cn)(`flex items-center mr-2`,r===`up`&&`text-green-500`,r===`down`&&`text-red-500`,r===`neutral`&&`text-yellow-500`),children:[r===`up`&&(0,d.jsx)(o.ArrowUpIcon,{className:`h-3 w-3 mr-1`}),r===`down`&&(0,d.jsx)(o.ArrowDownIcon,{className:`h-3 w-3 mr-1`}),r===`neutral`&&(0,d.jsx)(o.MinusIcon,{className:`h-3 w-3 mr-1`}),a]}),ke(s)]})]})})]})},je=({objectName:e,aggregate:o,filter:s,label:c,fallbackValue:l,trend:u,icon:f,className:p,description:m,dataSource:h,colorVariant:g,format:_,currency:v,prefix:y,suffix:b,invert:x,drillDown:C,title:w,compareTo:T,t:E,variant:D})=>{let O=(0,a.useContext)(n.SchemaRendererContext),k=h||O?.dataSource,[A,j]=(0,a.useState)(!1),[M,N]=(0,a.useState)(null),[P,F]=(0,a.useState)(null),[I,L]=(0,a.useState)(!1),[R,ee]=(0,a.useState)(null),[z,te]=(0,a.useState)(null);(0,a.useEffect)(()=>{let t=!0;if(!(!k||!e||typeof k.getObjectSchema!=`function`))return k.getObjectSchema(e).then(e=>{t&&te(e)}).catch(()=>{}),()=>{t=!1}},[k,e]);let B=(0,a.useMemo)(()=>{let e=o?.field;if(!e||!z?.fields)return null;let t=z.fields;return Array.isArray(t)?t.find(t=>t?.name===e)||null:t[e]||null},[z,o?.field]),ne=(0,a.useMemo)(()=>{if(_)return _;if(B){if(B.type===`currency`){let e=B.scale??0;return e>0?`0,0.${`0`.repeat(e)}`:`0,0`}if(B.type===`percent`)return`0,0%`;if(B.type===`number`||B.type===`integer`)return`0,0`}},[_,B]),{currency:re}=(0,r.useLocalization)(),ie=(0,a.useMemo)(()=>{if(v)return v;if(B?.type===`currency`)return(0,r.resolveFieldCurrency)(B,re)},[v,B,re]),H=(0,a.useMemo)(()=>o?JSON.stringify(o):``,[o]),U=(0,n.useFilterScope)(),W=(0,a.useMemo)(()=>(0,t.resolveFilterPlaceholders)(s,U),[s,U]),ae=(0,a.useMemo)(()=>W?JSON.stringify(W):``,[W]),G=(0,a.useMemo)(()=>T?JSON.stringify(T):``,[T]),oe=(0,a.useCallback)(async(t,n)=>{if(o&&typeof t.aggregate==`function`){let r=await t.aggregate(e,{field:o.field,function:o.function,groupBy:o.groupBy||`_all`,filter:n}),i=Array.isArray(r)?r:[];if(i.length===0)return 0;if(o.function===`count`){let e=`${o.field}_count`;return i.reduce((t,n)=>t+(Number(n[e])||Number(n[o.field])||Number(n.count)||0),0)}let a=i[0];return a[`${o.field}_${o.function}`]??a[o.field]??a.value??0}if(typeof t.find==`function`){let r=await t.find(e,{$filter:n});return(Array.isArray(r)?r:r?.data||r?.records||[]).length}return null},[e,H]),K=(0,a.useCallback)(async(n,r)=>{if(!(!n||!e)){r.current&&(L(!0),ee(null));try{let e=T?(0,t.shiftFilterByCompareTo)(s,T):null,[i,a]=await Promise.all([oe(n,W),e?oe(n,e):Promise.resolve(null)]);if(i===null)return;r.current&&(N(i),F(typeof a==`number`&&Number.isFinite(a)?a:null))}catch(e){console.error(`[ObjectMetricWidget] Fetch error:`,e),r.current&&ee(e instanceof Error?e.message:`Failed to load metric`)}finally{r.current&&L(!1)}}},[e,H,ae,G,oe]);(0,a.useEffect)(()=>{let t={current:!0};return k&&e?K(k,t):(N(null),ee(null)),()=>{t.current=!1}},[k,e,K]);let q=M===null?k?`—`:l??`—`:M;x&&typeof q==`number`&&isFinite(q)&&q>=0&&q<=1&&(q=1-q);let J=(0,a.useMemo)(()=>{if(!T||typeof M!=`number`||!Number.isFinite(M)||P===null)return;let e=S(M,P);if(!e)return;let n=(0,t.compareToTrendLabelKey)(T,s),r=`dashboard.trend.${n}`,i={vsPreviousPeriod:`vs previous period`,vsLastWeek:`vs last week`,vsLastMonth:`vs last month`,vsLastQuarter:`vs last quarter`,vsLastYear:`vs last year`,vsYesterday:`vs yesterday`},a=E?E(r,i[n]||n):i[n]||n;return{value:e.value,direction:e.direction,label:a}},[T,M,P,s,E])??u,Y=(0,t.isDrillEnabled)(C)&&!!e&&!!k,X=(0,a.useMemo)(()=>{let e=typeof c==`string`?c:c?.defaultValue||``,n=typeof w==`string`?w:w?.defaultValue||``;return(0,t.resolveDrillTitle)(C,{},n||e||`Details`)},[C,c,w]),se=(0,a.useMemo)(()=>{if(!Y)return null;let t=C?.target??`drawer`,r=C?.report,a=r&&typeof r==`object`&&(Array.isArray(r.columns)||`objectName`in r),o=a?null:(0,d.jsx)(V,{objectName:e,filter:W,onNavigate:()=>j(!1)}),s;if(a){let e=r.filter,t=e?W?{$and:[e,W]}:e:W,i={type:`spec-report`,...r,filter:t};s=(0,d.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,d.jsx)(n.SchemaRenderer,{schema:i})})}else s=(0,d.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,d.jsx)(n.SchemaRenderer,{schema:{type:`object-data-table`,objectName:e,filter:W,pageSize:25,drillDown:{enabled:!0,mode:`record`,target:`dialog`}}})});return t===`dialog`?(0,d.jsx)(i.Dialog,{open:!0,onOpenChange:e=>!e&&j(!1),children:(0,d.jsxs)(i.DialogContent,{className:`max-w-5xl`,children:[(0,d.jsxs)(i.DialogHeader,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,d.jsx)(i.DialogTitle,{children:X}),o]}),s]})}):(0,d.jsx)(i.Sheet,{open:!0,onOpenChange:e=>!e&&j(!1),children:(0,d.jsxs)(i.SheetContent,{side:`right`,className:`w-full sm:max-w-2xl md:max-w-3xl lg:max-w-5xl flex flex-col`,children:[(0,d.jsxs)(i.SheetHeader,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,d.jsx)(i.SheetTitle,{children:X}),o]}),(0,d.jsx)(`div`,{className:`flex-1 overflow-hidden mt-2`,children:s})]})})},[Y,C,e,W,X]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(Oe,{label:c,value:q,trend:J,icon:f,className:p,description:m,loading:I,error:R,colorVariant:g,format:ne,currency:ie,prefix:y,suffix:b,variant:D,onClick:Y?()=>j(!0):void 0}),A&&se]})};function Me(){return(0,r.useSafeTranslate)()(`dashboard.total`,`Total`)}function Ne(){return(0,r.useSafeTranslate)()(`dashboard.noDataAvailable`,`No data available`)}function Pe(e,t){if(!t)return String(e);let n=``,r=!1,i,a=t,o=a.match(/^([^0-9.,#]*)/);if(o&&o[1]){let e=o[1];n=e.replace(`,`,``),e.includes(`,`)&&(r=!0),a=a.slice(o[1].length)}a.includes(`,`)&&(r=!0,a=a.replace(/,/g,``));let s=a.match(/\.(\d+)f?/);s&&(i=Number(s[1]),a=a.slice(s[0].length));let c=a.replace(/[0-9#.f]/g,``),l=i===void 0?String(e):e.toFixed(i);if(r){let[e,t]=l.split(`.`),r=e.replace(/\B(?=(\d{3})+(?!\d))/g,`,`);return n+(t===void 0?r:`${r}.${t}`)+c}return n+l+c}var Fe=`—`;function Ie(e,t){return e===``?Fe:t?.[e]??e}var Le=new Set([`sum`,`count`,`avg`,`min`,`max`]);function Re(e,t){if(e.length===0)return 0;switch(t){case`sum`:return e.reduce((e,t)=>e+t,0);case`count`:return e.length;case`avg`:return e.reduce((e,t)=>e+t,0)/e.length;case`min`:return Math.min(...e);case`max`:return Math.max(...e);default:return NaN}}var ze=({schema:e,className:n,rowLabels:r,columnLabels:o,rowFieldLabel:s,onDrillDown:c})=>{let{title:l,rowField:u,columnField:f,valueField:p,aggregation:m=`sum`,data:h=[],showRowTotals:g=!1,showColumnTotals:_=!1,format:v,columnColors:y,drillDown:b}=e,x=Me(),S=Ne(),C=(0,t.isDrillEnabled)(b)&&typeof c==`function`,w=e=>{C&&c({...e,rowLabel:e.rowKey===void 0?e.rowLabel:r?.[e.rowKey]??e.rowKey,colLabel:e.colKey===void 0?e.colLabel:o?.[e.colKey]??e.colKey})},T=e=>t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},E=C?`cursor-pointer hover:bg-accent/40 focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring focus-visible:outline-offset-[-2px]`:``,D=Array.isArray(h)?h:[],{rowKeys:O,colKeys:k,matrix:A,rowTotals:j,colTotals:M,grandTotal:N}=(0,a.useMemo)(()=>{let e=new Map,t=new Map,n={};for(let r of D){let i=String(r[u]??``),a=String(r[f]??``),o=Number(r[p])||0;e.set(i,!0),t.set(a,!0),n[i]||(n[i]={}),n[i][a]||(n[i][a]=[]),n[i][a].push(o)}let r=Array.from(e.keys()),i=Array.from(t.keys()),a={},o={},s={};for(let e of r){a[e]={};let t=[];for(let r of i){let i=n[e]?.[r]??[],o=Re(i,m);a[e][r]=o,t.push(...i),!s[r]&&s[r]}o[e]=Re(t,m)}for(let e of i){let t=[];for(let i of r){let r=n[i]?.[e]??[];t.push(...r)}s[e]=Re(t,m)}let c=[];for(let e of D)c.push(Number(e[p])||0);return{rowKeys:r,colKeys:i,matrix:a,rowTotals:o,colTotals:s,grandTotal:Re(c,m)}},[D,u,f,p,m]),P=e=>Pe(e,v);return Le.has(m)?D.length===0?(0,d.jsxs)(`div`,{className:(0,i.cn)(`overflow-auto`,n),children:[l&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold mb-2`,children:l}),(0,d.jsx)(i.DataEmptyState,{"data-testid":`pivot-empty-state`,className:`py-8 gap-2 [&>h3]:hidden`,icon:(0,d.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,className:`h-8 w-8 opacity-40`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,d.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`7`}),(0,d.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`7`}),(0,d.jsx)(`rect`,{x:`3`,y:`14`,width:`7`,height:`7`}),(0,d.jsx)(`rect`,{x:`14`,y:`14`,width:`7`,height:`7`})]}),iconWrapperClassName:``,title:``,description:S})]}):(0,d.jsxs)(`div`,{className:(0,i.cn)(`overflow-auto`,n),children:[l&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold mb-2`,children:l}),(0,d.jsxs)(`table`,{className:`w-full text-sm border-collapse table-auto`,role:`table`,children:[(0,d.jsx)(`thead`,{children:(0,d.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,d.jsx)(`th`,{className:`text-left p-2 font-medium text-muted-foreground whitespace-nowrap`,children:s||u}),k.map(e=>{let t=()=>w({scope:`column`,colKey:e});return(0,d.jsx)(`th`,{className:(0,i.cn)(`text-right p-2 font-medium whitespace-nowrap`,e===``&&`italic text-muted-foreground/70`,y?.[e]??`text-muted-foreground`,E),title:e===``?`${f}: (empty)`:`${f}: ${e}`,role:C?`button`:void 0,tabIndex:C?0:void 0,onClick:C?t:void 0,onKeyDown:C?T(t):void 0,"aria-label":C?`Drill into ${f}: ${e||`(empty)`}`:void 0,children:Ie(e,o)},e)}),g&&(0,d.jsx)(`th`,{className:`text-right p-2 font-semibold text-muted-foreground bg-muted/20 whitespace-nowrap`,children:x})]})}),(0,d.jsx)(`tbody`,{children:O.map(e=>(0,d.jsxs)(`tr`,{className:`border-b border-border/50 hover:bg-muted/30`,children:[(0,d.jsx)(`td`,{className:(0,i.cn)(`p-2 font-medium whitespace-nowrap`,e===``&&`italic text-muted-foreground/70`,E),role:C?`button`:void 0,tabIndex:C?0:void 0,onClick:C?()=>w({scope:`row`,rowKey:e}):void 0,onKeyDown:C?T(()=>w({scope:`row`,rowKey:e})):void 0,"aria-label":C?`Drill into ${u}: ${e||`(empty)`}`:void 0,children:Ie(e,r)}),k.map(t=>{let n=A[e]?.[t]??0,r=()=>w({scope:`cell`,rowKey:e,colKey:t,value:n});return(0,d.jsx)(`td`,{className:(0,i.cn)(`text-right p-2 tabular-nums`,y?.[t],E),role:C?`button`:void 0,tabIndex:C?0:void 0,onClick:C?r:void 0,onKeyDown:C?T(r):void 0,"aria-label":C?`Drill into ${u}=${e||`(empty)`}, ${f}=${t||`(empty)`}`:void 0,children:P(n)},t)}),g&&(0,d.jsx)(`td`,{className:(0,i.cn)(`text-right p-2 font-semibold tabular-nums bg-muted/20`,E),role:C?`button`:void 0,tabIndex:C?0:void 0,onClick:C?()=>w({scope:`row`,rowKey:e,value:j[e]??0}):void 0,onKeyDown:C?T(()=>w({scope:`row`,rowKey:e,value:j[e]??0})):void 0,children:P(j[e]??0)})]},e))}),_&&(0,d.jsx)(`tfoot`,{children:(0,d.jsxs)(`tr`,{className:`border-t-2 border-border font-semibold bg-muted/40`,children:[(0,d.jsx)(`td`,{className:`p-2`,children:x}),k.map(e=>(0,d.jsx)(`td`,{className:(0,i.cn)(`text-right p-2 tabular-nums`,E),role:C?`button`:void 0,tabIndex:C?0:void 0,onClick:C?()=>w({scope:`column`,colKey:e,value:M[e]??0}):void 0,onKeyDown:C?T(()=>w({scope:`column`,colKey:e,value:M[e]??0})):void 0,children:P(M[e]??0)},e)),g&&(0,d.jsx)(`td`,{className:(0,i.cn)(`text-right p-2 tabular-nums font-bold`,E),role:C?`button`:void 0,tabIndex:C?0:void 0,onClick:C?()=>w({scope:`total`,value:N}):void 0,onKeyDown:C?T(()=>w({scope:`total`,value:N})):void 0,children:P(N)})]})})]})]}):(0,d.jsxs)(`div`,{className:(0,i.cn)(`overflow-auto`,n),"data-testid":`pivot-unsupported-aggregation`,children:[l&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold mb-2`,children:l}),(0,d.jsx)(`div`,{role:`alert`,className:`flex flex-col items-center justify-center py-8 text-destructive`,children:(0,d.jsxs)(`p`,{className:`text-xs`,children:[`Unsupported aggregation “`,String(m),`” — this pivot table renders`,` `,[...Le].join(`, `),`.`]})})]})},Be=({schema:e,dataSource:o,className:s})=>{let c=(0,a.useContext)(n.SchemaRendererContext),l=o||c?.dataSource,u=(0,n.useDataScope)(e.bind),[f,p]=(0,a.useState)([]),[m,h]=(0,a.useState)(!1),[g,_]=(0,a.useState)(null),[v,y]=(0,a.useState)({}),[b,x]=(0,a.useState)({}),[S,C]=(0,a.useState)(null),{fieldLabel:w,fieldOptionLabel:T}=(0,r.useSafeFieldLabel)(),E=(0,a.useRef)(w),D=(0,a.useRef)(T);(0,a.useEffect)(()=>{E.current=w,D.current=T},[w,T]),(0,a.useEffect)(()=>{if(!l||!e.objectName)return;let t=l.getObjectSchema;if(typeof t!=`function`)return;let n=!0;return Promise.resolve(t.call(l,e.objectName)).then(t=>{if(!n||!t?.fields)return;let r=e.objectName,i={},a={};for(let[e,n]of Object.entries(t.fields)){let t=n?.label?String(n.label):e;a[e]=E.current(r,e,t);let o=n?.options;if(Array.isArray(o)&&o.length>0){let t={};for(let n of o)if(n&&n.value!==void 0&&n.label!==void 0){let i=String(n.value),a=String(n.label);t[i]=D.current(r,e,i,a)}Object.keys(t).length>0&&(i[e]=t)}}y(i),x(a)}).catch(()=>{}),()=>{n=!1}},[l,e.objectName]);let O=(0,n.useFilterScope)();(0,a.useEffect)(()=>{let n=!0;return e.objectName&&!u&&(!e.data||e.data.length===0)&&(async()=>{if(!(!l||!e.objectName)){n&&(h(!0),_(null));try{let r;if(typeof l.find==`function`){let n=await l.find(e.objectName,{$filter:(0,t.resolveFilterPlaceholders)(e.filter,O)});r=(0,t.extractRecords)(n)}else return;n&&p(r)}catch(e){console.error(`[ObjectPivotTable] Fetch error:`,e),n&&_(e instanceof Error?e.message:`Failed to load data`)}finally{n&&h(!1)}}})(),()=>{n=!1}},[e.objectName,l,u,e.data,e.filter,O]);let k=u||e.data||f,A=Array.isArray(k)?k:[];if(m&&A.length===0)return(0,d.jsxs)(`div`,{className:(0,i.cn)(`overflow-auto`,s),"data-testid":`pivot-loading`,children:[e.title&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold mb-2`,children:e.title}),(0,d.jsxs)(`div`,{className:`space-y-2 p-2`,children:[(0,d.jsxs)(`div`,{className:`flex gap-2`,children:[(0,d.jsx)(i.Skeleton,{className:`h-6 w-24`}),(0,d.jsx)(i.Skeleton,{className:`h-6 w-20`}),(0,d.jsx)(i.Skeleton,{className:`h-6 w-20`}),(0,d.jsx)(i.Skeleton,{className:`h-6 w-20`})]}),[1,2,3].map(e=>(0,d.jsxs)(`div`,{className:`flex gap-2`,children:[(0,d.jsx)(i.Skeleton,{className:`h-5 w-24`}),(0,d.jsx)(i.Skeleton,{className:`h-5 w-20`}),(0,d.jsx)(i.Skeleton,{className:`h-5 w-20`}),(0,d.jsx)(i.Skeleton,{className:`h-5 w-20`})]},e))]})]});if(g)return(0,d.jsxs)(`div`,{className:(0,i.cn)(`overflow-auto`,s),"data-testid":`pivot-error`,children:[e.title&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold mb-2`,children:e.title}),(0,d.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-destructive`,"data-testid":`pivot-error-message`,children:[(0,d.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,d.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,d.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,d.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]}),(0,d.jsx)(`p`,{className:`text-xs`,children:g})]})]});if(!l&&e.objectName&&A.length===0)return(0,d.jsxs)(`div`,{className:(0,i.cn)(`overflow-auto`,s),children:[e.title&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold mb-2`,children:e.title}),(0,d.jsx)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:(0,d.jsxs)(`p`,{className:`text-xs`,children:[`No data source available for “`,e.objectName,`”`]})})]});let j={...e,data:A},M=e.rowField?v[e.rowField]:void 0,N=e.columnField?v[e.columnField]:void 0,P=e.rowField?b[e.rowField]:void 0,F=e.drillDown,I=(0,t.isDrillEnabled)(F)?e=>C(e):void 0;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(ze,{schema:j,className:s,rowLabels:M,columnLabels:N,rowFieldLabel:P,onDrillDown:I}),(()=>{if(!S||!e.objectName)return null;let n=(0,t.computeDrillFilter)(F,S,{rowField:e.rowField,columnField:e.columnField}),r={...e.filter||{},...n},i=(0,t.resolveDrillTitle)(F,S,e.title||`Details`);return(0,d.jsx)(ne,{open:!0,onClose:()=>C(null),title:i,target:F?.target??`drawer`,objectName:e.objectName,filter:r,dataSource:l,columns:F?.columns,maxRows:F?.maxRows,report:F?.report})})()]})},Ve={breadcrumb:[`Dashboard`,`Configuration`],sections:[{key:`layout`,title:`Layout`,collapsible:!0,fields:[{key:`columns`,label:`Columns`,type:`slider`,defaultValue:3,min:1,max:12,step:1},{key:`gap`,label:`Gap`,type:`slider`,defaultValue:4,min:0,max:16,step:1},{key:`rowHeight`,label:`Row height (px)`,type:`slider`,defaultValue:120,min:40,max:320,step:10}]},{key:`data`,title:`Data`,collapsible:!0,fields:[{key:`refreshInterval`,label:`Auto refresh`,type:`select`,defaultValue:`0`,options:[{value:`0`,label:`Off`},{value:`30`,label:`Every 30s`},{value:`60`,label:`Every 1 min`},{value:`300`,label:`Every 5 min`},{value:`900`,label:`Every 15 min`},{value:`1800`,label:`Every 30 min`},{value:`3600`,label:`Every 1 hour`}]}]},{key:`appearance`,title:`Appearance`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`title`,label:`Title`,type:`input`,placeholder:`Dashboard title`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Short summary shown under the title`},{key:`showDescription`,label:`Show description`,type:`switch`,defaultValue:!0},{key:`theme`,label:`Theme`,type:`select`,defaultValue:`auto`,options:[{value:`light`,label:`Light`},{value:`dark`,label:`Dark`},{value:`auto`,label:`Auto`}]}]}]};function He({open:e,onClose:t,config:n,onSave:r,onFieldChange:a}){let{draft:o,isDirty:s,updateField:c,discard:l}=(0,i.useConfigDraft)(n,{onUpdate:a});return(0,d.jsx)(i.ConfigPanelRenderer,{open:e,onClose:t,schema:Ve,draft:o,isDirty:s,onFieldChange:c,onSave:()=>r(o),onDiscard:l})}var Ue=[{value:`metric`,label:`Metric`},{value:`bar`,label:`Bar Chart`},{value:`horizontal-bar`,label:`Horizontal Bar`},{value:`line`,label:`Line Chart`},{value:`pie`,label:`Pie Chart`},{value:`donut`,label:`Donut Chart`},{value:`area`,label:`Area Chart`},{value:`scatter`,label:`Scatter Plot`},{value:`funnel`,label:`Funnel`},{value:`table`,label:`Table`},{value:`pivot`,label:`Pivot Table`}],We=[{value:`default`,label:`Default`},{value:`blue`,label:`Blue`},{value:`teal`,label:`Teal`},{value:`orange`,label:`Orange`},{value:`purple`,label:`Purple`},{value:`success`,label:`Success`},{value:`warning`,label:`Warning`},{value:`danger`,label:`Danger`}],Ge=[`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`scatter`,`funnel`],Ke=[`metric`,`gauge`,`solid-gauge`,`kpi`,`bullet`];function qe(e){return!!e&&Ge.includes(e)}function Je(e){return!!e&&!Ke.includes(e)}function Ye({names:e,options:t,placeholder:n,emptyText:r,onChange:s}){let[c,l]=a.useState(``),u=a.useMemo(()=>new Set(e),[e]),f=a.useMemo(()=>t.filter(e=>!u.has(e.value)),[t,u]),p=t=>{let n=t.trim();!n||u.has(n)||(s([...e,n]),l(``))},m=t=>s(e.filter(e=>e!==t));return(0,d.jsxs)(`div`,{className:`space-y-1.5`,children:[e.length===0?(0,d.jsx)(`p`,{className:`rounded border border-dashed px-2 py-1.5 text-center text-[11px] text-muted-foreground`,children:r}):(0,d.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>(0,d.jsxs)(`span`,{"data-testid":`dataset-name-chip-${e}`,className:(0,i.cn)(`inline-flex items-center gap-1 rounded bg-muted px-1.5 py-0.5`,`font-mono text-[11px] text-foreground`),children:[e,(0,d.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e}`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>m(e),children:(0,d.jsx)(o.X,{className:`h-3 w-3`})})]},e))}),f.length>0?(0,d.jsx)(i.Combobox,{options:f,value:``,onValueChange:p,placeholder:n,searchPlaceholder:`Search…`,emptyText:`Nothing left to add.`,className:`h-7 w-full text-xs`}):(0,d.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,d.jsx)(i.Input,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),p(c))},placeholder:n,className:`h-7 flex-1 text-xs`}),(0,d.jsx)(i.Button,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 px-2 text-xs`,onClick:()=>p(c),disabled:!c.trim(),children:`Add`})]})]})}function Xe(e,t){let n=e??[],r=n.length>0,a=n.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),o=e=>typeof e==`string`?n.find(t=>t.name===e):void 0,s=r?{key:`dataset`,label:`Dataset`,type:`custom`,helpText:`The semantic-layer dataset this widget binds to (ADR-0021).`,render:(e,t)=>(0,d.jsx)(i.ConfigRow,{label:`Dataset`,children:(0,d.jsx)(`div`,{"data-testid":`config-field-dataset`,children:(0,d.jsx)(i.Combobox,{options:a,value:e??``,onValueChange:t,placeholder:`Select dataset…`,searchPlaceholder:`Search datasets…`,emptyText:`No datasets found.`,className:`h-7 w-40 text-xs`})})})}:{key:`dataset`,label:`Dataset`,type:`input`,placeholder:`Dataset name`,helpText:`The semantic-layer dataset this widget binds to (ADR-0021).`},c={key:`dimensions`,label:`Dimensions`,type:`custom`,visibleWhen:e=>Je(e.type),helpText:t===`pivot`?`Group/split fields. The last dimension spreads across as columns.`:`Group/split the values by these dataset dimensions.`,render:(e,t,n)=>{let r=(o(n.dataset)?.dimensions??[]).map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));return(0,d.jsx)(i.ConfigRow,{label:`Dimensions`,children:(0,d.jsx)(`div`,{"data-testid":`config-field-dimensions`,className:`w-40`,children:(0,d.jsx)(Ye,{names:Array.isArray(e)?e:[],options:r,placeholder:`Add dimension…`,emptyText:`No dimensions selected.`,onChange:t})})})}};return{breadcrumb:[`Dashboard`,{pivot:`Pivot table`,table:`Table`}[t??``]??(qe(t)?`Chart`:`Widget`)],sections:[{key:`general`,title:`General`,fields:[{key:`title`,label:`Title`,type:`input`,placeholder:`Widget title`},{key:`description`,label:`Description`,type:`input`,placeholder:`Widget description`},{key:`type`,label:`Widget type`,type:`select`,options:Ue,defaultValue:`metric`}]},{key:`data`,title:`Data Binding`,collapsible:!0,fields:[s,c,{key:`values`,label:`Values`,type:`custom`,helpText:`Measure(s) from the dataset to display (at least one).`,render:(e,t,n)=>{let r=(o(n.dataset)?.measures??[]).map(e=>({value:e.name,label:e.aggregate?`${e.label??e.name} · ${e.aggregate}`:e.label??e.name}));return(0,d.jsx)(i.ConfigRow,{label:`Values`,children:(0,d.jsx)(`div`,{"data-testid":`config-field-values`,className:`w-40`,children:(0,d.jsx)(Ye,{names:Array.isArray(e)?e:[],options:r,placeholder:`Add measure…`,emptyText:`No measures selected.`,onChange:t})})})}}]},{key:`layout`,title:`Layout`,collapsible:!0,fields:[{key:`layoutW`,label:`Width (columns)`,type:`slider`,min:1,max:12,step:1,defaultValue:1},{key:`layoutH`,label:`Height (rows)`,type:`slider`,min:1,max:6,step:1,defaultValue:1}]},{key:`behavior`,title:`Behavior`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`actionUrl`,label:`Click-through URL`,type:`input`,placeholder:`https://...`}]},{key:`appearance`,title:`Appearance`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`colorVariant`,label:`Color variant`,type:`select`,options:We,defaultValue:`default`}]}]}}function Ze(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`object`){let t=e;return t.defaultValue||t.key||``}return String(e)}var Qe=[`object`,`categoryField`,`categoryGranularity`,`valueField`,`aggregate`,`aggregation`,`rowField`,`columnField`,`xAxisField`,`yAxisFields`,`xAxisLabel`,`yAxisLabel`,`measures`,`rowSortBy`,`rowSortOrder`,`columnSortBy`,`columnSortOrder`,`showRowLabels`,`showRowTotals`,`showColumnLabels`,`showColumnTotals`,`format`,`showLegend`,`searchable`,`pagination`];function $e(e){let t=e.type,n={...e};for(let e of Qe)delete n[e];return Je(t)||delete n.dimensions,n}function et({open:e,onClose:t,config:n,onSave:r,onFieldChange:o,headerExtra:s,datasets:c,datasetsLoading:l}){let u=a.useMemo(()=>({...n,title:typeof n.title==`object`?Ze(n.title):n.title,description:typeof n.description==`object`?Ze(n.description):n.description}),[n]),{draft:f,isDirty:p,updateField:m,discard:h}=(0,i.useConfigDraft)(u,{onUpdate:o}),g=a.useMemo(()=>Xe(c,f.type),[c,f.type]);return(0,d.jsx)(i.ConfigPanelRenderer,{open:e,onClose:t,schema:g,draft:f,isDirty:p,onFieldChange:m,onSave:()=>r($e(f)),onDiscard:h,headerExtra:s})}function tt({schema:e,config:t,onConfigSave:n,onWidgetSave:r,onRefresh:s,recordCount:c,defaultConfigOpen:l=!1,className:u,datasets:f,datasetsLoading:p}){let[m,h]=(0,a.useState)(l),[g,_]=(0,a.useState)(null),[v,y]=(0,a.useState)(e),[b,x]=(0,a.useState)(0);(0,a.useEffect)(()=>{y(e),x(e=>e+1)},[e]);let S=a.useMemo(()=>{if(!g||!v.widgets)return null;let e=v.widgets.find(e=>(e.id||e.title)===g);if(!e)return null;let t=e;return{id:e.id??``,title:e.title??``,description:e.description??``,type:e.type??``,dataset:typeof t.dataset==`string`?t.dataset:``,dimensions:Array.isArray(t.dimensions)?t.dimensions:[],values:Array.isArray(t.values)?t.values:[],colorVariant:e.colorVariant??`default`,actionUrl:e.actionUrl??``,layoutW:e.layout?.w??1,layoutH:e.layout?.h??1}},[g,b]),C=(0,a.useCallback)(e=>{_(e),h(!0)},[]),w=(0,a.useCallback)(()=>{_(null)},[]),T=(0,a.useCallback)((e,t)=>{g&&y(n=>n.widgets?{...n,widgets:n.widgets.map(n=>(n.id||n.title)===g?e===`layoutW`?{...n,layout:{...n.layout||{},w:t}}:e===`layoutH`?{...n,layout:{...n.layout||{},h:t}}:{...n,[e]:t}:n)}:n)},[g]),E=(0,a.useCallback)(e=>{g&&r&&r(g,e),_(null),x(e=>e+1)},[g,r]),D=(0,a.useCallback)(()=>{h(e=>!e),_(null)},[]);return(0,d.jsxs)(`div`,{className:(0,i.cn)(`flex h-full w-full`,u),"data-testid":`dashboard-with-config`,children:[(0,d.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-auto relative`,children:[(0,d.jsx)(`div`,{className:`absolute top-2 right-2 z-10`,children:(0,d.jsxs)(i.Button,{size:`sm`,variant:m?`default`:`outline`,onClick:D,"data-testid":`dashboard-config-toggle`,children:[(0,d.jsx)(o.Settings,{className:`h-3.5 w-3.5 mr-1`}),`Settings`]})}),(0,d.jsx)(ge,{schema:v,onRefresh:s,recordCount:c,designMode:m,selectedWidgetId:g,onWidgetClick:C})]}),m&&(0,d.jsx)(`div`,{className:`relative shrink-0`,children:g&&S?(0,d.jsx)(et,{open:!0,onClose:w,config:S,onSave:E,onFieldChange:T,datasets:f,datasetsLoading:p}):(0,d.jsx)(He,{open:!0,onClose:()=>h(!1),config:t,onSave:n})})]})}t.ComponentRegistry.register(`dashboard`,ge,{namespace:`view`,label:`Dashboard`,category:`Complex`,icon:`layout-dashboard`,inputs:[{name:`columns`,type:`number`,label:`Columns`,defaultValue:3},{name:`gap`,type:`number`,label:`Gap`,defaultValue:4},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{columns:3,widgets:[]}}),t.ComponentRegistry.register(`metric`,Oe,{namespace:`plugin-dashboard`,label:`Metric Widget`,category:`Dashboard`,inputs:[{name:`label`,type:`string`,label:`Label`},{name:`value`,type:`string`,label:`Value`}]}),t.ComponentRegistry.register(`metric-card`,Ae,{namespace:`plugin-dashboard`,label:`Metric Card`,category:`Dashboard`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`value`,type:`string`,label:`Value`,required:!0},{name:`icon`,type:`string`,label:`Icon (Lucide name)`},{name:`trend`,type:`enum`,label:`Trend`,enum:[{label:`Up`,value:`up`},{label:`Down`,value:`down`},{label:`Neutral`,value:`neutral`}]},{name:`trendValue`,type:`string`,label:`Trend Value (e.g., +12%)`},{name:`description`,type:`string`,label:`Description`}],defaultProps:{title:`Metric`,value:`0`}}),t.ComponentRegistry.register(`object-metric`,je,{namespace:`plugin-dashboard`,label:`Object Metric`,category:`Dashboard`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`label`,type:`string`,label:`Label`},{name:`aggregate`,type:`object`,label:`Aggregate`,description:`Aggregation config: { field, function, groupBy }`},{name:`icon`,type:`string`,label:`Icon (Lucide name)`}],defaultProps:{label:`Metric`}}),t.ComponentRegistry.register(`pivot`,ze,{namespace:`plugin-dashboard`,label:`Pivot Table`,category:`Dashboard`,icon:`table-2`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`rowField`,type:`string`,label:`Row Field`,required:!0},{name:`columnField`,type:`string`,label:`Column Field`,required:!0},{name:`valueField`,type:`string`,label:`Value Field`,required:!0},{name:`aggregation`,type:`enum`,label:`Aggregation`,enum:[{label:`Sum`,value:`sum`},{label:`Count`,value:`count`},{label:`Average`,value:`avg`},{label:`Min`,value:`min`},{label:`Max`,value:`max`}]},{name:`showRowTotals`,type:`boolean`,label:`Show Row Totals`},{name:`showColumnTotals`,type:`boolean`,label:`Show Column Totals`},{name:`format`,type:`string`,label:`Number Format`}],defaultProps:{rowField:``,columnField:``,valueField:``,aggregation:`sum`,data:[]}}),t.ComponentRegistry.register(`object-pivot`,Be,{namespace:`plugin-dashboard`,label:`Object Pivot Table`,category:`Dashboard`,icon:`table-2`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`title`,type:`string`,label:`Title`},{name:`rowField`,type:`string`,label:`Row Field`,required:!0},{name:`columnField`,type:`string`,label:`Column Field`,required:!0},{name:`valueField`,type:`string`,label:`Value Field`,required:!0},{name:`aggregation`,type:`enum`,label:`Aggregation`,enum:[{label:`Sum`,value:`sum`},{label:`Count`,value:`count`},{label:`Average`,value:`avg`},{label:`Min`,value:`min`},{label:`Max`,value:`max`}]},{name:`showRowTotals`,type:`boolean`,label:`Show Row Totals`},{name:`showColumnTotals`,type:`boolean`,label:`Show Column Totals`},{name:`filter`,type:`array`,label:`Filter`},{name:`format`,type:`string`,label:`Number Format`}],defaultProps:{rowField:``,columnField:``,valueField:``,aggregation:`sum`}}),t.ComponentRegistry.register(`dashboard-grid`,xe,{namespace:`plugin-dashboard`,label:`Dashboard Grid (Editable)`,category:`Complex`,icon:`layout-grid`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{title:`Dashboard`,widgets:[]}}),t.ComponentRegistry.register(`object-data-table`,B,{namespace:`plugin-dashboard`,label:`Object Data Table`,category:`Dashboard`,icon:`table`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`columns`,type:`array`,label:`Columns`},{name:`filter`,type:`array`,label:`Filter`},{name:`searchable`,type:`boolean`,label:`Searchable`},{name:`pagination`,type:`boolean`,label:`Pagination`}],defaultProps:{searchable:!1,pagination:!1}});var nt={DashboardRenderer:ge,DashboardGridLayout:xe,MetricWidget:Oe,MetricCard:Ae,ObjectMetricWidget:je,PivotTable:ze,ObjectPivotTable:Be,ObjectDataTable:B,DashboardConfigPanel:He,WidgetConfigPanel:et,DashboardWithConfig:tt};e.DashboardConfigPanel=He,e.DashboardGridLayout=xe,e.DashboardRenderer=ge,e.DashboardWithConfig=tt,e.DrillDownDrawer=ne,e.MetricCard=Ae,e.MetricWidget=Oe,e.ObjectDataTable=B,e.ObjectMetricWidget=je,e.ObjectPivotTable=Be,e.PivotTable=ze,e.WidgetConfigPanel=et,e.dashboardComponents=nt});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("@object-ui/core"),require("@object-ui/react"),require("@object-ui/i18n"),require("@object-ui/components"),require("lucide-react"),require("@dnd-kit/core"),require("@dnd-kit/sortable"),require("@dnd-kit/utilities"),require("@object-ui/fields"),require("react/jsx-runtime"),require("react-grid-layout"),require("react-grid-layout/css/styles.css")):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/i18n`,`@object-ui/components`,`lucide-react`,`@dnd-kit/core`,`@dnd-kit/sortable`,`@dnd-kit/utilities`,`@object-ui/fields`,`react/jsx-runtime`,`react-grid-layout`,`react-grid-layout/css/styles.css`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginDashboard={},e.React,e.ObjectUICore,e.ObjectUIReact,e.ObjectUII18n,e.ObjectUIComponents,e.lucide_react,e._dnd_kit_core,e._dnd_kit_sortable,e._dnd_kit_utilities,e.ObjectUIFields,e.react_jsx_runtime,e.ReactGridLayout,e.react_grid_layout_css_styles_css))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var m=Object.create,h=Object.defineProperty,g=Object.getOwnPropertyDescriptor,_=Object.getOwnPropertyNames,v=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty,b=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=_(t),a=0,o=i.length,s;a<o;a++)s=i[a],!y.call(e,s)&&s!==n&&h(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=g(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:m(v(e)),b(t||!e||!e.__esModule||!y.call(e,`default`)?h(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);function x(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&e.provider===`object`}function S(e){return e.replace(/_/g,` `).replace(/([A-Z])/g,` $1`).trim().replace(/\b\w/g,e=>e.toUpperCase())}function C(e){if(!Array.isArray(e)||e.length===0)return[];let t=e[0];return typeof t!=`object`||!t||Array.isArray(t)?[]:Object.keys(t).filter(e=>!e.startsWith(`_`)).map(e=>({header:S(e),accessorKey:e}))}function w(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 T={column:`bar`,"stacked-bar":`bar`,"grouped-bar":`bar`,"bi-polar-bar":`bar`,spline:`line`,"step-line":`line`,"stacked-area":`area`,pyramid:`funnel`,bubble:`scatter`},E=new Set([`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`scatter`,`funnel`,`radar`,`treemap`,`sankey`,`combo`]),D=new Set([`metric`,`gauge`,`solid-gauge`,`kpi`,`bullet`]),O=new Set([`table`,`list`]),k=new Set([`sunburst`,`word-cloud`,`choropleth`,`bubble-map`,`gl-map`,`heatmap`,`waterfall`,`box-plot`,`violin`,`candlestick`,`stock`]);function A(e){if(!e)return{family:`passthrough`};let t=T[e]??e;return E.has(t)?{family:`series`,chartType:t}:D.has(e)?{family:`metric`}:O.has(e)?{family:`table`}:e===`pivot`?{family:`pivot`}:e===`custom`?{family:`custom`}:k.has(e)?{family:`unsupported`}:{family:`passthrough`}}var j={type:`text`,value:`This widget uses a retired data format. Edit it to bind a dataset.`,variant:`caption`,align:`center`,className:`flex h-full w-full items-center justify-center rounded border border-dashed border-destructive/40 bg-destructive/5 p-4 text-center text-destructive`};function M(e){if(!e)return!1;let t=e;return!t.dataset&&!(t.data||t.options?.data)&&!!t.object}var N={default:`bg-muted text-muted-foreground`,blue:`bg-blue-500/10 text-blue-600 dark:text-blue-400`,teal:`bg-teal-500/10 text-teal-600 dark:text-teal-400`,orange:`bg-orange-500/10 text-orange-600 dark:text-orange-400`,purple:`bg-purple-500/10 text-purple-600 dark:text-purple-400`,success:`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`,warning:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,danger:`bg-rose-500/10 text-rose-600 dark:text-rose-400`},P={default:`text-foreground`,blue:`text-blue-600 dark:text-blue-400`,teal:`text-teal-600 dark:text-teal-400`,orange:`text-orange-600 dark:text-orange-400`,purple:`text-purple-600 dark:text-purple-400`,success:`text-emerald-600 dark:text-emerald-400`,warning:`text-amber-600 dark:text-amber-400`,danger:`text-rose-600 dark:text-rose-400`};function F(e){if(typeof e==`string`&&e!=="default")return P[e]}var I=new Set([`id`,`organization_id`,`tenant_id`,`created_at`,`updated_at`,`created_by`,`updated_by`,`deleted_at`,`deleted_by`,`version`,`_id`,`__typename`]);function L(e,t){return t&&(t.isSystem===!0||t.system===!0)?!0:I.has(e)}var R=new Set([`select`,`picklist`,`dropdown`,`status`]),z=new Set([`currency`,`money`,`number`,`integer`,`decimal`,`float`,`percent`,`percentage`]);function B(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 ee(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&&R.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?.scale}}function V(e){return z.has(e.type)||typeof e.format==`string`&&/^[$¥€£]|%$|0/.test(e.format)}function te(e,t,n,r){if(e==null||e===``)return``;let i=t.format;if(typeof i==`string`&&/^\$|¥|€|£/.test(i)&&typeof e==`number`){let r={$:`USD`,"¥":`JPY`,"€":`EUR`,"£":`GBP`}[i[0]];return(0,u.formatCurrency)(e,t.currency||r||n)}if(typeof i==`string`&&/%/.test(i)&&typeof e==`number`){let t=(i.match(/0\.(0+)%/)||[void 0,``])[1].length;return(0,u.formatPercent)(e,t,r)}if(typeof i==`string`&&/[YMDHms]/.test(i))return(0,u.formatDate)(e,i);let a=(0,u.getCellRenderer)((0,u.resolveCellRendererType)(t));return(0,d.jsx)(a,{value:e,field:t})}var ne=[`name`,`title`,`label`,`subject`,`display_name`,`full_name`];function H(e,t){if(t&&t.trim())return t;for(let t of ne){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 re=({record:e,objectName:n,objectSchema:r,fields:o,title:s,target:c=`drawer`,onClose:l})=>{let{fieldLabel:u,fieldOptionLabel:f}=(0,i.useSafeFieldLabel)(),{currency:p}=(0,i.useLocalization)(),m=(0,i.useDisplayLocale)(),h=(0,t.useMemo)(()=>{if(!e)return[];let t=B(r),i;return i=o&&o.length>0?o:Object.keys(t).length>0?Object.keys(t).filter(e=>!L(e,t[e])):Object.keys(e).filter(e=>!e.startsWith(`_`)&&!L(e)),i.map(r=>{let i=t[r],a=r.charAt(0).toUpperCase()+r.slice(1).replace(/([A-Z])/g,` $1`).replace(/_/g,` `),o=n?u(n,r,a):a,s=ee({accessorKey:r,label:o,def:i,objectName:n,fieldOptionLabel:f});return{key:r,label:o,node:te(e[r],s,p,m),numeric:V(s)}})},[e,r,n,o,u,f,p,m]);if(!e)return null;let g=H(e,s),_=(0,d.jsx)(`dl`,{className:`divide-y divide-border/60`,"data-testid":`record-detail-body`,children:h.map(e=>(0,d.jsxs)(`div`,{className:`grid grid-cols-3 gap-3 py-2.5`,children:[(0,d.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground self-center`,children:e.label}),(0,d.jsx)(`dd`,{className:`col-span-2 text-sm break-words ${e.numeric?`tabular-nums`:``}`,children:e.node===``||e.node==null?(0,d.jsx)(`span`,{className:`text-muted-foreground/60`,children:`—`}):e.node})]},e.key))});return c===`dialog`?(0,d.jsx)(a.Dialog,{open:!0,onOpenChange:e=>!e&&l(),children:(0,d.jsxs)(a.DialogContent,{className:`max-w-2xl`,children:[(0,d.jsx)(a.DialogHeader,{children:(0,d.jsx)(a.DialogTitle,{children:g})}),(0,d.jsx)(`div`,{className:`max-h-[70vh] overflow-auto`,children:_})]})}):(0,d.jsx)(a.Sheet,{open:!0,onOpenChange:e=>!e&&l(),children:(0,d.jsxs)(a.SheetContent,{side:`right`,className:`w-full sm:max-w-md md:max-w-lg flex flex-col`,children:[(0,d.jsx)(a.SheetHeader,{children:(0,d.jsx)(a.SheetTitle,{children:g})}),(0,d.jsx)(`div`,{className:`flex-1 overflow-auto mt-2 pr-1`,children:_})]})})},U=Object.freeze([]);function ie(e){return e.map(e=>{if(typeof e==`string`)return{header:S(e),accessorKey:e};if(!e)return e;let t={};if(!e.accessorKey){let r=(0,n.columnIdentity)(e);r&&(t.accessorKey=r)}if(!e.header){let r=(0,n.columnHeader)(e);r&&(t.header=r)}return Object.keys(t).length===0?e:{...e,...t}})}function W(e,t){if(!t?.fields)return[];let r={};if(Array.isArray(t.fields))for(let e of t.fields)e?.name&&(r[e.name]=e);else for(let[e,n]of Object.entries(t.fields))r[e]={name:e,...n};let i=e=>typeof e==`string`&&(0,n.isRetiredFieldType)(e)?((0,n.reportRetiredFieldType)(e),!1):n.EXPANDABLE_FIELD_TYPES.has(e),a=Array.isArray(e.columns)?e.columns:[],o=new Set;if(a.length>0){let e=a.map(e=>typeof e==`string`?e:e?.accessorKey||(0,n.columnIdentity)(e)).filter(Boolean);for(let t of e){let e=r[t];e&&i(e.type)&&o.add(t)}}else for(let[e,t]of Object.entries(r))i(t?.type)&&o.add(e);return Array.from(o)}var G=({schema:e,dataSource:o,className:s})=>{let{currency:c}=(0,i.useLocalization)(),l=(0,i.useDisplayLocale)(),u=(0,t.useContext)(r.SchemaRendererContext),f=o||u?.dataSource,p=(0,r.useDataScope)(e.bind),{fieldLabel:m,fieldOptionLabel:h}=(0,i.useSafeFieldLabel)(),g=`No data available`,_=`No data source available for`,{t:v}=(0,i.useObjectTranslation)(),y=v(`dashboard.noDataAvailable`);y&&y!==`dashboard.noDataAvailable`&&(g=y);let b=v(`dashboard.noDataSourceFor`);b&&b!==`dashboard.noDataSourceFor`&&(_=b);let[x,C]=(0,t.useState)([]),[w,T]=(0,t.useState)(null),[E,D]=(0,t.useState)(()=>!(Array.isArray(e.data)&&e.data.length>0)&&!!e.objectName),[O,k]=(0,t.useState)(null),A=e.drillDown,j=(0,n.isDrillEnabled)(A)&&(A?.mode??`record`)===`record`,[M,N]=(0,t.useState)(null),P=(0,t.useCallback)(e=>{N(e??null)},[]),F=(0,r.useFilterScope)();(0,t.useEffect)(()=>{let t=!0;return e.objectName&&!p&&(!e.data||e.data.length===0)?(async()=>{if(!f||!e.objectName){t&&D(!1);return}t&&(D(!0),k(null));try{let r;if(typeof f.find==`function`){let t=W(e,w),i={$filter:(0,n.resolveFilterPlaceholders)(e.filter,F)};t.length&&(i.$expand=t);let a=await f.find(e.objectName,i);r=(0,n.extractRecords)(a)}else return;t&&C(r)}catch(e){console.error(`[ObjectDataTable] Fetch error:`,e),t&&k(e instanceof Error?e.message:`Failed to load data`)}finally{t&&D(!1)}})():t&&D(!1),()=>{t=!1}},[e.objectName,f,p,e.data,e.filter,w,F]),(0,t.useEffect)(()=>{let t=!0;if(!(!f||!e.objectName||typeof f.getObjectSchema!=`function`))return f.getObjectSchema(e.objectName).then(e=>{t&&T(e)}).catch(()=>{}),()=>{t=!1}},[e.objectName,f]);let I=p||e.data||x,R=Array.isArray(I)?I:U,z=(0,t.useMemo)(()=>{let t=e.objectName,n={};if(w?.fields){let e=w.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 r=e=>{let n=S(e);return t?m(t,e,n):n},i=e=>{let r=ee({accessorKey:e.accessorKey,label:e.header,def:n[e.accessorKey],objectName:t,fieldOptionLabel:h,overrides:{type:e.type,format:e.format,options:e.options,referenceTo:e.referenceTo,currency:e.currency,decimals:e.decimals}}),i=e.align??(V(r)?`right`:void 0);if(typeof e.cell==`function`)return{...e,...r,align:i};let a=e=>te(e,r,c,l);return{...e,...r,align:i,cell:a}};if(e.columns&&e.columns.length>0){let n=ie(e.columns);return(t?n.map(e=>({...e,header:m(t,e.accessorKey,e.header)})):n).map(i)}return R.length===0?[]:(Object.keys(n).length>0?Object.keys(n).filter(e=>!L(e,n[e])):Object.keys(R[0]).filter(e=>!e.startsWith(`_`)&&!L(e))).map(e=>i({header:r(e),accessorKey:e}))},[e.columns,e.objectName,R,w,m,h,c,l]);if(E&&R.length===0)return(0,d.jsx)(`div`,{className:(0,a.cn)(`overflow-auto`,s),"data-testid":`table-loading`,children:(0,d.jsxs)(`div`,{className:`space-y-2 p-2`,children:[(0,d.jsxs)(`div`,{className:`flex gap-2`,children:[(0,d.jsx)(a.Skeleton,{className:`h-6 w-1/4`}),(0,d.jsx)(a.Skeleton,{className:`h-6 w-1/4`}),(0,d.jsx)(a.Skeleton,{className:`h-6 w-1/4`}),(0,d.jsx)(a.Skeleton,{className:`h-6 w-1/4`})]}),[1,2,3,4].map(e=>(0,d.jsxs)(`div`,{className:`flex gap-2`,children:[(0,d.jsx)(a.Skeleton,{className:`h-5 w-1/4`}),(0,d.jsx)(a.Skeleton,{className:`h-5 w-1/4`}),(0,d.jsx)(a.Skeleton,{className:`h-5 w-1/4`}),(0,d.jsx)(a.Skeleton,{className:`h-5 w-1/4`})]},e))]})});if(O)return(0,d.jsx)(`div`,{className:(0,a.cn)(`overflow-auto`,s),"data-testid":`table-error`,children:(0,d.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-destructive`,"data-testid":`table-error-message`,children:[(0,d.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,d.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,d.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,d.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]}),(0,d.jsx)(`p`,{className:`text-xs`,children:O})]})});if(!f&&e.objectName&&R.length===0)return(0,d.jsx)(`div`,{className:(0,a.cn)(`overflow-auto`,s),children:(0,d.jsx)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:(0,d.jsxs)(`p`,{className:`text-xs`,children:[_,` “`,e.objectName,`”`]})})});if(R.length===0)return(0,d.jsx)(`div`,{className:(0,a.cn)(`overflow-auto`,s),"data-testid":`table-empty-state`,children:(0,d.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,d.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,d.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`}),(0,d.jsx)(`line`,{x1:`3`,y1:`9`,x2:`21`,y2:`9`}),(0,d.jsx)(`line`,{x1:`9`,y1:`21`,x2:`9`,y2:`9`})]}),(0,d.jsx)(`p`,{className:`text-xs`,children:g})]})});let B={...e,type:`data-table`,data:R,columns:z,onRowClick:e.onRowClick??(j?P:void 0)},ne=A?.title&&!A.title.includes("${")?A.title:void 0;return(0,d.jsxs)(`div`,{className:(0,a.cn)(`relative`,s),children:[(0,d.jsx)(a.RefreshIndicator,{active:E&&R.length>0}),(0,d.jsx)(r.SchemaRenderer,{schema:B,className:s}),j&&(0,d.jsx)(re,{record:M,objectName:e.objectName,objectSchema:w,fields:A?.columns,title:ne,target:A?.target===`dialog`?`dialog`:`drawer`,onClose:()=>N(null)})]})},K=({objectName:e,filter:t,onNavigate:n,className:s})=>{let{openRecordList:c}=(0,r.useDrillNavigation)(),l=(0,i.useSafeTranslate)();return!c||!e?null:(0,d.jsxs)(a.Button,{type:`button`,variant:`ghost`,size:`sm`,className:s,"data-testid":`drill-open-in-list`,onClick:()=>{c(e,t),n?.()},children:[l(`dashboard.openInList`,`Open in list`),(0,d.jsx)(o.ArrowUpRight,{className:`ml-1 h-3.5 w-3.5`})]})},ae=({open:e,onClose:n,title:i,target:o=`drawer`,objectName:s,filter:c,dataSource:l,columns:u,maxRows:f,className:p,report:m})=>{let{openRecordList:h}=(0,r.useDrillNavigation)(),g=m&&typeof m==`object`&&(Array.isArray(m.columns)||`objectName`in m),_=o===`navigate`&&!!h&&!g&&!!s;if(t.default.useEffect(()=>{e&&_&&(h(s,c),n())},[e,_]),_)return null;let v=g?null:(0,d.jsx)(K,{objectName:s,filter:c,onNavigate:n}),y=(0,d.jsx)(`div`,{className:(0,a.cn)(`overflow-auto`,p),"data-testid":`drill-down-body`,children:g?(()=>{let e=m.filter,t=e?c?{$and:[e,c]}:e:c,n={...m,type:`spec-report`,report:{...m,filter:t},filter:t};return(0,d.jsx)(r.SchemaRenderer,{schema:n})})():(0,d.jsx)(G,{schema:{type:`object-data-table`,objectName:s,filter:c,columns:u?.map(e=>({accessorKey:e,header:e})),pagination:!0,searchable:!1,pageSize:f,drillDown:{enabled:!0,mode:`record`,target:`dialog`}},dataSource:l})});return o===`dialog`?(0,d.jsx)(a.Dialog,{open:e,onOpenChange:e=>!e&&n(),children:(0,d.jsxs)(a.DialogContent,{className:`max-w-5xl`,children:[(0,d.jsxs)(a.DialogHeader,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,d.jsx)(a.DialogTitle,{children:i}),v]}),y]})}):(0,d.jsx)(a.Sheet,{open:e,onOpenChange:e=>!e&&n(),children:(0,d.jsxs)(a.SheetContent,{side:`right`,className:`w-full sm:max-w-2xl md:max-w-3xl lg:max-w-4xl flex flex-col`,children:[(0,d.jsxs)(a.SheetHeader,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,d.jsx)(a.SheetTitle,{children:i}),v]}),(0,d.jsx)(`div`,{className:`flex-1 overflow-hidden mt-2`,children:y})]})})},oe=n.buildDatasetDrillFilter;function se(e,t,r,i){let a=[],o=[],s=new Set,c=new Set,l=new Map;return e.forEach((e,u)=>{let d=(0,n.pivotBucketId)(t.map(t=>(0,n.pivotDimensionValue)(e[t]))),f=(0,n.pivotBucketId)([(0,n.pivotDimensionValue)(e[r])]);s.has(d)||(s.add(d),a.push({id:d,labels:t.map(t=>(0,n.formatDimensionValue)(e[t],i))})),c.has(f)||(c.add(f),o.push({id:f,label:(0,n.formatDimensionValue)(e[r],i)})),l.set((0,n.pivotCellKey)(d,f),u)}),{rowHeaders:a,colHeaders:o,cellIndex:l}}function q(e){if(e==null)return``;let t=String(e);return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}function J(e){return e.map(e=>e.map(q).join(`,`)).join(`\r
2
+ `)}function Y(e,t){if(typeof document>`u`)return;let n=e&&e.trim()?e.trim():`export`,r=new Blob([`\uFEFF${J(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 ce=`__compare`,X=e=>`${e}${ce}`,le={vsLastQuarter:`vs last quarter`,vsLastMonth:`vs last month`,vsLastWeek:`vs last week`,vsLastYear:`vs last year`,vsYesterday:`vs yesterday`,vsPreviousPeriod:`vs previous period`},ue=/^\d{4}-\d{2}-\d{2}(?:[T ][\d:.]+(?:Z|[+-]\d{2}:?\d{2})?)?$/;function de(e){if(!e||typeof e!=`object`||Array.isArray(e))return null;let t=Object.keys(e);if(t.length!==2||!t.includes(`$gte`)||!t.includes(`$lte`))return null;let{$gte:n,$lte:r}=e;return typeof n!=`string`||typeof r!=`string`||!ue.test(n)||!ue.test(r)?null:[n,r]}function fe(e){let t=new Map,n=e=>{if(!e||typeof e!=`object`||Array.isArray(e))return e;let r={},i=null;for(let[a,o]of Object.entries(e)){if(a===`$and`&&Array.isArray(o)){i=o.map(n).filter(e=>!!e&&typeof e==`object`&&!Array.isArray(e)&&Object.keys(e).length>0);continue}if(a.startsWith(`$`)){r[a]=o;continue}let e=de(o);if(!e){r[a]=o;continue}let s=t.get(a);t.set(a,s?[s[0]>e[0]?s[0]:e[0],s[1]<e[1]?s[1]:e[1]]:e)}return i&&i.length>0&&(r.$and=i),r},r=n(e),i=r&&Object.keys(r).length>0?r:void 0,a=i&&Object.keys(i).length===1&&Array.isArray(i.$and)&&i.$and.length===1?i.$and[0]:void 0;return a&&(i=a),{windows:Array.from(t,([e,t])=>({dimension:e,dateRange:t})),rest:i}}var pe=new Set([`metric`,`kpi`,`gauge`,`solid-gauge`,`bullet`]),me={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`,combo:`combo`};function he({widget:e,dataSource:s}){let c=String(e?.dataset??``),l=(0,t.useMemo)(()=>Array.isArray(e?.dimensions)?e.dimensions.filter(Boolean):[],[e]),u=(0,t.useMemo)(()=>Array.isArray(e?.values)?e.values.filter(Boolean):[],[e]),f=e?.compareTo,p=String(e?.type??``),m=pe.has(p)||l.length===0,h=p===`table`||p===`pivot`,g=p===`pivot`&&l.length>=2,_=g?l.slice(0,-1):[],v=g?l[l.length-1]:``,y=e?.options&&typeof e.options==`object`&&!Array.isArray(e.options)?e.options:{},b=typeof y.dateGranularity==`string`?y.dateGranularity:void 0,x=typeof y.sortBy==`string`&&y.sortBy?y.sortBy:void 0,S=x&&(l.includes(x)||u.includes(x))?x:void 0,C=S?{[S]:y.sortOrder===`desc`?`desc`:`asc`}:void 0,T=typeof y.limit==`number`&&Number.isFinite(y.limit)&&y.limit>0?Math.floor(y.limit):void 0,E=h&&!g&&l.length>0&&T==null,D=g?[_,[v],[]]:E?[[]]:void 0,O=(0,i.useSafeTranslate)(),{fieldLabel:k,fieldOptionLabel:A}=(0,i.useSafeFieldLabel)(),j=(0,i.useDisplayLocale)(),M=(0,r.useFilterScope)(),N=e?.filter,P=(0,t.useMemo)(()=>N&&typeof N==`object`&&Object.keys(N).length>0?(0,n.resolveFilterPlaceholders)(N,M):void 0,[N,M]),{windows:I,rest:L}=(0,t.useMemo)(()=>f?fe(P):{windows:[],rest:P},[f,P]),[R,z]=(0,t.useState)({status:`idle`,rows:[]}),[B,ee]=(0,t.useState)(null),[V,te]=(0,t.useState)(null),ne=`${p}|${c}|${l.join(`,`)}|${u.join(`,`)}|${JSON.stringify(N??null)}|${JSON.stringify(f??null)}|${b??``}|${JSON.stringify(C??null)}|${T??``}`;(0,t.useEffect)(()=>{let e=s;if(!e||typeof e.queryDataset!=`function`){z({status:`error`,rows:[],error:O(`dashboard.datasetUnsupported`,`This data source does not support dataset queries.`)});return}if(u.length===0){z({status:`idle`,rows:[]});return}let t=!1;return z({status:`loading`,rows:[]}),e.queryDataset(c,{dimensions:l,measures:u,...L?{runtimeFilter:L}:{},...I.length>0?{timeDimensions:I}:{},...f?{compareTo:f}:{},...D?{totals:{groupings:D}}:{},...b?{dateGranularity:b}:{},...C?{order:C}:{},...T==null?{}:{limit:T}}).then(e=>{t||z({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,drillRanges:Array.isArray(e?.drillRanges)?e.drillRanges:void 0,totals:Array.isArray(e?.totals)?e.totals:void 0})}).catch(e=>{t||z({status:`error`,rows:[],error:String(e?.message??e)})}),()=>{t=!0}},[ne]);let H=(0,r.useDatasetDimensionMeta)(R.object,R.dimensionFields,l,{enabled:!m}),{categoryColors:re,dimensionLabels:U,categoryOrder:ie}=(0,t.useMemo)(()=>{if(!H)return{categoryColors:null,dimensionLabels:null,categoryOrder:null};let{metaByPath:e,relabel:t}=H,r=h?void 0:t[0]?.path,i=r?e[r]:void 0,a=r?(0,n.localizeFieldOptions)(i?.options,(0,n.dimensionOptionTranslator)(i,A)):void 0;return{categoryColors:(0,n.buildOptionColorMap)(a),dimensionLabels:(0,n.deriveDimensionLabelMaps)(e,t,A),categoryOrder:(0,n.buildCategoryOrder)(a)}},[H,A,h]);if(u.length===0)return(0,d.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:O(`dashboard.pickMeasures`,`Pick measures (values) for this dataset widget.`)});if(R.status===`loading`||R.status===`idle`)return(0,d.jsxs)(`div`,{className:`h-full w-full p-2`,"data-testid":`dataset-loading`,role:`status`,"aria-busy":`true`,"aria-live":`polite`,children:[(0,d.jsx)(`span`,{className:`sr-only`,children:O(`dashboard.loading`,`Loading…`)}),m?(0,d.jsxs)(`div`,{className:`flex h-full w-full flex-col items-start justify-center gap-2 p-2`,children:[(0,d.jsx)(a.Skeleton,{className:`h-8 w-32 rounded`}),(0,d.jsx)(a.Skeleton,{className:`h-3 w-20 rounded`})]}):h?(0,d.jsx)(a.GridSkeleton,{className:`h-full`,rows:5,columns:Math.max(2,l.length+u.length)}):(0,d.jsx)(a.ChartSkeleton,{className:`h-full`})]});if(R.status===`error`)return(0,d.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,d.jsx)(o.AlertTriangle,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,d.jsx)(`span`,{className:`break-words`,children:R.error})]});if(R.rows.length===0&&!m)return(0,d.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,d.jsx)(o.BarChart3,{className:`mr-2 h-4 w-4`}),O(`dashboard.noRows`,`No rows`)]});let{measureField:W,headerLabel:G}=(0,n.buildDatasetFieldHelpers)(R.fields,R.object,k),K=f?u.filter(e=>R.rows.some(t=>t[X(e)]!=null)):[],q=f?(0,n.compareToTrendLabelKey)(f,N):``,J=f?O(`dashboard.trend.${q}`,le[q]??`vs previous period`):``,{object:ue,dimensionFields:de,drillRawRows:he,drillRanges:ge}=R,Z=de?l.filter(e=>e in de):[],Q=!!ue&&(Z.length>0||!!ge?.length),_e=(t,n)=>{if(!ue)return;let r=oe(he?.[t],Z,de??{},P,ge?.[t]);ee({filter:r,title:n||String(e?.title??``)})},$=B&&ue?(0,d.jsx)(ae,{open:!0,onClose:()=>ee(null),title:B.title||String(e?.title??O(`dashboard.details`,`Details`)),objectName:ue,filter:B.filter,dataSource:s}):null;if(m){let t=W(u[0]),r=R.rows[0]?.[u[0]]??0,i=R.rows[0]?.[X(u[0])],s=K.includes(u[0])?w(typeof r==`number`?r:null,typeof i==`number`?i:null):null,c=F(e?.colorVariant);return(0,d.jsxs)(`div`,{className:`flex h-full w-full flex-col items-start justify-center gap-1 p-2`,children:[(0,d.jsx)(`span`,{className:(0,a.cn)(`text-2xl font-semibold tabular-nums`,c),children:(0,n.formatMeasure)(r,t?.format,t?.currency,t?.percentScale,j)}),s&&(0,d.jsxs)(`div`,{className:`mt-0.5 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5 text-xs text-muted-foreground`,"data-testid":`dataset-compare-trend`,children:[(0,d.jsxs)(`span`,{className:(0,a.cn)(`flex shrink-0 items-center font-medium`,s.direction===`up`&&`text-emerald-600 dark:text-emerald-400`,s.direction===`down`&&`text-rose-600 dark:text-rose-400`,s.direction===`neutral`&&`text-muted-foreground`),children:[s.direction===`up`&&(0,d.jsx)(o.ArrowUpIcon,{className:`mr-1 h-3 w-3`}),s.direction===`down`&&(0,d.jsx)(o.ArrowDownIcon,{className:`mr-1 h-3 w-3`}),s.direction===`neutral`&&(0,d.jsx)(o.MinusIcon,{className:`mr-1 h-3 w-3`}),s.value,`%`]}),(0,d.jsx)(`span`,{className:`min-w-0 truncate`,children:J})]}),(0,d.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:G(u[0])})]})}if(h){let t=(0,n.relabelDimensions)(R.rows,U),r=e=>{if(u.includes(e)||!e.endsWith(ce))return;let t=e.slice(0,-9);return u.includes(t)?t:void 0},i=e=>{let t=r(e);return t?`${G(t)} · ${J}`:G(e)},s=u.flatMap(e=>K.includes(e)?[e,X(e)]:[e]),f=[...l,...s],p=t=>Y(String(e?.title??c??`export`),[f.map(e=>i(e)),...t.map(e=>f.map(t=>{let n=e[t];return n==null?``:typeof n==`number`?n:String(n)}))]),m=e=>(0,d.jsx)(`button`,{type:`button`,onClick:()=>p(e),"data-testid":`dataset-export`,title:O(`dashboard.exportCsv`,`Export CSV`),"aria-label":O(`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,d.jsx)(o.Download,{className:`h-3.5 w-3.5`})}),h=m(t);if(g){let e=se(t,_,v,j),r=e.colHeaders.flatMap(e=>u.map(t=>({col:e,measure:t,header:u.length===1?e.label:`${e.label} · ${G(t)}`}))),i=(e,t)=>(0,n.formatMeasure)(e,W(t)?.format,W(t)?.currency,W(t)?.percentScale,j),s=(e,t)=>{if(!K.includes(t))return null;let n=e?.[X(t)];if(n==null)return null;let r=e?.[t],s=w(typeof r==`number`?r:null,typeof n==`number`?n:null);return(0,d.jsxs)(`div`,{className:`flex items-center justify-end gap-1 text-[10px] font-normal leading-tight text-muted-foreground`,"data-testid":`matrix-cell-compare`,"data-direction":s?.direction,title:J,children:[(0,d.jsx)(`span`,{className:`tabular-nums`,children:i(n,t)}),s&&(0,d.jsxs)(`span`,{className:(0,a.cn)(`flex shrink-0 items-center tabular-nums font-medium`,s.direction===`up`&&`text-emerald-600 dark:text-emerald-400`,s.direction===`down`&&`text-rose-600 dark:text-rose-400`),children:[s.direction===`up`&&(0,d.jsx)(o.ArrowUpIcon,{className:`h-2.5 w-2.5`}),s.direction===`down`&&(0,d.jsx)(o.ArrowDownIcon,{className:`h-2.5 w-2.5`}),s.direction===`neutral`&&(0,d.jsx)(o.MinusIcon,{className:`h-2.5 w-2.5`}),s.value,`%`]})]})},c=K.length>0?(0,d.jsx)(`caption`,{className:`px-2 pb-1 text-left text-[10px] font-normal text-muted-foreground`,"data-testid":`matrix-compare-caption`,children:J}):null,l=e=>{let t=R.totals?.find(t=>Array.isArray(t.dimensions)&&t.dimensions.join(`,`)===e.join(`,`))?.rows;return t&&(0,n.relabelDimensions)(t,U)},f=new Map;for(let e of l(_)??[])f.set((0,n.pivotBucketId)(_.map(t=>(0,n.pivotDimensionValue)(e[t]))),e);let p=new Map;for(let e of l([v])??[])p.set((0,n.pivotBucketId)([(0,n.pivotDimensionValue)(e[v])]),e);let m=l([])?.[0],g=f.size>0,y=p.size>0,b=O(`dashboard.total`,`Total`);return(0,d.jsxs)(`div`,{className:`relative h-full w-full overflow-auto p-1`,"data-testid":`dataset-matrix`,children:[h,(0,d.jsxs)(`table`,{className:`w-full text-xs`,children:[c,(0,d.jsx)(`thead`,{className:`bg-muted/40`,children:(0,d.jsxs)(`tr`,{children:[_.map(e=>(0,d.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:G(e)},e)),r.map(e=>(0,d.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,children:e.header},`${e.col.id}-${e.measure}`)),g&&u.map(e=>(0,d.jsx)(`th`,{className:`px-2 py-1.5 text-right font-medium whitespace-nowrap`,"data-testid":`matrix-total-col-header`,children:u.length===1?b:`${b} · ${G(e)}`},`total-${e}`))]})}),(0,d.jsxs)(`tbody`,{children:[e.rowHeaders.map(t=>(0,d.jsxs)(`tr`,{className:`border-t`,children:[t.labels.map((e,t)=>(0,d.jsx)(`td`,{className:`px-2 py-1 whitespace-nowrap font-medium`,children:e},t)),r.map(r=>{let o=e.cellIndex.get((0,n.pivotCellKey)(t.id,r.col.id)),c=o==null?void 0:R.rows[o],l=Q&&o!=null,u=[...t.labels,r.col.label].filter(Boolean).join(` / `);return(0,d.jsxs)(`td`,{className:(0,a.cn)(`px-2 py-1 text-right tabular-nums whitespace-nowrap`,l&&`cursor-pointer hover:bg-accent/40`),"data-testid":l?`dataset-drill-cell`:void 0,onClick:l?()=>_e(o,u):void 0,children:[c?i(c[r.measure],r.measure):`—`,s(c,r.measure)]},`${r.col.id}-${r.measure}`)}),g&&u.map(e=>{let n=f.get(t.id);return(0,d.jsxs)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap font-medium`,"data-testid":`matrix-row-total`,children:[i(n?.[e],e),s(n,e)]},`total-${e}`)})]},t.id)),y&&(0,d.jsxs)(`tr`,{className:`border-t bg-muted/30 font-medium`,"data-testid":`matrix-total-row`,children:[_.length>0&&(0,d.jsx)(`td`,{colSpan:_.length,className:`px-2 py-1 whitespace-nowrap`,children:b}),r.map(e=>{let t=p.get(e.col.id);return(0,d.jsxs)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,children:[i(t?.[e.measure],e.measure),s(t,e.measure)]},`${e.col.id}-${e.measure}`)}),g&&u.map(e=>(0,d.jsxs)(`td`,{className:`px-2 py-1 text-right tabular-nums whitespace-nowrap`,"data-testid":`matrix-grand-total`,children:[i(m?.[e],e),s(m,e)]},`grand-${e}`))]})]})]}),$]})}let y=[...l,...s],b=new Set(y.filter(e=>(u.includes(e)||r(e)!==void 0)&&t.every(t=>t[e]==null||typeof t[e]==`number`))),x=t.map((e,t)=>({row:e,index:t})),S=V&&y.includes(V.column)?V:null,C=S?x.map(e=>({...e,key:(0,n.getSortValue)(e.row[S.column])})).sort((e,t)=>{if(e.key===null&&t.key===null)return 0;if(e.key===null)return 1;if(t.key===null)return-1;let r=(0,n.compareSortValues)(e.key,t.key);return S.dir===`asc`?r:-r}):[...x].sort((e,t)=>{for(let r of l){let i=+((0,n.getSortValue)(e.row[r])===null),a=+((0,n.getSortValue)(t.row[r])===null);if(i!==a)return i-a}return 0}),T=e=>b.has(e)?`desc`:`asc`,D=e=>te(t=>{let n=T(e);return t?.column===e?t.dir===n?{column:e,dir:n===`asc`?`desc`:`asc`}:null:{column:e,dir:n}}),k=E?R.totals?.find(e=>Array.isArray(e.dimensions)&&e.dimensions.length===0)?.rows?.[0]:void 0,A=O(`dashboard.total`,`Total`),M=e=>{if(S?.column!==e)return(0,d.jsx)(o.ChevronsUpDown,{className:`ml-0.5 h-3 w-3 shrink-0 opacity-0 transition-opacity group-hover:opacity-50`,"aria-hidden":`true`});let t=S.dir===`asc`?o.ChevronUp:o.ChevronDown;return(0,d.jsx)(t,{className:`ml-0.5 h-3 w-3 shrink-0 text-primary`,"aria-hidden":`true`})};return(0,d.jsxs)(`div`,{className:`relative h-full w-full overflow-auto p-1`,children:[m(C.map(e=>e.row)),(0,d.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,d.jsx)(`thead`,{className:`bg-muted/40`,children:(0,d.jsx)(`tr`,{children:y.map(e=>{let t=b.has(e);return(0,d.jsx)(`th`,{scope:`col`,"aria-sort":S?.column===e?S.dir===`asc`?`ascending`:`descending`:`none`,className:(0,a.cn)(`group px-2 py-1.5 font-medium whitespace-nowrap`,t?`text-right`:`text-left`),"data-testid":r(e)?`dataset-compare-column`:void 0,children:(0,d.jsxs)(`button`,{type:`button`,onClick:()=>D(e),"data-testid":`dataset-table-sort`,className:(0,a.cn)(`inline-flex w-full select-none items-center font-medium transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,t?`justify-end`:`justify-between`),children:[(0,d.jsx)(`span`,{className:`truncate`,children:i(e)}),M(e)]})},e)})})}),(0,d.jsx)(`tbody`,{children:C.map(({row:e,index:t})=>(0,d.jsx)(`tr`,{className:(0,a.cn)(`border-t transition-colors hover:bg-muted/40`,Q&&`cursor-pointer hover:bg-accent/40`),"data-testid":Q?`dataset-drill-row`:void 0,onClick:Q?()=>_e(t,Z.map(t=>(0,n.formatDimensionValue)(e[t],j)).filter(Boolean).join(` / `)):void 0,children:y.map(t=>{let i=r(t)??(u.includes(t)?t:void 0);return(0,d.jsx)(`td`,{className:(0,a.cn)(`px-2 py-1 whitespace-nowrap tabular-nums`,b.has(t)&&`text-right`),children:i?(0,n.formatMeasure)(e[t],W(i)?.format,W(i)?.currency,W(i)?.percentScale,j):(0,n.formatDimensionValue)(e[t],j)},t)})},t))}),k&&(0,d.jsx)(`tfoot`,{className:`bg-muted/30`,children:(0,d.jsxs)(`tr`,{className:`border-t font-medium`,"data-testid":`dataset-table-total-row`,children:[(0,d.jsx)(`td`,{colSpan:l.length,className:`px-2 py-1 whitespace-nowrap`,children:A}),s.map(e=>{let t=r(e)??e;return(0,d.jsx)(`td`,{className:(0,a.cn)(`px-2 py-1 whitespace-nowrap tabular-nums`,b.has(e)&&`text-right`),children:(0,n.formatMeasure)(k[e],W(t)?.format,W(t)?.currency,W(t)?.percentScale,j)},e)})]})})]}),$]})}let ve=me[p]??`bar`,ye=(0,n.relabelDimensions)(R.rows,U),be=O(`chart.nullCategory`,`(None)`),{data:xe,xAxisKey:Se,series:Ce}=(0,n.buildChartSeries)(ye,l,u,R.fields,{nullCategoryLabel:be}),{series:we,axes:Te}=(0,n.mergeAuthoredPresentation)(Ce,e?.chartConfig),Ee=l.length>=2&&u.length===1?[]:K.map(e=>{let t=we.find(t=>t.dataKey===e);return{dataKey:X(e),label:`${G(e)} · ${J}`,variant:`comparison`,...t?.chartType?{chartType:t.chartType}:{},...t?.yAxis?{yAxis:t.yAxis}:{}}}),De=Ee.length>0?[...we.map(e=>({...e,variant:e.variant??`current`})),...Ee]:we,Oe=(Array.isArray(y.stageOrder)?y.stageOrder:void 0)?.flatMap(e=>{let t=String(e),n=U?.[l[0]]?.[t];return n&&n!==t?[t,n]:[t]}),ke=Oe?.length?Oe:ie,Ae=(0,n.chartConfigPresentation)(e?.chartConfig,re),je=Q?e=>{let t=(0,n.findChartSeriesRow)(ye,l,u,e?.category,e?.series,{nullCategoryLabel:be,bucketId:e?.categoryId});if(t<0)return;let r=l.length>=2&&u.length===1,i=e?.seriesLabel??e?.series,a=[e?.category,r?i:void 0].filter(Boolean).map(String).join(` / `);_e(t,a)}:void 0;return(0,d.jsxs)(`div`,{className:(0,a.cn)(`relative h-full w-full min-h-[220px]`),children:[(0,d.jsx)(r.SchemaRenderer,{schema:{type:`chart`,chartType:ve,data:xe,xAxisKey:Se,series:De,isAnimationActive:!1,...Ae,...Te,...ke?{categoryOrder:ke}:{}},onChartClick:je,onSegmentClick:je}),$]})}function ge(e){let{language:t}=(0,i.useObjectTranslation)();return(0,i.pickLocalized)(e.label,t)}var Z=`__all__`,Q=`__custom__`;function _e(e,t){if(e){if(e.preset)return t(e.preset);if(e.from||e.to)return`${e.from??`…`} – ${e.to??`…`}`}}function $(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function ve({def:e,value:r,onChange:s}){let c=(0,i.useSafeTranslate)(),l=ge(e),[u,f]=(0,t.useState)(!1),p=e.allowCustomRange!==!1,m=e=>c(`dashboard.filters.range.${e}`,e.replace(/_/g,` `)),h=r?.preset??(r?.from||r?.to?Q:Z);return(0,d.jsxs)(`div`,{className:`flex items-center gap-1`,"data-testid":`dashboard-filter-${e.name}`,children:[(0,d.jsxs)(a.Select,{value:h,onValueChange:e=>{e===Z?s(void 0):e===Q?f(!0):s({preset:e})},children:[(0,d.jsxs)(a.SelectTrigger,{className:`h-8 w-auto min-w-36 gap-1`,"aria-label":l||c(`dashboard.filters.dateRange`,`Date range`),children:[(0,d.jsx)(o.CalendarIcon,{className:`size-3.5 opacity-60`}),(0,d.jsx)(a.SelectValue,{placeholder:c(`dashboard.filters.dateRange`,`Date range`),children:_e(r,m)??c(`dashboard.filters.allTime`,`All time`)})]}),(0,d.jsxs)(a.SelectContent,{children:[(0,d.jsx)(a.SelectItem,{value:Z,children:c(`dashboard.filters.allTime`,`All time`)}),n.DATE_RANGE_PRESETS.map(e=>(0,d.jsx)(a.SelectItem,{value:e,children:m(e)},e)),p&&(0,d.jsx)(a.SelectItem,{value:Q,children:c(`dashboard.filters.custom`,`Custom…`)})]})]}),p&&(0,d.jsxs)(a.Popover,{open:u,onOpenChange:f,children:[(0,d.jsx)(a.PopoverTrigger,{asChild:!0,children:(0,d.jsx)(`span`,{"aria-hidden":!0,className:`size-0`})}),(0,d.jsx)(a.PopoverContent,{className:`w-auto p-0`,align:`start`,children:(0,d.jsx)(a.Calendar,{mode:`range`,numberOfMonths:2,selected:{from:r?.from&&!r.from.startsWith(`{`)?new Date(r.from):void 0,to:r?.to&&!r.to.startsWith(`{`)?new Date(r.to):void 0},onSelect:e=>{if(!e?.from&&!e?.to){s(void 0);return}s({...e?.from?{from:$(e.from)}:{},...e?.to?{to:$(e.to)}:{}})}})})]})]})}function ye(e,t,n){let r=Array.isArray(t)&&t.length===e.length&&t.some(e=>e?.[n.valueField]!==void 0)?t:void 0,i=new Map;for(let t=0;t<e.length;t++){let a=e[t],o=r?r[t]?.[n.valueField]:a?.[n.valueField];if(o==null||o===``)continue;let s=String(o);if(i.has(s))continue;let c=n.labelField?a?.[n.labelField]:a?.[n.valueField];i.set(s,String(c??s))}return Array.from(i,([e,t])=>({value:e,label:t}))}function be({def:e,value:n,onChange:r,dataSource:o}){let s=(0,i.useSafeTranslate)(),{language:c}=(0,i.useObjectTranslation)(),l=ge(e),[u,f]=(0,t.useState)(null),p=e.optionsFrom;(0,t.useEffect)(()=>{if(!p||!o)return;let e=!1,t=()=>{if(typeof o.find!=`function`){e||f([]);return}o.find(p.object,{$select:[...new Set([p.valueField,...p.labelField?[p.labelField]:[]])],...p.filter?{$filter:p.filter}:{},$top:200}).then(t=>{if(e)return;let n=Array.isArray(t)?t:t?.data??[];f(ye(n,void 0,p))}).catch(()=>{e||f([])})};if(typeof o.queryDataset==`function`){let n=[{name:p.valueField,field:p.valueField}];p.labelField&&p.labelField!==p.valueField&&n.push({name:p.labelField,field:p.labelField}),o.queryDataset({name:`dashboard_filter_options`,label:`Dashboard filter options`,object:p.object,dimensions:n,measures:[{name:`option_count`,aggregate:`count`}]},{dimensions:n.map(e=>e.name),measures:[`option_count`],...p.filter?{runtimeFilter:p.filter}:{},order:{[p.valueField]:`asc`},limit:1e3}).then(t=>{if(e)return;let n=Array.isArray(t?.rows)?t.rows:[],r=Array.isArray(t?.drillRawRows)?t.drillRawRows:void 0;f(ye(n,r,p))}).catch(()=>{e||t()})}else t();return()=>{e=!0}},[p?.object,p?.valueField,p?.labelField,o]);let m=(0,t.useMemo)(()=>(e.options?.length?e.options:u??[]).map(e=>({value:e.value,label:(0,i.pickLocalized)(e.label,c)||e.value})),[e.options,u,c]),h=l||e.name,g=n?m.find(e=>e.value===String(n))?.label??String(n):void 0;return(0,d.jsxs)(a.Select,{value:n?String(n):Z,onValueChange:e=>r(e===Z?void 0:e),children:[(0,d.jsx)(a.SelectTrigger,{className:`h-8 w-auto min-w-32`,"aria-label":h,"data-testid":`dashboard-filter-${e.name}`,children:(0,d.jsx)(a.SelectValue,{children:g??`${h}: ${s(`dashboard.filters.all`,`All`)}`})}),(0,d.jsxs)(a.SelectContent,{children:[(0,d.jsx)(a.SelectItem,{value:Z,children:s(`dashboard.filters.all`,`All`)}),m.map(e=>(0,d.jsx)(a.SelectItem,{value:e.value,children:e.label},e.value))]})]})}function xe({def:e,value:n,onChange:r}){let i=ge(e)||e.name,[o,s]=(0,t.useState)(n==null?``:String(n));(0,t.useEffect)(()=>{s(n==null?``:String(n))},[n]);let c=()=>{let t=o.trim();if(t===``){r(void 0);return}r(e.type===`number`?Number(t):t)};return(0,d.jsx)(a.Input,{className:`h-8 w-36`,type:e.type===`number`?`number`:`text`,placeholder:i,value:o,onChange:e=>s(e.target.value),onBlur:c,onKeyDown:e=>{e.key===`Enter`&&c()},"aria-label":i,"data-testid":`dashboard-filter-${e.name}`})}function Se({defs:e,values:t,onChange:n,onReset:r,dataSource:s,className:c}){let l=(0,i.useSafeTranslate)();if(e.length===0)return null;let u=e=>e==null||e===``||typeof e==`object`&&Object.keys(e).length===0,f=e.some(e=>{let n=t[e.name],r=e.defaultValue;return u(n)&&u(r)?!1:JSON.stringify(n??null)!==JSON.stringify(r??null)});return(0,d.jsxs)(`div`,{className:(0,a.cn)(`col-span-full flex flex-wrap items-center gap-2`,c),"data-testid":`dashboard-filter-bar`,role:`group`,"aria-label":l(`dashboard.filters.label`,`Dashboard filters`),children:[e.map(e=>{let r=t[e.name],i=t=>n(e.name,t);return e.type===`dateRange`||e.type===`date`?(0,d.jsx)(ve,{def:e,value:r,onChange:i},e.name):e.type===`select`||e.type===`lookup`?(0,d.jsx)(be,{def:e,value:r,onChange:i,dataSource:s},e.name):(0,d.jsx)(xe,{def:e,value:r,onChange:i},e.name)}),r&&f&&(0,d.jsxs)(a.Button,{variant:`ghost`,size:`sm`,onClick:r,className:`text-muted-foreground`,children:[(0,d.jsx)(o.RotateCcw,{className:`size-3.5`}),l(`dashboard.filters.reset`,`Reset`)]})]})}function Ce({id:e,disabled:t,gridSpan:n,className:r,children:i}){let{attributes:o,listeners:s,setNodeRef:u,transform:f,transition:p,isDragging:m,isOver:h}=(0,c.useSortable)({id:e,disabled:t}),g={transform:l.CSS.Transform.toString(f),transition:p,opacity:m?.4:1,...n?{gridColumn:`span ${n.w}`,gridRow:`span ${n.h}`}:{}};return(0,d.jsx)(`div`,{ref:u,style:g,className:(0,a.cn)(`h-full w-full`,r,!t&&`cursor-grab active:cursor-grabbing`,h&&!m&&`ring-2 ring-primary ring-offset-2 rounded-lg`),"data-sortable-widget-id":e,...o,...s,children:i})}function we(e){return e?(0,a.getLazyIcon)(e):null}var Te=[`hsl(var(--chart-1))`,`hsl(var(--chart-2))`,`hsl(var(--chart-3))`,`hsl(var(--chart-4))`,`hsl(var(--chart-5))`],Ee=new Set([`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`funnel`,`scatter`,`treemap`,`sankey`]);function De(e){return Ee.has(e)?{enabled:!0}:void 0}var Oe=new Set([`object-chart`,`object-metric`,`object-data-table`]),ke=(0,t.forwardRef)(({schema:e,className:l,dataSource:u,onRefresh:f,recordCount:p,userActions:m,designMode:h,selectedWidgetId:g,onWidgetClick:_,onWidgetsReorder:v,modalHandler:y,scriptHandlers:b,hideHeaderText:S,...w},T)=>{let E=(()=>{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})(),O=E,k=e.gap||4,N=e.columns!=null||E!==4,[P,F]=(0,t.useState)(!1),[I,L]=(0,t.useState)(!1),R=(0,t.useRef)(null),z=(0,t.useMemo)(()=>(0,n.resolveDashboardFilterDefs)(e),[e.globalFilters,e.dateRange]),{variables:B,setVariable:ee,resetVariables:V}=(0,r.usePageVariables)(),te=(0,t.useMemo)(()=>(e.header?.actions??[]).map(e=>({name:e.actionUrl||e.label,type:e.actionType||`url`,target:e.actionUrl,label:e.label})),[e.header?.actions]),{executeAction:ne,engine:H}=(0,r.useActionEngine)({actions:te}),{dashboardLabel:re,dashboardDescription:U,dashboardActionLabel:ie,widgetTitle:W,widgetDescription:G,widgetSubCaption:K,fieldLabel:ae}=(0,r.useObjectLabel)(),{t:oe,language:se}=(0,i.useObjectTranslation)(),q=(0,t.useCallback)(e=>{if(e!=null)return(0,i.pickLocalized)(e,se)||void 0},[se]),J=(0,t.useCallback)((e,t,n)=>n&&(!t||t===`value`||t===`count`||n===`count`)?oe(`report.aggregate.${n}`,{defaultValue:n}):e?ae(e,t,t):t,[oe,ae]),Y=e.name,ce=(0,t.useCallback)(e=>{if(!Y)return e.label;let t=e.actionUrl||e.label;return ie(Y,t,e.label)},[Y,ie]),X=(0,t.useCallback)(e=>{let t=q(e.title);return!Y||!e.id||t===void 0?t:W(Y,e.id,t)},[Y,W,q]),le=(0,t.useCallback)(e=>{let t=q(e.description);return!Y||!e.id?t:G(Y,e.id,t)},[Y,G,q]),ue=(0,t.useCallback)(e=>{let t=e.options?.description,n=q(t);return!Y||!e.id?n:K(Y,e.id,n)},[Y,K,q]);(0,t.useEffect)(()=>{let e=H.getRunner();if(y&&e.setModalHandler(y),b)for(let[t,n]of Object.entries(b))e.registerScript(t,n)},[H,y,b]),(0,t.useEffect)(()=>{let e=()=>L(window.innerWidth<768);return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let de=(0,t.useCallback)(()=>{f&&(F(!0),f(),setTimeout(()=>F(!1),600))},[f]);(0,t.useEffect)(()=>{if(!(!e.refreshInterval||e.refreshInterval<=0||!f))return R.current=setInterval(de,e.refreshInterval*1e3),()=>{R.current&&clearInterval(R.current)}},[e.refreshInterval,f,de]);let fe=(0,t.useCallback)((e,t)=>{!h||!_||!t||(e.stopPropagation(),_(t))},[h,_]),pe=(0,t.useCallback)((t,n,r)=>{if(!h||!_)return;let i=e.widgets||[];if(t.key===`Enter`||t.key===` `)t.preventDefault(),_(n??null);else if(t.key===`ArrowRight`||t.key===`ArrowDown`){t.preventDefault();let e=r+1<i.length?i[r+1]:null;e?.id&&_(e.id)}else if(t.key===`ArrowLeft`||t.key===`ArrowUp`){t.preventDefault();let e=r-1>=0?i[r-1]:null;e?.id&&_(e.id)}else t.key===`Escape`&&(t.preventDefault(),_(null))},[h,_,e.widgets]),me=(0,t.useCallback)(e=>{!h||!_||e.target===e.currentTarget&&_(null)},[h,_]),ge=e=>{me(e),typeof w.onClick==`function`&&w.onClick(e)},Z=!!(h&&v),Q=(0,s.useSensors)((0,s.useSensor)(s.PointerSensor,{activationConstraint:{distance:5}})),_e=(0,t.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||v?.((0,c.arrayMove)(i,a,o))},[Z,e.widgets,v]),$=(e,i,o)=>{let s=e.type===`metric`||D.has(e.type||``),c=N?{w:Math.min(s?3:6,O),h:s?2:4}:void 0,l=e.layout??c,f=l?{...l,w:Math.min(l.w,O)}:void 0,p=!!e.dataset,m=()=>{if(e.component)return e.component;let t=e.type,n=e.options||{},r=e.data||n.data;if(M(e))return j;let i=A(t),a=i.chartType??t;if(i.family===`series`&&i.chartType){let t=n.xField||`name`,o=n.yField||`value`;if(x(r)){let s=r.aggregate,c=s?{field:s.field,function:s.function,groupBy:s.groupBy}:void 0,l=c?.field||o;return{type:`object-chart`,chartType:a,objectName:r.object,aggregate:c,filter:r.filter||e.filter,xAxisKey:t,series:[{dataKey:l,label:J(r.object,l,c?.function)}],colors:Te,isAnimationActive:!1,drillDown:n.drillDown??De(i.chartType),compareTo:e.compareTo,className:`h-[200px] sm:h-[250px] md:h-[300px]`}}return{type:`chart`,chartType:a,data:Array.isArray(r)?r:r?.items||[],xAxisKey:t,series:[{dataKey:o,label:J(void 0,o,void 0)}],colors:Te,isAnimationActive:!1,className:`h-[200px] sm:h-[250px] md:h-[300px]`}}if(i.family===`metric`){let i=X(e)||t,a=ue(e);if(x(r)){let t=r.aggregate;return{type:`object-metric`,...n,objectName:r.object,label:i,description:a,aggregate:t?{field:t.field,function:t.function,groupBy:t.groupBy}:void 0,filter:r.filter||e.filter}}let o=Array.isArray(r)?r:r?.items||[],s=n.yField||`value`;return{type:`metric`,...n,label:i,description:a,value:n.value??o[0]?.[s]??`—`}}if(i.family===`table`){let i=t===`list`;if(x(r)){let{data:t,...a}=n;return{type:`object-data-table`,...a,objectName:r.object,dataProvider:r,filter:r.filter||e.filter,searchable:i?!1:e.searchable??!1,pagination:i?!1:e.pagination??!1,drillDown:n.drillDown??{enabled:!0,mode:`record`},className:`border-0`}}let a=Array.isArray(r)?r:r?.items||[];return{type:`data-table`,...n,data:a,columns:Array.isArray(n.columns)&&n.columns.length>0?n.columns:C(a),searchable:!1,pagination:!1,className:`border-0`}}return i.family===`pivot`?j:i.family===`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`}:i.family===`unsupported`?{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}},_=z.length>0?(0,n.buildWidgetScopedFilter)(e,z,B):void 0,v=(()=>{let e=m();return _&&e&&Oe.has(e.type)?{...e,filter:(0,n.mergeFilters)(e.filter,_)}:e})(),y=_&&p?{...e,filter:(0,n.mergeFilters)(e.filter,_)}:e,b=e.type===`metric`&&!p,S=X(e),w=le(e),T=e.id||S||`widget-${i}`,E=h&&g===e.id,k=h?{"data-testid":`dashboard-preview-widget-${e.id}`,"data-widget-id":e.id,role:`button`,tabIndex:0,"aria-selected":E,"aria-label":`Widget: ${S||`Widget ${i+1}`}`,onClick:t=>fe(t,e.id),onKeyDown:t=>pe(t,e.id,i)}:{},P=h?(0,a.cn)(`cursor-pointer rounded-lg transition-all outline-none`,`focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,E?`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,F=!I&&f&&!Z?{gridColumn:`span ${f.w}`,gridRow:`span ${f.h}`}:void 0,L=b?(0,d.jsxs)(`div`,{className:(0,a.cn)(`h-full w-full`,h&&`relative`,P),style:F,...k,children:[(0,d.jsx)(r.SchemaRenderer,{schema:v,className:(0,a.cn)(`h-full w-full`,h&&`pointer-events-none`),dataSource:u}),h&&(0,d.jsx)(`div`,{className:`absolute inset-0 z-10`,"aria-hidden":`true`,"data-testid":`widget-click-overlay`})]}):(0,d.jsxs)(a.Card,{className:(0,a.cn)(`overflow-hidden border-border/50 shadow-sm transition-all hover:shadow-md`,`bg-card/50 backdrop-blur-sm`,o&&`w-full`,h&&`relative`,P),style:F,...k,children:[S&&(0,d.jsxs)(a.CardHeader,{className:`pb-2 border-b border-border/40 bg-muted/20 px-3 sm:px-6`,children:[(0,d.jsx)(a.CardTitle,{className:`text-sm sm:text-base font-medium tracking-tight truncate`,title:S,children:S}),w&&(0,d.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5 line-clamp-2`,children:w})]}),(0,d.jsx)(a.CardContent,{className:`p-0`,children:(0,d.jsx)(`div`,{className:(0,a.cn)(`h-full w-full`,`p-3 sm:p-4 md:p-6`,h&&`pointer-events-none`),children:p?(0,d.jsx)(he,{widget:y,dataSource:u}):(0,d.jsx)(r.SchemaRenderer,{schema:v,dataSource:u})})}),h&&(0,d.jsx)(`div`,{className:`absolute inset-0 z-10`,"aria-hidden":`true`,"data-testid":`widget-click-overlay`})]});return Z&&e.id?(0,d.jsx)(Ce,{id:e.id,gridSpan:!I&&f?{w:f.w,h:f.h}:void 0,children:L},T):(0,d.jsx)(t.Fragment,{children:L},T)},ve=e.title||e.label,ye=e.header,be=!S&&ye?.showTitle!==!1&&!!ve,xe=!S&&ye?.showDescription!==!1&&!!e.description,Ee=ye?.actions??[],ke=ye&&(be||xe||Ee.length>0)&&(0,d.jsxs)(`div`,{className:`col-span-full mb-4`,children:[be&&(0,d.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:Y?re({name:Y,label:q(ve)}):q(ve)}),xe&&(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:Y?U({name:Y,description:q(e.description)}):q(e.description)}),Ee.length>0&&(0,d.jsx)(`div`,{className:`flex gap-2 mt-3`,children:Ee.map((e,t)=>{let n=we(e.icon);return(0,d.jsxs)(a.Button,{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}let i=await ne(n||r);i?.success||console.warn(`[DashboardRenderer] action failed`,i?.error)},children:[n&&(0,d.jsx)(n,{className:`w-4 h-4 mr-1.5`}),ce(e)]},t)})})]}),Ae=z.length>0&&(0,d.jsx)(Se,{defs:z,values:B,onChange:ee,onReset:V,dataSource:u,className:`mb-2`}),je=p!==void 0&&(0,d.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[p.toLocaleString(),` records`]}),Me=m?JSON.stringify(m):void 0,Ne=(0,n.toDomProps)(w),Pe=f&&(0,d.jsxs)(`div`,{className:(0,a.cn)(`flex items-center justify-end gap-3 mb-2`,!I&&`col-span-full`),children:[je,(0,d.jsxs)(a.Button,{variant:`outline`,size:`sm`,onClick:de,disabled:P,"aria-label":`Refresh dashboard`,children:[(0,d.jsx)(o.RefreshCw,{className:(0,a.cn)(`h-4 w-4 mr-2`,P&&`animate-spin`)}),P?`Refreshing…`:`Refresh All`]})]}),Fe=(0,t.useMemo)(()=>(e.widgets??[]).map(e=>e.id).filter(e=>!!e),[e.widgets]),Ie=(0,t.useMemo)(()=>(e.widgets??[]).filter(e=>e.type===`metric`).map(e=>e.id).filter(e=>!!e),[e.widgets]),Le=(0,t.useMemo)(()=>(e.widgets??[]).filter(e=>e.type!==`metric`).map(e=>e.id).filter(e=>!!e),[e.widgets]);if(I){let t=e.widgets?.filter(e=>e.type===`metric`)||[],n=e.widgets?.filter(e=>e.type!==`metric`)||[],r=(0,d.jsxs)(`div`,{ref:T,...Ne,className:(0,a.cn)(`flex flex-col gap-4 px-4`,l),"data-user-actions":Me,onClick:ge,children:[ke,Ae,Pe,t.length>0&&(0,d.jsx)(`div`,{className:`grid grid-cols-2 gap-3`,onClick:me,children:(0,d.jsx)(c.SortableContext,{items:Ie,strategy:c.rectSortingStrategy,disabled:!Z,children:t.map((e,t)=>$(e,t))})}),n.length>0&&(0,d.jsx)(`div`,{className:`flex flex-col gap-4`,onClick:me,children:(0,d.jsx)(c.SortableContext,{items:Le,strategy:c.verticalListSortingStrategy,disabled:!Z,children:n.map((e,t)=>$(e,t,!0))})})]});return Z?(0,d.jsx)(s.DndContext,{sensors:Q,collisionDetection:s.closestCenter,onDragEnd:_e,children:r}):r}let Re=(0,d.jsxs)(`div`,{ref:T,...Ne,className:(0,a.cn)(`grid`,!N&&`auto-rows-min grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,l),style:{...N&&{gridTemplateColumns:`repeat(${O}, minmax(0, 1fr))`,gridAutoRows:`minmax(5rem, auto)`},gap:`${k*.25}rem`},"data-user-actions":Me,onClick:ge,children:[ke,Ae,Pe,(0,d.jsx)(c.SortableContext,{items:Fe,strategy:c.rectSortingStrategy,disabled:!Z,children:e.widgets?.map((e,t)=>$(e,t))})]});return Z?(0,d.jsx)(s.DndContext,{sensors:Q,collisionDetection:s.closestCenter,onDragEnd:_e,children:Re}):Re});ke.displayName=`DashboardRendererInner`;var Ae=(0,t.forwardRef)((e,i)=>{let{schema:a}=e,o=(0,t.useMemo)(()=>(0,n.resolveDashboardFilterDefs)(a),[a.globalFilters,a.dateRange]);return o.length===0?(0,d.jsx)(ke,{ref:i,...e}):(0,d.jsx)(r.PageVariablesProvider,{definitions:(0,n.dashboardFilterVariableDefs)(o),children:(0,d.jsx)(ke,{ref:i,...e})})});Ae.displayName=`DashboardRenderer`;function je({editMode:e}){let n=(0,r.useDnd)();return t.useEffect(()=>{if(e)return n.startDrag({id:`dashboard-layout`,type:`dashboard-widget`,data:{}}),()=>{n.endDrag()};n.endDrag(`dashboard`)},[e,n]),null}var Me=[`hsl(var(--chart-1))`,`hsl(var(--chart-2))`,`hsl(var(--chart-3))`,`hsl(var(--chart-4))`,`hsl(var(--chart-5))`];function Ne(e,t){if(!e.widgets?.length)return e;let n=new Map(t.map(e=>[e.i,e])),r=e.widgets.map((e,t)=>{let r=e.id||`widget-${t}`,i=n.get(r);return i?{...e,layout:{x:i.x,y:i.y,w:i.w,h:i.h}}:e});return{...e,widgets:r}}function Pe(e){return{lg:e.widgets?.map((e,t)=>({i:e.id||`widget-${t}`,x:e.layout?.x??t%4*3,y:e.layout?.y??Math.floor(t/4)*4,w:e.layout?.w??3,h:e.layout?.h??4}))||[]}}var Fe=({schema:e,className:n,dataSource:s,onLayoutChange:c,onSchemaChange:l,onRefresh:u})=>{let{width:p,containerRef:m,mounted:h}=(0,f.useContainerWidth)(),[g,_]=t.useState(!1),[v,y]=t.useState(!1),b=(0,r.useHasDndProvider)(),{language:S}=(0,i.useObjectTranslation)(),w=t.useRef(null),T=t.useCallback(()=>{u&&(y(!0),u(),setTimeout(()=>y(!1),600))},[u]);t.useEffect(()=>{if(!(!e.refreshInterval||e.refreshInterval<=0||!u))return w.current=setInterval(T,e.refreshInterval*1e3),()=>{w.current&&clearInterval(w.current)}},[e.refreshInterval,u,T]);let[E,D]=t.useState(()=>Pe(e)),O=t.useMemo(()=>JSON.stringify(e.widgets?.map((e,t)=>({i:e.id||`widget-${t}`,x:e.layout?.x,y:e.layout?.y,w:e.layout?.w,h:e.layout?.h}))??[]),[e.widgets]);t.useEffect(()=>{D(Pe(e))},[O]);let k=t.useCallback((e,t)=>{D(t),c?.(e)},[c]),N=t.useCallback(()=>{l?l(Ne(e,E.lg)):globalThis.process?.env?.NODE_ENV!==`production`&&console.warn("[DashboardGridLayout] Layout edits are in-memory only. Wire `onSchemaChange` to persist via your data adapter."),_(!1)},[l,e,E]),P=t.useCallback(()=>{D(Pe(e))},[e]),F=t.useCallback(e=>{if(e.component)return e.component;if(M(e))return j;let t=e.type,n=e.options||{},r=A(t);if(r.family===`series`&&r.chartType){let t=e.data||n.data,i=n.xField||`name`,a=n.yField||`value`;if(x(t)){let e=t.aggregate,n=e?{field:e.field,function:e.function,groupBy:e.groupBy}:void 0,o=n?.field||a;return{type:`object-chart`,chartType:r.chartType,objectName:t.object,aggregate:n,xAxisKey:i,series:[{dataKey:o}],colors:Me,isAnimationActive:!1,className:`h-full`}}let o=Array.isArray(t)?t:t?.items||[];return{type:`chart`,chartType:r.chartType,data:o,xAxisKey:i,series:[{dataKey:a}],colors:Me,isAnimationActive:!1,className:`h-full`}}if(r.family===`metric`){let r=e.data||n.data,i=e.title||t;if(x(r)){let t=r.aggregate;return{type:`object-metric`,...n,objectName:r.object,label:i,aggregate:t?{field:t.field,function:t.function,groupBy:t.groupBy}:void 0,filter:r.filter||e.filter}}let a=Array.isArray(r)?r:r?.items||[],o=n.yField||`value`;return{type:`metric`,...n,label:i,value:n.value??a[0]?.[o]??`—`}}if(r.family===`table`){let t=e.data||n.data;if(x(t)){let{data:e,...r}=n;return{type:`data-table`,...r,objectName:t.object,dataProvider:t,data:[],searchable:!1,pagination:!1,className:`border-0`}}let r=Array.isArray(t)?t:t?.items||[];return{type:`data-table`,...n,data:r,columns:Array.isArray(n.columns)&&n.columns.length>0?n.columns:C(r),searchable:!1,pagination:!1,className:`border-0`}}if(r.family===`pivot`){let t=e.data||n.data;if(x(t)){let{data:e,...r}=n;return{type:`pivot`,...r,objectName:t.object,dataProvider:t,data:[]}}return{type:`pivot`,...n,data:Array.isArray(t)?t:t?.items||[]}}return r.family===`unsupported`?{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}},[]);return(0,d.jsxs)(`div`,{ref:m,className:(0,a.cn)(`w-full`,n),"data-testid":`grid-layout`,children:[b&&(0,d.jsx)(je,{editMode:g}),(0,d.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,d.jsx)(`h2`,{className:`text-2xl font-bold`,children:e.title||(0,i.pickLocalized)(e.label,S)||`Dashboard`}),(0,d.jsx)(`div`,{className:`flex gap-2`,children:g?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(a.Button,{onClick:N,size:`sm`,variant:`default`,children:[(0,d.jsx)(o.Save,{className:`h-4 w-4 mr-2`}),`Save Layout`]}),(0,d.jsxs)(a.Button,{onClick:P,size:`sm`,variant:`outline`,children:[(0,d.jsx)(o.X,{className:`h-4 w-4 mr-2`}),`Reset`]}),(0,d.jsx)(a.Button,{onClick:()=>_(!1),size:`sm`,variant:`ghost`,children:`Cancel`})]}):(0,d.jsxs)(d.Fragment,{children:[u&&(0,d.jsxs)(a.Button,{onClick:T,size:`sm`,variant:`outline`,disabled:v,"aria-label":`Refresh dashboard`,children:[(0,d.jsx)(o.RefreshCw,{className:(0,a.cn)(`h-4 w-4 mr-2`,v&&`animate-spin`)}),v?`Refreshing…`:`Refresh All`]}),(0,d.jsxs)(a.Button,{onClick:()=>_(!0),size:`sm`,variant:`outline`,children:[(0,d.jsx)(o.Edit,{className:`h-4 w-4 mr-2`}),`Edit Layout`]})]})})]}),h&&(0,d.jsx)(f.ResponsiveGridLayout,{className:`layout`,width:p,layouts:E,breakpoints:{lg:1200,md:996,sm:768,xs:480,xxs:0},cols:{lg:12,md:10,sm:6,xs:4,xxs:2},rowHeight:60,dragConfig:{enabled:g,handle:`.drag-handle`},resizeConfig:{enabled:g},onLayoutChange:k,children:e.widgets?.map((e,t)=>{let n=e.id||`widget-${t}`,c=F(e),l=!!e.dataset,u=e.type===`metric`&&!l,f=(0,i.pickLocalized)(e.title,S);return(0,d.jsx)(`div`,{className:`h-full`,children:u?(0,d.jsxs)(`div`,{className:`h-full w-full relative`,children:[g&&(0,d.jsx)(`div`,{className:`drag-handle absolute top-2 right-2 z-10 cursor-move p-1 bg-background/80 rounded border border-border`,children:(0,d.jsx)(o.GripVertical,{className:`h-4 w-4`})}),(0,d.jsx)(r.SchemaRenderer,{schema:c,className:`h-full w-full`})]}):(0,d.jsxs)(a.Card,{className:(0,a.cn)(`h-full overflow-hidden border-border/50 shadow-sm transition-all`,`bg-card/50 backdrop-blur-sm`,g&&`ring-2 ring-primary/20`),children:[f&&(0,d.jsxs)(a.CardHeader,{className:`pb-2 border-b border-border/40 bg-muted/20 flex flex-row items-center justify-between`,children:[(0,d.jsx)(a.CardTitle,{className:`text-base font-medium tracking-tight truncate`,title:f,children:f}),g&&(0,d.jsx)(`div`,{className:`drag-handle cursor-move p-1 hover:bg-muted/40 rounded`,children:(0,d.jsx)(o.GripVertical,{className:`h-4 w-4`})})]}),(0,d.jsx)(a.CardContent,{className:`p-0 h-full`,children:(0,d.jsx)(`div`,{className:(0,a.cn)(`h-full w-full overflow-auto p-4`),children:l?(0,d.jsx)(he,{widget:e,dataSource:s}):(0,d.jsx)(r.SchemaRenderer,{schema:c})})})]})},n)})})]})},Ie=(0,i.createSafeTranslation)({"dashboard.trend.vsLastQuarter":`vs last quarter`,"dashboard.trend.vsLastMonth":`vs last month`,"dashboard.trend.vsLastWeek":`vs last week`,"dashboard.trend.vsLastYear":`vs last year`,"dashboard.trend.vsYesterday":`vs yesterday`,"dashboard.trend.vsPreviousPeriod":`vs previous period`},`dashboard.trend.vsLastQuarter`);function Le(e){switch(e.trim().toLowerCase().replace(/\s+/g,` `)){case`vs last quarter`:case`vs previous quarter`:return`dashboard.trend.vsLastQuarter`;case`vs last month`:case`vs previous month`:return`dashboard.trend.vsLastMonth`;case`vs last week`:case`vs previous week`:return`dashboard.trend.vsLastWeek`;case`vs last year`:case`vs previous year`:return`dashboard.trend.vsLastYear`;case`vs yesterday`:return`dashboard.trend.vsYesterday`;case`vs previous period`:case`vs prior period`:return`dashboard.trend.vsPreviousPeriod`;default:return}}function Re(e,t,n,r){if(e==null)return``;if(typeof e==`string`){let i=Number(e);return!isFinite(i)||e.trim()===``?e:Re(i,t,n,r)}if(!isFinite(e))return String(e);let a={$:`USD`,"¥":`JPY`,"€":`EUR`,"£":`GBP`},o=(t||``).trim(),s=!!n||o.length>0&&a[o[0]]!==void 0,c=o.endsWith(`%`),l=o.match(/0\.(0+)/),u=l?l[1].length:0;if(/a/i.test(o)){let t={locale:r,notation:`compact`,maximumFractionDigits:u||1};s&&(t.currency=n||a[o[0]]||`USD`);try{return(0,i.formatDisplayNumber)(e,t)}catch{}}if(s){let t=n||a[o[0]]||`USD`;try{return(0,i.formatDisplayNumber)(e,{locale:r,currency:t,minimumFractionDigits:u,maximumFractionDigits:u})}catch{return`${t} ${e.toFixed(u)}`}}return c?`${(e>1?e:e*100).toFixed(u)}%`:(0,i.formatDisplayNumber)(e,{locale:r,minimumFractionDigits:u,maximumFractionDigits:u})}var ze=({label:e,value:n,trend:r,icon:s,className:c,description:l,loading:u,error:f,colorVariant:p=`default`,format:m,currency:h,prefix:g,suffix:_,onClick:v,variant:y=`card`,schema:b,bind:x,events:S,props:C,ariaLabel:w,ariaDescribedBy:T,dataSource:E,...D})=>{let O=N[p]||N.default,{t:k}=Ie(),A=(0,i.useDisplayLocale)(),{language:j}=(0,i.useObjectTranslation)(),M=(0,t.useMemo)(()=>(0,i.pickLocalized)(e,j)||void 0,[e,j]),F=(0,t.useMemo)(()=>{let e=(0,i.pickLocalized)(l,j)||(0,i.pickLocalized)(r?.label,j)||void 0;if(!e)return e;let t=Le(e);return t?k(t):e},[l,r?.label,k,j]),I=(0,t.useMemo)(()=>{let e=typeof n==`number`||typeof n==`string`&&n.trim()!==``&&isFinite(Number(n))?Re(n,m,h,A):n??``,t=String(e);return`${g&&t.startsWith(g)?``:g??``}${t}${_&&t.endsWith(_)?``:_??``}`},[n,m,h,g,_,A]),L=(0,t.useMemo)(()=>{if(typeof s==`string`){let e=(0,a.getLazyIcon)(s);return e?(0,d.jsx)(e,{className:`h-4 w-4`}):null}return s},[s]);if(y===`bare`){let e=P[p]||P.default;return(0,d.jsx)(`div`,{className:(0,a.cn)(`flex flex-col gap-1 min-w-0`,v&&`cursor-pointer`,c),onClick:v,role:v?`button`:void 0,tabIndex:v?0:void 0,onKeyDown:v?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),v())}:void 0,children:u?(0,d.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,"data-testid":`metric-loading`,children:[(0,d.jsx)(o.Loader2,{className:`h-4 w-4 animate-spin`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Loading…`})]}):f?(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,"data-testid":`metric-error`,role:`alert`,children:[(0,d.jsx)(o.AlertCircle,{className:`h-4 w-4 text-destructive shrink-0`}),(0,d.jsx)(`span`,{className:`text-xs text-destructive truncate`,children:f})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{className:(0,a.cn)(`text-[2rem] leading-none font-extrabold tabular-nums tracking-tight truncate`,e),children:I}),(0,d.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground truncate`,children:M})]})})}return(0,d.jsxs)(a.Card,{className:(0,a.cn)(`h-full overflow-hidden`,v&&`cursor-pointer transition-colors hover:bg-accent/40 focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none`,c),onClick:v,role:v?`button`:void 0,tabIndex:v?0:void 0,onKeyDown:v?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),v())}:void 0,...D,children:[(0,d.jsxs)(a.CardHeader,{className:`flex flex-row items-center justify-between space-y-0 pb-2`,children:[(0,d.jsx)(a.CardTitle,{className:`text-sm font-medium truncate`,children:M}),L&&(0,d.jsx)(`div`,{className:(0,a.cn)(`flex h-8 w-8 items-center justify-center rounded-md shrink-0`,O),children:L})]}),(0,d.jsx)(a.CardContent,{children:u?(0,d.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,"data-testid":`metric-loading`,children:[(0,d.jsx)(o.Loader2,{className:`h-4 w-4 animate-spin`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Loading…`})]}):f?(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,"data-testid":`metric-error`,role:`alert`,children:[(0,d.jsx)(o.AlertCircle,{className:`h-4 w-4 text-destructive shrink-0`}),(0,d.jsx)(`span`,{className:`text-xs text-destructive truncate`,children:f})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{className:`text-2xl font-bold tabular-nums tracking-tight truncate`,children:I}),(r||l)&&(0,d.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 min-w-0`,children:[r&&(0,d.jsxs)(`span`,{className:(0,a.cn)(`flex items-center shrink-0 font-medium`,r.direction===`up`&&`text-emerald-600 dark:text-emerald-400`,r.direction===`down`&&`text-rose-600 dark:text-rose-400`,r.direction===`neutral`&&`text-muted-foreground`),children:[r.direction===`up`&&(0,d.jsx)(o.ArrowUpIcon,{className:`h-3 w-3 mr-1`}),r.direction===`down`&&(0,d.jsx)(o.ArrowDownIcon,{className:`h-3 w-3 mr-1`}),r.direction===`neutral`&&(0,d.jsx)(o.MinusIcon,{className:`h-3 w-3 mr-1`}),r.value,`%`]}),(0,d.jsx)(`span`,{className:`truncate min-w-0`,children:F})]})]})})]})},Be=({title:e,value:t,icon:n,trend:r,trendValue:s,description:c,className:l,loading:u,error:f,schema:p,bind:m,events:h,props:g,ariaLabel:_,ariaDescribedBy:v,dataSource:y,...b})=>{let x=n?(0,a.getLazyIcon)(n):null,{language:S}=(0,i.useObjectTranslation)();return(0,d.jsxs)(a.Card,{className:(0,a.cn)(`h-full`,l),...b,children:[(0,d.jsxs)(a.CardHeader,{className:`flex flex-row items-center justify-between space-y-0 pb-2`,children:[(0,d.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:(0,i.pickLocalized)(e,S)}),x&&(0,d.jsx)(x,{className:`h-4 w-4 text-muted-foreground`})]}),(0,d.jsx)(a.CardContent,{children:u?(0,d.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,"data-testid":`metric-card-loading`,children:[(0,d.jsx)(o.Loader2,{className:`h-4 w-4 animate-spin`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Loading…`})]}):f?(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,"data-testid":`metric-card-error`,role:`alert`,children:[(0,d.jsx)(o.AlertCircle,{className:`h-4 w-4 text-destructive shrink-0`}),(0,d.jsx)(`span`,{className:`text-xs text-destructive truncate`,children:f})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{className:`text-2xl font-bold`,children:t}),(r||s||c)&&(0,d.jsxs)(`p`,{className:`text-xs text-muted-foreground flex items-center mt-1`,children:[r&&s&&(0,d.jsxs)(`span`,{className:(0,a.cn)(`flex items-center mr-2`,r===`up`&&`text-green-500`,r===`down`&&`text-red-500`,r===`neutral`&&`text-yellow-500`),children:[r===`up`&&(0,d.jsx)(o.ArrowUpIcon,{className:`h-3 w-3 mr-1`}),r===`down`&&(0,d.jsx)(o.ArrowDownIcon,{className:`h-3 w-3 mr-1`}),r===`neutral`&&(0,d.jsx)(o.MinusIcon,{className:`h-3 w-3 mr-1`}),s]}),(0,i.pickLocalized)(c,S)]})]})})]})},Ve=({objectName:e,aggregate:o,filter:s,label:c,fallbackValue:l,trend:u,icon:f,className:p,description:m,dataSource:h,colorVariant:g,format:_,currency:v,prefix:y,suffix:b,invert:x,drillDown:S,title:C,compareTo:T,t:E,variant:D})=>{let O=(0,t.useContext)(r.SchemaRendererContext),k=h||O?.dataSource,[A,j]=(0,t.useState)(!1),[M,N]=(0,t.useState)(null),[P,F]=(0,t.useState)(null),[I,L]=(0,t.useState)(!1),[R,z]=(0,t.useState)(null),[B,ee]=(0,t.useState)(null);(0,t.useEffect)(()=>{let t=!0;if(!(!k||!e||typeof k.getObjectSchema!=`function`))return k.getObjectSchema(e).then(e=>{t&&ee(e)}).catch(()=>{}),()=>{t=!1}},[k,e]);let V=(0,t.useMemo)(()=>{let e=o?.field;if(!e||!B?.fields)return null;let t=B.fields;return Array.isArray(t)?t.find(t=>t?.name===e)||null:t[e]||null},[B,o?.field]),te=(0,t.useMemo)(()=>{if(_)return _;if(V){if(V.type===`currency`){let e=V.scale??0;return e>0?`0,0.${`0`.repeat(e)}`:`0,0`}if(V.type===`percent`)return`0,0%`;if(V.type===`number`||V.type===`integer`)return`0,0`}},[_,V]),{currency:ne}=(0,i.useLocalization)(),{language:H}=(0,i.useObjectTranslation)(),re=(0,t.useMemo)(()=>{if(v)return v;if(V?.type===`currency`)return(0,i.resolveFieldCurrency)(V,ne)},[v,V,ne]),U=(0,t.useMemo)(()=>o?JSON.stringify(o):``,[o]),ie=(0,r.useFilterScope)(),W=(0,t.useMemo)(()=>(0,n.resolveFilterPlaceholders)(s,ie),[s,ie]),G=(0,t.useMemo)(()=>W?JSON.stringify(W):``,[W]),ae=(0,t.useMemo)(()=>T?JSON.stringify(T):``,[T]),oe=(0,t.useCallback)(async(t,n)=>{if(o&&typeof t.aggregate==`function`){let r=await t.aggregate(e,{field:o.field,function:o.function,groupBy:o.groupBy||`_all`,filter:n}),i=Array.isArray(r)?r:[];if(i.length===0)return 0;if(o.function===`count`){let e=`${o.field}_count`;return i.reduce((t,n)=>t+(Number(n[e])||Number(n[o.field])||Number(n.count)||0),0)}let a=i[0];return a[`${o.field}_${o.function}`]??a[o.field]??a.value??0}if(typeof t.find==`function`){let r=await t.find(e,{$filter:n});return(Array.isArray(r)?r:r?.data||r?.records||[]).length}return null},[e,U]),se=(0,t.useCallback)(async(t,r)=>{if(!(!t||!e)){r.current&&(L(!0),z(null));try{let e=T?(0,n.shiftFilterByCompareTo)(s,T):null,[i,a]=await Promise.all([oe(t,W),e?oe(t,e):Promise.resolve(null)]);if(i===null)return;r.current&&(N(i),F(typeof a==`number`&&Number.isFinite(a)?a:null))}catch(e){console.error(`[ObjectMetricWidget] Fetch error:`,e),r.current&&z(e instanceof Error?e.message:`Failed to load metric`)}finally{r.current&&L(!1)}}},[e,U,G,ae,oe]);(0,t.useEffect)(()=>{let t={current:!0};return k&&e?se(k,t):(N(null),z(null)),()=>{t.current=!1}},[k,e,se]);let q=M===null?k?`—`:l??`—`:M;x&&typeof q==`number`&&isFinite(q)&&q>=0&&q<=1&&(q=1-q);let J=(0,t.useMemo)(()=>{if(!T||typeof M!=`number`||!Number.isFinite(M)||P===null)return;let e=w(M,P);if(!e)return;let t=(0,n.compareToTrendLabelKey)(T,s),r=`dashboard.trend.${t}`,i={vsPreviousPeriod:`vs previous period`,vsLastWeek:`vs last week`,vsLastMonth:`vs last month`,vsLastQuarter:`vs last quarter`,vsLastYear:`vs last year`,vsYesterday:`vs yesterday`},a=E?E(r,i[t]||t):i[t]||t;return{value:e.value,direction:e.direction,label:a}},[T,M,P,s,E])??u,Y=(0,n.isDrillEnabled)(S)&&!!e&&!!k,ce=(0,t.useMemo)(()=>{let e=(0,i.pickLocalized)(c,H),t=(0,i.pickLocalized)(C,H);return(0,n.resolveDrillTitle)(S,{},t||e||`Details`)},[S,c,C,H]),X=(0,t.useMemo)(()=>{if(!Y)return null;let t=S?.target??`drawer`,n=S?.report,i=n&&typeof n==`object`&&(Array.isArray(n.columns)||`objectName`in n),o=i?null:(0,d.jsx)(K,{objectName:e,filter:W,onNavigate:()=>j(!1)}),s;if(i){let e=n.filter,t=e?W?{$and:[e,W]}:e:W,i={type:`spec-report`,...n,filter:t};s=(0,d.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,d.jsx)(r.SchemaRenderer,{schema:i})})}else s=(0,d.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,d.jsx)(r.SchemaRenderer,{schema:{type:`object-data-table`,objectName:e,filter:W,pageSize:25,drillDown:{enabled:!0,mode:`record`,target:`dialog`}}})});return t===`dialog`?(0,d.jsx)(a.Dialog,{open:!0,onOpenChange:e=>!e&&j(!1),children:(0,d.jsxs)(a.DialogContent,{className:`max-w-5xl`,children:[(0,d.jsxs)(a.DialogHeader,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,d.jsx)(a.DialogTitle,{children:ce}),o]}),s]})}):(0,d.jsx)(a.Sheet,{open:!0,onOpenChange:e=>!e&&j(!1),children:(0,d.jsxs)(a.SheetContent,{side:`right`,className:`w-full sm:max-w-2xl md:max-w-3xl lg:max-w-5xl flex flex-col`,children:[(0,d.jsxs)(a.SheetHeader,{className:`flex-row items-center justify-between gap-4 pr-8`,children:[(0,d.jsx)(a.SheetTitle,{children:ce}),o]}),(0,d.jsx)(`div`,{className:`flex-1 overflow-hidden mt-2`,children:s})]})})},[Y,S,e,W,ce]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(ze,{label:c,value:q,trend:J,icon:f,className:p,description:m,loading:I,error:R,colorVariant:g,format:te,currency:re,prefix:y,suffix:b,variant:D,onClick:Y?()=>j(!0):void 0}),A&&X]})};function He(){return(0,i.useSafeTranslate)()(`dashboard.total`,`Total`)}function Ue(){return(0,i.useSafeTranslate)()(`dashboard.noDataAvailable`,`No data available`)}function We(e,t){if(!t)return String(e);let n=``,r=!1,i,a=t,o=a.match(/^([^0-9.,#]*)/);if(o&&o[1]){let e=o[1];n=e.replace(`,`,``),e.includes(`,`)&&(r=!0),a=a.slice(o[1].length)}a.includes(`,`)&&(r=!0,a=a.replace(/,/g,``));let s=a.match(/\.(\d+)f?/);s&&(i=Number(s[1]),a=a.slice(s[0].length));let c=a.replace(/[0-9#.f]/g,``),l=i===void 0?String(e):e.toFixed(i);if(r){let[e,t]=l.split(`.`),r=e.replace(/\B(?=(\d{3})+(?!\d))/g,`,`);return n+(t===void 0?r:`${r}.${t}`)+c}return n+l+c}var Ge=`—`;function Ke(e,t){return e===``?Ge:t?.[e]??e}var qe=Object.freeze([]),Je=new Set([`sum`,`count`,`avg`,`min`,`max`]);function Ye(e,t){if(e.length===0)return 0;switch(t){case`sum`:return e.reduce((e,t)=>e+t,0);case`count`:return e.length;case`avg`:return e.reduce((e,t)=>e+t,0)/e.length;case`min`:return Math.min(...e);case`max`:return Math.max(...e);default:return NaN}}var Xe=({schema:e,className:r,rowLabels:i,columnLabels:o,rowFieldLabel:s,onDrillDown:c})=>{let{title:l,rowField:u,columnField:f,valueField:p,aggregation:m=`sum`,data:h=qe,showRowTotals:g=!1,showColumnTotals:_=!1,format:v,columnColors:y,drillDown:b}=e,x=He(),S=Ue(),C=(0,n.isDrillEnabled)(b)&&typeof c==`function`,w=e=>{C&&c({...e,rowLabel:e.rowKey===void 0?e.rowLabel:i?.[e.rowKey]??e.rowKey,colLabel:e.colKey===void 0?e.colLabel:o?.[e.colKey]??e.colKey})},T=e=>t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},E=C?`cursor-pointer hover:bg-accent/40 focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring focus-visible:outline-offset-[-2px]`:``,D=Array.isArray(h)?h:qe,{rowKeys:O,colKeys:k,matrix:A,rowTotals:j,colTotals:M,grandTotal:N}=(0,t.useMemo)(()=>{let e=new Map,t=new Map,n={};for(let r of D){let i=String(r[u]??``),a=String(r[f]??``),o=Number(r[p])||0;e.set(i,!0),t.set(a,!0),n[i]||(n[i]={}),n[i][a]||(n[i][a]=[]),n[i][a].push(o)}let r=Array.from(e.keys()),i=Array.from(t.keys()),a={},o={},s={};for(let e of r){a[e]={};let t=[];for(let r of i){let i=n[e]?.[r]??[],o=Ye(i,m);a[e][r]=o,t.push(...i),!s[r]&&s[r]}o[e]=Ye(t,m)}for(let e of i){let t=[];for(let i of r){let r=n[i]?.[e]??[];t.push(...r)}s[e]=Ye(t,m)}let c=[];for(let e of D)c.push(Number(e[p])||0);return{rowKeys:r,colKeys:i,matrix:a,rowTotals:o,colTotals:s,grandTotal:Ye(c,m)}},[D,u,f,p,m]),P=e=>We(e,v);return Je.has(m)?D.length===0?(0,d.jsxs)(`div`,{className:(0,a.cn)(`overflow-auto`,r),children:[l&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold mb-2`,children:l}),(0,d.jsx)(a.DataEmptyState,{"data-testid":`pivot-empty-state`,className:`py-8 gap-2 [&>h3]:hidden`,icon:(0,d.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,className:`h-8 w-8 opacity-40`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,d.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`7`}),(0,d.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`7`}),(0,d.jsx)(`rect`,{x:`3`,y:`14`,width:`7`,height:`7`}),(0,d.jsx)(`rect`,{x:`14`,y:`14`,width:`7`,height:`7`})]}),iconWrapperClassName:``,title:``,description:S})]}):(0,d.jsxs)(`div`,{className:(0,a.cn)(`overflow-auto`,r),children:[l&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold mb-2`,children:l}),(0,d.jsxs)(`table`,{className:`w-full text-sm border-collapse table-auto`,role:`table`,children:[(0,d.jsx)(`thead`,{children:(0,d.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,d.jsx)(`th`,{className:`text-left p-2 font-medium text-muted-foreground whitespace-nowrap`,children:s||u}),k.map(e=>{let t=()=>w({scope:`column`,colKey:e});return(0,d.jsx)(`th`,{className:(0,a.cn)(`text-right p-2 font-medium whitespace-nowrap`,e===``&&`italic text-muted-foreground/70`,y?.[e]??`text-muted-foreground`,E),title:e===``?`${f}: (empty)`:`${f}: ${e}`,role:C?`button`:void 0,tabIndex:C?0:void 0,onClick:C?t:void 0,onKeyDown:C?T(t):void 0,"aria-label":C?`Drill into ${f}: ${e||`(empty)`}`:void 0,children:Ke(e,o)},e)}),g&&(0,d.jsx)(`th`,{className:`text-right p-2 font-semibold text-muted-foreground bg-muted/20 whitespace-nowrap`,children:x})]})}),(0,d.jsx)(`tbody`,{children:O.map(e=>(0,d.jsxs)(`tr`,{className:`border-b border-border/50 hover:bg-muted/30`,children:[(0,d.jsx)(`td`,{className:(0,a.cn)(`p-2 font-medium whitespace-nowrap`,e===``&&`italic text-muted-foreground/70`,E),role:C?`button`:void 0,tabIndex:C?0:void 0,onClick:C?()=>w({scope:`row`,rowKey:e}):void 0,onKeyDown:C?T(()=>w({scope:`row`,rowKey:e})):void 0,"aria-label":C?`Drill into ${u}: ${e||`(empty)`}`:void 0,children:Ke(e,i)}),k.map(t=>{let n=A[e]?.[t]??0,r=()=>w({scope:`cell`,rowKey:e,colKey:t,value:n});return(0,d.jsx)(`td`,{className:(0,a.cn)(`text-right p-2 tabular-nums`,y?.[t],E),role:C?`button`:void 0,tabIndex:C?0:void 0,onClick:C?r:void 0,onKeyDown:C?T(r):void 0,"aria-label":C?`Drill into ${u}=${e||`(empty)`}, ${f}=${t||`(empty)`}`:void 0,children:P(n)},t)}),g&&(0,d.jsx)(`td`,{className:(0,a.cn)(`text-right p-2 font-semibold tabular-nums bg-muted/20`,E),role:C?`button`:void 0,tabIndex:C?0:void 0,onClick:C?()=>w({scope:`row`,rowKey:e,value:j[e]??0}):void 0,onKeyDown:C?T(()=>w({scope:`row`,rowKey:e,value:j[e]??0})):void 0,children:P(j[e]??0)})]},e))}),_&&(0,d.jsx)(`tfoot`,{children:(0,d.jsxs)(`tr`,{className:`border-t-2 border-border font-semibold bg-muted/40`,children:[(0,d.jsx)(`td`,{className:`p-2`,children:x}),k.map(e=>(0,d.jsx)(`td`,{className:(0,a.cn)(`text-right p-2 tabular-nums`,E),role:C?`button`:void 0,tabIndex:C?0:void 0,onClick:C?()=>w({scope:`column`,colKey:e,value:M[e]??0}):void 0,onKeyDown:C?T(()=>w({scope:`column`,colKey:e,value:M[e]??0})):void 0,children:P(M[e]??0)},e)),g&&(0,d.jsx)(`td`,{className:(0,a.cn)(`text-right p-2 tabular-nums font-bold`,E),role:C?`button`:void 0,tabIndex:C?0:void 0,onClick:C?()=>w({scope:`total`,value:N}):void 0,onKeyDown:C?T(()=>w({scope:`total`,value:N})):void 0,children:P(N)})]})})]})]}):(0,d.jsxs)(`div`,{className:(0,a.cn)(`overflow-auto`,r),"data-testid":`pivot-unsupported-aggregation`,children:[l&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold mb-2`,children:l}),(0,d.jsx)(`div`,{role:`alert`,className:`flex flex-col items-center justify-center py-8 text-destructive`,children:(0,d.jsxs)(`p`,{className:`text-xs`,children:[`Unsupported aggregation “`,String(m),`” — this pivot table renders`,` `,[...Je].join(`, `),`.`]})})]})},Ze=Object.freeze([]),Qe=({schema:e,dataSource:o,className:s})=>{let c=(0,t.useContext)(r.SchemaRendererContext),l=o||c?.dataSource,u=(0,r.useDataScope)(e.bind),[f,p]=(0,t.useState)([]),[m,h]=(0,t.useState)(!1),[g,_]=(0,t.useState)(null),[v,y]=(0,t.useState)({}),[b,x]=(0,t.useState)({}),[S,C]=(0,t.useState)(null),{fieldLabel:w,fieldOptionLabel:T}=(0,i.useSafeFieldLabel)();(0,t.useEffect)(()=>{if(!l||!e.objectName)return;let t=l.getObjectSchema;if(typeof t!=`function`)return;let n=!0;return Promise.resolve(t.call(l,e.objectName)).then(t=>{if(!n||!t?.fields)return;let r=e.objectName,i={},a={};for(let[e,n]of Object.entries(t.fields)){let t=n?.label?String(n.label):e;a[e]=w(r,e,t);let o=n?.options;if(Array.isArray(o)&&o.length>0){let t={};for(let n of o)if(n&&n.value!==void 0&&n.label!==void 0){let i=String(n.value),a=String(n.label);t[i]=T(r,e,i,a)}Object.keys(t).length>0&&(i[e]=t)}}y(i),x(a)}).catch(()=>{}),()=>{n=!1}},[l,e.objectName,w,T]);let E=(0,r.useFilterScope)();(0,t.useEffect)(()=>{let t=!0;return e.objectName&&!u&&(!e.data||e.data.length===0)&&(async()=>{if(!(!l||!e.objectName)){t&&(h(!0),_(null));try{let r;if(typeof l.find==`function`){let t=await l.find(e.objectName,{$filter:(0,n.resolveFilterPlaceholders)(e.filter,E)});r=(0,n.extractRecords)(t)}else return;t&&p(r)}catch(e){console.error(`[ObjectPivotTable] Fetch error:`,e),t&&_(e instanceof Error?e.message:`Failed to load data`)}finally{t&&h(!1)}}})(),()=>{t=!1}},[e.objectName,l,u,e.data,e.filter,E]);let D=u||e.data||f,O=Array.isArray(D)?D:Ze;if(m&&O.length===0)return(0,d.jsxs)(`div`,{className:(0,a.cn)(`overflow-auto`,s),"data-testid":`pivot-loading`,children:[e.title&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold mb-2`,children:e.title}),(0,d.jsxs)(`div`,{className:`space-y-2 p-2`,children:[(0,d.jsxs)(`div`,{className:`flex gap-2`,children:[(0,d.jsx)(a.Skeleton,{className:`h-6 w-24`}),(0,d.jsx)(a.Skeleton,{className:`h-6 w-20`}),(0,d.jsx)(a.Skeleton,{className:`h-6 w-20`}),(0,d.jsx)(a.Skeleton,{className:`h-6 w-20`})]}),[1,2,3].map(e=>(0,d.jsxs)(`div`,{className:`flex gap-2`,children:[(0,d.jsx)(a.Skeleton,{className:`h-5 w-24`}),(0,d.jsx)(a.Skeleton,{className:`h-5 w-20`}),(0,d.jsx)(a.Skeleton,{className:`h-5 w-20`}),(0,d.jsx)(a.Skeleton,{className:`h-5 w-20`})]},e))]})]});if(g)return(0,d.jsxs)(`div`,{className:(0,a.cn)(`overflow-auto`,s),"data-testid":`pivot-error`,children:[e.title&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold mb-2`,children:e.title}),(0,d.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-destructive`,"data-testid":`pivot-error-message`,children:[(0,d.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,d.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,d.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,d.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]}),(0,d.jsx)(`p`,{className:`text-xs`,children:g})]})]});if(!l&&e.objectName&&O.length===0)return(0,d.jsxs)(`div`,{className:(0,a.cn)(`overflow-auto`,s),children:[e.title&&(0,d.jsx)(`h3`,{className:`text-sm font-semibold mb-2`,children:e.title}),(0,d.jsx)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:(0,d.jsxs)(`p`,{className:`text-xs`,children:[`No data source available for “`,e.objectName,`”`]})})]});let k={...e,data:O},A=e.rowField?v[e.rowField]:void 0,j=e.columnField?v[e.columnField]:void 0,M=e.rowField?b[e.rowField]:void 0,N=e.drillDown,P=(0,n.isDrillEnabled)(N)?e=>C(e):void 0;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(Xe,{schema:k,className:s,rowLabels:A,columnLabels:j,rowFieldLabel:M,onDrillDown:P}),(()=>{if(!S||!e.objectName)return null;let t=(0,n.computeDrillFilter)(N,S,{rowField:e.rowField,columnField:e.columnField}),r={...e.filter||{},...t},i=(0,n.resolveDrillTitle)(N,S,e.title||`Details`);return(0,d.jsx)(ae,{open:!0,onClose:()=>C(null),title:i,target:N?.target??`drawer`,objectName:e.objectName,filter:r,dataSource:l,columns:N?.columns,maxRows:N?.maxRows,report:N?.report})})()]})},$e={"dashboard.config.breadcrumb.dashboard":`Dashboard`,"dashboard.config.breadcrumb.configuration":`Configuration`,"dashboard.config.breadcrumb.widget":`Widget`,"dashboard.config.breadcrumb.chart":`Chart`,"dashboard.config.breadcrumb.table":`Table`,"dashboard.config.breadcrumb.pivotTable":`Pivot table`,"dashboard.config.section.general":`General`,"dashboard.config.section.layout":`Layout`,"dashboard.config.section.data":`Data`,"dashboard.config.section.dataBinding":`Data Binding`,"dashboard.config.section.appearance":`Appearance`,"dashboard.config.field.title":`Title`,"dashboard.config.field.description":`Description`,"dashboard.config.field.columns":`Columns`,"dashboard.config.field.gap":`Gap`,"dashboard.config.field.rowHeight":`Row height (px)`,"dashboard.config.field.autoRefresh":`Auto refresh`,"dashboard.config.field.showDescription":`Show description`,"dashboard.config.field.theme":`Theme`,"dashboard.config.field.widgetType":`Widget type`,"dashboard.config.field.colorVariant":`Color variant`,"dashboard.config.field.dataset":`Dataset`,"dashboard.config.field.dimensions":`Dimensions`,"dashboard.config.field.values":`Values`,"dashboard.config.field.width":`Width (columns)`,"dashboard.config.field.height":`Height (rows)`,"dashboard.config.placeholder.dashboardTitle":`Dashboard title`,"dashboard.config.placeholder.dashboardDescription":`Short summary shown under the title`,"dashboard.config.placeholder.widgetTitle":`Widget title`,"dashboard.config.placeholder.widgetDescription":`Widget description`,"dashboard.config.placeholder.datasetName":`Dataset name`,"dashboard.config.placeholder.selectDataset":`Select dataset…`,"dashboard.config.placeholder.searchDatasets":`Search datasets…`,"dashboard.config.placeholder.addDimension":`Add dimension…`,"dashboard.config.placeholder.addMeasure":`Add measure…`,"dashboard.config.placeholder.searchMembers":`Search…`,"dashboard.config.empty.datasets":`No datasets found.`,"dashboard.config.empty.dimensions":`No dimensions selected.`,"dashboard.config.empty.measures":`No measures selected.`,"dashboard.config.empty.nothingToAdd":`Nothing left to add.`,"dashboard.config.help.dataset":`The semantic-layer dataset this widget binds to (ADR-0021).`,"dashboard.config.help.dimensions":`Group/split the values by these dataset dimensions.`,"dashboard.config.help.dimensionsPivot":`Group/split fields. The last dimension spreads across as columns.`,"dashboard.config.help.values":`Measure(s) from the dataset to display (at least one).`,"dashboard.config.action.add":`Add`,"dashboard.config.action.remove":`Remove {{name}}`,"dashboard.config.refresh.off":`Off`,"dashboard.config.refresh.every30s":`Every 30s`,"dashboard.config.refresh.every1m":`Every 1 min`,"dashboard.config.refresh.every5m":`Every 5 min`,"dashboard.config.refresh.every15m":`Every 15 min`,"dashboard.config.refresh.every30m":`Every 30 min`,"dashboard.config.refresh.every1h":`Every 1 hour`,"dashboard.config.themeOption.light":`Light`,"dashboard.config.themeOption.dark":`Dark`,"dashboard.config.themeOption.auto":`Auto`,"dashboard.config.widgetType.metric":`Metric`,"dashboard.config.widgetType.bar":`Bar Chart`,"dashboard.config.widgetType.horizontalBar":`Horizontal Bar`,"dashboard.config.widgetType.line":`Line Chart`,"dashboard.config.widgetType.pie":`Pie Chart`,"dashboard.config.widgetType.donut":`Donut Chart`,"dashboard.config.widgetType.area":`Area Chart`,"dashboard.config.widgetType.scatter":`Scatter Plot`,"dashboard.config.widgetType.funnel":`Funnel`,"dashboard.config.widgetType.table":`Table`,"dashboard.config.widgetType.pivot":`Pivot Table`,"dashboard.config.color.default":`Default`,"dashboard.config.color.blue":`Blue`,"dashboard.config.color.teal":`Teal`,"dashboard.config.color.orange":`Orange`,"dashboard.config.color.purple":`Purple`,"dashboard.config.color.success":`Success`,"dashboard.config.color.warning":`Warning`,"dashboard.config.color.danger":`Danger`},et=(0,i.createSafeTranslation)($e,`dashboard.config.section.general`);function tt(e){return[{value:`0`,label:e(`dashboard.config.refresh.off`)},{value:`30`,label:e(`dashboard.config.refresh.every30s`)},{value:`60`,label:e(`dashboard.config.refresh.every1m`)},{value:`300`,label:e(`dashboard.config.refresh.every5m`)},{value:`900`,label:e(`dashboard.config.refresh.every15m`)},{value:`1800`,label:e(`dashboard.config.refresh.every30m`)},{value:`3600`,label:e(`dashboard.config.refresh.every1h`)}]}function nt(e){return[{value:`light`,label:e(`dashboard.config.themeOption.light`)},{value:`dark`,label:e(`dashboard.config.themeOption.dark`)},{value:`auto`,label:e(`dashboard.config.themeOption.auto`)}]}function rt(e){return{breadcrumb:[e(`dashboard.config.breadcrumb.dashboard`),e(`dashboard.config.breadcrumb.configuration`)],sections:[{key:`layout`,title:e(`dashboard.config.section.layout`),collapsible:!0,fields:[{key:`columns`,label:e(`dashboard.config.field.columns`),type:`slider`,defaultValue:3,min:1,max:12,step:1},{key:`gap`,label:e(`dashboard.config.field.gap`),type:`slider`,defaultValue:4,min:0,max:16,step:1},{key:`rowHeight`,label:e(`dashboard.config.field.rowHeight`),type:`slider`,defaultValue:120,min:40,max:320,step:10}]},{key:`data`,title:e(`dashboard.config.section.data`),collapsible:!0,fields:[{key:`refreshInterval`,label:e(`dashboard.config.field.autoRefresh`),type:`select`,defaultValue:`0`,options:tt(e)}]},{key:`appearance`,title:e(`dashboard.config.section.appearance`),collapsible:!0,defaultCollapsed:!0,fields:[{key:`title`,label:e(`dashboard.config.field.title`),type:`input`,placeholder:e(`dashboard.config.placeholder.dashboardTitle`)},{key:`description`,label:e(`dashboard.config.field.description`),type:`textarea`,placeholder:e(`dashboard.config.placeholder.dashboardDescription`)},{key:`showDescription`,label:e(`dashboard.config.field.showDescription`),type:`switch`,defaultValue:!0},{key:`theme`,label:e(`dashboard.config.field.theme`),type:`select`,defaultValue:`auto`,options:nt(e)}]}]}}function it({open:e,onClose:n,config:r,onSave:i,onFieldChange:o}){let{t:s}=et(),{draft:c,isDirty:l,updateField:u,discard:f}=(0,a.useConfigDraft)(r,{onUpdate:o}),p=t.useMemo(()=>rt(s),[s]);return(0,d.jsx)(a.ConfigPanelRenderer,{open:e,onClose:n,schema:p,draft:c,isDirty:l,onFieldChange:u,onSave:()=>i(c),onDiscard:f})}function at(e){return[{value:`metric`,label:e(`dashboard.config.widgetType.metric`)},{value:`bar`,label:e(`dashboard.config.widgetType.bar`)},{value:`horizontal-bar`,label:e(`dashboard.config.widgetType.horizontalBar`)},{value:`line`,label:e(`dashboard.config.widgetType.line`)},{value:`pie`,label:e(`dashboard.config.widgetType.pie`)},{value:`donut`,label:e(`dashboard.config.widgetType.donut`)},{value:`area`,label:e(`dashboard.config.widgetType.area`)},{value:`scatter`,label:e(`dashboard.config.widgetType.scatter`)},{value:`funnel`,label:e(`dashboard.config.widgetType.funnel`)},{value:`table`,label:e(`dashboard.config.widgetType.table`)},{value:`pivot`,label:e(`dashboard.config.widgetType.pivot`)}]}function ot(e){return[{value:`default`,label:e(`dashboard.config.color.default`)},{value:`blue`,label:e(`dashboard.config.color.blue`)},{value:`teal`,label:e(`dashboard.config.color.teal`)},{value:`orange`,label:e(`dashboard.config.color.orange`)},{value:`purple`,label:e(`dashboard.config.color.purple`)},{value:`success`,label:e(`dashboard.config.color.success`)},{value:`warning`,label:e(`dashboard.config.color.warning`)},{value:`danger`,label:e(`dashboard.config.color.danger`)}]}var st=[`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`scatter`,`funnel`],ct=[`metric`,`gauge`,`solid-gauge`,`kpi`,`bullet`];function lt(e){return!!e&&st.includes(e)}function ut(e){return!!e&&!ct.includes(e)}function dt(e,t){return t===`pivot`?e(`dashboard.config.breadcrumb.pivotTable`):t===`table`?e(`dashboard.config.breadcrumb.table`):lt(t)?e(`dashboard.config.breadcrumb.chart`):e(`dashboard.config.breadcrumb.widget`)}function ft({names:e,options:n,placeholder:r,emptyText:i,onChange:s}){let{t:c}=et(),[l,u]=t.useState(``),f=t.useMemo(()=>new Set(e),[e]),p=t.useMemo(()=>n.filter(e=>!f.has(e.value)),[n,f]),m=t=>{let n=t.trim();!n||f.has(n)||(s([...e,n]),u(``))},h=t=>s(e.filter(e=>e!==t));return(0,d.jsxs)(`div`,{className:`space-y-1.5`,children:[e.length===0?(0,d.jsx)(`p`,{className:`rounded border border-dashed px-2 py-1.5 text-center text-[11px] text-muted-foreground`,children:i}):(0,d.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>(0,d.jsxs)(`span`,{"data-testid":`dataset-name-chip-${e}`,className:(0,a.cn)(`inline-flex items-center gap-1 rounded bg-muted px-1.5 py-0.5`,`font-mono text-[11px] text-foreground`),children:[e,(0,d.jsx)(`button`,{type:`button`,"aria-label":c(`dashboard.config.action.remove`,{name:e}),className:`text-muted-foreground hover:text-foreground`,onClick:()=>h(e),children:(0,d.jsx)(o.X,{className:`h-3 w-3`})})]},e))}),p.length>0?(0,d.jsx)(a.Combobox,{options:p,value:``,onValueChange:m,placeholder:r,searchPlaceholder:c(`dashboard.config.placeholder.searchMembers`),emptyText:c(`dashboard.config.empty.nothingToAdd`),className:`h-7 w-full text-xs`}):(0,d.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,d.jsx)(a.Input,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m(l))},placeholder:r,className:`h-7 flex-1 text-xs`}),(0,d.jsx)(a.Button,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 px-2 text-xs`,onClick:()=>m(l),disabled:!l.trim(),children:c(`dashboard.config.action.add`)})]})]})}function pt(e,t,n){let r=t??[],i=r.length>0,o=r.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),s=e=>typeof e==`string`?r.find(t=>t.name===e):void 0,c=e(`dashboard.config.field.dataset`),l=e(`dashboard.config.help.dataset`),u=i?{key:`dataset`,label:c,type:`custom`,helpText:l,render:(t,n)=>(0,d.jsx)(a.ConfigRow,{label:c,children:(0,d.jsx)(`div`,{"data-testid":`config-field-dataset`,children:(0,d.jsx)(a.Combobox,{options:o,value:t??``,onValueChange:n,placeholder:e(`dashboard.config.placeholder.selectDataset`),searchPlaceholder:e(`dashboard.config.placeholder.searchDatasets`),emptyText:e(`dashboard.config.empty.datasets`),className:`h-7 w-40 text-xs`})})})}:{key:`dataset`,label:c,type:`input`,placeholder:e(`dashboard.config.placeholder.datasetName`),helpText:l},f=e(`dashboard.config.field.dimensions`),p={key:`dimensions`,label:f,type:`custom`,visibleWhen:e=>ut(e.type),helpText:e(n===`pivot`?`dashboard.config.help.dimensionsPivot`:`dashboard.config.help.dimensions`),render:(t,n,r)=>{let i=(s(r.dataset)?.dimensions??[]).map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));return(0,d.jsx)(a.ConfigRow,{label:f,children:(0,d.jsx)(`div`,{"data-testid":`config-field-dimensions`,className:`w-40`,children:(0,d.jsx)(ft,{names:Array.isArray(t)?t:[],options:i,placeholder:e(`dashboard.config.placeholder.addDimension`),emptyText:e(`dashboard.config.empty.dimensions`),onChange:n})})})}},m=e(`dashboard.config.field.values`),h={key:`values`,label:m,type:`custom`,helpText:e(`dashboard.config.help.values`),render:(t,n,r)=>{let i=(s(r.dataset)?.measures??[]).map(e=>({value:e.name,label:e.aggregate?`${e.label??e.name} · ${e.aggregate}`:e.label??e.name}));return(0,d.jsx)(a.ConfigRow,{label:m,children:(0,d.jsx)(`div`,{"data-testid":`config-field-values`,className:`w-40`,children:(0,d.jsx)(ft,{names:Array.isArray(t)?t:[],options:i,placeholder:e(`dashboard.config.placeholder.addMeasure`),emptyText:e(`dashboard.config.empty.measures`),onChange:n})})})}};return{breadcrumb:[e(`dashboard.config.breadcrumb.dashboard`),dt(e,n)],sections:[{key:`general`,title:e(`dashboard.config.section.general`),fields:[{key:`title`,label:e(`dashboard.config.field.title`),type:`input`,placeholder:e(`dashboard.config.placeholder.widgetTitle`)},{key:`description`,label:e(`dashboard.config.field.description`),type:`input`,placeholder:e(`dashboard.config.placeholder.widgetDescription`)},{key:`type`,label:e(`dashboard.config.field.widgetType`),type:`select`,options:at(e),defaultValue:`metric`}]},{key:`data`,title:e(`dashboard.config.section.dataBinding`),collapsible:!0,fields:[u,p,h]},{key:`layout`,title:e(`dashboard.config.section.layout`),collapsible:!0,fields:[{key:`layoutW`,label:e(`dashboard.config.field.width`),type:`slider`,min:1,max:12,step:1,defaultValue:1},{key:`layoutH`,label:e(`dashboard.config.field.height`),type:`slider`,min:1,max:6,step:1,defaultValue:1}]},{key:`appearance`,title:e(`dashboard.config.section.appearance`),collapsible:!0,defaultCollapsed:!0,fields:[{key:`colorVariant`,label:e(`dashboard.config.field.colorVariant`),type:`select`,options:ot(e),defaultValue:`default`}]}]}}var mt=[`title`,`description`];function ht(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function gt(e,t,n){let r=e;for(let a of mt){let o=t?.[a];if(!ht(o))continue;let s=e[a];typeof s==`string`&&(r===e&&(r={...e}),r[a]=s===(0,i.pickLocalized)(o,n)?o:(0,i.setLocalized)(o,n,s))}return r}var _t=[`actionUrl`,`actionType`,`actionIcon`],vt=[`object`,`categoryField`,`categoryGranularity`,`valueField`,`aggregate`,`aggregation`,`rowField`,`columnField`,`xAxisField`,`yAxisFields`,`xAxisLabel`,`yAxisLabel`,`measures`,`rowSortBy`,`rowSortOrder`,`columnSortBy`,`columnSortOrder`,`showRowLabels`,`showRowTotals`,`showColumnLabels`,`showColumnTotals`,`format`,`showLegend`,`searchable`,`pagination`];function yt(e){let t=e.type,n={...e};for(let e of vt)delete n[e];for(let e of _t)delete n[e];return ut(t)||delete n.dimensions,n}function bt({open:e,onClose:n,config:r,onSave:o,onFieldChange:s,headerExtra:c,datasets:l,datasetsLoading:u}){let{t:f,language:p}=et(),m=t.useMemo(()=>({...r,title:typeof r.title==`object`?(0,i.pickLocalized)(r.title,p):r.title,description:typeof r.description==`object`?(0,i.pickLocalized)(r.description,p):r.description}),[r,p]),h=t.useCallback((e,t)=>{if(!s)return;let n=r?.[e];s(e,mt.includes(e)&&ht(n)&&typeof t==`string`?(0,i.setLocalized)(n,p,t):t)},[s,r,p]),{draft:g,isDirty:_,updateField:v,discard:y}=(0,a.useConfigDraft)(m,{onUpdate:h}),b=t.useMemo(()=>pt(f,l,g.type),[f,l,g.type]);return(0,d.jsx)(a.ConfigPanelRenderer,{open:e,onClose:n,schema:b,draft:g,isDirty:_,onFieldChange:v,onSave:()=>o(yt(gt(g,r,p))),onDiscard:y,headerExtra:c})}function xt({schema:e,config:n,onConfigSave:r,onWidgetSave:i,onRefresh:s,recordCount:c,defaultConfigOpen:l=!1,className:u,datasets:f,datasetsLoading:p}){let[m,h]=(0,t.useState)(l),[g,_]=(0,t.useState)(null),[v,y]=(0,t.useState)(e),[b,x]=(0,t.useState)(0);(0,t.useEffect)(()=>{y(e),x(e=>e+1)},[e]);let S=t.useMemo(()=>{if(!g||!v.widgets)return null;let e=v.widgets.find(e=>(e.id||e.title)===g);if(!e)return null;let t=e;return{id:e.id??``,title:e.title??``,description:e.description??``,type:e.type??``,dataset:typeof t.dataset==`string`?t.dataset:``,dimensions:Array.isArray(t.dimensions)?t.dimensions:[],values:Array.isArray(t.values)?t.values:[],colorVariant:e.colorVariant??`default`,layoutW:e.layout?.w??1,layoutH:e.layout?.h??1}},[g,b]),C=(0,t.useCallback)(e=>{_(e),h(!0)},[]),w=(0,t.useCallback)(()=>{_(null)},[]),T=(0,t.useCallback)((e,t)=>{g&&y(n=>n.widgets?{...n,widgets:n.widgets.map(n=>(n.id||n.title)===g?e===`layoutW`?{...n,layout:{...n.layout||{},w:t}}:e===`layoutH`?{...n,layout:{...n.layout||{},h:t}}:{...n,[e]:t}:n)}:n)},[g]),E=(0,t.useCallback)(e=>{g&&i&&i(g,e),_(null),x(e=>e+1)},[g,i]),D=(0,t.useCallback)(()=>{h(e=>!e),_(null)},[]);return(0,d.jsxs)(`div`,{className:(0,a.cn)(`flex h-full w-full`,u),"data-testid":`dashboard-with-config`,children:[(0,d.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-auto relative`,children:[(0,d.jsx)(`div`,{className:`absolute top-2 right-2 z-10`,children:(0,d.jsxs)(a.Button,{size:`sm`,variant:m?`default`:`outline`,onClick:D,"data-testid":`dashboard-config-toggle`,children:[(0,d.jsx)(o.Settings,{className:`h-3.5 w-3.5 mr-1`}),`Settings`]})}),(0,d.jsx)(Ae,{schema:v,onRefresh:s,recordCount:c,designMode:m,selectedWidgetId:g,onWidgetClick:C})]}),m&&(0,d.jsx)(`div`,{className:`relative shrink-0`,children:g&&S?(0,d.jsx)(bt,{open:!0,onClose:w,config:S,onSave:E,onFieldChange:T,datasets:f,datasetsLoading:p}):(0,d.jsx)(it,{open:!0,onClose:()=>h(!1),config:n,onSave:r})})]})}n.ComponentRegistry.register(`dashboard`,Ae,{namespace:`view`,label:`Dashboard`,category:`Complex`,icon:`layout-dashboard`,inputs:[{name:`widgets`,type:`array`,label:`Widgets`,description:`The widget tree — the spec’s DashboardWidget[]. Each widget binds a dataset (ADR-0021) and may carry a layout ({ x, y, w, h }) and filterBindings. When omitted the dashboard renders an empty grid.`},{name:`label`,type:[`string`,`object`],label:`Label`,description:'Display name, shown as the header title when `header` is declared — a string or an inline per-locale map such as { en, "zh-CN" }. Spec-canonical spelling; the legacy `title` spelling is not authoring surface.'},{name:`description`,type:[`string`,`object`],label:`Description`,description:"Header description shown under the title — a string or an inline per-locale map. Rendered only when `header` is declared and `header.showDescription` is not false."},{name:`header`,type:`object`,label:`Header`,description:`Header block: { showTitle?, showDescription?, actions? }. Strict — the contract rejects any other key. Renders nothing (zero pixels) when everything it would show is suppressed.`},{name:`globalFilters`,type:`array`,label:`Global Filters`,description:`Dashboard-level filter bar — the spec’s GlobalFilter[]. Filter values live as dashboard variables (readable in widget expressions as page.<name>) and are AND-merged into each bound widget’s query per its filterBindings.`},{name:`dateRange`,type:`object`,label:`Date Range`,description:'Built-in date-range filter: { field?, defaultRange?, allowCustomRange? }. `defaultRange` takes the spec’s date presets plus "custom"; the bound field defaults to created_at.'},{name:`refreshInterval`,type:`number`,label:`Refresh Interval`,description:`Auto-refresh period in seconds. Zero or a negative value disables the timer, and it only runs when the host wires an onRefresh handler.`},{name:`columns`,type:`number`,label:`Columns`,defaultValue:3},{name:`gap`,type:`number`,label:`Gap`,defaultValue:4},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{columns:3,widgets:[]}}),n.ComponentRegistry.register(`metric`,ze,{namespace:`plugin-dashboard`,label:`Metric Widget`,category:`Dashboard`,inputs:[{name:`label`,type:`string`,label:`Label`},{name:`value`,type:`string`,label:`Value`}]}),n.ComponentRegistry.register(`metric-card`,Be,{namespace:`plugin-dashboard`,label:`Metric Card`,category:`Dashboard`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`value`,type:`string`,label:`Value`,required:!0},{name:`icon`,type:`string`,label:`Icon (Lucide name)`},{name:`trend`,type:`enum`,label:`Trend`,enum:[{label:`Up`,value:`up`},{label:`Down`,value:`down`},{label:`Neutral`,value:`neutral`}]},{name:`trendValue`,type:`string`,label:`Trend Value (e.g., +12%)`},{name:`description`,type:`string`,label:`Description`}],defaultProps:{title:`Metric`,value:`0`}});var St={filter:!0},Ct=({schema:e,...t})=>(0,d.jsx)(r.ElementDataSourceGate,{schema:e,mapping:St,dataSource:t.dataSource,testId:`object-metric`,errorTitle:`This metric’s data source could not be resolved`,children:e=>(0,d.jsx)(Ve,{...t,objectName:e?.objectName??t.objectName,filter:e?.filter??t.filter})});n.ComponentRegistry.register(`object-metric`,Ct,{namespace:`plugin-dashboard`,label:`Object Metric`,category:`Dashboard`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`label`,type:`string`,label:`Label`},{name:`aggregate`,type:`object`,label:`Aggregate`,description:`Aggregation config: { field, function, groupBy }`},{name:`icon`,type:`string`,label:`Icon (Lucide name)`},{name:`description`,type:`string`,label:`Description`,description:`Helper text rendered under the value.`},{name:`title`,type:`string`,label:`Drill-down Title`,description:"Heading of the drill-down panel. Defaults to `label` — set it only when the records list wants a different name from the tile."},{name:`filter`,type:`array`,label:`Filter`,description:`Criteria the aggregation is scoped by. The same filter narrows the drill-down list, so the number and the records behind it always agree.`},{name:`colorVariant`,type:`enum`,label:`Color Variant`,enum:[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`],description:"Colour of the icon container. Semantic, not decorative: `success` / `warning` / `danger` should track what the number means."},{name:`variant`,type:`enum`,label:`Layout Variant`,enum:[`card`,`bare`],description:"`card` draws the tile’s own surface; `bare` drops it, for a metric already sitting inside a card."},{name:`format`,type:`string`,label:`Number Format`,description:"Numeral-style format pattern, e.g. `0,0`, `$0,0`, `0%`. Use `currency` instead of hard-coding a currency symbol here."},{name:`currency`,type:`string`,label:`Currency Code`,description:"ISO 4217 code, e.g. `USD`. Enables locale-aware currency formatting of the value."},{name:`prefix`,type:`string`,label:`Prefix`,description:`Static text placed before the formatted value.`},{name:`suffix`,type:`string`,label:`Suffix`,description:`Static text placed after the formatted value.`},{name:`invert`,type:`boolean`,label:`Invert`,description:"Display `1 - value` — for gauges whose good direction is down, such as error rate shown as uptime."},{name:`fallbackValue`,type:`string`,label:`Fallback Value`,description:`Value shown when no data source resolves. For static/demo tiles; a bound metric should not need it.`},{name:`trend`,type:`object`,label:`Trend`,description:"Static trend badge: `{ value, label, direction }`. Use `compareTo` instead when the trend should be computed from data."},{name:`compareTo`,type:`object`,label:`Compare To`,description:'Period-over-period comparison, `{ kind: "previousPeriod" }` or `{ kind: "previousYear" }` — the computed alternative to a static `trend`.'},{name:`drillDown`,type:`object`,label:`Drill Down`,description:`Click-through config that opens the records behind the number.`}],defaultProps:{label:`Metric`}}),n.ComponentRegistry.register(`pivot`,Xe,{namespace:`plugin-dashboard`,label:`Pivot Table`,category:`Dashboard`,icon:`table-2`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`rowField`,type:`string`,label:`Row Field`,required:!0},{name:`columnField`,type:`string`,label:`Column Field`,required:!0},{name:`valueField`,type:`string`,label:`Value Field`,required:!0},{name:`aggregation`,type:`enum`,label:`Aggregation`,enum:[{label:`Sum`,value:`sum`},{label:`Count`,value:`count`},{label:`Average`,value:`avg`},{label:`Min`,value:`min`},{label:`Max`,value:`max`}]},{name:`showRowTotals`,type:`boolean`,label:`Show Row Totals`},{name:`showColumnTotals`,type:`boolean`,label:`Show Column Totals`},{name:`format`,type:`string`,label:`Number Format`}],defaultProps:{rowField:``,columnField:``,valueField:``,aggregation:`sum`,data:[]}});var wt={filter:!0},Tt=({schema:e,...t})=>(0,d.jsx)(r.ElementDataSourceGate,{schema:e,mapping:wt,dataSource:t.dataSource,testId:`object-pivot`,errorTitle:`This pivot table’s data source could not be resolved`,children:e=>(0,d.jsx)(Qe,{...t,schema:e})});n.ComponentRegistry.register(`object-pivot`,Tt,{namespace:`plugin-dashboard`,label:`Object Pivot Table`,category:`Dashboard`,icon:`table-2`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`title`,type:`string`,label:`Title`},{name:`rowField`,type:`string`,label:`Row Field`,required:!0},{name:`columnField`,type:`string`,label:`Column Field`,required:!0},{name:`valueField`,type:`string`,label:`Value Field`,required:!0},{name:`aggregation`,type:`enum`,label:`Aggregation`,enum:[{label:`Sum`,value:`sum`},{label:`Count`,value:`count`},{label:`Average`,value:`avg`},{label:`Min`,value:`min`},{label:`Max`,value:`max`}]},{name:`showRowTotals`,type:`boolean`,label:`Show Row Totals`},{name:`showColumnTotals`,type:`boolean`,label:`Show Column Totals`},{name:`filter`,type:`array`,label:`Filter`},{name:`format`,type:`string`,label:`Number Format`}],defaultProps:{rowField:``,columnField:``,valueField:``,aggregation:`sum`}}),n.ComponentRegistry.register(`dashboard-grid`,Fe,{namespace:`plugin-dashboard`,label:`Dashboard Grid (Editable)`,category:`Complex`,icon:`layout-grid`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{title:`Dashboard`,widgets:[]}}),n.ComponentRegistry.register(`object-data-table`,G,{namespace:`plugin-dashboard`,label:`Object Data Table`,category:`Dashboard`,icon:`table`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`columns`,type:`array`,label:`Columns`},{name:`filter`,type:`array`,label:`Filter`},{name:`searchable`,type:`boolean`,label:`Searchable`},{name:`pagination`,type:`boolean`,label:`Pagination`}],defaultProps:{searchable:!1,pagination:!1}});var Et={dashboard:Ae,metric:ze,"metric-card":Be,"object-metric":Ct,pivot:Xe,"object-pivot":Tt,"dashboard-grid":Fe,"object-data-table":G};e.CONFIG_PANEL_DEFAULT_TRANSLATIONS=$e,e.DashboardConfigPanel=it,e.DashboardGridLayout=Fe,e.DashboardRenderer=Ae,e.DashboardWithConfig=xt,e.DrillDownDrawer=ae,e.MetricCard=Be,e.MetricWidget=ze,e.ObjectDataTable=G,e.ObjectMetricWidget=Ve,e.ObjectPivotTable=Qe,e.PivotTable=Xe,e.WidgetConfigPanel=bt,e.dashboardComponents=Et,e.useConfigPanelTranslation=et});
@@ -0,0 +1,41 @@
1
+ import { DashboardWidgetSchema } from '@object-ui/types';
2
+ /**
3
+ * The placeholder schema rendered in place of a retired inline-analytics widget.
4
+ *
5
+ * A `text` node rather than a thrown error or an empty box: it has to reach the
6
+ * author *inside the dashboard*, in the tile where the chart used to be, and it
7
+ * has to say what to do next — a placeholder that only signals "something is
8
+ * wrong" is a prettier blank. The wording is contract (one condition, one
9
+ * wording) and is pinned verbatim by both surfaces' `legacyRetired` suites.
10
+ */
11
+ export declare const LEGACY_RETIRED_WIDGET_SCHEMA: {
12
+ readonly type: "text";
13
+ readonly value: "This widget uses a retired data format. Edit it to bind a dataset.";
14
+ readonly variant: "caption";
15
+ readonly align: "center";
16
+ readonly className: "flex h-full w-full items-center justify-center rounded border border-dashed border-destructive/40 bg-destructive/5 p-4 text-center text-destructive";
17
+ };
18
+ /**
19
+ * Does this widget still carry the retired pre-ADR-0021 inline-analytics shape?
20
+ *
21
+ * True when all three hold, in this order:
22
+ *
23
+ * 1. no `dataset` — a dataset-bound widget is the CURRENT shape and renders
24
+ * through the governed `queryDataset` path;
25
+ * 2. no renderer-internal data — neither `widget.data` nor `options.data`, which
26
+ * covers both the static inline array and the live `provider: 'object'`
27
+ * nested config;
28
+ * 3. a top-level `object` — the retired binding itself.
29
+ *
30
+ * `||` (not `??`) between the two data spellings, preserving `DashboardRenderer`
31
+ * byte for byte.
32
+ *
33
+ * Step 1 is stated here rather than inherited from a caller's render fork:
34
+ * `DashboardRenderer` never reached the placeholder for a dataset-bound widget
35
+ * because `datasetBound` picks `DatasetWidget` at the render site regardless of
36
+ * what `getComponentSchema` returned — so naming the condition costs that
37
+ * surface no observable behavior, and it keeps the predicate true on its own
38
+ * terms for any surface that has no such fork.
39
+ */
40
+ export declare function isLegacyRetiredWidget(widget: DashboardWidgetSchema | null | undefined): boolean;
41
+ //# sourceMappingURL=legacyRetiredWidget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacyRetiredWidget.d.ts","sourceRoot":"","sources":["../src/legacyRetiredWidget.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B;;;;;;CAM/B,CAAC;AAoBX;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAM/F"}
@@ -64,7 +64,46 @@ export declare function isNumericFieldMeta(fieldMeta: Pick<FieldMeta, 'type' | '
64
64
  * field/format that declares no explicit code of its own, so both the table
65
65
  * cell and the record-detail drawer honor the tenant default.
66
66
  */
67
- export declare function renderFieldValue(value: any, fieldMeta: FieldMeta, tenantCurrency?: string): React.ReactNode;
68
- /** Whether a field is a relation/lookup (used to drive `$expand`). */
67
+ export declare function renderFieldValue(value: any, fieldMeta: FieldMeta, tenantCurrency?: string, displayLocale?: string): React.ReactNode;
68
+ /**
69
+ * Whether a field is a relation/lookup (used to drive `$expand`).
70
+ *
71
+ * THE GATE (objectui#4914, ruling B) runs ahead of the membership test.
72
+ * Measured before the ruling: `isLookupType('owner')` was `true` — a retired
73
+ * spelling holding first-class relation status. It answers `false` now, and
74
+ * says why once.
75
+ *
76
+ * The membership half is no longer a private table (objectui#5692). It used to
77
+ * be `new Set(['lookup', 'reference', 'master_detail', 'user'])`, one of TWO
78
+ * copies this package held — the other inline in `computeLookupExpand` — and
79
+ * neither derived from nor pinned against {@link EXPANDABLE_FIELD_TYPES}, the
80
+ * family `@object-ui/core` publishes for exactly this question. objectui#5312's
81
+ * claim to have converted "the LAST private copy" was false by these two: they
82
+ * predate that sweep and were outside its file surface.
83
+ *
84
+ * The convergence moved membership in two directions, each decided by
85
+ * measurement rather than by preference (objectui#5692):
86
+ *
87
+ * - `tree` is GAINED. A self-referencing hierarchy field is reference-bearing,
88
+ * it is a member of the spec's closed `FieldType`, and the form / grid road
89
+ * already `$expand`s it. The dashboard road giving it the same treatment is
90
+ * family behaviour restored, not a new decision.
91
+ * - `reference` is DROPPED, and dropping it is a no-op on spec-compliant data.
92
+ * The spelling is absent from `@objectstack/spec`'s closed `FieldType`
93
+ * vocabulary and is refused by `FieldSchema.safeParse` — measured with
94
+ * `lookup` / `master_detail` / `user` / `tree` as live controls and the
95
+ * retired `owner` plus a nonsense spelling as dead ones — so no
96
+ * spec-compliant object schema can declare a field whose stored type is
97
+ * `reference`. Where the spelling IS live it is a legacy DIALECT alias on the
98
+ * action-param surface, folded to `lookup` before any field-type data is read
99
+ * (`PARAM_TYPE_ALIASES` in `app-shell/src/utils/paramToField.ts`). Keeping it
100
+ * here would be a lenient renderer-side alias for off-spec metadata, which is
101
+ * what AGENTS.md #0.1 bans.
102
+ *
103
+ * Extending this surface later: OR in a second, surface-local set, the way the
104
+ * object form's `needsDataSourceWiring` does. Never
105
+ * `new Set([...EXPANDABLE_FIELD_TYPES, …])` — a copy re-forks the table, which
106
+ * is the defect this change removed, and the identity pin fails on it by design.
107
+ */
69
108
  export declare function isLookupType(t: unknown): boolean;
70
109
  //# sourceMappingURL=recordFields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"recordFields.d.ts","sourceRoot":"","sources":["../src/recordFields.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAY1B;;;GAGG;AACH,eAAO,MAAM,aAAa,aAIxB,CAAC;AAEH,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,OAAO,CAG9D;AAKD,+DAA+D;AAC/D,eAAO,MAAM,mBAAmB,aAE9B,CAAC;AAEH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAUxE;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAClG,wEAAwE;IACxE,SAAS,CAAC,EAAE;QACV,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,SAAS,CAoCtE;AAED,oFAAoF;AACpF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG,OAAO,CAKzF;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,GAAG,EACV,SAAS,EAAE,SAAS,EACpB,cAAc,CAAC,EAAE,MAAM,GACtB,KAAK,CAAC,SAAS,CAqBjB;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAEhD"}
1
+ {"version":3,"file":"recordFields.d.ts","sourceRoot":"","sources":["../src/recordFields.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAoB1B;;;GAGG;AACH,eAAO,MAAM,aAAa,aAIxB,CAAC;AAEH,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,OAAO,CAG9D;AAKD,+DAA+D;AAC/D,eAAO,MAAM,mBAAmB,aAE9B,CAAC;AAEH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAUxE;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAClG,wEAAwE;IACxE,SAAS,CAAC,EAAE;QACV,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,SAAS,CAoCtE;AAED,oFAAoF;AACpF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG,OAAO,CAKzF;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,GAAG,EACV,SAAS,EAAE,SAAS,EACpB,cAAc,CAAC,EAAE,MAAM,EAKvB,aAAa,CAAC,EAAE,MAAM,GACrB,KAAK,CAAC,SAAS,CAiDjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAMhD"}