@object-ui/plugin-dashboard 16.0.0 → 17.1.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.
@@ -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?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=new Set([`id`,`organization_id`,`tenant_id`,`created_at`,`updated_at`,`created_by`,`updated_by`,`deleted_at`,`deleted_by`,`version`,`_id`,`__typename`]);function w(e,t){return t&&(t.isSystem===!0||t.system===!0)?!0:C.has(e)}var T=new Set([`select`,`picklist`,`dropdown`,`status`]),E=new Set([`currency`,`money`,`number`,`integer`,`decimal`,`float`,`percent`,`percentage`]);function D(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 O(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&&T.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 k(e){return E.has(e.type)||typeof e.format==`string`&&/^[\$¥€£]|%$|0/.test(e.format)}function A(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+)%/)||[,``])[1].length;return(0,u.formatPercent)((e>1?e/100:e)*100,t)}return typeof r==`string`&&/[YMDHms]/.test(r)?(0,u.formatDate)(e,r):(0,d.jsx)((0,u.getCellRenderer)((0,u.resolveCellRendererType)(t)),{value:e,field:t})}var j=[`name`,`title`,`label`,`subject`,`display_name`,`full_name`];function M(e,t){if(t&&t.trim())return t;for(let t of j){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 N=({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=D(n),i;return i=o&&o.length>0?o:Object.keys(r).length>0?Object.keys(r).filter(e=>!w(e,r[e])):Object.keys(e).filter(e=>!e.startsWith(`_`)&&!w(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=O({accessorKey:n,label:o,def:i,objectName:t,fieldOptionLabel:f});return{key:n,label:o,node:A(e[n],s,p),numeric:k(s)}})},[e,n,t,o,u,f,p]);if(!e)return null;let h=M(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 P(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 F(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 I=({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`;try{let{t:e}=(0,r.useObjectTranslation)(),t=e(`dashboard.noDataAvailable`);t&&t!==`dashboard.noDataAvailable`&&(h=t);let n=e(`dashboard.noDataSourceFor`);n&&n!==`dashboard.noDataSourceFor`&&(g=n)}catch{}let[_,v]=(0,a.useState)([]),[y,b]=(0,a.useState)(null),[x,S]=(0,a.useState)(()=>!(Array.isArray(e.data)&&e.data.length>0)&&!!e.objectName),[C,T]=(0,a.useState)(null),E=e.drillDown,D=(0,t.isDrillEnabled)(E)&&(E?.mode??`record`)===`record`,[j,M]=(0,a.useState)(null),I=(0,a.useCallback)(e=>{M(e??null)},[]);(0,a.useEffect)(()=>{let n=!0;return e.objectName&&!f&&(!e.data||e.data.length===0)?(async()=>{if(!u||!e.objectName){n&&S(!1);return}n&&(S(!0),T(null));try{let r;if(typeof u.find==`function`){let n=F(e,y),i={$filter:(0,t.resolveDateMacros)(e.filter)};n.length&&(i.$expand=n),r=(0,t.extractRecords)(await u.find(e.objectName,i))}else return;n&&v(r)}catch(e){console.error(`[ObjectDataTable] Fetch error:`,e),n&&T(e instanceof Error?e.message:`Failed to load data`)}finally{n&&S(!1)}})():n&&S(!1),()=>{n=!1}},[e.objectName,u,f,e.data,e.filter,y]),(0,a.useEffect)(()=>{let t=!0;if(!(!u||!e.objectName||typeof u.getObjectSchema!=`function`))return u.getObjectSchema(e.objectName).then(e=>{t&&b(e)}).catch(()=>{}),()=>{t=!1}},[e.objectName,u]);let L=f||e.data||_,R=Array.isArray(L)?L:[],ee=(0,a.useMemo)(()=>{let t=e.objectName,n={};if(y?.fields){let e=y.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=O({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??(k(r)?`right`:void 0);if(typeof e.cell==`function`)return{...e,...r,align:i};let a=e=>A(e,r,c);return{...e,...r,align:i,cell:a}};if(e.columns&&e.columns.length>0){let n=P(e.columns);return(t?n.map(e=>({...e,header:p(t,e.accessorKey,e.header)})):n).map(i)}return R.length===0?[]:(Object.keys(n).length>0?Object.keys(n).filter(e=>!w(e,n[e])):Object.keys(R[0]).filter(e=>!e.startsWith(`_`)&&!w(e))).map(e=>i({header:r(e),accessorKey:e}))},[e.columns,e.objectName,R,y,p,m,c]);if(x&&R.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(C)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:C})]})});if(!u&&e.objectName&&R.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(R.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 z={...e,type:`data-table`,data:R,columns:ee,onRowClick:e.onRowClick??(D?I:void 0)},B=E?.title&&!E.title.includes("${")?E.title:void 0;return(0,d.jsxs)(`div`,{className:(0,i.cn)(`relative`,s),children:[(0,d.jsx)(i.RefreshIndicator,{active:x&&R.length>0}),(0,d.jsx)(n.SchemaRenderer,{schema:z,className:s}),D&&(0,d.jsx)(N,{record:j,objectName:e.objectName,objectSchema:y,fields:E?.columns,title:B,target:E?.target===`dialog`?`dialog`:`drawer`,onClose:()=>M(null)})]})},L=({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`})]})},R=({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)(L,{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;return(0,d.jsx)(n.SchemaRenderer,{schema:{...m,type:`spec-report`,report:{...m,filter:t},filter:t}})})():(0,d.jsx)(I,{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})]})})},ee=t.buildDatasetDrillFilter;function z(e,n,r){let i=[],a=[],o=new Set,s=new Set,c=new Map;return e.forEach((e,l)=>{let u=n.map(t=>String(e[t]??`∅`)).join(``),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(`${u} ${d}`,l)}),{rowHeaders:i,colHeaders:a,cellIndex:c}}function B(e){if(e==null)return``;let t=String(e);return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}function V(e){return e.map(e=>e.map(B).join(`,`)).join(`\r
2
- `)}function H(e,t){if(typeof document>`u`)return;let n=e&&e.trim()?e.trim():`export`,r=new Blob([`${V(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 te=new Set([`metric`,`kpi`,`gauge`,`solid-gauge`,`bullet`]),ne={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 re({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=te.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=(0,r.useSafeTranslate)(),{fieldLabel:x}=(0,r.useSafeFieldLabel)(),S=e?.filter,C=(0,a.useMemo)(()=>S&&typeof S==`object`&&Object.keys(S).length>0?(0,t.resolveDateMacros)(S):void 0,[S]),[w,T]=(0,a.useState)({status:`idle`,rows:[]}),[E,D]=(0,a.useState)(null),[O,k]=(0,a.useState)(null),[A,j]=(0,a.useState)(null);if((0,a.useEffect)(()=>{let e=s;if(!e||typeof e.queryDataset!=`function`){T({status:`error`,rows:[],error:b(`dashboard.datasetUnsupported`,`This data source does not support dataset queries.`)});return}if(u.length===0){T({status:`idle`,rows:[]});return}let t=!1;return T({status:`loading`,rows:[]}),e.queryDataset(c,{dimensions:l,measures:u,...C?{runtimeFilter:C}:{},...f?{compareTo:f}:{},...y?{totals:{groupings:y}}:{}}).then(e=>{t||T({status:`ok`,rows:Array.isArray(e?.rows)?e.rows:[],fields:Array.isArray(e?.fields)?e.fields:[],object:e?.object,dimensionFields:e?.dimensionFields,drillRawRows:Array.isArray(e?.drillRawRows)?e.drillRawRows:void 0,totals:Array.isArray(e?.totals)?e.totals:void 0})}).catch(e=>{t||T({status:`error`,rows:[],error:String(e?.message??e)})}),()=>{t=!0}},[`${p}|${c}|${l.join(`,`)}|${u.join(`,`)}|${JSON.stringify(S??null)}|${JSON.stringify(f??null)}`]),(0,a.useEffect)(()=>{if(m||h){k(null),j(null);return}let e=w.object;if(!e||l.length===0){k(null),j(null);return}let n=e=>w.dimensionFields&&w.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=(0,t.buildOptionColorMap)(a?.fields?.[n(l[0])]?.options),s={};for(let e of l){let r=(0,t.buildDimensionLabelMap)(a?.fields?.[n(e)]?.options);r&&(s[e]=r)}r||(k(o),j(Object.keys(s).length>0?s:null))}catch{r||(k(null),j(null))}})(),()=>{r=!0}},[w.object,w.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:b(`dashboard.pickMeasures`,`Pick measures (values) for this dataset widget.`)});if(w.status===`loading`||w.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:b(`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(w.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:w.error})]});if(w.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`}),b(`dashboard.noRows`,`No rows`)]});let{measureField:M,headerLabel:N}=(0,t.buildDatasetFieldHelpers)(w.fields,w.object,x),{object:P,dimensionFields:F,drillRawRows:I}=w,L=F?l.filter(e=>e in F):[],B=!!P&&L.length>0,V=(t,n)=>{if(!P||!F)return;let r=ee(I?.[t],L,F,C);D({filter:r,title:n||String(e?.title??``)})},re=E&&P?(0,d.jsx)(R,{open:!0,onClose:()=>D(null),title:E.title||String(e?.title??b(`dashboard.details`,`Details`)),objectName:P,filter:E.filter,dataSource:s}):null;if(m){let e=M(u[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)(w.rows[0]?.[u[0]]??0,e?.format,e?.currency)}),(0,d.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:N(u[0])})]})}if(h){let n=[...l,...u],r=(0,d.jsx)(`button`,{type:`button`,onClick:()=>H(String(e?.title??c??`export`),[n.map(e=>N(e)),...w.rows.map(e=>n.map(t=>{let n=e[t];return n==null?``:typeof n==`number`?n:String(n)}))]),"data-testid":`dataset-export`,title:b(`dashboard.exportCsv`,`Export CSV`),"aria-label":b(`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=z(w.rows,_,v),n=e.colHeaders.flatMap(e=>u.map(t=>({col:e,measure:t,header:u.length===1?e.label:`${e.label} · ${N(t)}`}))),a=(e,n)=>(0,t.formatMeasure)(e,M(n)?.format,M(n)?.currency),o=e=>w.totals?.find(t=>Array.isArray(t.dimensions)&&t.dimensions.join(`,`)===e.join(`,`))?.rows,s=new Map;for(let e of o(_)??[])s.set(_.map(t=>String(e[t]??`∅`)).join(``),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=b(`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:N(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} · ${N(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)),n.map(n=>{let r=e.cellIndex.get(`${t.id} ${n.col.id}`),o=r==null?void 0:w.rows[r],s=B&&r!=null,c=[...t.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`,s&&`cursor-pointer hover:bg-accent/40`),"data-testid":s?`dataset-drill-cell`:void 0,onClick:s?()=>V(r,c):void 0,children:o?a(o[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(t.id)?.[e],e)},`total-${e}`))]},t.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}`))]})]})]}),re]})}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:N(e)},e))})}),(0,d.jsx)(`tbody`,{children:w.rows.map((e,n)=>(0,d.jsx)(`tr`,{className:(0,i.cn)(`border-t`,B&&`cursor-pointer hover:bg-accent/40`),"data-testid":B?`dataset-drill-row`:void 0,onClick:B?()=>V(n,L.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],M(n)?.format,M(n)?.currency):(0,t.formatDimensionValue)(e[n])},n))},n))})]}),re]})}let U=ne[p]??`bar`,W=(0,t.relabelDimensions)(w.rows,A),{data:ie,xAxisKey:G,series:K}=(0,t.buildChartSeries)(W,l,u,w.fields),q=B?e=>{let n=(0,t.findChartSeriesRow)(W,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(` / `);V(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:U,data:ie,xAxisKey:G,series:K,...O?{categoryColors:O}:{}},onChartClick:q,onSegmentClick:q}),re]})}var U=`__all__`,W=`__custom__`;function ie(e,t){if(e){if(e.preset)return t(e.preset);if(e.from||e.to)return`${e.from??`…`} – ${e.to??`…`}`}}function G(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function K({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?W:U);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===U?s(void 0):e===W?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:ie(n,p)??c(`dashboard.filters.allTime`,`All time`)})]}),(0,d.jsxs)(i.SelectContent,{children:[(0,d.jsx)(i.SelectItem,{value:U,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:W,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:G(e.from)}:{},...e?.to?{to:G(e.to)}:{}})}})})]})]})}function q({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):U,onValueChange:e=>n(e===U?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:U,children:s(`dashboard.filters.all`,`All`)}),f.map(e=>(0,d.jsx)(i.SelectItem,{value:e.value,children:e.label},e.value))]})]})}function J({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 ae({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)(K,{def:e,value:r,onChange:i},e.name):e.type===`select`||e.type===`lookup`?(0,d.jsx)(q,{def:e,value:r,onChange:i,dataSource:s},e.name):(0,d.jsx)(J,{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 oe({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});return(0,d.jsx)(`div`,{ref:u,style:{transform:l.CSS.Transform.toString(f),transition:p,opacity:m?.4:1,...n?{gridColumn:`span ${n.w}`,gridRow:`span ${n.h}`}:{}},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 se(e){return e?(0,i.getLazyIcon)(e):null}function Y(e){if(e!=null)return typeof e==`string`?e:e.defaultValue||e.key}var ce=[`hsl(var(--chart-1))`,`hsl(var(--chart-2))`,`hsl(var(--chart-3))`,`hsl(var(--chart-4))`,`hsl(var(--chart-5))`],le={column:`bar`,"stacked-bar":`bar`,"grouped-bar":`bar`,"bi-polar-bar":`bar`,spline:`line`,"step-line":`line`,"stacked-area":`area`,pyramid:`funnel`,bubble:`scatter`},ue=new Set([`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`scatter`,`funnel`,`radar`,`treemap`,`sankey`]),de=new Set([`gauge`,`solid-gauge`,`kpi`,`bullet`]),fe=new Set([`sunburst`,`word-cloud`,`choropleth`,`bubble-map`,`gl-map`,`heatmap`,`waterfall`,`box-plot`,`violin`,`candlestick`,`stock`]),pe=new Set([`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`funnel`,`scatter`,`treemap`,`sankey`]);function me(e){return pe.has(e)?{enabled:!0}:void 0}var he=new Set([`object-chart`,`object-metric`,`object-data-table`,`object-pivot`]),X=(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 T=(()=>{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})(),E=T,D=e.gap||4,O=e.columns!=null||T!==4,[k,A]=(0,a.useState)(!1),[j,M]=(0,a.useState)(!1),N=(0,a.useRef)(null),P=(0,a.useMemo)(()=>(0,t.resolveDashboardFilterDefs)(e),[e.globalFilters,e.dateRange]),{variables:F,setVariable:I,resetVariables:L}=(0,n.usePageVariables)(),[R,ee]=(0,a.useState)({});(0,a.useEffect)(()=>{if(P.length===0||!u||typeof u.getObjectSchema!=`function`)return;let t=Array.from(new Set((e.widgets??[]).map(e=>e.object).filter(e=>typeof e==`string`&&e.length>0))),n=!1;for(let e of t)u.getObjectSchema(e).then(t=>{if(n)return;let r=t?.fields;!r||typeof r!=`object`||ee(t=>({...t,[e]:new Set(Object.keys(r))}))}).catch(()=>{});return()=>{n=!0}},[P.length,u,e.widgets]);let{executeAction:z,engine:B}=(0,n.useActionEngine)({actions:(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])}),{dashboardLabel:V,dashboardDescription:H,dashboardActionLabel:te,widgetTitle:ne,widgetDescription:U,fieldLabel:W}=(0,n.useObjectLabel)(),{t:ie}=(0,r.useObjectTranslation)(),G=(0,a.useCallback)((e,t,n)=>n&&(!t||t===`value`||t===`count`||n===`count`)?ie(`report.aggregate.${n}`,{defaultValue:n}):e?W(e,t,t):t,[ie,W]),K=e.name,q=(0,a.useCallback)(e=>{if(!K)return e.label;let t=e.actionUrl||e.label;return te(K,t,e.label)},[K,te]),J=(0,a.useCallback)(e=>{let t=Y(e.title);return!K||!e.id||t===void 0?t:ne(K,e.id,t)},[K,ne]),pe=(0,a.useCallback)(e=>{let t=Y(e.description);return!K||!e.id?t:U(K,e.id,t)},[K,U]);(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=()=>M(window.innerWidth<768);return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let X=(0,a.useCallback)(()=>{f&&(A(!0),f(),setTimeout(()=>A(!1),600))},[f]);(0,a.useEffect)(()=>{if(!(!e.refreshInterval||e.refreshInterval<=0||!f))return N.current=setInterval(X,e.refreshInterval*1e3),()=>{N.current&&clearInterval(N.current)}},[e.refreshInterval,f,X]);let Z=(0,a.useCallback)((e,t)=>{!h||!_||!t||(e.stopPropagation(),_(t))},[h,_]),ge=(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]),Q=(0,a.useCallback)(e=>{!h||!_||e.target===e.currentTarget&&_(null)},[h,_]),$=!!(h&&v),_e=(0,s.useSensors)((0,s.useSensor)(s.PointerSensor,{activationConstraint:{distance:5}})),ve=(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]),ye=(e,r,o)=>{let s=e.type===`metric`||de.has(e.type||``),c=O?{w:Math.min(s?3:6,E),h:s?2:4}:void 0,l=e.layout??c,f=l?{...l,w:Math.min(l.w,E)}:void 0,p=!!e.dataset,m=()=>{if(e.component)return e.component;let t=e.type,n=e.options||{};if(t===`metric`&&e.object){let t=n.data,r=x(t)&&t.aggregate?{field:e.valueField||t.aggregate.field,function:e.aggregate||t.aggregate.function,groupBy:e.categoryField??t.aggregate.groupBy??`_all`}:e.aggregate?{field:e.valueField||`value`,function:e.aggregate,groupBy:e.categoryField||`_all`}:void 0;return{type:`object-metric`,objectName:e.object||(x(t)?t.object:void 0),aggregate:r,filter:(x(t)?t.filter:void 0)||e.filter,label:n.label||J(e)||``,fallbackValue:n.value,trend:n.trend,icon:n.icon,description:n.description,colorVariant:e.colorVariant,format:n.format,currency:n.currency,prefix:n.prefix,suffix:n.suffix,drillDown:n.drillDown??{enabled:!0},title:n.label||J(e)||``,compareTo:e.compareTo}}if(de.has(t||``)&&e.object){let t=e.aggregate?{field:e.valueField||`value`,function:e.aggregate,groupBy:e.categoryField||`_all`}:void 0;return{type:`object-metric`,objectName:e.object,aggregate:t,filter:e.filter,label:n.label||J(e)||``,fallbackValue:n.fallbackValue??n.value,icon:n.icon,description:n.description,colorVariant:e.colorVariant,format:n.format,currency:n.currency,prefix:n.prefix,suffix:n.suffix,invert:n.invert,compareTo:e.compareTo}}let r=t&&le[t]||t;if(r&&ue.has(r)){let t=e.data||n.data,i=e.categoryField||n.xField||`name`,a=e.valueField||n.yField||`value`;if(x(t)){let o=t.aggregate,s=(()=>{let t=e.categoryField||o?.groupBy;if(t)return e.categoryGranularity&&typeof t==`string`?{field:t,dateGranularity:e.categoryGranularity}:t})(),c=o?{field:e.valueField||o.field,function:e.aggregate||o.function,groupBy:s}:void 0,l=c?.field||a,u=e.object||t.object;return{type:`object-chart`,chartType:r,objectName:u,aggregate:c,filter:t.filter||e.filter,xAxisKey:i,series:[{dataKey:l,label:G(u,l,c?.function)}],colors:ce,drillDown:n.drillDown??me(r),compareTo:e.compareTo,className:`h-[200px] sm:h-[250px] md:h-[300px]`}}if(!t&&e.object){let t=e.categoryField||`name`,a=e.categoryGranularity?{field:t,dateGranularity:e.categoryGranularity}:t,o=e.aggregate?{field:e.valueField||`value`,function:e.aggregate,groupBy:a}:void 0,s=e.valueField||`value`;return{type:`object-chart`,chartType:r,objectName:e.object,aggregate:o,filter:e.filter,xAxisKey:i,series:[{dataKey:s,label:G(e.object,s,e.aggregate)}],colors:ce,drillDown:n.drillDown??me(r),compareTo:e.compareTo,className:`h-[200px] sm:h-[250px] md:h-[300px]`}}return{type:`chart`,chartType:r,data:Array.isArray(t)?t:t?.items||[],xAxisKey:i,series:[{dataKey:a,label:G(e.object,a,e.aggregate)}],colors:ce,className:`h-[200px] sm:h-[250px] md:h-[300px]`}}if(t===`table`){let t=e.data||n.data,r=x(t)||!t&&e.object?n.drillDown??{enabled:!0,mode:`record`}:void 0;if(x(t)){let{data:i,...a}=n;return{type:`object-data-table`,...a,objectName:e.object||t.object,dataProvider:t,filter:t.filter||e.filter,searchable:e.searchable??!1,pagination:e.pagination??!1,drillDown:r,className:`border-0`}}return!t&&e.object?{type:`object-data-table`,...n,objectName:e.object,filter:e.filter,searchable:e.searchable??!1,pagination:e.pagination??!1,drillDown:r,className:`border-0`}:{type:`data-table`,...n,data:t?.items||[],searchable:!1,pagination:!1,className:`border-0`}}if(t===`pivot`){let t=e.data||n.data,r=e,i={rowField:r.rowField??n.rowField,columnField:r.columnField??n.columnField,valueField:r.valueField??n.valueField,aggregation:r.aggregation??n.aggregation??`sum`,showRowTotals:r.showRowTotals??n.showRowTotals,showColumnTotals:r.showColumnTotals??n.showColumnTotals,format:r.format??n.format},a=(x(t)||!t&&e.object)&&n.drillDown===void 0?{...n,drillDown:{enabled:!0}}:n;if(x(t)){let{data:n,...r}=a;return{type:`object-pivot`,...r,...i,objectName:e.object||t.object,dataProvider:t,filter:t.filter||e.filter}}return!t&&e.object?{type:`object-pivot`,...a,...i,objectName:e.object,filter:e.filter}:{type:`pivot`,...n,...i,data:Array.isArray(t)?t:t?.items||[]}}if(t===`list`){let t=e.data||n.data,r=x(t)||!t&&e.object?n.drillDown??{enabled:!0,mode:`record`}:void 0;if(x(t)){let{data:i,...a}=n;return{type:`object-data-table`,...a,objectName:e.object||t.object,dataProvider:t,filter:t.filter||e.filter,searchable:!1,pagination:!1,drillDown:r,className:`border-0`}}return!t&&e.object?{type:`object-data-table`,...n,objectName:e.object,filter:e.filter,searchable:!1,pagination:!1,drillDown:r,className:`border-0`}:{type:`data-table`,...n,data:Array.isArray(t)?t:t?.items||[],searchable:!1,pagination:!1,className:`border-0`}}return t===`custom`?{type:`text`,value:"Custom widget — set `component` to a UIComponent schema.",variant:`caption`,align:`center`,className:`flex h-full w-full items-center justify-center rounded border border-dashed bg-muted/20 p-4 text-muted-foreground`}:t&&fe.has(t)?{type:`text`,value:`「${t}」chart type is not supported yet`,variant:`caption`,align:`center`,className:`flex h-full w-full items-center justify-center rounded border border-dashed bg-muted/20 p-4 text-muted-foreground`}:{...e,...n}},_=P.length>0?(0,t.buildWidgetScopedFilter)(e,P,F,typeof e.object==`string`?R[e.object]:void 0):void 0,v=(()=>{let e=m();return _&&e&&he.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=J(e),C=pe(e),w=e.id||S||`widget-${r}`,T=h&&g===e.id,D=h?{"data-testid":`dashboard-preview-widget-${e.id}`,"data-widget-id":e.id,role:`button`,tabIndex:0,"aria-selected":T,"aria-label":`Widget: ${S||`Widget ${r+1}`}`,onClick:t=>Z(t,e.id),onKeyDown:t=>ge(t,e.id,r)}:{},k=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`,T?`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,A=!j&&f&&!$?{gridColumn:`span ${f.w}`,gridRow:`span ${f.h}`}:void 0,M=b?(0,d.jsxs)(`div`,{className:(0,i.cn)(`h-full w-full`,h&&`relative`,k),style:A,...D,children:[p?(0,d.jsx)(`div`,{className:(0,i.cn)(`h-full w-full`,h&&`pointer-events-none`),children:(0,d.jsx)(re,{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`,k),style:A,...D,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)(re,{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)(oe,{id:e.id,gridSpan:!j&&f?{w:f.w,h:f.h}:void 0,children:M},w):(0,d.jsx)(a.Fragment,{children:M},w)},be=e.header&&(0,d.jsxs)(`div`,{className:`col-span-full mb-4`,children:[!S&&e.header.showTitle!==!1&&e.title&&(0,d.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:K?V({name:K,label:Y(e.title)}):Y(e.title)}),!S&&e.header.showDescription!==!1&&e.description&&(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:K?H({name:K,description:Y(e.description)}):Y(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=se(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}if(t===`modal`||t===`script`){let e=await z(n||r);e?.success||console.warn(`[DashboardRenderer] action failed`,e?.error);return}console.warn(`[DashboardRenderer] Unknown header actionType="${t}" for "${r}"`)},children:[n&&(0,d.jsx)(n,{className:`w-4 h-4 mr-1.5`}),q(e)]},t)})})]}),xe=P.length>0&&(0,d.jsx)(ae,{defs:P,values:F,onChange:I,onReset:L,dataSource:u,className:`mb-2`}),Se=p!==void 0&&(0,d.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[p.toLocaleString(),` records`]}),Ce=m?JSON.stringify(m):void 0,we=f&&(0,d.jsxs)(`div`,{className:(0,i.cn)(`flex items-center justify-end gap-3 mb-2`,!j&&`col-span-full`),children:[Se,(0,d.jsxs)(i.Button,{variant:`outline`,size:`sm`,onClick:X,disabled:k,"aria-label":`Refresh dashboard`,children:[(0,d.jsx)(o.RefreshCw,{className:(0,i.cn)(`h-4 w-4 mr-2`,k&&`animate-spin`)}),k?`Refreshing…`:`Refresh All`]})]}),Te=(0,a.useMemo)(()=>(e.widgets??[]).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]),De=(0,a.useMemo)(()=>(e.widgets??[]).filter(e=>e.type!==`metric`).map(e=>e.id).filter(e=>!!e),[e.widgets]);if(j){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":Ce,onClick:Q,...C,children:[be,xe,we,t.length>0&&(0,d.jsx)(`div`,{className:`grid grid-cols-2 gap-3`,onClick:Q,children:(0,d.jsx)(c.SortableContext,{items:Ee,strategy:c.rectSortingStrategy,disabled:!$,children:t.map((e,t)=>ye(e,t))})}),n.length>0&&(0,d.jsx)(`div`,{className:`flex flex-col gap-4`,onClick:Q,children:(0,d.jsx)(c.SortableContext,{items:De,strategy:c.verticalListSortingStrategy,disabled:!$,children:n.map((e,t)=>ye(e,t,!0))})})]});return $?(0,d.jsx)(s.DndContext,{sensors:_e,collisionDetection:s.closestCenter,onDragEnd:ve,children:r}):r}let Oe=(0,d.jsxs)(`div`,{ref:w,className:(0,i.cn)(`grid`,!O&&`auto-rows-min grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,l),style:{...O&&{gridTemplateColumns:`repeat(${E}, minmax(0, 1fr))`,gridAutoRows:`minmax(5rem, auto)`},gap:`${D*.25}rem`},"data-user-actions":Ce,onClick:Q,...C,children:[be,xe,we,(0,d.jsx)(c.SortableContext,{items:Te,strategy:c.rectSortingStrategy,disabled:!$,children:e.widgets?.map((e,t)=>ye(e,t))})]});return $?(0,d.jsx)(s.DndContext,{sensors:_e,collisionDetection:s.closestCenter,onDragEnd:ve,children:Oe}):Oe});X.displayName=`DashboardRendererInner`;var Z=(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)(X,{ref:r,...e}):(0,d.jsx)(n.PageVariablesProvider,{definitions:(0,t.dashboardFilterVariableDefs)(o),children:(0,d.jsx)(X,{ref:r,...e})})});Z.displayName=`DashboardRenderer`;function ge({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 Q=[`hsl(var(--chart-1))`,`hsl(var(--chart-2))`,`hsl(var(--chart-3))`,`hsl(var(--chart-4))`,`hsl(var(--chart-5))`];function $(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 _e(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 ve=({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(()=>_e(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(_e(e))},[w]);let T=a.useCallback((e,t)=>{C(t),r?.(e)},[r]),E=a.useCallback(()=>{s?s($(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(_e(e))},[e]),O=a.useCallback(e=>{if(e.component)return e.component;let t=e.type,n=e.options||{};if(t===`bar`||t===`horizontal-bar`||t===`line`||t===`area`||t===`pie`||t===`donut`||t===`scatter`||t===`funnel`){let r=e.data||n.data,i=e.categoryField||n.xField||`name`,a=e.valueField||n.yField||`value`;if(x(r)){let n=r.aggregate,o=n?{field:e.valueField||n.field,function:e.aggregate||n.function,groupBy:e.categoryField||n.groupBy}:void 0,s=o?.field||a;return{type:`object-chart`,chartType:t,objectName:e.object||r.object,aggregate:o,xAxisKey:i,series:[{dataKey:s}],colors:Q,className:`h-full`}}if(!r&&e.object){let n=e.aggregate?{field:e.valueField||`value`,function:e.aggregate,groupBy:e.categoryField||`name`}:void 0;return{type:`object-chart`,chartType:t,objectName:e.object,aggregate:n,xAxisKey:i,series:[{dataKey:e.valueField||`value`}],colors:Q,className:`h-full`}}return{type:`chart`,chartType:t,data:Array.isArray(r)?r:r?.items||[],xAxisKey:i,series:[{dataKey:a}],colors:Q,className:`h-full`}}if(t===`table`){let t=e.data||n.data;if(x(t)){let{data:r,...i}=n;return{type:`data-table`,...i,objectName:e.object||t.object,dataProvider:t,data:[],searchable:!1,pagination:!1,className:`border-0`}}return!t&&e.object?{type:`data-table`,...n,objectName:e.object,data:[],searchable:!1,pagination:!1,className:`border-0`}:{type:`data-table`,...n,data:t?.items||[],searchable:!1,pagination:!1,className:`border-0`}}if(t===`pivot`){let t=e.data||n.data;if(x(t)){let{data:r,...i}=n;return{type:`pivot`,...i,objectName:e.object||t.object,dataProvider:t,data:[]}}return{type:`pivot`,...n,data:Array.isArray(t)?t:t?.items||[]}}return{...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)(ge,{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||`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=O(e);return(0,d.jsx)(`div`,{className:`h-full`,children:e.type===`metric`?(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)})})]})},ye=(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 be(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 xe(e,t,n){if(e==null)return``;if(typeof e==`string`){let r=Number(e);return!isFinite(r)||e.trim()===``?e:xe(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 Se(e){if(e!=null)return typeof e==`string`?e:e.defaultValue||e.key}var Ce={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`},we={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`},Te=({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=Ce[f]||Ce.default,{t:x}=ye(),S=(0,a.useMemo)(()=>{let e=Se(c)||Se(n?.label);if(!e)return e;let t=be(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))?xe(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=we[f]||we.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:Se(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:Se(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 Ee(e){if(e!=null)return typeof e==`string`?e:e.defaultValue||e.key}var De=({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:Ee(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]}),Ee(s)]})]})})]})},Oe=({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,R]=(0,a.useState)(!1),[ee,z]=(0,a.useState)(null),[B,V]=(0,a.useState)(null);(0,a.useEffect)(()=>{let t=!0;if(!(!k||!e||typeof k.getObjectSchema!=`function`))return k.getObjectSchema(e).then(e=>{t&&V(e)}).catch(()=>{}),()=>{t=!1}},[k,e]);let H=(0,a.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,a.useMemo)(()=>{if(_)return _;if(H){if(H.type===`currency`){let e=H.scale??0;return e>0?`0,0.${`0`.repeat(e)}`:`0,0`}if(H.type===`percent`)return`0,0%`;if(H.type===`number`||H.type===`integer`)return`0,0`}},[_,H]),{currency:ne}=(0,r.useLocalization)(),re=(0,a.useMemo)(()=>{if(v)return v;if(H?.type===`currency`)return(0,r.resolveFieldCurrency)(H,ne)},[v,H,ne]),U=(0,a.useMemo)(()=>o?JSON.stringify(o):``,[o]),W=(0,a.useMemo)(()=>(0,t.resolveDateMacros)(s),[s]),ie=(0,a.useMemo)(()=>W?JSON.stringify(W):``,[W]),G=(0,a.useMemo)(()=>T?JSON.stringify(T):``,[T]),K=(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,U]),q=(0,a.useCallback)(async(n,r)=>{if(!(!n||!e)){r.current&&(R(!0),z(null));try{let e=T?(0,t.shiftFilterByCompareTo)(s,T):null,[i,a]=await Promise.all([K(n,W),e?K(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&&z(e instanceof Error?e.message:`Failed to load metric`)}finally{r.current&&R(!1)}}},[e,U,ie,G,K]);(0,a.useEffect)(()=>{let t={current:!0};return k&&e?q(k,t):(N(null),z(null)),()=>{t.current=!1}},[k,e,q]);let J=M===null?k?`—`:l??`—`:M;x&&typeof J==`number`&&isFinite(J)&&J>=0&&J<=1&&(J=1-J);let ae=(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,oe=(0,t.isDrillEnabled)(C)&&!!e&&!!k,se=(0,a.useMemo)(()=>{let e=typeof c==`string`?c:c?.defaultValue||``;return(0,t.resolveDrillTitle)(C,{},(typeof w==`string`?w:w?.defaultValue||``)||e||`Details`)},[C,c,w]),Y=(0,a.useMemo)(()=>{if(!oe)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)(L,{objectName:e,filter:W,onNavigate:()=>j(!1)}),s;if(a){let e=r.filter,t=e?W?{$and:[e,W]}:e:W;s=(0,d.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,d.jsx)(n.SchemaRenderer,{schema:{type:`spec-report`,...r,filter:t}})})}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:se}),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:se}),o]}),(0,d.jsx)(`div`,{className:`flex-1 overflow-hidden mt-2`,children:s})]})})},[oe,C,e,W,se]);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(Te,{label:c,value:J,trend:ae,icon:f,className:p,description:m,loading:I,error:ee,colorVariant:g,format:te,currency:re,prefix:y,suffix:b,variant:D,onClick:oe?()=>j(!0):void 0}),A&&Y]})};function ke(){return(0,r.useSafeTranslate)()(`dashboard.total`,`Total`)}function Ae(){return(0,r.useSafeTranslate)()(`dashboard.noDataAvailable`,`No data available`)}function je(e,t){if(!t)return String(e);let n=``,r=``,i=!1,a,o=t,s=o.match(/^([^0-9.,#]*)/);if(s&&s[1]){let e=s[1];n=e.replace(`,`,``),e.includes(`,`)&&(i=!0),o=o.slice(s[1].length)}o.includes(`,`)&&(i=!0,o=o.replace(/,/g,``));let c=o.match(/\.(\d+)f?/);c&&(a=Number(c[1]),o=o.slice(c[0].length)),r=o.replace(/[0-9#.f]/g,``);let l=a===void 0?String(e):e.toFixed(a);if(i){let[e,t]=l.split(`.`),i=e.replace(/\B(?=(\d{3})+(?!\d))/g,`,`);return n+(t===void 0?i:`${i}.${t}`)+r}return n+l+r}var Me=`—`;function Ne(e,t){return e===``?Me:t?.[e]??e}function Pe(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 e.reduce((e,t)=>e+t,0)}}var Fe=({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=ke(),S=Ae(),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=Pe(i,m);a[e][r]=o,t.push(...i),!s[r]&&s[r]}o[e]=Pe(t,m)}for(let e of i){let t=[];for(let i of r){let r=n[i]?.[e]??[];t.push(...r)}s[e]=Pe(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:Pe(c,m)}},[D,u,f,p,m]),P=e=>je(e,v);return 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:Ne(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:Ne(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)})]})})]})]})},Ie=({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]),(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`)r=(0,t.extractRecords)(await l.find(e.objectName,{$filter:(0,t.resolveDateMacros)(e.filter)}));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]);let O=u||e.data||f,k=Array.isArray(O)?O:[];if(m&&k.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&&k.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 A={...e,data:k},j=e.rowField?v[e.rowField]:void 0,M=e.columnField?v[e.columnField]:void 0,N=e.rowField?b[e.rowField]:void 0,P=e.drillDown,F=(0,t.isDrillEnabled)(P)?e=>C(e):void 0;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(Fe,{schema:A,className:s,rowLabels:j,columnLabels:M,rowFieldLabel:N,onDrillDown:F}),(()=>{if(!S||!e.objectName)return null;let n=(0,t.computeDrillFilter)(P,S,{rowField:e.rowField,columnField:e.columnField}),r={...e.filter||{},...n};return(0,d.jsx)(R,{open:!0,onClose:()=>C(null),title:(0,t.resolveDrillTitle)(P,S,e.title||`Details`),target:P?.target??`drawer`,objectName:e.objectName,filter:r,dataSource:l,columns:P?.columns,maxRows:P?.maxRows,report:P?.report})})()]})},Le={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 Re({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:Le,draft:o,isDirty:s,onFieldChange:c,onSave:()=>r(o),onDiscard:l})}var ze=[{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`}],Be=[{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`}],Ve=[{value:`count`,label:`Count`},{value:`sum`,label:`Sum`},{value:`avg`,label:`Average`},{value:`min`,label:`Min`},{value:`max`,label:`Max`}],He=[`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`scatter`,`funnel`],Ue=[`bar`,`horizontal-bar`,`line`,`area`,`scatter`],We=[`pie`,`donut`,`funnel`],Ge=[`metric`,...He],Ke=[...He],qe=[`pivot`,`metric`,`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`funnel`,`scatter`,`treemap`,`sankey`,`table`,`list`];function Je(e){return!!e&&He.includes(e)}function Ye(e){return!!e&&Ue.includes(e)}function Xe(e){return!!e&&Ke.includes(e)}function Ze(e){return!!e&&Ge.includes(e)}function Qe(e){return!!e&&qe.includes(e)}var $e=[{value:`drawer`,label:`Side drawer`},{value:`dialog`,label:`Center dialog`}],et=[{value:`group`,label:`Group`},{value:`value`,label:`Value`}],tt=[{value:`asc`,label:`↑`},{value:`desc`,label:`↓`}];function nt(e,t,n,r){return{key:e,label:t,type:`custom`,render:(a,o,s)=>(0,d.jsx)(i.ConfigRow,{label:t,children:(0,d.jsx)(`div`,{"data-testid":`config-field-${e}`,children:(0,d.jsx)(i.Combobox,{options:r??[],value:a??``,onValueChange:o,placeholder:n,searchPlaceholder:`Search fields…`,emptyText:`No fields found.`,className:`h-7 w-32 text-xs`,disabled:!s.object})})})}}function rt(e,t,n){let r=e&&e.length>0,a=r?{key:`object`,label:`Data source`,type:`custom`,render:(t,n)=>(0,d.jsx)(i.ConfigRow,{label:`Data source`,children:(0,d.jsx)(`div`,{"data-testid":`config-field-object`,children:(0,d.jsx)(i.Combobox,{options:e,value:t??``,onValueChange:n,placeholder:`Select object…`,searchPlaceholder:`Search objects…`,emptyText:`No objects found.`,className:`h-7 w-32 text-xs`})})})}:{key:`object`,label:`Data source`,type:`input`,placeholder:`Object name`},o=r?{...nt(`categoryField`,`Category field`,`Select field…`,t),helpText:`Group records by this field (one bar/slice/segment per value).`,visibleWhen:e=>Xe(e.type)}:{key:`categoryField`,label:`Category field`,type:`input`,placeholder:`e.g. status`,helpText:`Group records by this field (one bar/slice/segment per value).`,visibleWhen:e=>Xe(e.type)},s=r?{...nt(`valueField`,`Value field`,`Select field…`,t),helpText:`Field to aggregate (sum / average / min / max).`,visibleWhen:e=>Ze(e.type)&&(e.aggregate??`count`)!==`count`}:{key:`valueField`,label:`Value field`,type:`input`,placeholder:`e.g. amount`,helpText:`Field to aggregate (sum / average / min / max).`,visibleWhen:e=>Ze(e.type)&&(e.aggregate??`count`)!==`count`},c=r?nt(`rowField`,`Field`,`Select row field…`,t):{key:`rowField`,label:`Field`,type:`input`,placeholder:`e.g. owner`},l=r?nt(`columnField`,`Field`,`Select column field…`,t):{key:`columnField`,label:`Field`,type:`input`,placeholder:`e.g. stage`},u=r?nt(`valueField`,`Field`,`Select value field…`,t):{key:`valueField`,label:`Field`,type:`input`,placeholder:`e.g. amount`};return{breadcrumb:[`Dashboard`,{pivot:`Pivot table`,table:`Table`}[n??``]??(Je(n)?`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:ze,defaultValue:`metric`}]},{key:`data`,title:`Data Binding`,collapsible:!0,visibleWhen:e=>e.type!==`pivot`,fields:[a,o,s,{key:`aggregate`,label:`Aggregation`,type:`select`,options:Ve,defaultValue:`count`,helpText:`Count ignores Value field; Sum / Avg / Min / Max require it.`,visibleWhen:e=>Ze(e.type)}]},{key:`pivot-data`,title:`Data`,collapsible:!0,visibleWhen:e=>e.type===`pivot`,fields:[a]},{key:`pivot-rows`,title:`Rows`,collapsible:!0,visibleWhen:e=>e.type===`pivot`,fields:[c,{key:`rowSortBy`,label:`Sort by`,type:`icon-group`,options:et,defaultValue:`group`},{key:`rowSortOrder`,label:`Sort order`,type:`icon-group`,options:tt,defaultValue:`asc`},{key:`showRowLabels`,label:`Show label`,type:`switch`,defaultValue:!0},{key:`showRowTotals`,label:`Show totals`,type:`switch`,defaultValue:!1}]},{key:`pivot-columns`,title:`Columns`,collapsible:!0,visibleWhen:e=>e.type===`pivot`,fields:[l,{key:`columnSortBy`,label:`Sort by`,type:`icon-group`,options:et,defaultValue:`group`},{key:`columnSortOrder`,label:`Sort order`,type:`icon-group`,options:tt,defaultValue:`asc`},{key:`showColumnLabels`,label:`Show label`,type:`switch`,defaultValue:!0},{key:`showColumnTotals`,label:`Show totals`,type:`switch`,defaultValue:!1}]},{key:`pivot-values`,title:`Values`,collapsible:!0,visibleWhen:e=>e.type===`pivot`,fields:[u,{key:`aggregation`,label:`Aggregation`,type:`select`,options:Ve,defaultValue:`sum`},{key:`format`,label:`Number format`,type:`input`,placeholder:`e.g. $,.2f`}]},{key:`chart-axis`,title:`Axis & Series`,collapsible:!0,visibleWhen:e=>Ye(e.type),fields:[{key:`xAxisLabel`,label:`X-axis label`,type:`input`,placeholder:`e.g. Month`},{key:`yAxisLabel`,label:`Y-axis label`,type:`input`,placeholder:`e.g. Revenue`},{key:`showLegend`,label:`Show legend`,type:`switch`,defaultValue:!0}]},{key:`chart-legend`,title:`Display`,collapsible:!0,visibleWhen:e=>!!e.type&&We.includes(e.type),fields:[{key:`showLegend`,label:`Show legend`,type:`switch`,defaultValue:!0}]},{key:`table-options`,title:`Table options`,collapsible:!0,visibleWhen:e=>e.type===`table`,fields:[{key:`searchable`,label:`Searchable`,type:`switch`,defaultValue:!1},{key:`pagination`,label:`Pagination`,type:`switch`,defaultValue:!1}]},{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:`drill-down`,title:`Drill-down`,collapsible:!0,defaultCollapsed:!0,visibleWhen:e=>Qe(e.type),fields:[{key:`drillDownEnabled`,label:`Enable drill-down`,type:`switch`,defaultValue:!1,helpText:`When enabled, clicking a chart segment / pivot cell opens a filtered list of underlying records; clicking a table or list row opens that record.`},{key:`drillDownTarget`,label:`Open in`,type:`select`,options:$e,defaultValue:`drawer`,visibleWhen:e=>!!e.drillDownEnabled}]},{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:Be,defaultValue:`default`}]}]}}function it(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)}function at(e){let t=e.type,n={...e};return Xe(t)||delete n.categoryField,Ze(t)?(n.aggregate??`count`)===`count`&&delete n.valueField:(delete n.valueField,delete n.aggregate),Ye(t)||(delete n.xAxisLabel,delete n.yAxisLabel),t===`pivot`?(delete n.aggregate,delete n.categoryField):(delete n.rowField,delete n.columnField,delete n.aggregation,delete n.rowSortBy,delete n.rowSortOrder,delete n.columnSortBy,delete n.columnSortOrder,delete n.showRowLabels,delete n.showRowTotals,delete n.showColumnLabels,delete n.showColumnTotals,delete n.format),t!==`table`&&(delete n.searchable,delete n.pagination),Qe(t)||(delete n.drillDownEnabled,delete n.drillDownTarget),n}function ot({open:e,onClose:t,config:n,onSave:r,onFieldChange:o,headerExtra:s,availableObjects:c,availableFields:l}){let{draft:u,isDirty:f,updateField:p,discard:m}=(0,i.useConfigDraft)(a.useMemo(()=>({...n,title:typeof n.title==`object`?it(n.title):n.title,description:typeof n.description==`object`?it(n.description):n.description}),[n]),{onUpdate:o});return(0,d.jsx)(i.ConfigPanelRenderer,{open:e,onClose:t,schema:a.useMemo(()=>rt(c,l,u.type),[c,l,u.type]),draft:u,isDirty:f,onFieldChange:p,onSave:()=>r(at(u)),onDiscard:m,headerExtra:s})}function st({schema:e,config:t,onConfigSave:n,onWidgetSave:r,onRefresh:s,recordCount:c,defaultConfigOpen:l=!1,className:u}){let[f,p]=(0,a.useState)(l),[m,h]=(0,a.useState)(null),[g,_]=(0,a.useState)(e),[v,y]=(0,a.useState)(0);(0,a.useEffect)(()=>{_(e),y(e=>e+1)},[e]);let b=a.useMemo(()=>{if(!m||!g.widgets)return null;let e=g.widgets.find(e=>(e.id||e.title)===m);if(!e)return null;let t=e.options||{};return{...t,id:e.id??``,title:e.title??``,description:e.description??``,type:e.type??``,object:e.object??``,categoryField:e.categoryField??t.categoryField??``,valueField:e.valueField??t.valueField??``,aggregate:e.aggregate??t.aggregate??``,colorVariant:e.colorVariant??t.colorVariant??`default`,actionUrl:e.actionUrl??t.actionUrl??``,drillDownEnabled:t.drillDown?.enabled??!!(e.object&&(e.type===`pivot`||e.type===`metric`||e.type===`bar`||e.type===`horizontal-bar`||e.type===`line`||e.type===`area`||e.type===`pie`||e.type===`donut`||e.type===`funnel`)),drillDownTarget:t.drillDown?.target??`drawer`,layoutW:e.layout?.w??1,layoutH:e.layout?.h??1}},[m,v]),x=(0,a.useCallback)(e=>{h(e),p(!0)},[]),S=(0,a.useCallback)(()=>{h(null)},[]),C=(0,a.useCallback)((e,t)=>{m&&_(n=>n.widgets?{...n,widgets:n.widgets.map(n=>{if((n.id||n.title)!==m)return n;if(e===`layoutW`)return{...n,layout:{...n.layout||{},w:t}};if(e===`layoutH`)return{...n,layout:{...n.layout||{},h:t}};if(e===`drillDownEnabled`||e===`drillDownTarget`){let r=n.options?.drillDown??{},i=e===`drillDownEnabled`?{...r,enabled:!!t}:{...r,target:t};return{...n,options:{...n.options||{},drillDown:i}}}return{...n,[e]:t}})}:n)},[m]),w=(0,a.useCallback)(e=>{if(m&&r){let{drillDownEnabled:t,drillDownTarget:n,...i}=e,a={...i};(t||n)&&(a.options={...i.options||{},drillDown:{...i.options?.drillDown||{},...t===void 0?{}:{enabled:!!t},...n===void 0?{}:{target:n}}}),r(m,a)}h(null),y(e=>e+1)},[m,r]),T=(0,a.useCallback)(()=>{p(e=>!e),h(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:f?`default`:`outline`,onClick:T,"data-testid":`dashboard-config-toggle`,children:[(0,d.jsx)(o.Settings,{className:`h-3.5 w-3.5 mr-1`}),`Settings`]})}),(0,d.jsx)(Z,{schema:g,onRefresh:s,recordCount:c,designMode:f,selectedWidgetId:m,onWidgetClick:x})]}),f&&(0,d.jsx)(`div`,{className:`relative shrink-0`,children:m&&b?(0,d.jsx)(ot,{open:!0,onClose:S,config:b,onSave:w,onFieldChange:C}):(0,d.jsx)(Re,{open:!0,onClose:()=>p(!1),config:t,onSave:n})})]})}t.ComponentRegistry.register(`dashboard`,Z,{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`,Te,{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`,De,{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`,Oe,{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`,Fe,{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`,Ie,{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`,ve,{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`,I,{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 ct={DashboardRenderer:Z,DashboardGridLayout:ve,MetricWidget:Te,MetricCard:De,ObjectMetricWidget:Oe,PivotTable:Fe,ObjectPivotTable:Ie,ObjectDataTable:I,DashboardConfigPanel:Re,WidgetConfigPanel:ot,DashboardWithConfig:st};e.DashboardConfigPanel=Re,e.DashboardGridLayout=ve,e.DashboardRenderer=Z,e.DashboardWithConfig=st,e.DrillDownDrawer=R,e.MetricCard=De,e.MetricWidget=Te,e.ObjectDataTable=I,e.ObjectMetricWidget=Oe,e.ObjectPivotTable=Ie,e.PivotTable=Fe,e.WidgetConfigPanel=ot,e.dashboardComponents=ct});
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?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`]),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;return(0,u.formatPercent)((e>1?e/100:e)*100,t)}return typeof r==`string`&&/[YMDHms]/.test(r)?(0,u.formatDate)(e,r):(0,d.jsx)((0,u.getCellRenderer)((0,u.resolveCellRendererType)(t)),{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 B(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 V=({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=B(e,S),i={$filter:(0,t.resolveFilterPlaceholders)(e.filter,L)};n.length&&(i.$expand=n),r=(0,t.extractRecords)(await u.find(e.objectName,i))}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,V=Array.isArray(R)?R:[],H=(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 V.length===0?[]:(Object.keys(n).length>0?Object.keys(n).filter(e=>!A(e,n[e])):Object.keys(V[0]).filter(e=>!e.startsWith(`_`)&&!A(e))).map(e=>i({header:r(e),accessorKey:e}))},[e.columns,e.objectName,V,S,p,m,c]);if(w&&V.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&&V.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(V.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 te={...e,type:`data-table`,data:V,columns:H,onRowClick:e.onRowClick??(k?N:void 0)},ne=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&&V.length>0}),(0,d.jsx)(n.SchemaRenderer,{schema:te,className:s}),k&&(0,d.jsx)(ee,{record:j,objectName:e.objectName,objectSchema:S,fields:O?.columns,title:ne,target:O?.target===`dialog`?`dialog`:`drawer`,onClose:()=>M(null)})]})},H=({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`})]})},te=({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)(H,{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;return(0,d.jsx)(n.SchemaRenderer,{schema:{...m,type:`spec-report`,report:{...m,filter:t},filter:t}})})():(0,d.jsx)(V,{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})]})})},ne=t.buildDatasetDrillFilter;function re(e,n,r){let i=[],a=[],o=new Set,s=new Set,c=new Map;return e.forEach((e,l)=>{let u=n.map(t=>String(e[t]??`∅`)).join(``),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(`${u} ${d}`,l)}),{rowHeaders:i,colHeaders:a,cellIndex:c}}function U(e){if(e==null)return``;let t=String(e);return/[",\n\r]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}function ie(e){return e.map(e=>e.map(U).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${ie(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 G=new Set([`metric`,`kpi`,`gauge`,`solid-gauge`,`bullet`]),ae={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=G.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);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}},[`${p}|${c}|${l.join(`,`)}|${u.join(`,`)}|${JSON.stringify(k??null)}|${JSON.stringify(f??null)}|${x??``}|${JSON.stringify(w??null)}|${T??``}`]),(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:ie,drillRanges:oe}=j,K=U?l.filter(e=>e in U):[],q=!!H&&(K.length>0||!!oe?.length),J=(t,n)=>{if(!H)return;let r=ne(ie?.[t],K,U??{},A,oe?.[t]);P({filter:r,title:n||String(e?.title??``)})},Y=N&&H?(0,d.jsx)(te,{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]);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)(j.rows[0]?.[u[0]]??0,e?.format,e?.currency)}),(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=re(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),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(_.map(t=>String(e[t]??`∅`)).join(``),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(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)),n.map(n=>{let r=e.cellIndex.get(`${t.id} ${n.col.id}`),o=r==null?void 0:j.rows[r],s=q&&r!=null,c=[...t.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`,s&&`cursor-pointer hover:bg-accent/40`),"data-testid":s?`dataset-drill-cell`:void 0,onClick:s?()=>J(r,c):void 0,children:o?a(o[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(t.id)?.[e],e)},`total-${e}`))]},t.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}`))]})]})]}),Y]})}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`,q&&`cursor-pointer hover:bg-accent/40`),"data-testid":q?`dataset-drill-row`:void 0,onClick:q?()=>J(n,K.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):(0,t.formatDimensionValue)(e[n])},n))},n))})]}),Y]})}let se=ae[p]??`bar`,X=(0,t.relabelDimensions)(j.rows,L),{data:Z,xAxisKey:ce,series:le}=(0,t.buildChartSeries)(X,l,u,j.fields),ue=(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]}),Q=ue?.length?ue:ee,de=q?e=>{let n=(0,t.findChartSeriesRow)(X,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(` / `);J(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:Z,xAxisKey:ce,series:le,isAnimationActive:!1,...F?{categoryColors:F}:{},...Q?{categoryOrder:Q}:{}},onChartClick:de,onSegmentClick:de}),Y]})}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 se({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 X({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)(se,{def:e,value:r,onChange:i},e.name):e.type===`select`||e.type===`lookup`?(0,d.jsx)(X,{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});return(0,d.jsx)(`div`,{ref:u,style:{transform:l.CSS.Transform.toString(f),transition:p,opacity:m?.4:1,...n?{gridColumn:`span ${n.w}`,gridRow:`span ${n.h}`}:{}},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))`],fe=new Set([`bar`,`horizontal-bar`,`line`,`area`,`pie`,`donut`,`funnel`,`scatter`,`treemap`,`sankey`]);function pe(e){return fe.has(e)?{enabled:!0}:void 0}var me=new Set([`object-chart`,`object-metric`,`object-data-table`]),he={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`},ge=(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)(),{executeAction:z,engine:B}=(0,n.useActionEngine)({actions:(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])}),{dashboardLabel:V,dashboardDescription:H,dashboardActionLabel:te,widgetTitle:ne,widgetDescription:re,fieldLabel:U}=(0,n.useObjectLabel)(),{t:ie}=(0,r.useObjectTranslation)(),W=(0,a.useCallback)((e,t,n)=>n&&(!t||t===`value`||t===`count`||n===`count`)?ie(`report.aggregate.${n}`,{defaultValue:n}):e?U(e,t,t):t,[ie,U]),G=e.name,ae=(0,a.useCallback)(e=>{if(!G)return e.label;let t=e.actionUrl||e.label;return te(G,t,e.label)},[G,te]),K=(0,a.useCallback)(e=>{let t=Q(e.title);return!G||!e.id||t===void 0?t:ne(G,e.id,t)},[G,ne]),q=(0,a.useCallback)(e=>{let t=Q(e.description);return!G||!e.id?t:re(G,e.id,t)},[G,re]);(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 J=(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(J,e.refreshInterval*1e3),()=>{F.current&&clearInterval(F.current)}},[e.refreshInterval,f,J]);let Y=(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]),X=(0,a.useCallback)(e=>{!h||!_||e.target===e.currentTarget&&_(null)},[h,_]),Z=!!(h&&v),fe=(0,s.useSensors)((0,s.useSensor)(s.PointerSensor,{activationConstraint:{distance:5}})),ge=(0,a.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,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 he;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:W(r.object,l,c?.function)}],colors:de,isAnimationActive:!1,drillDown:n.drillDown??pe(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:W(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`?he: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&&me.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=K(e),C=q(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=>Y(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&&!Z?{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 Z&&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)},_e=e.title||e.label,ve=e.header&&(0,d.jsxs)(`div`,{className:`col-span-full mb-4`,children:[!S&&e.header.showTitle!==!1&&_e&&(0,d.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:G?V({name:G,label:Q(_e)}):Q(_e)}),!S&&e.header.showDescription!==!1&&e.description&&(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:G?H({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 z(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`}),ae(e)]},t)})})]}),ye=I.length>0&&(0,d.jsx)(ce,{defs:I,values:L,onChange:R,onReset:ee,dataSource:u,className:`mb-2`}),be=p!==void 0&&(0,d.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[p.toLocaleString(),` records`]}),xe=m?JSON.stringify(m):void 0,Se=f&&(0,d.jsxs)(`div`,{className:(0,i.cn)(`flex items-center justify-end gap-3 mb-2`,!N&&`col-span-full`),children:[be,(0,d.jsxs)(i.Button,{variant:`outline`,size:`sm`,onClick:J,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`]})]}),Ce=(0,a.useMemo)(()=>(e.widgets??[]).map(e=>e.id).filter(e=>!!e),[e.widgets]),we=(0,a.useMemo)(()=>(e.widgets??[]).filter(e=>e.type===`metric`).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]);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":xe,onClick:X,...C,children:[ve,ye,Se,t.length>0&&(0,d.jsx)(`div`,{className:`grid grid-cols-2 gap-3`,onClick:X,children:(0,d.jsx)(c.SortableContext,{items:we,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:X,children:(0,d.jsx)(c.SortableContext,{items:Te,strategy:c.verticalListSortingStrategy,disabled:!Z,children:n.map((e,t)=>$(e,t,!0))})})]});return Z?(0,d.jsx)(s.DndContext,{sensors:fe,collisionDetection:s.closestCenter,onDragEnd:ge,children:r}):r}let Ee=(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":xe,onClick:X,...C,children:[ve,ye,Se,(0,d.jsx)(c.SortableContext,{items:Ce,strategy:c.rectSortingStrategy,disabled:!Z,children:e.widgets?.map((e,t)=>$(e,t))})]});return Z?(0,d.jsx)(s.DndContext,{sensors:fe,collisionDetection:s.closestCenter,onDragEnd:ge,children:Ee}):Ee});ge.displayName=`DashboardRendererInner`;var $=(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)(ge,{ref:r,...e}):(0,d.jsx)(n.PageVariablesProvider,{definitions:(0,t.dashboardFilterVariableDefs)(o),children:(0,d.jsx)(ge,{ref:r,...e})})});$.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);return(0,d.jsx)(`div`,{className:`h-full`,children:e.type===`metric`?(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,B]=(0,a.useState)(null);(0,a.useEffect)(()=>{let t=!0;if(!(!k||!e||typeof k.getObjectSchema!=`function`))return k.getObjectSchema(e).then(e=>{t&&B(e)}).catch(()=>{}),()=>{t=!1}},[k,e]);let V=(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]),te=(0,a.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,r.useLocalization)(),re=(0,a.useMemo)(()=>{if(v)return v;if(V?.type===`currency`)return(0,r.resolveFieldCurrency)(V,ne)},[v,V,ne]),U=(0,a.useMemo)(()=>o?JSON.stringify(o):``,[o]),ie=(0,n.useFilterScope)(),W=(0,a.useMemo)(()=>(0,t.resolveFilterPlaceholders)(s,ie),[s,ie]),G=(0,a.useMemo)(()=>W?JSON.stringify(W):``,[W]),ae=(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,U]),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,U,G,ae,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,se=(0,a.useMemo)(()=>{let e=typeof c==`string`?c:c?.defaultValue||``;return(0,t.resolveDrillTitle)(C,{},(typeof w==`string`?w:w?.defaultValue||``)||e||`Details`)},[C,c,w]),X=(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)(H,{objectName:e,filter:W,onNavigate:()=>j(!1)}),s;if(a){let e=r.filter,t=e?W?{$and:[e,W]}:e:W;s=(0,d.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,d.jsx)(n.SchemaRenderer,{schema:{type:`spec-report`,...r,filter:t}})})}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:se}),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:se}),o]}),(0,d.jsx)(`div`,{className:`flex-1 overflow-hidden mt-2`,children:s})]})})},[Y,C,e,W,se]);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:te,currency:re,prefix:y,suffix:b,variant:D,onClick:Y?()=>j(!0):void 0}),A&&X]})};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`)r=(0,t.extractRecords)(await l.find(e.objectName,{$filter:(0,t.resolveFilterPlaceholders)(e.filter,O)}));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};return(0,d.jsx)(te,{open:!0,onClose:()=>C(null),title:(0,t.resolveDrillTitle)(F,S,e.title||`Details`),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{draft:u,isDirty:f,updateField:p,discard:m}=(0,i.useConfigDraft)(a.useMemo(()=>({...n,title:typeof n.title==`object`?Ze(n.title):n.title,description:typeof n.description==`object`?Ze(n.description):n.description}),[n]),{onUpdate:o});return(0,d.jsx)(i.ConfigPanelRenderer,{open:e,onClose:t,schema:a.useMemo(()=>Xe(c,u.type),[c,u.type]),draft:u,isDirty:f,onFieldChange:p,onSave:()=>r($e(u)),onDiscard:m,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)($,{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`,$,{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`,V,{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:$,DashboardGridLayout:xe,MetricWidget:Oe,MetricCard:Ae,ObjectMetricWidget:je,PivotTable:ze,ObjectPivotTable:Be,ObjectDataTable:V,DashboardConfigPanel:He,WidgetConfigPanel:et,DashboardWithConfig:tt};e.DashboardConfigPanel=He,e.DashboardGridLayout=xe,e.DashboardRenderer=$,e.DashboardWithConfig=tt,e.DrillDownDrawer=te,e.MetricCard=Ae,e.MetricWidget=Oe,e.ObjectDataTable=V,e.ObjectMetricWidget=je,e.ObjectPivotTable=Be,e.PivotTable=ze,e.WidgetConfigPanel=et,e.dashboardComponents=nt});
package/dist/utils.d.ts CHANGED
@@ -12,7 +12,7 @@ export declare function isObjectProvider(widgetData: unknown): widgetData is {
12
12
  aggregate?: any;
13
13
  filter?: any;
14
14
  };
15
- export { resolveDateMacros } from '@object-ui/core';
15
+ export { resolveDateMacros, resolveFilterPlaceholders } from '@object-ui/core';
16
16
  export { shiftFilterByCompareTo, compareToTrendLabelKey, type CompareToConfig, } from '@object-ui/core';
17
17
  /**
18
18
  * Compute a percentage delta between the current and previous metric values.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,4FAA4F;AAC5F,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,IAAI;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,GAAG,CAAC;IAAC,MAAM,CAAC,EAAE,GAAG,CAAA;CAAE,CAO1I;AAID,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,eAAe,GACrB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAClC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAClC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,IAAI,CAkBhE"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,4FAA4F;AAC5F,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,IAAI;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,GAAG,CAAC;IAAC,MAAM,CAAC,EAAE,GAAG,CAAA;CAAE,CAO1I;AAUD,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAG/E,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,eAAe,GACrB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAClC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAClC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,IAAI,CAkBhE"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /**
9
+ * Widget-type → dispatch family, shared by every dashboard surface.
10
+ *
11
+ * Three surfaces used to restate this knowledge independently and disagree:
12
+ * `DatasetWidget` covered all 19 `ChartTypeSchema` values, `DashboardRenderer`
13
+ * covered 15, and `DashboardGridLayout` 8. A type the surface didn't name fell
14
+ * through to `{ ...widget }`, whose `type` no component registers — so
15
+ * `SchemaRenderer` rendered a red `role="alert"` panel dumping the widget JSON
16
+ * (#2943).
17
+ *
18
+ * The single-value families were the sharpest case: `DashboardRenderer` already
19
+ * had `METRIC_LIKE_TYPES = ['gauge','solid-gauge','kpi','bullet']` with a
20
+ * docstring saying they "render as a metric card rather than a chart" — and
21
+ * consulted it only to pick a grid span. The tile was sized correctly and the
22
+ * widget was never routed.
23
+ */
24
+ /**
25
+ * Spec chart families that only render as another family. Normalizing them
26
+ * here is what lets one branch serve `column` and `bar` (the spec's own
27
+ * `ChartTypeSchema` comment records the same equivalences).
28
+ */
29
+ export declare const CHART_TYPE_ALIASES: Record<string, string>;
30
+ /** Cartesian / categorical / flow families the chart renderer draws. */
31
+ export declare const SERIES_CHART_TYPES: ReadonlySet<string>;
32
+ /**
33
+ * Single-value "performance" families — one number, optionally against a
34
+ * target. They render as a metric card, which is what the spec's own
35
+ * `ChartTypeSchema` comment calls "honest single-value variants pending a real
36
+ * dial/target renderer". `metric` is the objectui widget spelling of the same
37
+ * thing.
38
+ */
39
+ export declare const METRIC_LIKE_TYPES: ReadonlySet<string>;
40
+ /** Tabular families — a grouped/flat table of records. */
41
+ export declare const TABLE_LIKE_TYPES: ReadonlySet<string>;
42
+ /**
43
+ * Chart families with no renderer and no honest approximation (they need
44
+ * richer data — OHLC, per-record distributions — or a geo dependency). Some
45
+ * were dropped from `ChartTypeSchema` entirely; they stay named so stale
46
+ * stored dashboards get a labelled placeholder rather than a red error box.
47
+ */
48
+ export declare const UNSUPPORTED_CHART_TYPES: ReadonlySet<string>;
49
+ /** How a dashboard surface should render one widget type. */
50
+ export type WidgetDispatchFamily =
51
+ /** A series chart (the resolved base family is in `chartType`). */
52
+ 'series'
53
+ /** A single-value metric card. */
54
+ | 'metric'
55
+ /** A records table. */
56
+ | 'table'
57
+ /** Cross-tab — dataset-bound only; a non-dataset pivot is stale metadata. */
58
+ | 'pivot'
59
+ /** Author-supplied component schema required. */
60
+ | 'custom'
61
+ /** Known family, no renderer — labelled placeholder. */
62
+ | 'unsupported'
63
+ /** Not a widget vocabulary member — the surface passes it through. */
64
+ | 'passthrough';
65
+ export interface WidgetDispatch {
66
+ family: WidgetDispatchFamily;
67
+ /** For `series`: the alias-resolved base family to draw. */
68
+ chartType?: string;
69
+ }
70
+ /**
71
+ * Classify a widget `type` into its dispatch family. Exported for the
72
+ * spec-parity test, which asserts that no `ChartTypeSchema` value lands on
73
+ * `passthrough` (the branch that produces the red box).
74
+ */
75
+ export declare function classifyWidgetType(widgetType: string | undefined): WidgetDispatch;
76
+ //# sourceMappingURL=widgetDispatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widgetDispatch.d.ts","sourceRoot":"","sources":["../src/widgetDispatch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAUrD,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAGjD,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAEhD,CAAC;AAEH,0DAA0D;AAC1D,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAA8B,CAAC;AAEhF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAGtD,CAAC;AAEH,6DAA6D;AAC7D,MAAM,MAAM,oBAAoB;AAC9B,mEAAmE;AACjE,QAAQ;AACV,kCAAkC;GAChC,QAAQ;AACV,uBAAuB;GACrB,OAAO;AACT,6EAA6E;GAC3E,OAAO;AACT,iDAAiD;GAC/C,QAAQ;AACV,wDAAwD;GACtD,aAAa;AACf,sEAAsE;GACpE,aAAa,CAAC;AAElB,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,oBAAoB,CAAC;IAC7B,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,CAUjF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-dashboard",
3
- "version": "16.0.0",
3
+ "version": "17.1.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Dashboard plugin for Object UI",
@@ -19,16 +19,16 @@
19
19
  "@dnd-kit/sortable": "^10.0.0",
20
20
  "@dnd-kit/utilities": "^3.2.2",
21
21
  "clsx": "^2.1.1",
22
- "lucide-react": "^1.24.0",
23
- "react": "19.2.7",
24
- "react-dom": "19.2.7",
22
+ "lucide-react": "^1.25.0",
23
+ "react": "19.2.8",
24
+ "react-dom": "19.2.8",
25
25
  "tailwind-merge": "^3.6.0",
26
- "@object-ui/components": "16.0.0",
27
- "@object-ui/core": "16.0.0",
28
- "@object-ui/fields": "16.0.0",
29
- "@object-ui/i18n": "16.0.0",
30
- "@object-ui/types": "16.0.0",
31
- "@object-ui/react": "16.0.0"
26
+ "@object-ui/components": "17.1.0",
27
+ "@object-ui/core": "17.1.0",
28
+ "@object-ui/fields": "17.1.0",
29
+ "@object-ui/i18n": "17.1.0",
30
+ "@object-ui/react": "17.1.0",
31
+ "@object-ui/types": "17.1.0"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": "^18.0.0 || ^19.0.0",
@@ -36,11 +36,12 @@
36
36
  "react-grid-layout": "^2.2.0 || ^1.4.0"
37
37
  },
38
38
  "devDependencies": {
39
+ "@objectstack/spec": "^17.0.0-rc.0",
39
40
  "@types/react-grid-layout": "^2.1.0",
40
- "@vitejs/plugin-react": "^6.0.3",
41
+ "@vitejs/plugin-react": "^6.0.4",
41
42
  "react-grid-layout": "^2.2.3",
42
43
  "typescript": "^6.0.3",
43
- "vite": "^8.1.4",
44
+ "vite": "^8.1.5",
44
45
  "vite-plugin-dts": "^5.0.3"
45
46
  },
46
47
  "keywords": [
@@ -78,6 +79,7 @@
78
79
  ],
79
80
  "scripts": {
80
81
  "build": "vite build",
82
+ "type-check": "tsc --noEmit",
81
83
  "test": "vitest run",
82
84
  "lint": "eslint ."
83
85
  }