@object-ui/plugin-report 4.0.1 → 4.0.4

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,10 +1,10 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@object-ui/core`),require(`react`),require(`@object-ui/components`),require(`@object-ui/react`),require(`lucide-react`)):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/components`,`@object-ui/react`,`lucide-react`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginReport={},e.ObjectUICore,e.React,e.ObjectUIComponents,e.ObjectUIReact,e.lucide_react))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=Object.create,s=Object.defineProperty,c=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,u=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty,f=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),p=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=l(t),a=0,o=i.length,u;a<o;a++)u=i[a],!d.call(e,u)&&u!==n&&s(e,u,{get:(e=>t[e]).bind(null,u),enumerable:!(r=c(t,u))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:o(u(e)),p(t||!e||!e.__esModule?s(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var m=f((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),h=f(((e,t)=>{t.exports=m()}))(),g=({schema:e})=>{let{title:n,description:i,data:a,columns:o}=e;e.chart?.type;let s=!!e.chart;return(0,h.jsxs)(r.Card,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,h.jsxs)(r.CardHeader,{children:[n&&(0,h.jsx)(r.CardTitle,{children:n}),i&&(0,h.jsx)(r.CardDescription,{children:i})]}),(0,h.jsxs)(r.CardContent,{className:`flex-1 overflow-auto space-y-4`,children:[s&&(()=>{let n=e.chart?.type,r=n?t.ComponentRegistry.get(n):null;return r||=t.ComponentRegistry.get(`chart`),r?(0,h.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,h.jsx)(r,{schema:{...e.chart,data:e.chart.data||a}})}):(0,h.jsxs)(`div`,{className:`min-h-[100px] border rounded-md p-4 bg-muted/20 text-muted-foreground flex items-center justify-center`,children:[`Unknown component type: `,n||`chart`]})})(),a&&a.length>0&&(0,h.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=t.ComponentRegistry.get(`aggrid`)||t.ComponentRegistry.get(`table`);return e?(0,h.jsx)(e,{schema:{type:`aggrid`,rowData:a,columnDefs:o,domLayout:`autoHeight`}}):(0,h.jsx)(`div`,{className:`overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,h.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,h.jsx)(`tr`,{children:o?.map(e=>(0,h.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,h.jsx)(`tbody`,{children:a.map((e,t)=>(0,h.jsx)(`tr`,{className:`bg-background border-b`,children:o?.map(t=>(0,h.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function _(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=w(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
2
- `))?`"${n.replace(/"/g,`""`)}"`:n??``}));D([...n?.includeHeaders===!1?[]:[i.join(`,`)],...a.map(e=>e.join(`,`))].join(`
3
- `),n?.filename||`${e.title||`report`}.csv`,`text/csv`)}function v(e,t,n){let r={title:e.title,description:e.description,generatedAt:new Date().toISOString(),data:t};D(JSON.stringify(r,null,2),n?.filename||`${e.title||`report`}.json`,`application/json`)}function y(e,t,n){let r=e.fields||[],i=E(n?.orientation),a=T(n?.pageSize);D(`<!DOCTYPE html>
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@object-ui/core`),require(`react`),require(`@object-ui/components`),require(`react/jsx-runtime`),require(`@object-ui/react`),require(`lucide-react`)):typeof define==`function`&&define.amd?define([`exports`,`@object-ui/core`,`react`,`@object-ui/components`,`react/jsx-runtime`,`@object-ui/react`,`lucide-react`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginReport={},e.ObjectUICore,e.React,e.ObjectUIComponents,e.react_jsx_runtime,e.ObjectUIReact,e.lucide_react))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=Object.create,c=Object.defineProperty,l=Object.getOwnPropertyDescriptor,u=Object.getOwnPropertyNames,d=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,p=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=u(t),a=0,o=i.length,s;a<o;a++)s=i[a],!f.call(e,s)&&s!==n&&c(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=l(t,s))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:s(d(e)),p(t||!e||!e.__esModule?c(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var m=({schema:e})=>{let{title:n,description:a,data:o,columns:s}=e;e.chart?.type;let c=!!e.chart;return(0,i.jsxs)(r.Card,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,i.jsxs)(r.CardHeader,{children:[n&&(0,i.jsx)(r.CardTitle,{children:n}),a&&(0,i.jsx)(r.CardDescription,{children:a})]}),(0,i.jsxs)(r.CardContent,{className:`flex-1 overflow-auto space-y-4`,children:[c&&(()=>{let n=e.chart?.type,r=n?t.ComponentRegistry.get(n):null;return r||=t.ComponentRegistry.get(`chart`),r?(0,i.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,i.jsx)(r,{schema:{...e.chart,data:e.chart.data||o}})}):(0,i.jsxs)(`div`,{className:`min-h-[100px] border rounded-md p-4 bg-muted/20 text-muted-foreground flex items-center justify-center`,children:[`Unknown component type: `,n||`chart`]})})(),o&&o.length>0&&(0,i.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=t.ComponentRegistry.get(`aggrid`)||t.ComponentRegistry.get(`table`);return e?(0,i.jsx)(e,{schema:{type:`aggrid`,rowData:o,columnDefs:s,domLayout:`autoHeight`}}):(0,i.jsx)(`div`,{className:`overflow-x-auto`,children:(0,i.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,i.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,i.jsx)(`tr`,{children:s?.map(e=>(0,i.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,i.jsx)(`tbody`,{children:o.map((e,t)=>(0,i.jsx)(`tr`,{className:`bg-background border-b`,children:s?.map(t=>(0,i.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function h(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=S(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
2
+ `))?`"${n.replace(/"/g,`""`)}"`:n??``}));T([...n?.includeHeaders===!1?[]:[i.join(`,`)],...a.map(e=>e.join(`,`))].join(`
3
+ `),n?.filename||`${e.title||`report`}.csv`,`text/csv`)}function g(e,t,n){let r={title:e.title,description:e.description,generatedAt:new Date().toISOString(),data:t};T(JSON.stringify(r,null,2),n?.filename||`${e.title||`report`}.json`,`application/json`)}function _(e,t,n){let r=e.fields||[],i=w(n?.orientation),a=C(n?.pageSize);T(`<!DOCTYPE html>
4
4
  <html>
5
5
  <head>
6
6
  <meta charset="utf-8">
7
- <title>${C(e.title||`Report`)}</title>
7
+ <title>${x(e.title||`Report`)}</title>
8
8
  <style>
9
9
  @page { size: ${a} ${i}; margin: 20mm; }
10
10
  body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
@@ -18,19 +18,19 @@
18
18
  </style>
19
19
  </head>
20
20
  <body>
21
- <h1>${C(e.title||`Report`)}</h1>
22
- ${e.description?`<p class="description">${C(e.description)}</p>`:``}
21
+ <h1>${x(e.title||`Report`)}</h1>
22
+ ${e.description?`<p class="description">${x(e.description)}</p>`:``}
23
23
  <p class="meta">Generated: ${new Date().toLocaleString()}</p>
24
24
  <table>
25
- <thead><tr>${r.map(e=>`<th>${C(e.label||e.name)}</th>`).join(``)}</tr></thead>
26
- <tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${C(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
25
+ <thead><tr>${r.map(e=>`<th>${x(e.label||e.name)}</th>`).join(``)}</tr></thead>
26
+ <tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${x(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
27
27
  </table>
28
28
  </body>
29
- </html>`,n?.filename||`${e.title||`report`}.html`,`text/html`)}function b(e,t,n){let r=e.fields||[],i=E(n?.orientation),a=T(n?.pageSize),o=window.open(``,`_blank`);if(!o){y(e,t,{...n,format:`html`,filename:n?.filename?.replace(/\.pdf$/,`.html`)||`${e.title||`report`}.html`});return}o.document.write(`<!DOCTYPE html>
29
+ </html>`,n?.filename||`${e.title||`report`}.html`,`text/html`)}function v(e,t,n){let r=e.fields||[],i=w(n?.orientation),a=C(n?.pageSize),o=window.open(``,`_blank`);if(!o){_(e,t,{...n,format:`html`,filename:n?.filename?.replace(/\.pdf$/,`.html`)||`${e.title||`report`}.html`});return}o.document.write(`<!DOCTYPE html>
30
30
  <html>
31
31
  <head>
32
32
  <meta charset="utf-8">
33
- <title>${C(e.title||`Report`)}</title>
33
+ <title>${x(e.title||`Report`)}</title>
34
34
  <style>
35
35
  @page { size: ${a} ${i}; margin: 20mm; }
36
36
  @media print { .no-print { display: none; } }
@@ -45,15 +45,15 @@ ${e.description?`<p class="description">${C(e.description)}</p>`:``}
45
45
  </style>
46
46
  </head>
47
47
  <body>
48
- <h1>${C(e.title||`Report`)}</h1>
49
- ${e.description?`<p class="description">${C(e.description)}</p>`:``}
48
+ <h1>${x(e.title||`Report`)}</h1>
49
+ ${e.description?`<p class="description">${x(e.description)}</p>`:``}
50
50
  <p class="meta">Generated: ${new Date().toLocaleString()}</p>
51
51
  <table>
52
- <thead><tr>${r.map(e=>`<th>${C(e.label||e.name)}</th>`).join(``)}</tr></thead>
53
- <tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${C(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
52
+ <thead><tr>${r.map(e=>`<th>${x(e.label||e.name)}</th>`).join(``)}</tr></thead>
53
+ <tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${x(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
54
54
  </table>
55
55
  </body>
56
- </html>`),o.document.close(),o.onload=()=>{o.print()}}function x(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=w(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
57
- `)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));D(``+[...n?.includeHeaders===!1?[]:[i.join(` `)],...a.map(e=>e.join(` `))].join(`
58
- `),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function S(e,t,n,r){switch(e){case`csv`:_(t,n,r);break;case`json`:v(t,n,r);break;case`html`:y(t,n,r);break;case`pdf`:b(t,n,r);break;case`excel`:x(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function C(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`)}function w(e){if(typeof e==`string`&&e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`\t${e}`}return e}function T(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function E(e){return e===`landscape`?`landscape`:`portrait`}function D(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function O(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||k(e))return A(e);if(n===`number`||typeof e==`number`){let t=typeof e==`number`?e:Number(e);return isNaN(t)?String(e):r===`currency`||r===`currency_cny`?`¥${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`currency_usd`?`$${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`percent`?`${t.toLocaleString(`en-US`,{minimumFractionDigits:1,maximumFractionDigits:1})}%`:t.toLocaleString(`en-US`)}return String(e)}function k(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function A(e){try{let t=new Date(e);return isNaN(t.getTime())?String(e):`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}catch{return String(e)}}function j(e,t){if(!t||t.length===0||!e||e.length===0)return null;let n=t[0],r=n.field,i=new Map;for(let t of e){let e=String(t[r]??`(empty)`);i.has(e)||i.set(e,[]),i.get(e).push(t)}let a=[];for(let[e,t]of i)a.push({key:e,label:`${n.label||r}: ${e}`,rows:t});let o=n.sort===`desc`?-1:1;return a.sort((e,t)=>e.key.localeCompare(t.key)*o),a}var M=({schema:e,onRefresh:o})=>{let{report:s,data:c,showToolbar:l=!0,allowExport:u=!0,allowPrint:d=!0,loading:f=!1}=e,p=e=>{if(!s){console.warn(`ReportViewer: Cannot export, no report defined`);return}S(e,s,c||[],s.exportConfigs?.[e])},m=()=>{window.print()},g=()=>{o?.()},_=(e,t)=>{if(!c)return 0;let n=c.map(t=>Number(t[e])||0);switch(t){case`count`:return c.length;case`sum`:return n.reduce((e,t)=>e+t,0);case`avg`:return n.length>0?(n.reduce((e,t)=>e+t,0)/n.length).toFixed(2):0;case`min`:return n.length>0?Math.min(...n):0;case`max`:return n.length>0?Math.max(...n):0;default:return``}},v=(e,t)=>{let n=s?.conditionalFormatting;if(!(!n||!Array.isArray(n)))for(let r of n){if(r.field!==e)continue;let n=String(t??``),i=String(r.value??``),a=!1;switch(r.operator){case`equals`:a=n===i;break;case`not_equals`:a=n!==i;break;case`contains`:a=n.includes(i);break;case`greater_than`:a=Number(t)>Number(r.value);break;case`less_than`:a=Number(t)<Number(r.value);break}if(a){let e={};return r.backgroundColor&&(e.backgroundColor=r.backgroundColor),r.textColor&&(e.color=r.textColor),e}}},y=(e,t)=>e==null||e===``?``:t.renderAs===`badge`?(0,h.jsx)(r.Badge,{className:t.colorMap?.[String(e)]||``,children:String(e)}):O(e,t);return s?(0,h.jsxs)(`div`,{className:`space-y-4`,children:[l&&(0,h.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`h2`,{className:`text-lg font-semibold`,children:s.title}),s.description&&(0,h.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:s.description})]}),(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.refreshInterval&&(0,h.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:g,children:[(0,h.jsx)(a.RefreshCw,{className:`h-4 w-4 mr-2`}),`Refresh`]}),d&&(0,h.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:m,children:[(0,h.jsx)(a.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),u&&s.showExportButtons&&(0,h.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,h.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>p(`pdf`),children:[(0,h.jsx)(a.Download,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,h.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>p(`excel`),children:[(0,h.jsx)(a.Download,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,h.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>p(`csv`),children:[(0,h.jsx)(a.Download,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,h.jsxs)(r.Card,{children:[(0,h.jsxs)(r.CardHeader,{children:[!l&&s.title&&(0,h.jsx)(r.CardTitle,{children:s.title}),!l&&s.description&&(0,h.jsx)(r.CardDescription,{children:s.description})]}),(0,h.jsxs)(r.CardContent,{className:`space-y-6`,children:[f&&(0,h.jsxs)(`div`,{className:`space-y-6`,children:[(0,h.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,h.jsx)(r.Card,{children:(0,h.jsxs)(r.CardContent,{className:`p-4 space-y-2`,children:[(0,h.jsx)(r.Skeleton,{className:`h-4 w-20`}),(0,h.jsx)(r.Skeleton,{className:`h-8 w-28`})]})},e))}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(r.Skeleton,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,h.jsx)(r.Skeleton,{className:`h-8 w-full`},e))]})]}),!f&&s.sections?.map((e,a)=>e.visible===!1?null:(0,h.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,h.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,h.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,h.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:s.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,h.jsx)(r.Card,{children:(0,h.jsxs)(r.CardContent,{className:`p-4`,children:[(0,h.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,h.jsx)(`div`,{className:`text-2xl font-bold`,children:O(_(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,h.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let n=e.chart.type,r=!!e.chart.chartType;!n&&r&&(n=`chart`),n&&t.ComponentRegistry.get(n)||(n=`chart`);let a=n===`chart`?{xAxisKey:e.chart.xAxisKey||e.chart.xAxisField||`name`,series:e.chart.series||(e.chart.yAxisFields?e.chart.yAxisFields.map(e=>({dataKey:e})):[]),chartType:e.chart.chartType||`bar`}:{};return(0,h.jsx)(i.SchemaRenderer,{schema:{...e.chart,type:n,...a,data:c||e.chart.data,className:e.chart.className||`w-full h-[350px]`}})})()}),e.type===`table`&&(0,h.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,h.jsx)(`thead`,{className:`bg-muted`,children:(0,h.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,h.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,h.jsx)(`tbody`,{children:(()=>{let t=j(c||[],s.groupBy||[]);return t?t.map(t=>(0,h.jsxs)(n.default.Fragment,{children:[(0,h.jsx)(`tr`,{className:`bg-muted/60`,children:(0,h.jsxs)(`td`,{colSpan:e.columns?.length||1,className:`px-4 py-2 font-semibold text-sm`,children:[t.label,` (`,t.rows.length,`)`]})}),t.rows.map((t,n)=>(0,h.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,h.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:v(e.name,t[e.name]),children:y(t[e.name],e)},n))},n))]},t.key)):c?.map((t,n)=>(0,h.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,h.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:v(e.name,t[e.name]),children:y(t[e.name],e)},n))},n))})()})]})}),e.type===`text`&&e.text&&(0,h.jsx)(`div`,{className:`prose max-w-none`,children:(0,h.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,h.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,h.jsx)(i.SchemaRenderer,{schema:e.content})]},a)),!s.sections&&c&&c.length>0&&(0,h.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,h.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,h.jsx)(`thead`,{className:`bg-muted`,children:(0,h.jsx)(`tr`,{children:s.fields?.map((e,t)=>(0,h.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,h.jsx)(`tbody`,{children:c.map((e,t)=>(0,h.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:s.fields?.map((t,n)=>(0,h.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:v(t.name,e[t.name]),children:y(e[t.name],t)},n))},t))})]})})]})]})]}):(0,h.jsx)(r.Card,{children:(0,h.jsx)(r.CardContent,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})},N=({schedule:e,onChange:t})=>{let[i,o]=(0,n.useState)(e||{enabled:!1,frequency:`weekly`,time:`09:00`,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:[`pdf`]}),s=e=>{let n={...i,...e};o(n),t?.(n)};return(0,h.jsxs)(r.Card,{children:[(0,h.jsx)(r.CardHeader,{children:(0,h.jsxs)(r.CardTitle,{className:`flex items-center gap-2`,children:[(0,h.jsx)(a.Calendar,{className:`h-5 w-5`}),`Schedule Configuration`]})}),(0,h.jsxs)(r.CardContent,{className:`space-y-4`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,id:`schedule-enabled`,checked:i.enabled||!1,onChange:e=>s({enabled:e.target.checked}),className:`rounded`}),(0,h.jsx)(r.Label,{htmlFor:`schedule-enabled`,children:`Enable Scheduled Report`})]}),i.enabled&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(r.Label,{children:`Frequency`}),(0,h.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:i.frequency||`weekly`,onChange:e=>s({frequency:e.target.value}),children:[{value:`once`,label:`Once`},{value:`daily`,label:`Daily`},{value:`weekly`,label:`Weekly`},{value:`monthly`,label:`Monthly`},{value:`quarterly`,label:`Quarterly`},{value:`yearly`,label:`Yearly`}].map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),i.frequency===`weekly`&&(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(r.Label,{children:`Day of Week`}),(0,h.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:i.dayOfWeek??1,onChange:e=>s({dayOfWeek:Number(e.target.value)}),children:[{value:0,label:`Sunday`},{value:1,label:`Monday`},{value:2,label:`Tuesday`},{value:3,label:`Wednesday`},{value:4,label:`Thursday`},{value:5,label:`Friday`},{value:6,label:`Saturday`}].map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),i.frequency===`monthly`&&(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(r.Label,{children:`Day of Month`}),(0,h.jsx)(r.Input,{type:`number`,min:1,max:31,value:i.dayOfMonth??1,onChange:e=>s({dayOfMonth:Number(e.target.value)})})]}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsxs)(r.Label,{className:`flex items-center gap-2`,children:[(0,h.jsx)(a.Clock,{className:`h-4 w-4`}),`Time`]}),(0,h.jsx)(r.Input,{type:`time`,value:i.time||`09:00`,onChange:e=>s({time:e.target.value})})]}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(r.Label,{children:`Timezone`}),(0,h.jsx)(r.Input,{value:i.timezone||``,onChange:e=>s({timezone:e.target.value}),placeholder:`e.g. America/New_York`})]}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(r.Label,{children:`Export Formats`}),(0,h.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:[{value:`pdf`,label:`PDF`},{value:`excel`,label:`Excel`},{value:`csv`,label:`CSV`},{value:`html`,label:`HTML`}].map(e=>(0,h.jsxs)(`label`,{className:`flex items-center gap-1.5 px-3 py-1.5 border rounded-md cursor-pointer hover:bg-muted/50`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:i.formats?.includes(e.value)||!1,onChange:t=>{let n=i.formats||[];s({formats:t.target.checked?[...n,e.value]:n.filter(t=>t!==e.value)})},className:`rounded`}),(0,h.jsx)(`span`,{className:`text-sm`,children:e.label})]},e.value))})]}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsxs)(r.Label,{className:`flex items-center gap-2`,children:[(0,h.jsx)(a.Mail,{className:`h-4 w-4`}),`Email Recipients`]}),(0,h.jsx)(r.Input,{placeholder:`email1@example.com, email2@example.com`,value:i.recipients?.join(`, `)||``,onChange:e=>s({recipients:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})]}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(r.Label,{children:`Email Subject`}),(0,h.jsx)(r.Input,{value:i.subject||``,onChange:e=>s({subject:e.target.value}),placeholder:`Scheduled Report: {report_title}`})]})]})]})]})},P=({schema:e})=>{let{report:t,dataSources:i=[],availableFields:o=[],showPreview:s=!0,onSave:c,onCancel:l}=e,[u,d]=(0,n.useState)(t||{type:`report`,title:`New Report`,fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[f,p]=(0,n.useState)(u.fields||[]),[m,g]=(0,n.useState)(u.filters||[]),[_,v]=(0,n.useState)(u.groupBy||[]),[y,b]=(0,n.useState)(u.sections||[]),x=()=>{if(o.length>0&&f.length<o.length){let e=o.find(e=>!f.some(t=>t.name===e.name));if(e){let t=[...f,e];p(t),d({...u,fields:t})}}},S=e=>{let t=f.filter((t,n)=>n!==e);p(t),d({...u,fields:t})},C=(e,t)=>{let n=[...f];n[e]=t,p(n),d({...u,fields:n})},w=()=>{let e={field:o[0]?.name||``,operator:`equals`,value:``},t=[...m,e];g(t),d({...u,filters:t})},T=e=>{let t=m.filter((t,n)=>n!==e);g(t),d({...u,filters:t})},E=(e,t)=>{let n=[...m];n[e]=t,g(n),d({...u,filters:n})},D=()=>{let e={field:o[0]?.name||``,sort:`asc`},t=[..._,e];v(t),d({...u,groupBy:t})},O=e=>{let t=_.filter((t,n)=>n!==e);v(t),d({...u,groupBy:t})},k=(e,t)=>{let n=[..._];n[e]=t,v(n),d({...u,groupBy:n})},A=e=>{let t={type:e,title:`New ${e} Section`},n=[...y,t];b(n),d({...u,sections:n})},j=e=>{let t=y.filter((t,n)=>n!==e);b(t),d({...u,sections:t})},P=(e,t)=>{let n=[...y];n[e]=t,b(n),d({...u,sections:n})};return(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsxs)(r.Card,{children:[(0,h.jsxs)(r.CardHeader,{children:[(0,h.jsx)(r.CardTitle,{children:`Report Builder`}),(0,h.jsx)(r.CardDescription,{children:`Configure your report settings, fields, filters, and sections`})]}),(0,h.jsxs)(r.CardContent,{children:[(0,h.jsxs)(r.Tabs,{defaultValue:`basic`,className:`w-full`,children:[(0,h.jsxs)(r.TabsList,{className:`grid w-full grid-cols-6`,children:[(0,h.jsxs)(r.TabsTrigger,{value:`basic`,children:[(0,h.jsx)(a.Settings,{className:`h-4 w-4 mr-2`}),`Basic`]}),(0,h.jsxs)(r.TabsTrigger,{value:`fields`,children:[(0,h.jsx)(a.Layers,{className:`h-4 w-4 mr-2`}),`Fields`]}),(0,h.jsxs)(r.TabsTrigger,{value:`filters`,children:[(0,h.jsx)(a.Filter,{className:`h-4 w-4 mr-2`}),`Filters`]}),(0,h.jsxs)(r.TabsTrigger,{value:`grouping`,children:[(0,h.jsx)(a.Layers,{className:`h-4 w-4 mr-2`}),`Group By`]}),(0,h.jsxs)(r.TabsTrigger,{value:`sections`,children:[(0,h.jsx)(a.Layers,{className:`h-4 w-4 mr-2`}),`Sections`]}),(0,h.jsxs)(r.TabsTrigger,{value:`schedule`,children:[(0,h.jsx)(a.Calendar,{className:`h-4 w-4 mr-2`}),`Schedule`]})]}),(0,h.jsx)(r.TabsContent,{value:`basic`,className:`space-y-4 mt-4`,children:(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(r.Label,{htmlFor:`report-title`,children:`Report Title`}),(0,h.jsx)(r.Input,{id:`report-title`,value:u.title||``,onChange:e=>d({...u,title:e.target.value}),placeholder:`Enter report title`})]}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(r.Label,{htmlFor:`report-description`,children:`Description`}),(0,h.jsx)(r.Input,{id:`report-description`,value:u.description||``,onChange:e=>d({...u,description:e.target.value}),placeholder:`Enter report description`})]}),i.length>0&&(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(r.Label,{children:`Data Source`}),(0,h.jsxs)(`select`,{className:`w-full border rounded-md p-2`,children:[(0,h.jsx)(`option`,{value:``,children:`Select a data source`}),i.map((e,t)=>(0,h.jsxs)(`option`,{value:t,children:[`Data Source `,t+1]},t))]})]}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(r.Label,{children:`Export Options`}),(0,h.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:u.showExportButtons||!1,onChange:e=>d({...u,showExportButtons:e.target.checked})}),(0,h.jsx)(`span`,{className:`text-sm`,children:`Show Export Buttons`})]}),(0,h.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:u.showPrintButton||!1,onChange:e=>d({...u,showPrintButton:e.target.checked})}),(0,h.jsx)(`span`,{className:`text-sm`,children:`Show Print Button`})]})]})]}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[(0,h.jsx)(r.Label,{htmlFor:`export-format`,children:`Default Export Format`}),(0,h.jsxs)(`select`,{id:`export-format`,className:`w-full border rounded-md p-2`,value:u.defaultExportFormat||`pdf`,onChange:e=>d({...u,defaultExportFormat:e.target.value}),children:[(0,h.jsx)(`option`,{value:`pdf`,children:`PDF`}),(0,h.jsx)(`option`,{value:`excel`,children:`Excel`}),(0,h.jsx)(`option`,{value:`csv`,children:`CSV`}),(0,h.jsx)(`option`,{value:`json`,children:`JSON`}),(0,h.jsx)(`option`,{value:`html`,children:`HTML`})]})]})]})}),(0,h.jsxs)(r.TabsContent,{value:`fields`,className:`space-y-4 mt-4`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,h.jsx)(r.Label,{children:`Report Fields`}),(0,h.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:x,disabled:f.length>=o.length,children:[(0,h.jsx)(a.Plus,{className:`h-4 w-4 mr-2`}),`Add Field`]})]}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[f.map((e,t)=>(0,h.jsx)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:(0,h.jsxs)(`div`,{className:`flex-1 grid grid-cols-4 gap-2`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`Field Name`}),(0,h.jsx)(`div`,{className:`text-sm font-medium`,children:e.name})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`Label`}),(0,h.jsx)(r.Input,{className:`h-8 text-sm`,value:e.label||e.name,onChange:n=>C(t,{...e,label:n.target.value})})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`Aggregation`}),(0,h.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.aggregation||``,onChange:n=>C(t,{...e,aggregation:n.target.value}),children:[(0,h.jsx)(`option`,{value:``,children:`None`}),(0,h.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,h.jsx)(`option`,{value:`count`,children:`Count`}),(0,h.jsx)(`option`,{value:`avg`,children:`Average`}),(0,h.jsx)(`option`,{value:`min`,children:`Min`}),(0,h.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,h.jsx)(`div`,{className:`flex items-end justify-end`,children:(0,h.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>S(t),children:(0,h.jsx)(a.Trash2,{className:`h-4 w-4`})})})]})},t)),f.length===0&&(0,h.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No fields selected. Click "Add Field" to begin.`})]})]}),(0,h.jsxs)(r.TabsContent,{value:`filters`,className:`space-y-4 mt-4`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,h.jsx)(r.Label,{children:`Report Filters`}),(0,h.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:w,children:[(0,h.jsx)(a.Plus,{className:`h-4 w-4 mr-2`}),`Add Filter`]})]}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[m.map((e,t)=>(0,h.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,h.jsxs)(`div`,{className:`flex-1 grid grid-cols-3 gap-2`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`Field`}),(0,h.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>E(t,{...e,field:n.target.value}),children:o.map((e,t)=>(0,h.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`Operator`}),(0,h.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.operator,onChange:n=>E(t,{...e,operator:n.target.value}),children:[(0,h.jsx)(`option`,{value:`equals`,children:`Equals`}),(0,h.jsx)(`option`,{value:`contains`,children:`Contains`}),(0,h.jsx)(`option`,{value:`gt`,children:`Greater Than`}),(0,h.jsx)(`option`,{value:`lt`,children:`Less Than`}),(0,h.jsx)(`option`,{value:`between`,children:`Between`})]})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`Value`}),(0,h.jsx)(r.Input,{className:`h-8 text-sm`,value:String(e.value),onChange:n=>E(t,{...e,value:n.target.value})})]})]}),(0,h.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>T(t),children:(0,h.jsx)(a.Trash2,{className:`h-4 w-4`})})]},t)),m.length===0&&(0,h.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No filters defined.`})]})]}),(0,h.jsxs)(r.TabsContent,{value:`grouping`,className:`space-y-4 mt-4`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,h.jsx)(r.Label,{children:`Grouping Rules`}),(0,h.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:D,children:[(0,h.jsx)(a.Plus,{className:`h-4 w-4 mr-2`}),`Add Group`]})]}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[_.map((e,t)=>(0,h.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,h.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`Field`}),(0,h.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>k(t,{...e,field:n.target.value}),children:o.map((e,t)=>(0,h.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`Sort Order`}),(0,h.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.sort||`asc`,onChange:n=>k(t,{...e,sort:n.target.value}),children:[(0,h.jsx)(`option`,{value:`asc`,children:`Ascending`}),(0,h.jsx)(`option`,{value:`desc`,children:`Descending`})]})]})]}),(0,h.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>O(t),children:(0,h.jsx)(a.Trash2,{className:`h-4 w-4`})})]},t)),_.length===0&&(0,h.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No grouping rules applied.`})]})]}),(0,h.jsxs)(r.TabsContent,{value:`sections`,className:`space-y-4 mt-4`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,h.jsx)(r.Label,{children:`Report Sections`}),(0,h.jsxs)(`div`,{className:`flex gap-2`,children:[(0,h.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`header`),children:[(0,h.jsx)(a.Plus,{className:`h-4 w-4 mr-2`}),`Header`]}),(0,h.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`chart`),children:[(0,h.jsx)(a.Plus,{className:`h-4 w-4 mr-2`}),`Chart`]}),(0,h.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`table`),children:[(0,h.jsx)(a.Plus,{className:`h-4 w-4 mr-2`}),`Table`]})]})]}),(0,h.jsxs)(`div`,{className:`space-y-2`,children:[y.map((e,t)=>(0,h.jsxs)(`div`,{className:`p-3 border rounded-lg space-y-2`,children:[(0,h.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,h.jsxs)(`div`,{className:`font-medium flex items-center gap-2`,children:[(0,h.jsx)(`div`,{className:`text-xs bg-muted px-2 py-0.5 rounded uppercase`,children:e.type}),e.title]}),(0,h.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>j(t),children:(0,h.jsx)(a.Trash2,{className:`h-4 w-4`})})]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`Title`}),(0,h.jsx)(r.Input,{className:`h-8 text-sm`,value:e.title||``,onChange:n=>P(t,{...e,title:n.target.value})})]}),e.type===`text`&&(0,h.jsxs)(`div`,{className:`col-span-2`,children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`Content`}),(0,h.jsx)(r.Input,{className:`h-8 text-sm`,value:e.text||``,onChange:n=>P(t,{...e,text:n.target.value})})]}),e.type===`chart`&&(0,h.jsxs)(`div`,{className:`col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded`,children:[(0,h.jsx)(`div`,{className:`col-span-2`,children:(0,h.jsx)(r.Label,{className:`text-xs font-semibold`,children:`Chart Configuration`})}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`Chart Type`}),(0,h.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.chartType||`bar`,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,chartType:n.target.value}}),children:[(0,h.jsx)(`option`,{value:`bar`,children:`Bar`}),(0,h.jsx)(`option`,{value:`line`,children:`Line`}),(0,h.jsx)(`option`,{value:`area`,children:`Area`}),(0,h.jsx)(`option`,{value:`pie`,children:`Pie`})]})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`X-Axis Field`}),(0,h.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.xAxisField||``,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,xAxisField:n.target.value}}),children:[(0,h.jsx)(`option`,{value:``,children:`Select Field...`}),o.map(e=>(0,h.jsx)(`option`,{value:e.name,children:e.label||e.name},e.name)),o.length===0&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`option`,{value:`name`,children:`Name`}),(0,h.jsx)(`option`,{value:`month`,children:`Month`})]})]})]}),(0,h.jsxs)(`div`,{className:`col-span-2`,children:[(0,h.jsx)(r.Label,{className:`text-xs`,children:`Y-Axis Fields (comma separated)`}),(0,h.jsx)(r.Input,{className:`h-8 text-sm`,placeholder:`e.g. value, count`,value:e.chart?.yAxisFields?.join(`, `)||``,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,yAxisFields:n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}})})]})]})]})]},t)),y.length===0&&(0,h.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No customized sections. The default report layout will be used.`})]})]}),(0,h.jsx)(r.TabsContent,{value:`schedule`,className:`space-y-4 mt-4`,children:(0,h.jsx)(N,{schedule:u.schedule,onChange:e=>d({...u,schedule:e})})})]}),(0,h.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-6 pt-4 border-t`,children:[(0,h.jsx)(r.Button,{variant:`outline`,onClick:()=>{l&&console.log(`Report cancelled:`,l)},children:`Cancel`}),(0,h.jsxs)(r.Button,{onClick:()=>{console.log(`Saving report:`,u),c&&alert(`Report saved! (Handler: `+c+`)`)},children:[(0,h.jsx)(a.Save,{className:`h-4 w-4 mr-2`}),`Save Report`]})]})]})]}),s&&(0,h.jsxs)(r.Card,{className:`mt-8 border-2 border-blue-100`,children:[(0,h.jsx)(r.CardHeader,{className:`bg-blue-50/50`,children:(0,h.jsx)(r.CardTitle,{className:`text-blue-900 text-sm uppercase tracking-wide`,children:`Live Preview`})}),(0,h.jsx)(r.CardContent,{className:`pt-6`,children:(0,h.jsx)(M,{schema:{type:`report-viewer`,report:{...u,fields:f,filters:m,groupBy:_,sections:y},data:[{id:1,name:`Sample Item A`,value:100,status:`New`},{id:2,name:`Sample Item B`,value:250,status:`Active`},{id:3,name:`Sample Item C`,value:75,status:`Closed`}]}})})]})]})},F=[{value:``,label:`None`},{value:`sum`,label:`Sum`},{value:`count`,label:`Count`},{value:`avg`,label:`Average`},{value:`min`,label:`Min`},{value:`max`,label:`Max`}];function I({availableFields:e,value:t,onChange:n}){let i=Array.isArray(t)?t.map(e=>typeof e==`string`?{name:e,label:e,type:`string`}:{name:e.name||e.field||e.value,label:e.label||e.name||``,type:e.type||`string`,aggregation:e.aggregation}):[],a=i.map(e=>e.name),o=t=>{let r=a.includes(t),o;if(r)o=i.filter(e=>e.name!==t);else{let n=e.find(e=>e.value===t);o=[...i,{name:t,label:n?.label||t,type:n?.type||`string`}]}n(o)},s=(e,t)=>{n(i.map(n=>n.name===e?{...n,aggregation:t||void 0,showInSummary:!!t}:n))};return e.length===0?(0,h.jsx)(`div`,{className:`text-xs text-muted-foreground py-2`,"data-testid":`field-picker-empty`,children:`No fields available`}):(0,h.jsx)(`div`,{className:`space-y-1 py-1`,"data-testid":`field-picker`,children:e.map(e=>{let t=a.includes(e.value),n=i.find(t=>t.name===e.value);return(0,h.jsxs)(`div`,{className:`flex items-center gap-2 px-1 py-0.5 rounded hover:bg-muted/50 text-xs`,children:[(0,h.jsxs)(`label`,{className:`flex items-center gap-2 flex-1 cursor-pointer`,children:[(0,h.jsx)(r.Checkbox,{checked:t,onCheckedChange:()=>o(e.value),"data-testid":`field-picker-${e.value}`}),(0,h.jsx)(`span`,{className:`flex-1`,children:e.label}),e.type&&(0,h.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.type})]}),t&&(0,h.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background`,value:n?.aggregation||``,onChange:t=>s(e.value,t.target.value),"data-testid":`field-agg-${e.value}`,children:F.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))})]},e.value)})})}var L=[{value:``,label:`None`},{value:`bar`,label:`Bar Chart`},{value:`line`,label:`Line Chart`},{value:`pie`,label:`Pie Chart`},{value:`area`,label:`Area Chart`},{value:`donut`,label:`Donut Chart`},{value:`scatter`,label:`Scatter Plot`}];function R({availableFields:e,value:t,onChange:n}){let r=t||{},i=e=>n({...r,...e});return(0,h.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`chart-config`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`Chart type`}),(0,h.jsx)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:r.chartType||``,onChange:e=>i({chartType:e.target.value||void 0}),"data-testid":`chart-type-select`,children:L.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),r.chartType&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`X-axis field`}),(0,h.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:r.xAxisField||``,onChange:e=>i({xAxisField:e.target.value||void 0}),"data-testid":`chart-x-field`,children:[(0,h.jsx)(`option`,{value:``,children:`Select field…`}),e.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`Y-axis field`}),(0,h.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:r.yAxisFields?.[0]||``,onChange:e=>i({yAxisFields:e.target.value?[e.target.value]:[]}),"data-testid":`chart-y-field`,children:[(0,h.jsx)(`option`,{value:``,children:`Select field…`}),e.filter(e=>e.type===`number`).map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]})]})]})}var z=[{value:`equals`,label:`=`},{value:`not_equals`,label:`≠`},{value:`greater_than`,label:`>`},{value:`less_than`,label:`<`},{value:`contains`,label:`Contains`}];function B({availableFields:e,value:t,onChange:n}){let i=Array.isArray(t)?t:[],o=()=>{n([...i,{field:e[0]?.value||``,operator:`equals`,value:``,backgroundColor:`#fef9c3`,textColor:``}])},s=e=>{n(i.filter((t,n)=>n!==e))},c=(e,t)=>{n(i.map((n,r)=>r===e?{...n,...t}:n))};return(0,h.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`conditional-format-rules`,children:[i.map((t,n)=>(0,h.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1 border rounded bg-muted/20`,children:[(0,h.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background flex-1`,value:t.field,onChange:e=>c(n,{field:e.target.value}),"data-testid":`cf-rule-field-${n}`,children:e.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-12`,value:t.operator,onChange:e=>c(n,{operator:e.target.value}),children:z.map(e=>(0,h.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,h.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-16`,value:t.value,placeholder:`value`,onChange:e=>c(n,{value:e.target.value}),"data-testid":`cf-rule-value-${n}`}),(0,h.jsx)(`input`,{type:`color`,className:`h-5 w-5 rounded border cursor-pointer`,value:t.backgroundColor||`#fef9c3`,onChange:e=>c(n,{backgroundColor:e.target.value}),title:`Background color`}),(0,h.jsx)(r.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0`,onClick:()=>s(n),"data-testid":`cf-rule-remove-${n}`,children:(0,h.jsx)(a.Trash2,{className:`h-3 w-3`})})]},n)),(0,h.jsxs)(r.Button,{type:`button`,size:`sm`,variant:`outline`,className:`h-6 text-[10px] w-full`,onClick:o,"data-testid":`cf-add-rule`,children:[(0,h.jsx)(a.Plus,{className:`h-3 w-3 mr-1`}),`Add Rule`]})]})}var V=[{value:`header`,label:`Header`},{value:`summary`,label:`Summary`},{value:`table`,label:`Table`},{value:`chart`,label:`Chart`},{value:`text`,label:`Text`}];function H({value:e,onChange:t}){let n=Array.isArray(e)?e:[],i=e=>{t([...n,{type:e,title:`New ${e}`,visible:!0}])},o=e=>{t(n.filter((t,n)=>n!==e))},s=(e,r)=>{t(n.map((t,n)=>n===e?{...t,...r}:t))},c=(e,r)=>{let i=e+r;if(i<0||i>=n.length)return;let a=[...n];[a[e],a[i]]=[a[i],a[e]],t(a)};return(0,h.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`section-manager`,children:[n.map((e,t)=>(0,h.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1.5 border rounded bg-muted/20`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-0.5 mr-1`,children:[(0,h.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===0,onClick:()=>c(t,-1),"data-testid":`section-up-${t}`,children:`▲`}),(0,h.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===n.length-1,onClick:()=>c(t,1),"data-testid":`section-down-${t}`,children:`▼`})]}),(0,h.jsx)(`span`,{className:`text-[9px] bg-muted px-1.5 py-0.5 rounded uppercase font-medium shrink-0`,children:e.type}),(0,h.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background flex-1 min-w-0`,value:e.title||``,placeholder:`Section title`,onChange:e=>s(t,{title:e.target.value}),"data-testid":`section-title-${t}`}),(0,h.jsx)(r.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0 shrink-0`,onClick:()=>o(t),"data-testid":`section-remove-${t}`,children:(0,h.jsx)(a.Trash2,{className:`h-3 w-3`})})]},t)),(0,h.jsx)(`div`,{className:`flex gap-1 flex-wrap`,children:V.map(e=>(0,h.jsxs)(r.Button,{type:`button`,size:`sm`,variant:`outline`,className:`h-6 text-[10px]`,onClick:()=>i(e.value),"data-testid":`section-add-${e.value}`,children:[(0,h.jsx)(a.Plus,{className:`h-3 w-3 mr-0.5`}),e.label]},e.value))})]})}function U(e=[]){return{breadcrumb:[`Report`,`Configuration`],sections:[{key:`basic`,title:`Basic`,fields:[{key:`title`,label:`Title`,type:`input`,placeholder:`Report title`},{key:`description`,label:`Description`,type:`input`,placeholder:`Report description`},{key:`reportType`,label:`Report type`,type:`select`,defaultValue:`tabular`,options:[{value:`tabular`,label:`Tabular`},{value:`summary`,label:`Summary`},{value:`matrix`,label:`Matrix`}],helpText:`Tabular: flat table. Summary: grouped with subtotals. Matrix: pivot table (planned).`}]},{key:`data`,title:`Data`,collapsible:!0,fields:[{key:`objectName`,label:`Data source`,type:`input`,placeholder:`e.g. opportunity`,helpText:`Object name to query data from`},{key:`limit`,label:`Row limit`,type:`input`,defaultValue:`100`,placeholder:`e.g. 100`}]},{key:`columns`,title:`Columns`,collapsible:!0,hint:`Select fields to display as report columns. Set aggregation per column for summary reports.`,fields:[{key:`fields`,label:`Report columns`,type:`custom`,render:(t,n)=>(0,h.jsx)(I,{availableFields:e,value:t,onChange:n})}]},{key:`filters`,title:`Filters`,collapsible:!0,hint:`Define filter conditions for the report data`,fields:[{key:`filters`,label:`Conditions`,type:`filter`,fields:e}]},{key:`groupBy`,title:`Group By`,collapsible:!0,hint:`Group report data and compute aggregations`,fields:[{key:`groupBy`,label:`Grouping`,type:`sort`,fields:e}]},{key:`chart`,title:`Chart`,collapsible:!0,hint:`Add a chart visualization to the report`,fields:[{key:`chartConfig`,label:`Chart`,type:`custom`,render:(t,n)=>(0,h.jsx)(R,{availableFields:e,value:t,onChange:n})}]},{key:`conditionalFormatting`,title:`Conditional Format`,collapsible:!0,defaultCollapsed:!0,hint:`Highlight cells based on field value conditions`,fields:[{key:`conditionalFormatting`,label:`Rules`,type:`custom`,render:(t,n)=>(0,h.jsx)(B,{availableFields:e,value:t,onChange:n})}]},{key:`sections`,title:`Sections`,collapsible:!0,defaultCollapsed:!0,hint:`Manage report layout blocks (header, table, chart, summary)`,fields:[{key:`sections`,label:`Report sections`,type:`custom`,render:(e,t)=>(0,h.jsx)(H,{value:e,onChange:t})}]},{key:`export`,title:`Export`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`showExportButtons`,label:`Show export buttons`,type:`switch`,defaultValue:!0},{key:`showPrintButton`,label:`Show print button`,type:`switch`,defaultValue:!0},{key:`defaultExportFormat`,label:`Default export format`,type:`select`,defaultValue:`pdf`,options:[{value:`pdf`,label:`PDF`},{value:`excel`,label:`Excel`},{value:`csv`,label:`CSV`},{value:`json`,label:`JSON`},{value:`html`,label:`HTML`}]}]},{key:`schedule`,title:`Schedule`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`schedule`,label:`Schedule`,type:`custom`,render:(e,t)=>(0,h.jsx)(N,{schedule:e,onChange:t})}]},{key:`appearance`,title:`Appearance`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`showToolbar`,label:`Show toolbar`,type:`switch`,defaultValue:!0},{key:`refreshInterval`,label:`Refresh interval`,type:`select`,defaultValue:`0`,options:[{value:`0`,label:`Manual`},{value:`30`,label:`30s`},{value:`60`,label:`1 min`},{value:`300`,label:`5 min`}]}]}]}}function W({open:e,onClose:t,config:i,onSave:a,onFieldChange:o,availableFields:s}){let{draft:c,isDirty:l,updateField:u,discard:d,undo:f,redo:p,canUndo:m,canRedo:g}=(0,r.useConfigDraft)(i,{onUpdate:o});return(0,h.jsx)(r.ConfigPanelRenderer,{open:e,onClose:t,schema:n.useMemo(()=>U(s),[s]),draft:c,isDirty:l,onFieldChange:u,onSave:()=>a(c),onDiscard:d,onUndo:f,onRedo:p,canUndo:m,canRedo:g})}async function G(e,t){let{dataSource:n,resource:r,queryParams:i,format:a,exportConfig:o}=t,s=a||e.defaultExportFormat||`pdf`;try{let t=(await n.find(r,i)).data||[];return S(s,e,t,{format:s,...e.exportConfigs?.[s],...o}),{success:!0,recordCount:t.length,format:s}}catch(e){return{success:!1,recordCount:0,format:s,error:e.message}}}function K(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(J),s=o.map(e=>e.header),c=t.map((e,t)=>o.map(n=>{if(n.formula)return n.formula.replace(/\{ROW\}/g,String(t+2));let r=e[n.name];return Y(r,n.numberFormat)}));if(a&&t.length>0){let n=o.map((n,r)=>{let i=(e.fields||[]).find(e=>e.name===n.name);if(i?.aggregation){let e=Z(r),n=t.length+1;switch(i.aggregation){case`sum`:return`=SUM(${e}2:${e}${n})`;case`avg`:return`=AVERAGE(${e}2:${e}${n})`;case`count`:return`=COUNTA(${e}2:${e}${n})`;case`min`:return`=MIN(${e}2:${e}${n})`;case`max`:return`=MAX(${e}2:${e}${n})`;default:return``}}return``});c.push(n)}$(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
59
- `),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function q(e,t,n,r){return async()=>{let i=e.schedule;if(!i?.enabled)return[];let a=i.formats||[e.defaultExportFormat||`pdf`],o=[];for(let r of a){let i=await G(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function J(e){return{name:e.name,header:e.label||e.name}}function Y(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,X(t)):Q(String(e))}function X(e){if(e.includes(`%`))return{style:`percent`,minimumFractionDigits:0};let t=(e.match(/0/g)||[]).length;return{minimumFractionDigits:Math.max(0,t-1),maximumFractionDigits:Math.max(0,t-1)}}function Z(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function Q(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function $(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}t.ComponentRegistry.register(`report`,g,{namespace:`report`,label:`Report`,category:`Report`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`chart`,type:`code`,label:`Chart Configuration`}]}),t.ComponentRegistry.register(`report-viewer`,M,{namespace:`report`,label:`Report Viewer`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Report Definition`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`}]}),t.ComponentRegistry.register(`report-builder`,P,{namespace:`report`,label:`Report Builder`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Initial Report`}]}),e.ReportBuilder=P,e.ReportConfigPanel=W,e.ReportRenderer=g,e.ReportViewer=M,e.ScheduleConfig=N,e.createScheduleTrigger=q,e.exportAsCSV=_,e.exportAsExcel=x,e.exportAsHTML=y,e.exportAsJSON=v,e.exportAsPDF=b,e.exportExcelWithFormulas=K,e.exportReport=S,e.exportWithLiveData=G,e.formatValue=O});
56
+ </html>`),o.document.close(),o.onload=()=>{o.print()}}function y(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=S(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
57
+ `)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));T(``+[...n?.includeHeaders===!1?[]:[i.join(` `)],...a.map(e=>e.join(` `))].join(`
58
+ `),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function b(e,t,n,r){switch(e){case`csv`:h(t,n,r);break;case`json`:g(t,n,r);break;case`html`:_(t,n,r);break;case`pdf`:v(t,n,r);break;case`excel`:y(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function x(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`)}function S(e){if(typeof e==`string`&&e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`\t${e}`}return e}function C(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function w(e){return e===`landscape`?`landscape`:`portrait`}function T(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function E(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||D(e))return O(e);if(n===`number`||typeof e==`number`){let t=typeof e==`number`?e:Number(e);return isNaN(t)?String(e):r===`currency`||r===`currency_cny`?`¥${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`currency_usd`?`$${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`percent`?`${t.toLocaleString(`en-US`,{minimumFractionDigits:1,maximumFractionDigits:1})}%`:t.toLocaleString(`en-US`)}return String(e)}function D(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function O(e){try{let t=new Date(e);return isNaN(t.getTime())?String(e):`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}catch{return String(e)}}function k(e,t){if(!t||t.length===0||!e||e.length===0)return null;let n=t[0],r=n.field,i=new Map;for(let t of e){let e=String(t[r]??`(empty)`);i.has(e)||i.set(e,[]),i.get(e).push(t)}let a=[];for(let[e,t]of i)a.push({key:e,label:`${n.label||r}: ${e}`,rows:t});let o=n.sort===`desc`?-1:1;return a.sort((e,t)=>e.key.localeCompare(t.key)*o),a}var A=({schema:e,onRefresh:s})=>{let{report:c,data:l,showToolbar:u=!0,allowExport:d=!0,allowPrint:f=!0,loading:p=!1}=e,m=e=>{if(!c){console.warn(`ReportViewer: Cannot export, no report defined`);return}b(e,c,l||[],c.exportConfigs?.[e])},h=()=>{window.print()},g=()=>{s?.()},_=(e,t)=>{if(!l)return 0;let n=l.map(t=>Number(t[e])||0);switch(t){case`count`:return l.length;case`sum`:return n.reduce((e,t)=>e+t,0);case`avg`:return n.length>0?(n.reduce((e,t)=>e+t,0)/n.length).toFixed(2):0;case`min`:return n.length>0?Math.min(...n):0;case`max`:return n.length>0?Math.max(...n):0;default:return``}},v=(e,t)=>{let n=c?.conditionalFormatting;if(!(!n||!Array.isArray(n)))for(let r of n){if(r.field!==e)continue;let n=String(t??``),i=String(r.value??``),a=!1;switch(r.operator){case`equals`:a=n===i;break;case`not_equals`:a=n!==i;break;case`contains`:a=n.includes(i);break;case`greater_than`:a=Number(t)>Number(r.value);break;case`less_than`:a=Number(t)<Number(r.value);break}if(a){let e={};return r.backgroundColor&&(e.backgroundColor=r.backgroundColor),r.textColor&&(e.color=r.textColor),e}}},y=(e,t)=>e==null||e===``?``:t.renderAs===`badge`?(0,i.jsx)(r.Badge,{className:t.colorMap?.[String(e)]||``,children:String(e)}):E(e,t);return c?(0,i.jsxs)(`div`,{className:`space-y-4`,children:[u&&(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`h2`,{className:`text-lg font-semibold`,children:c.title}),c.description&&(0,i.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:c.description})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c.refreshInterval&&(0,i.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:g,children:[(0,i.jsx)(o.RefreshCw,{className:`h-4 w-4 mr-2`}),`Refresh`]}),f&&(0,i.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:h,children:[(0,i.jsx)(o.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),d&&c.showExportButtons&&(0,i.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,i.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>m(`pdf`),children:[(0,i.jsx)(o.Download,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,i.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>m(`excel`),children:[(0,i.jsx)(o.Download,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,i.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>m(`csv`),children:[(0,i.jsx)(o.Download,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,i.jsxs)(r.Card,{children:[(0,i.jsxs)(r.CardHeader,{children:[!u&&c.title&&(0,i.jsx)(r.CardTitle,{children:c.title}),!u&&c.description&&(0,i.jsx)(r.CardDescription,{children:c.description})]}),(0,i.jsxs)(r.CardContent,{className:`space-y-6`,children:[p&&(0,i.jsxs)(`div`,{className:`space-y-6`,children:[(0,i.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,i.jsx)(r.Card,{children:(0,i.jsxs)(r.CardContent,{className:`p-4 space-y-2`,children:[(0,i.jsx)(r.Skeleton,{className:`h-4 w-20`}),(0,i.jsx)(r.Skeleton,{className:`h-8 w-28`})]})},e))}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Skeleton,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,i.jsx)(r.Skeleton,{className:`h-8 w-full`},e))]})]}),!p&&c.sections?.map((e,o)=>e.visible===!1?null:(0,i.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,i.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,i.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,i.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:c.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,i.jsx)(r.Card,{children:(0,i.jsxs)(r.CardContent,{className:`p-4`,children:[(0,i.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,i.jsx)(`div`,{className:`text-2xl font-bold`,children:E(_(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,i.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let n=e.chart.type,r=!!e.chart.chartType;!n&&r&&(n=`chart`),n&&t.ComponentRegistry.get(n)||(n=`chart`);let o=n===`chart`?{xAxisKey:e.chart.xAxisKey||e.chart.xAxisField||`name`,series:e.chart.series||(e.chart.yAxisFields?e.chart.yAxisFields.map(e=>({dataKey:e})):[]),chartType:e.chart.chartType||`bar`}:{};return(0,i.jsx)(a.SchemaRenderer,{schema:{...e.chart,type:n,...o,data:l||e.chart.data,className:e.chart.className||`w-full h-[350px]`}})})()}),e.type===`table`&&(0,i.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,i.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,i.jsx)(`thead`,{className:`bg-muted`,children:(0,i.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,i.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,i.jsx)(`tbody`,{children:(()=>{let t=k(l||[],c.groupBy||[]);return t?t.map(t=>(0,i.jsxs)(n.default.Fragment,{children:[(0,i.jsx)(`tr`,{className:`bg-muted/60`,children:(0,i.jsxs)(`td`,{colSpan:e.columns?.length||1,className:`px-4 py-2 font-semibold text-sm`,children:[t.label,` (`,t.rows.length,`)`]})}),t.rows.map((t,n)=>(0,i.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,i.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:v(e.name,t[e.name]),children:y(t[e.name],e)},n))},n))]},t.key)):l?.map((t,n)=>(0,i.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,i.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:v(e.name,t[e.name]),children:y(t[e.name],e)},n))},n))})()})]})}),e.type===`text`&&e.text&&(0,i.jsx)(`div`,{className:`prose max-w-none`,children:(0,i.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,i.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,i.jsx)(a.SchemaRenderer,{schema:e.content})]},o)),!c.sections&&l&&l.length>0&&(0,i.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,i.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,i.jsx)(`thead`,{className:`bg-muted`,children:(0,i.jsx)(`tr`,{children:c.fields?.map((e,t)=>(0,i.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,i.jsx)(`tbody`,{children:l.map((e,t)=>(0,i.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:c.fields?.map((t,n)=>(0,i.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:v(t.name,e[t.name]),children:y(e[t.name],t)},n))},t))})]})})]})]})]}):(0,i.jsx)(r.Card,{children:(0,i.jsx)(r.CardContent,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})},j=({schedule:e,onChange:t})=>{let[a,s]=(0,n.useState)(e||{enabled:!1,frequency:`weekly`,time:`09:00`,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:[`pdf`]}),c=e=>{let n={...a,...e};s(n),t?.(n)};return(0,i.jsxs)(r.Card,{children:[(0,i.jsx)(r.CardHeader,{children:(0,i.jsxs)(r.CardTitle,{className:`flex items-center gap-2`,children:[(0,i.jsx)(o.Calendar,{className:`h-5 w-5`}),`Schedule Configuration`]})}),(0,i.jsxs)(r.CardContent,{className:`space-y-4`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`input`,{type:`checkbox`,id:`schedule-enabled`,checked:a.enabled||!1,onChange:e=>c({enabled:e.target.checked}),className:`rounded`}),(0,i.jsx)(r.Label,{htmlFor:`schedule-enabled`,children:`Enable Scheduled Report`})]}),a.enabled&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Frequency`}),(0,i.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:a.frequency||`weekly`,onChange:e=>c({frequency:e.target.value}),children:[{value:`once`,label:`Once`},{value:`daily`,label:`Daily`},{value:`weekly`,label:`Weekly`},{value:`monthly`,label:`Monthly`},{value:`quarterly`,label:`Quarterly`},{value:`yearly`,label:`Yearly`}].map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),a.frequency===`weekly`&&(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Day of Week`}),(0,i.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:a.dayOfWeek??1,onChange:e=>c({dayOfWeek:Number(e.target.value)}),children:[{value:0,label:`Sunday`},{value:1,label:`Monday`},{value:2,label:`Tuesday`},{value:3,label:`Wednesday`},{value:4,label:`Thursday`},{value:5,label:`Friday`},{value:6,label:`Saturday`}].map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),a.frequency===`monthly`&&(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Day of Month`}),(0,i.jsx)(r.Input,{type:`number`,min:1,max:31,value:a.dayOfMonth??1,onChange:e=>c({dayOfMonth:Number(e.target.value)})})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsxs)(r.Label,{className:`flex items-center gap-2`,children:[(0,i.jsx)(o.Clock,{className:`h-4 w-4`}),`Time`]}),(0,i.jsx)(r.Input,{type:`time`,value:a.time||`09:00`,onChange:e=>c({time:e.target.value})})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Timezone`}),(0,i.jsx)(r.Input,{value:a.timezone||``,onChange:e=>c({timezone:e.target.value}),placeholder:`e.g. America/New_York`})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Export Formats`}),(0,i.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:[{value:`pdf`,label:`PDF`},{value:`excel`,label:`Excel`},{value:`csv`,label:`CSV`},{value:`html`,label:`HTML`}].map(e=>(0,i.jsxs)(`label`,{className:`flex items-center gap-1.5 px-3 py-1.5 border rounded-md cursor-pointer hover:bg-muted/50`,children:[(0,i.jsx)(`input`,{type:`checkbox`,checked:a.formats?.includes(e.value)||!1,onChange:t=>{let n=a.formats||[];c({formats:t.target.checked?[...n,e.value]:n.filter(t=>t!==e.value)})},className:`rounded`}),(0,i.jsx)(`span`,{className:`text-sm`,children:e.label})]},e.value))})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsxs)(r.Label,{className:`flex items-center gap-2`,children:[(0,i.jsx)(o.Mail,{className:`h-4 w-4`}),`Email Recipients`]}),(0,i.jsx)(r.Input,{placeholder:`email1@example.com, email2@example.com`,value:a.recipients?.join(`, `)||``,onChange:e=>c({recipients:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Email Subject`}),(0,i.jsx)(r.Input,{value:a.subject||``,onChange:e=>c({subject:e.target.value}),placeholder:`Scheduled Report: {report_title}`})]})]})]})]})},M=({schema:e})=>{let{report:t,dataSources:a=[],availableFields:s=[],showPreview:c=!0,onSave:l,onCancel:u}=e,[d,f]=(0,n.useState)(t||{type:`report`,title:`New Report`,fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[p,m]=(0,n.useState)(d.fields||[]),[h,g]=(0,n.useState)(d.filters||[]),[_,v]=(0,n.useState)(d.groupBy||[]),[y,b]=(0,n.useState)(d.sections||[]),x=()=>{if(s.length>0&&p.length<s.length){let e=s.find(e=>!p.some(t=>t.name===e.name));if(e){let t=[...p,e];m(t),f({...d,fields:t})}}},S=e=>{let t=p.filter((t,n)=>n!==e);m(t),f({...d,fields:t})},C=(e,t)=>{let n=[...p];n[e]=t,m(n),f({...d,fields:n})},w=()=>{let e={field:s[0]?.name||``,operator:`equals`,value:``},t=[...h,e];g(t),f({...d,filters:t})},T=e=>{let t=h.filter((t,n)=>n!==e);g(t),f({...d,filters:t})},E=(e,t)=>{let n=[...h];n[e]=t,g(n),f({...d,filters:n})},D=()=>{let e={field:s[0]?.name||``,sort:`asc`},t=[..._,e];v(t),f({...d,groupBy:t})},O=e=>{let t=_.filter((t,n)=>n!==e);v(t),f({...d,groupBy:t})},k=(e,t)=>{let n=[..._];n[e]=t,v(n),f({...d,groupBy:n})},M=e=>{let t={type:e,title:`New ${e} Section`},n=[...y,t];b(n),f({...d,sections:n})},N=e=>{let t=y.filter((t,n)=>n!==e);b(t),f({...d,sections:t})},P=(e,t)=>{let n=[...y];n[e]=t,b(n),f({...d,sections:n})};return(0,i.jsxs)(`div`,{className:`space-y-4`,children:[(0,i.jsxs)(r.Card,{children:[(0,i.jsxs)(r.CardHeader,{children:[(0,i.jsx)(r.CardTitle,{children:`Report Builder`}),(0,i.jsx)(r.CardDescription,{children:`Configure your report settings, fields, filters, and sections`})]}),(0,i.jsxs)(r.CardContent,{children:[(0,i.jsxs)(r.Tabs,{defaultValue:`basic`,className:`w-full`,children:[(0,i.jsxs)(r.TabsList,{className:`grid w-full grid-cols-6`,children:[(0,i.jsxs)(r.TabsTrigger,{value:`basic`,children:[(0,i.jsx)(o.Settings,{className:`h-4 w-4 mr-2`}),`Basic`]}),(0,i.jsxs)(r.TabsTrigger,{value:`fields`,children:[(0,i.jsx)(o.Layers,{className:`h-4 w-4 mr-2`}),`Fields`]}),(0,i.jsxs)(r.TabsTrigger,{value:`filters`,children:[(0,i.jsx)(o.Filter,{className:`h-4 w-4 mr-2`}),`Filters`]}),(0,i.jsxs)(r.TabsTrigger,{value:`grouping`,children:[(0,i.jsx)(o.Layers,{className:`h-4 w-4 mr-2`}),`Group By`]}),(0,i.jsxs)(r.TabsTrigger,{value:`sections`,children:[(0,i.jsx)(o.Layers,{className:`h-4 w-4 mr-2`}),`Sections`]}),(0,i.jsxs)(r.TabsTrigger,{value:`schedule`,children:[(0,i.jsx)(o.Calendar,{className:`h-4 w-4 mr-2`}),`Schedule`]})]}),(0,i.jsx)(r.TabsContent,{value:`basic`,className:`space-y-4 mt-4`,children:(0,i.jsxs)(`div`,{className:`space-y-4`,children:[(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{htmlFor:`report-title`,children:`Report Title`}),(0,i.jsx)(r.Input,{id:`report-title`,value:d.title||``,onChange:e=>f({...d,title:e.target.value}),placeholder:`Enter report title`})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{htmlFor:`report-description`,children:`Description`}),(0,i.jsx)(r.Input,{id:`report-description`,value:d.description||``,onChange:e=>f({...d,description:e.target.value}),placeholder:`Enter report description`})]}),a.length>0&&(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Data Source`}),(0,i.jsxs)(`select`,{className:`w-full border rounded-md p-2`,children:[(0,i.jsx)(`option`,{value:``,children:`Select a data source`}),a.map((e,t)=>(0,i.jsxs)(`option`,{value:t,children:[`Data Source `,t+1]},t))]})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{children:`Export Options`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,i.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`input`,{type:`checkbox`,checked:d.showExportButtons||!1,onChange:e=>f({...d,showExportButtons:e.target.checked})}),(0,i.jsx)(`span`,{className:`text-sm`,children:`Show Export Buttons`})]}),(0,i.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`input`,{type:`checkbox`,checked:d.showPrintButton||!1,onChange:e=>f({...d,showPrintButton:e.target.checked})}),(0,i.jsx)(`span`,{className:`text-sm`,children:`Show Print Button`})]})]})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(r.Label,{htmlFor:`export-format`,children:`Default Export Format`}),(0,i.jsxs)(`select`,{id:`export-format`,className:`w-full border rounded-md p-2`,value:d.defaultExportFormat||`pdf`,onChange:e=>f({...d,defaultExportFormat:e.target.value}),children:[(0,i.jsx)(`option`,{value:`pdf`,children:`PDF`}),(0,i.jsx)(`option`,{value:`excel`,children:`Excel`}),(0,i.jsx)(`option`,{value:`csv`,children:`CSV`}),(0,i.jsx)(`option`,{value:`json`,children:`JSON`}),(0,i.jsx)(`option`,{value:`html`,children:`HTML`})]})]})]})}),(0,i.jsxs)(r.TabsContent,{value:`fields`,className:`space-y-4 mt-4`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,i.jsx)(r.Label,{children:`Report Fields`}),(0,i.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:x,disabled:p.length>=s.length,children:[(0,i.jsx)(o.Plus,{className:`h-4 w-4 mr-2`}),`Add Field`]})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[p.map((e,t)=>(0,i.jsx)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:(0,i.jsxs)(`div`,{className:`flex-1 grid grid-cols-4 gap-2`,children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Field Name`}),(0,i.jsx)(`div`,{className:`text-sm font-medium`,children:e.name})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Label`}),(0,i.jsx)(r.Input,{className:`h-8 text-sm`,value:e.label||e.name,onChange:n=>C(t,{...e,label:n.target.value})})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Aggregation`}),(0,i.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.aggregation||``,onChange:n=>C(t,{...e,aggregation:n.target.value}),children:[(0,i.jsx)(`option`,{value:``,children:`None`}),(0,i.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,i.jsx)(`option`,{value:`count`,children:`Count`}),(0,i.jsx)(`option`,{value:`avg`,children:`Average`}),(0,i.jsx)(`option`,{value:`min`,children:`Min`}),(0,i.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,i.jsx)(`div`,{className:`flex items-end justify-end`,children:(0,i.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>S(t),children:(0,i.jsx)(o.Trash2,{className:`h-4 w-4`})})})]})},t)),p.length===0&&(0,i.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No fields selected. Click "Add Field" to begin.`})]})]}),(0,i.jsxs)(r.TabsContent,{value:`filters`,className:`space-y-4 mt-4`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,i.jsx)(r.Label,{children:`Report Filters`}),(0,i.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:w,children:[(0,i.jsx)(o.Plus,{className:`h-4 w-4 mr-2`}),`Add Filter`]})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[h.map((e,t)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,i.jsxs)(`div`,{className:`flex-1 grid grid-cols-3 gap-2`,children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Field`}),(0,i.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>E(t,{...e,field:n.target.value}),children:s.map((e,t)=>(0,i.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Operator`}),(0,i.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.operator,onChange:n=>E(t,{...e,operator:n.target.value}),children:[(0,i.jsx)(`option`,{value:`equals`,children:`Equals`}),(0,i.jsx)(`option`,{value:`contains`,children:`Contains`}),(0,i.jsx)(`option`,{value:`gt`,children:`Greater Than`}),(0,i.jsx)(`option`,{value:`lt`,children:`Less Than`}),(0,i.jsx)(`option`,{value:`between`,children:`Between`})]})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Value`}),(0,i.jsx)(r.Input,{className:`h-8 text-sm`,value:String(e.value),onChange:n=>E(t,{...e,value:n.target.value})})]})]}),(0,i.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>T(t),children:(0,i.jsx)(o.Trash2,{className:`h-4 w-4`})})]},t)),h.length===0&&(0,i.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No filters defined.`})]})]}),(0,i.jsxs)(r.TabsContent,{value:`grouping`,className:`space-y-4 mt-4`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,i.jsx)(r.Label,{children:`Grouping Rules`}),(0,i.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:D,children:[(0,i.jsx)(o.Plus,{className:`h-4 w-4 mr-2`}),`Add Group`]})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[_.map((e,t)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,i.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Field`}),(0,i.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>k(t,{...e,field:n.target.value}),children:s.map((e,t)=>(0,i.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Sort Order`}),(0,i.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.sort||`asc`,onChange:n=>k(t,{...e,sort:n.target.value}),children:[(0,i.jsx)(`option`,{value:`asc`,children:`Ascending`}),(0,i.jsx)(`option`,{value:`desc`,children:`Descending`})]})]})]}),(0,i.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>O(t),children:(0,i.jsx)(o.Trash2,{className:`h-4 w-4`})})]},t)),_.length===0&&(0,i.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No grouping rules applied.`})]})]}),(0,i.jsxs)(r.TabsContent,{value:`sections`,className:`space-y-4 mt-4`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,i.jsx)(r.Label,{children:`Report Sections`}),(0,i.jsxs)(`div`,{className:`flex gap-2`,children:[(0,i.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:()=>M(`header`),children:[(0,i.jsx)(o.Plus,{className:`h-4 w-4 mr-2`}),`Header`]}),(0,i.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:()=>M(`chart`),children:[(0,i.jsx)(o.Plus,{className:`h-4 w-4 mr-2`}),`Chart`]}),(0,i.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:()=>M(`table`),children:[(0,i.jsx)(o.Plus,{className:`h-4 w-4 mr-2`}),`Table`]})]})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[y.map((e,t)=>(0,i.jsxs)(`div`,{className:`p-3 border rounded-lg space-y-2`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,i.jsxs)(`div`,{className:`font-medium flex items-center gap-2`,children:[(0,i.jsx)(`div`,{className:`text-xs bg-muted px-2 py-0.5 rounded uppercase`,children:e.type}),e.title]}),(0,i.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>N(t),children:(0,i.jsx)(o.Trash2,{className:`h-4 w-4`})})]}),(0,i.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Title`}),(0,i.jsx)(r.Input,{className:`h-8 text-sm`,value:e.title||``,onChange:n=>P(t,{...e,title:n.target.value})})]}),e.type===`text`&&(0,i.jsxs)(`div`,{className:`col-span-2`,children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Content`}),(0,i.jsx)(r.Input,{className:`h-8 text-sm`,value:e.text||``,onChange:n=>P(t,{...e,text:n.target.value})})]}),e.type===`chart`&&(0,i.jsxs)(`div`,{className:`col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded`,children:[(0,i.jsx)(`div`,{className:`col-span-2`,children:(0,i.jsx)(r.Label,{className:`text-xs font-semibold`,children:`Chart Configuration`})}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Chart Type`}),(0,i.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.chartType||`bar`,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,chartType:n.target.value}}),children:[(0,i.jsx)(`option`,{value:`bar`,children:`Bar`}),(0,i.jsx)(`option`,{value:`line`,children:`Line`}),(0,i.jsx)(`option`,{value:`area`,children:`Area`}),(0,i.jsx)(`option`,{value:`pie`,children:`Pie`})]})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`X-Axis Field`}),(0,i.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.xAxisField||``,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,xAxisField:n.target.value}}),children:[(0,i.jsx)(`option`,{value:``,children:`Select Field...`}),s.map(e=>(0,i.jsx)(`option`,{value:e.name,children:e.label||e.name},e.name)),s.length===0&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`option`,{value:`name`,children:`Name`}),(0,i.jsx)(`option`,{value:`month`,children:`Month`})]})]})]}),(0,i.jsxs)(`div`,{className:`col-span-2`,children:[(0,i.jsx)(r.Label,{className:`text-xs`,children:`Y-Axis Fields (comma separated)`}),(0,i.jsx)(r.Input,{className:`h-8 text-sm`,placeholder:`e.g. value, count`,value:e.chart?.yAxisFields?.join(`, `)||``,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,yAxisFields:n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}})})]})]})]})]},t)),y.length===0&&(0,i.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No customized sections. The default report layout will be used.`})]})]}),(0,i.jsx)(r.TabsContent,{value:`schedule`,className:`space-y-4 mt-4`,children:(0,i.jsx)(j,{schedule:d.schedule,onChange:e=>f({...d,schedule:e})})})]}),(0,i.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-6 pt-4 border-t`,children:[(0,i.jsx)(r.Button,{variant:`outline`,onClick:()=>{u&&console.log(`Report cancelled:`,u)},children:`Cancel`}),(0,i.jsxs)(r.Button,{onClick:()=>{console.log(`Saving report:`,d),l&&alert(`Report saved! (Handler: `+l+`)`)},children:[(0,i.jsx)(o.Save,{className:`h-4 w-4 mr-2`}),`Save Report`]})]})]})]}),c&&(0,i.jsxs)(r.Card,{className:`mt-8 border-2 border-blue-100`,children:[(0,i.jsx)(r.CardHeader,{className:`bg-blue-50/50`,children:(0,i.jsx)(r.CardTitle,{className:`text-blue-900 text-sm uppercase tracking-wide`,children:`Live Preview`})}),(0,i.jsx)(r.CardContent,{className:`pt-6`,children:(0,i.jsx)(A,{schema:{type:`report-viewer`,report:{...d,fields:p,filters:h,groupBy:_,sections:y},data:[{id:1,name:`Sample Item A`,value:100,status:`New`},{id:2,name:`Sample Item B`,value:250,status:`Active`},{id:3,name:`Sample Item C`,value:75,status:`Closed`}]}})})]})]})},N=[{value:``,label:`None`},{value:`sum`,label:`Sum`},{value:`count`,label:`Count`},{value:`avg`,label:`Average`},{value:`min`,label:`Min`},{value:`max`,label:`Max`}];function P({availableFields:e,value:t,onChange:n}){let a=Array.isArray(t)?t.map(e=>typeof e==`string`?{name:e,label:e,type:`string`}:{name:e.name||e.field||e.value,label:e.label||e.name||``,type:e.type||`string`,aggregation:e.aggregation}):[],o=a.map(e=>e.name),s=t=>{let r=o.includes(t),i;if(r)i=a.filter(e=>e.name!==t);else{let n=e.find(e=>e.value===t);i=[...a,{name:t,label:n?.label||t,type:n?.type||`string`}]}n(i)},c=(e,t)=>{n(a.map(n=>n.name===e?{...n,aggregation:t||void 0,showInSummary:!!t}:n))};return e.length===0?(0,i.jsx)(`div`,{className:`text-xs text-muted-foreground py-2`,"data-testid":`field-picker-empty`,children:`No fields available`}):(0,i.jsx)(`div`,{className:`space-y-1 py-1`,"data-testid":`field-picker`,children:e.map(e=>{let t=o.includes(e.value),n=a.find(t=>t.name===e.value);return(0,i.jsxs)(`div`,{className:`flex items-center gap-2 px-1 py-0.5 rounded hover:bg-muted/50 text-xs`,children:[(0,i.jsxs)(`label`,{className:`flex items-center gap-2 flex-1 cursor-pointer`,children:[(0,i.jsx)(r.Checkbox,{checked:t,onCheckedChange:()=>s(e.value),"data-testid":`field-picker-${e.value}`}),(0,i.jsx)(`span`,{className:`flex-1`,children:e.label}),e.type&&(0,i.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.type})]}),t&&(0,i.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background`,value:n?.aggregation||``,onChange:t=>c(e.value,t.target.value),"data-testid":`field-agg-${e.value}`,children:N.map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))})]},e.value)})})}var F=[{value:``,label:`None`},{value:`bar`,label:`Bar Chart`},{value:`line`,label:`Line Chart`},{value:`pie`,label:`Pie Chart`},{value:`area`,label:`Area Chart`},{value:`donut`,label:`Donut Chart`},{value:`scatter`,label:`Scatter Plot`}];function I({availableFields:e,value:t,onChange:n}){let r=t||{},a=e=>n({...r,...e});return(0,i.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`chart-config`,children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`Chart type`}),(0,i.jsx)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:r.chartType||``,onChange:e=>a({chartType:e.target.value||void 0}),"data-testid":`chart-type-select`,children:F.map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),r.chartType&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`X-axis field`}),(0,i.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:r.xAxisField||``,onChange:e=>a({xAxisField:e.target.value||void 0}),"data-testid":`chart-x-field`,children:[(0,i.jsx)(`option`,{value:``,children:`Select field…`}),e.map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`Y-axis field`}),(0,i.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:r.yAxisFields?.[0]||``,onChange:e=>a({yAxisFields:e.target.value?[e.target.value]:[]}),"data-testid":`chart-y-field`,children:[(0,i.jsx)(`option`,{value:``,children:`Select field…`}),e.filter(e=>e.type===`number`).map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]})]})]})}var L=[{value:`equals`,label:`=`},{value:`not_equals`,label:`≠`},{value:`greater_than`,label:`>`},{value:`less_than`,label:`<`},{value:`contains`,label:`Contains`}];function R({availableFields:e,value:t,onChange:n}){let a=Array.isArray(t)?t:[],s=()=>{n([...a,{field:e[0]?.value||``,operator:`equals`,value:``,backgroundColor:`#fef9c3`,textColor:``}])},c=e=>{n(a.filter((t,n)=>n!==e))},l=(e,t)=>{n(a.map((n,r)=>r===e?{...n,...t}:n))};return(0,i.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`conditional-format-rules`,children:[a.map((t,n)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1 border rounded bg-muted/20`,children:[(0,i.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background flex-1`,value:t.field,onChange:e=>l(n,{field:e.target.value}),"data-testid":`cf-rule-field-${n}`,children:e.map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,i.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-12`,value:t.operator,onChange:e=>l(n,{operator:e.target.value}),children:L.map(e=>(0,i.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,i.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-16`,value:t.value,placeholder:`value`,onChange:e=>l(n,{value:e.target.value}),"data-testid":`cf-rule-value-${n}`}),(0,i.jsx)(`input`,{type:`color`,className:`h-5 w-5 rounded border cursor-pointer`,value:t.backgroundColor||`#fef9c3`,onChange:e=>l(n,{backgroundColor:e.target.value}),title:`Background color`}),(0,i.jsx)(r.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0`,onClick:()=>c(n),"data-testid":`cf-rule-remove-${n}`,children:(0,i.jsx)(o.Trash2,{className:`h-3 w-3`})})]},n)),(0,i.jsxs)(r.Button,{type:`button`,size:`sm`,variant:`outline`,className:`h-6 text-[10px] w-full`,onClick:s,"data-testid":`cf-add-rule`,children:[(0,i.jsx)(o.Plus,{className:`h-3 w-3 mr-1`}),`Add Rule`]})]})}var z=[{value:`header`,label:`Header`},{value:`summary`,label:`Summary`},{value:`table`,label:`Table`},{value:`chart`,label:`Chart`},{value:`text`,label:`Text`}];function B({value:e,onChange:t}){let n=Array.isArray(e)?e:[],a=e=>{t([...n,{type:e,title:`New ${e}`,visible:!0}])},s=e=>{t(n.filter((t,n)=>n!==e))},c=(e,r)=>{t(n.map((t,n)=>n===e?{...t,...r}:t))},l=(e,r)=>{let i=e+r;if(i<0||i>=n.length)return;let a=[...n];[a[e],a[i]]=[a[i],a[e]],t(a)};return(0,i.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`section-manager`,children:[n.map((e,t)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1.5 border rounded bg-muted/20`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col gap-0.5 mr-1`,children:[(0,i.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===0,onClick:()=>l(t,-1),"data-testid":`section-up-${t}`,children:`▲`}),(0,i.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===n.length-1,onClick:()=>l(t,1),"data-testid":`section-down-${t}`,children:`▼`})]}),(0,i.jsx)(`span`,{className:`text-[9px] bg-muted px-1.5 py-0.5 rounded uppercase font-medium shrink-0`,children:e.type}),(0,i.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background flex-1 min-w-0`,value:e.title||``,placeholder:`Section title`,onChange:e=>c(t,{title:e.target.value}),"data-testid":`section-title-${t}`}),(0,i.jsx)(r.Button,{type:`button`,size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0 shrink-0`,onClick:()=>s(t),"data-testid":`section-remove-${t}`,children:(0,i.jsx)(o.Trash2,{className:`h-3 w-3`})})]},t)),(0,i.jsx)(`div`,{className:`flex gap-1 flex-wrap`,children:z.map(e=>(0,i.jsxs)(r.Button,{type:`button`,size:`sm`,variant:`outline`,className:`h-6 text-[10px]`,onClick:()=>a(e.value),"data-testid":`section-add-${e.value}`,children:[(0,i.jsx)(o.Plus,{className:`h-3 w-3 mr-0.5`}),e.label]},e.value))})]})}function V(e=[]){return{breadcrumb:[`Report`,`Configuration`],sections:[{key:`basic`,title:`Basic`,fields:[{key:`title`,label:`Title`,type:`input`,placeholder:`Report title`},{key:`description`,label:`Description`,type:`input`,placeholder:`Report description`},{key:`reportType`,label:`Report type`,type:`select`,defaultValue:`tabular`,options:[{value:`tabular`,label:`Tabular`},{value:`summary`,label:`Summary`},{value:`matrix`,label:`Matrix`}],helpText:`Tabular: flat table. Summary: grouped with subtotals. Matrix: pivot table (planned).`}]},{key:`data`,title:`Data`,collapsible:!0,fields:[{key:`objectName`,label:`Data source`,type:`input`,placeholder:`e.g. opportunity`,helpText:`Object name to query data from`},{key:`limit`,label:`Row limit`,type:`input`,defaultValue:`100`,placeholder:`e.g. 100`}]},{key:`columns`,title:`Columns`,collapsible:!0,hint:`Select fields to display as report columns. Set aggregation per column for summary reports.`,fields:[{key:`fields`,label:`Report columns`,type:`custom`,render:(t,n)=>(0,i.jsx)(P,{availableFields:e,value:t,onChange:n})}]},{key:`filters`,title:`Filters`,collapsible:!0,hint:`Define filter conditions for the report data`,fields:[{key:`filters`,label:`Conditions`,type:`filter`,fields:e}]},{key:`groupBy`,title:`Group By`,collapsible:!0,hint:`Group report data and compute aggregations`,fields:[{key:`groupBy`,label:`Grouping`,type:`sort`,fields:e}]},{key:`chart`,title:`Chart`,collapsible:!0,hint:`Add a chart visualization to the report`,fields:[{key:`chartConfig`,label:`Chart`,type:`custom`,render:(t,n)=>(0,i.jsx)(I,{availableFields:e,value:t,onChange:n})}]},{key:`conditionalFormatting`,title:`Conditional Format`,collapsible:!0,defaultCollapsed:!0,hint:`Highlight cells based on field value conditions`,fields:[{key:`conditionalFormatting`,label:`Rules`,type:`custom`,render:(t,n)=>(0,i.jsx)(R,{availableFields:e,value:t,onChange:n})}]},{key:`sections`,title:`Sections`,collapsible:!0,defaultCollapsed:!0,hint:`Manage report layout blocks (header, table, chart, summary)`,fields:[{key:`sections`,label:`Report sections`,type:`custom`,render:(e,t)=>(0,i.jsx)(B,{value:e,onChange:t})}]},{key:`export`,title:`Export`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`showExportButtons`,label:`Show export buttons`,type:`switch`,defaultValue:!0},{key:`showPrintButton`,label:`Show print button`,type:`switch`,defaultValue:!0},{key:`defaultExportFormat`,label:`Default export format`,type:`select`,defaultValue:`pdf`,options:[{value:`pdf`,label:`PDF`},{value:`excel`,label:`Excel`},{value:`csv`,label:`CSV`},{value:`json`,label:`JSON`},{value:`html`,label:`HTML`}]}]},{key:`schedule`,title:`Schedule`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`schedule`,label:`Schedule`,type:`custom`,render:(e,t)=>(0,i.jsx)(j,{schedule:e,onChange:t})}]},{key:`appearance`,title:`Appearance`,collapsible:!0,defaultCollapsed:!0,fields:[{key:`showToolbar`,label:`Show toolbar`,type:`switch`,defaultValue:!0},{key:`refreshInterval`,label:`Refresh interval`,type:`select`,defaultValue:`0`,options:[{value:`0`,label:`Manual`},{value:`30`,label:`30s`},{value:`60`,label:`1 min`},{value:`300`,label:`5 min`}]}]}]}}function H({open:e,onClose:t,config:a,onSave:o,onFieldChange:s,availableFields:c}){let{draft:l,isDirty:u,updateField:d,discard:f,undo:p,redo:m,canUndo:h,canRedo:g}=(0,r.useConfigDraft)(a,{onUpdate:s});return(0,i.jsx)(r.ConfigPanelRenderer,{open:e,onClose:t,schema:n.useMemo(()=>V(c),[c]),draft:l,isDirty:u,onFieldChange:d,onSave:()=>o(l),onDiscard:f,onUndo:p,onRedo:m,canUndo:h,canRedo:g})}async function U(e,t){let{dataSource:n,resource:r,queryParams:i,format:a,exportConfig:o}=t,s=a||e.defaultExportFormat||`pdf`;try{let t=(await n.find(r,i)).data||[];return b(s,e,t,{format:s,...e.exportConfigs?.[s],...o}),{success:!0,recordCount:t.length,format:s}}catch(e){return{success:!1,recordCount:0,format:s,error:e.message}}}function W(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(K),s=o.map(e=>e.header),c=t.map((e,t)=>o.map(n=>{if(n.formula)return n.formula.replace(/\{ROW\}/g,String(t+2));let r=e[n.name];return q(r,n.numberFormat)}));if(a&&t.length>0){let n=o.map((n,r)=>{let i=(e.fields||[]).find(e=>e.name===n.name);if(i?.aggregation){let e=Y(r),n=t.length+1;switch(i.aggregation){case`sum`:return`=SUM(${e}2:${e}${n})`;case`avg`:return`=AVERAGE(${e}2:${e}${n})`;case`count`:return`=COUNTA(${e}2:${e}${n})`;case`min`:return`=MIN(${e}2:${e}${n})`;case`max`:return`=MAX(${e}2:${e}${n})`;default:return``}}return``});c.push(n)}Z(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
59
+ `),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function G(e,t,n,r){return async()=>{let i=e.schedule;if(!i?.enabled)return[];let a=i.formats||[e.defaultExportFormat||`pdf`],o=[];for(let r of a){let i=await U(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function K(e){return{name:e.name,header:e.label||e.name}}function q(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,J(t)):X(String(e))}function J(e){if(e.includes(`%`))return{style:`percent`,minimumFractionDigits:0};let t=(e.match(/0/g)||[]).length;return{minimumFractionDigits:Math.max(0,t-1),maximumFractionDigits:Math.max(0,t-1)}}function Y(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function X(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function Z(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}t.ComponentRegistry.register(`report`,m,{namespace:`report`,label:`Report`,category:`Report`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`chart`,type:`code`,label:`Chart Configuration`}]}),t.ComponentRegistry.register(`report-viewer`,A,{namespace:`report`,label:`Report Viewer`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Report Definition`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`}]}),t.ComponentRegistry.register(`report-builder`,M,{namespace:`report`,label:`Report Builder`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Initial Report`}]}),e.ReportBuilder=M,e.ReportConfigPanel=H,e.ReportRenderer=m,e.ReportViewer=A,e.ScheduleConfig=j,e.createScheduleTrigger=G,e.exportAsCSV=h,e.exportAsExcel=y,e.exportAsHTML=_,e.exportAsJSON=g,e.exportAsPDF=v,e.exportExcelWithFormulas=W,e.exportReport=b,e.exportWithLiveData=U,e.formatValue=E});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-report",
3
- "version": "4.0.1",
3
+ "version": "4.0.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.umd.cjs",
6
6
  "module": "dist/index.js",
@@ -22,11 +22,11 @@
22
22
  "clsx": "^2.1.1",
23
23
  "lucide-react": "^1.14.0",
24
24
  "tailwind-merge": "^3.5.0",
25
- "@object-ui/components": "4.0.1",
26
- "@object-ui/core": "4.0.1",
27
- "@object-ui/fields": "4.0.1",
28
- "@object-ui/react": "4.0.1",
29
- "@object-ui/types": "4.0.1"
25
+ "@object-ui/components": "4.0.4",
26
+ "@object-ui/core": "4.0.4",
27
+ "@object-ui/fields": "4.0.4",
28
+ "@object-ui/react": "4.0.4",
29
+ "@object-ui/types": "4.0.4"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "react": "^18.0.0",