@object-ui/plugin-report 3.1.5 → 3.3.1

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,15 +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),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);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=>{process.env.NODE_ENV!==`production`&&(function(){function t(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===O?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(typeof e.tag==`number`&&console.error(`Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.`),e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var n=e.render;return e=e.displayName,e||=(e=n.displayName||n.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return n=e.displayName||null,n===null?t(e.type)||`Memo`:n;case E:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function n(e){return``+e}function r(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var r=t.error,i=typeof Symbol==`function`&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||`Object`;return r.call(t,`The provided key is an unsupported type %s. This value must be coerced to a string before using it here.`,i),n(e)}}function i(e){if(e===_)return`<>`;if(typeof e==`object`&&e&&e.$$typeof===E)return`<...>`;try{var n=t(e);return n?`<`+n+`>`:`<...>`}catch{return`<...>`}}function a(){var e=k.A;return e===null?null:e.getOwner()}function o(){return Error(`react-stack-top-frame`)}function s(e){if(A.call(e,`key`)){var t=Object.getOwnPropertyDescriptor(e,`key`).get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function c(e,t){function n(){N||(N=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,`key`,{get:n,configurable:!0})}function l(){var e=t(this.type);return P[e]||(P[e]=!0,console.error(`Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.`)),e=this.props.ref,e===void 0?null:e}function u(e,t,n,r,i,a){var o=n.ref;return e={$$typeof:h,type:e,key:t,props:n,_owner:r},(o===void 0?null:o)===null?Object.defineProperty(e,`ref`,{enumerable:!1,value:null}):Object.defineProperty(e,`ref`,{enumerable:!1,get:l}),e._store={},Object.defineProperty(e._store,`validated`,{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,`_debugInfo`,{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,`_debugStack`,{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.defineProperty(e,`_debugTask`,{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,n,i,o,l,d){var p=n.children;if(p!==void 0)if(o)if(j(p)){for(o=0;o<p.length;o++)f(p[o]);Object.freeze&&Object.freeze(p)}else console.error(`React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.`);else f(p);if(A.call(n,`key`)){p=t(e);var m=Object.keys(n).filter(function(e){return e!==`key`});o=0<m.length?`{key: someKey, `+m.join(`: ..., `)+`: ...}`:`{key: someKey}`,L[p+o]||(m=0<m.length?`{`+m.join(`: ..., `)+`: ...}`:`{}`,console.error(`A props object containing a "key" prop is being spread into JSX:
2
- let props = %s;
3
- <%s {...props} />
4
- React keys must be passed directly to JSX without using spread:
5
- let props = %s;
6
- <%s key={someKey} {...props} />`,o,p,m,p),L[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require(`react`),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.client.reference`),k=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,A=Object.prototype.hasOwnProperty,j=Array.isArray,M=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var N,P={},F=m.react_stack_bottom_frame.bind(m,o)(),I=M(i(o)),L={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)},e.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)}})()})),g=f(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=m():t.exports=h()}))(),_=({schema:e})=>{let{title:n,description:i,data:a,columns:o}=e;e.chart?.type;let s=!!e.chart,c=process.env.NODE_ENV!==`test`;return(0,g.jsxs)(r.Card,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,g.jsxs)(r.CardHeader,{children:[n&&(0,g.jsx)(r.CardTitle,{children:n}),i&&(0,g.jsx)(r.CardDescription,{children:i})]}),(0,g.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,g.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,g.jsx)(r,{schema:{...e.chart,data:e.chart.data||a}})}):(0,g.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,g.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=c?t.ComponentRegistry.get(`aggrid`)||t.ComponentRegistry.get(`table`):null;return e?(0,g.jsx)(e,{schema:{type:`aggrid`,rowData:a,columnDefs:o,domLayout:`autoHeight`}}):(0,g.jsx)(`div`,{className:`overflow-x-auto`,children:(0,g.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,g.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,g.jsx)(`tr`,{children:o?.map(e=>(0,g.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,g.jsx)(`tbody`,{children:a.map((e,t)=>(0,g.jsx)(`tr`,{className:`bg-background border-b`,children:o?.map(t=>(0,g.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function v(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=T(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
7
- `))?`"${n.replace(/"/g,`""`)}"`:n??``}));O([...n?.includeHeaders===!1?[]:[i.join(`,`)],...a.map(e=>e.join(`,`))].join(`
8
- `),n?.filename||`${e.title||`report`}.csv`,`text/csv`)}function y(e,t,n){let r={title:e.title,description:e.description,generatedAt:new Date().toISOString(),data:t};O(JSON.stringify(r,null,2),n?.filename||`${e.title||`report`}.json`,`application/json`)}function b(e,t,n){let r=e.fields||[],i=D(n?.orientation),a=E(n?.pageSize);O(`<!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(`@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>
9
4
  <html>
10
5
  <head>
11
6
  <meta charset="utf-8">
12
- <title>${w(e.title||`Report`)}</title>
7
+ <title>${C(e.title||`Report`)}</title>
13
8
  <style>
14
9
  @page { size: ${a} ${i}; margin: 20mm; }
15
10
  body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
@@ -23,19 +18,19 @@ React keys must be passed directly to JSX without using spread:
23
18
  </style>
24
19
  </head>
25
20
  <body>
26
- <h1>${w(e.title||`Report`)}</h1>
27
- ${e.description?`<p class="description">${w(e.description)}</p>`:``}
21
+ <h1>${C(e.title||`Report`)}</h1>
22
+ ${e.description?`<p class="description">${C(e.description)}</p>`:``}
28
23
  <p class="meta">Generated: ${new Date().toLocaleString()}</p>
29
24
  <table>
30
- <thead><tr>${r.map(e=>`<th>${w(e.label||e.name)}</th>`).join(``)}</tr></thead>
31
- <tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${w(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
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>
32
27
  </table>
33
28
  </body>
34
- </html>`,n?.filename||`${e.title||`report`}.html`,`text/html`)}function x(e,t,n){let r=e.fields||[],i=D(n?.orientation),a=E(n?.pageSize),o=window.open(``,`_blank`);if(!o){b(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 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>
35
30
  <html>
36
31
  <head>
37
32
  <meta charset="utf-8">
38
- <title>${w(e.title||`Report`)}</title>
33
+ <title>${C(e.title||`Report`)}</title>
39
34
  <style>
40
35
  @page { size: ${a} ${i}; margin: 20mm; }
41
36
  @media print { .no-print { display: none; } }
@@ -50,15 +45,15 @@ ${e.description?`<p class="description">${w(e.description)}</p>`:``}
50
45
  </style>
51
46
  </head>
52
47
  <body>
53
- <h1>${w(e.title||`Report`)}</h1>
54
- ${e.description?`<p class="description">${w(e.description)}</p>`:``}
48
+ <h1>${C(e.title||`Report`)}</h1>
49
+ ${e.description?`<p class="description">${C(e.description)}</p>`:``}
55
50
  <p class="meta">Generated: ${new Date().toLocaleString()}</p>
56
51
  <table>
57
- <thead><tr>${r.map(e=>`<th>${w(e.label||e.name)}</th>`).join(``)}</tr></thead>
58
- <tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${w(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
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>
59
54
  </table>
60
55
  </body>
61
- </html>`),o.document.close(),o.onload=()=>{o.print()}}function S(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=T(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
62
- `)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));O(``+[...n?.includeHeaders===!1?[]:[i.join(` `)],...a.map(e=>e.join(` `))].join(`
63
- `),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function C(e,t,n,r){switch(e){case`csv`:v(t,n,r);break;case`json`:y(t,n,r);break;case`html`:b(t,n,r);break;case`pdf`:x(t,n,r);break;case`excel`:S(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function w(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`)}function T(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 E(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function D(e){return e===`landscape`?`landscape`:`portrait`}function O(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 k(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||A(e))return j(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 A(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function j(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 M(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 N=({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}C(e,s,c||[],s.exportConfigs?.[e])},m=()=>{window.print()},h=()=>{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,g.jsx)(r.Badge,{className:t.colorMap?.[String(e)]||``,children:String(e)}):k(e,t);return s?(0,g.jsxs)(`div`,{className:`space-y-4`,children:[l&&(0,g.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`h2`,{className:`text-lg font-semibold`,children:s.title}),s.description&&(0,g.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:s.description})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.refreshInterval&&(0,g.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:h,children:[(0,g.jsx)(a.RefreshCw,{className:`h-4 w-4 mr-2`}),`Refresh`]}),d&&(0,g.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:m,children:[(0,g.jsx)(a.Printer,{className:`h-4 w-4 mr-2`}),`Print`]}),u&&s.showExportButtons&&(0,g.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,g.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>p(`pdf`),children:[(0,g.jsx)(a.Download,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,g.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>p(`excel`),children:[(0,g.jsx)(a.Download,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,g.jsxs)(r.Button,{variant:`outline`,size:`sm`,onClick:()=>p(`csv`),children:[(0,g.jsx)(a.Download,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,g.jsxs)(r.Card,{children:[(0,g.jsxs)(r.CardHeader,{children:[!l&&s.title&&(0,g.jsx)(r.CardTitle,{children:s.title}),!l&&s.description&&(0,g.jsx)(r.CardDescription,{children:s.description})]}),(0,g.jsxs)(r.CardContent,{className:`space-y-6`,children:[f&&(0,g.jsxs)(`div`,{className:`space-y-6`,children:[(0,g.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,g.jsx)(r.Card,{children:(0,g.jsxs)(r.CardContent,{className:`p-4 space-y-2`,children:[(0,g.jsx)(r.Skeleton,{className:`h-4 w-20`}),(0,g.jsx)(r.Skeleton,{className:`h-8 w-28`})]})},e))}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(r.Skeleton,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,g.jsx)(r.Skeleton,{className:`h-8 w-full`},e))]})]}),!f&&s.sections?.map((e,a)=>e.visible===!1?null:(0,g.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,g.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,g.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,g.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:s.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,g.jsx)(r.Card,{children:(0,g.jsxs)(r.CardContent,{className:`p-4`,children:[(0,g.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,g.jsx)(`div`,{className:`text-2xl font-bold`,children:k(_(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,g.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,g.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,g.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,g.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,g.jsx)(`thead`,{className:`bg-muted`,children:(0,g.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,g.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,g.jsx)(`tbody`,{children:(()=>{let t=M(c||[],s.groupBy||[]);return t?t.map(t=>(0,g.jsxs)(n.default.Fragment,{children:[(0,g.jsx)(`tr`,{className:`bg-muted/60`,children:(0,g.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,g.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,g.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,g.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,g.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,g.jsx)(`div`,{className:`prose max-w-none`,children:(0,g.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,g.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,g.jsx)(i.SchemaRenderer,{schema:e.content})]},a)),!s.sections&&c&&c.length>0&&(0,g.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,g.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,g.jsx)(`thead`,{className:`bg-muted`,children:(0,g.jsx)(`tr`,{children:s.fields?.map((e,t)=>(0,g.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,g.jsx)(`tbody`,{children:c.map((e,t)=>(0,g.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:s.fields?.map((t,n)=>(0,g.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,g.jsx)(r.Card,{children:(0,g.jsx)(r.CardContent,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})},P=({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,g.jsxs)(r.Card,{children:[(0,g.jsx)(r.CardHeader,{children:(0,g.jsxs)(r.CardTitle,{className:`flex items-center gap-2`,children:[(0,g.jsx)(a.Calendar,{className:`h-5 w-5`}),`Schedule Configuration`]})}),(0,g.jsxs)(r.CardContent,{className:`space-y-4`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`input`,{type:`checkbox`,id:`schedule-enabled`,checked:i.enabled||!1,onChange:e=>s({enabled:e.target.checked}),className:`rounded`}),(0,g.jsx)(r.Label,{htmlFor:`schedule-enabled`,children:`Enable Scheduled Report`})]}),i.enabled&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(r.Label,{children:`Frequency`}),(0,g.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,g.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),i.frequency===`weekly`&&(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(r.Label,{children:`Day of Week`}),(0,g.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,g.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),i.frequency===`monthly`&&(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(r.Label,{children:`Day of Month`}),(0,g.jsx)(r.Input,{type:`number`,min:1,max:31,value:i.dayOfMonth??1,onChange:e=>s({dayOfMonth:Number(e.target.value)})})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsxs)(r.Label,{className:`flex items-center gap-2`,children:[(0,g.jsx)(a.Clock,{className:`h-4 w-4`}),`Time`]}),(0,g.jsx)(r.Input,{type:`time`,value:i.time||`09:00`,onChange:e=>s({time:e.target.value})})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(r.Label,{children:`Timezone`}),(0,g.jsx)(r.Input,{value:i.timezone||``,onChange:e=>s({timezone:e.target.value}),placeholder:`e.g. America/New_York`})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(r.Label,{children:`Export Formats`}),(0,g.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,g.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,g.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,g.jsx)(`span`,{className:`text-sm`,children:e.label})]},e.value))})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsxs)(r.Label,{className:`flex items-center gap-2`,children:[(0,g.jsx)(a.Mail,{className:`h-4 w-4`}),`Email Recipients`]}),(0,g.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,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(r.Label,{children:`Email Subject`}),(0,g.jsx)(r.Input,{value:i.subject||``,onChange:e=>s({subject:e.target.value}),placeholder:`Scheduled Report: {report_title}`})]})]})]})]})},F=({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,h]=(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];h(t),d({...u,filters:t})},T=e=>{let t=m.filter((t,n)=>n!==e);h(t),d({...u,filters:t})},E=(e,t)=>{let n=[...m];n[e]=t,h(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})},M=(e,t)=>{let n=[...y];n[e]=t,b(n),d({...u,sections:n})};return(0,g.jsxs)(`div`,{className:`space-y-4`,children:[(0,g.jsxs)(r.Card,{children:[(0,g.jsxs)(r.CardHeader,{children:[(0,g.jsx)(r.CardTitle,{children:`Report Builder`}),(0,g.jsx)(r.CardDescription,{children:`Configure your report settings, fields, filters, and sections`})]}),(0,g.jsxs)(r.CardContent,{children:[(0,g.jsxs)(r.Tabs,{defaultValue:`basic`,className:`w-full`,children:[(0,g.jsxs)(r.TabsList,{className:`grid w-full grid-cols-6`,children:[(0,g.jsxs)(r.TabsTrigger,{value:`basic`,children:[(0,g.jsx)(a.Settings,{className:`h-4 w-4 mr-2`}),`Basic`]}),(0,g.jsxs)(r.TabsTrigger,{value:`fields`,children:[(0,g.jsx)(a.Layers,{className:`h-4 w-4 mr-2`}),`Fields`]}),(0,g.jsxs)(r.TabsTrigger,{value:`filters`,children:[(0,g.jsx)(a.Filter,{className:`h-4 w-4 mr-2`}),`Filters`]}),(0,g.jsxs)(r.TabsTrigger,{value:`grouping`,children:[(0,g.jsx)(a.Layers,{className:`h-4 w-4 mr-2`}),`Group By`]}),(0,g.jsxs)(r.TabsTrigger,{value:`sections`,children:[(0,g.jsx)(a.Layers,{className:`h-4 w-4 mr-2`}),`Sections`]}),(0,g.jsxs)(r.TabsTrigger,{value:`schedule`,children:[(0,g.jsx)(a.Calendar,{className:`h-4 w-4 mr-2`}),`Schedule`]})]}),(0,g.jsx)(r.TabsContent,{value:`basic`,className:`space-y-4 mt-4`,children:(0,g.jsxs)(`div`,{className:`space-y-4`,children:[(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(r.Label,{htmlFor:`report-title`,children:`Report Title`}),(0,g.jsx)(r.Input,{id:`report-title`,value:u.title||``,onChange:e=>d({...u,title:e.target.value}),placeholder:`Enter report title`})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(r.Label,{htmlFor:`report-description`,children:`Description`}),(0,g.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,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(r.Label,{children:`Data Source`}),(0,g.jsxs)(`select`,{className:`w-full border rounded-md p-2`,children:[(0,g.jsx)(`option`,{value:``,children:`Select a data source`}),i.map((e,t)=>(0,g.jsxs)(`option`,{value:t,children:[`Data Source `,t+1]},t))]})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(r.Label,{children:`Export Options`}),(0,g.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,g.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`input`,{type:`checkbox`,checked:u.showExportButtons||!1,onChange:e=>d({...u,showExportButtons:e.target.checked})}),(0,g.jsx)(`span`,{className:`text-sm`,children:`Show Export Buttons`})]}),(0,g.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`input`,{type:`checkbox`,checked:u.showPrintButton||!1,onChange:e=>d({...u,showPrintButton:e.target.checked})}),(0,g.jsx)(`span`,{className:`text-sm`,children:`Show Print Button`})]})]})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsx)(r.Label,{htmlFor:`export-format`,children:`Default Export Format`}),(0,g.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,g.jsx)(`option`,{value:`pdf`,children:`PDF`}),(0,g.jsx)(`option`,{value:`excel`,children:`Excel`}),(0,g.jsx)(`option`,{value:`csv`,children:`CSV`}),(0,g.jsx)(`option`,{value:`json`,children:`JSON`}),(0,g.jsx)(`option`,{value:`html`,children:`HTML`})]})]})]})}),(0,g.jsxs)(r.TabsContent,{value:`fields`,className:`space-y-4 mt-4`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,g.jsx)(r.Label,{children:`Report Fields`}),(0,g.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:x,disabled:f.length>=o.length,children:[(0,g.jsx)(a.Plus,{className:`h-4 w-4 mr-2`}),`Add Field`]})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[f.map((e,t)=>(0,g.jsx)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:(0,g.jsxs)(`div`,{className:`flex-1 grid grid-cols-4 gap-2`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`Field Name`}),(0,g.jsx)(`div`,{className:`text-sm font-medium`,children:e.name})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`Label`}),(0,g.jsx)(r.Input,{className:`h-8 text-sm`,value:e.label||e.name,onChange:n=>C(t,{...e,label:n.target.value})})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`Aggregation`}),(0,g.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,g.jsx)(`option`,{value:``,children:`None`}),(0,g.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,g.jsx)(`option`,{value:`count`,children:`Count`}),(0,g.jsx)(`option`,{value:`avg`,children:`Average`}),(0,g.jsx)(`option`,{value:`min`,children:`Min`}),(0,g.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,g.jsx)(`div`,{className:`flex items-end justify-end`,children:(0,g.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>S(t),children:(0,g.jsx)(a.Trash2,{className:`h-4 w-4`})})})]})},t)),f.length===0&&(0,g.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,g.jsxs)(r.TabsContent,{value:`filters`,className:`space-y-4 mt-4`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,g.jsx)(r.Label,{children:`Report Filters`}),(0,g.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:w,children:[(0,g.jsx)(a.Plus,{className:`h-4 w-4 mr-2`}),`Add Filter`]})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[m.map((e,t)=>(0,g.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,g.jsxs)(`div`,{className:`flex-1 grid grid-cols-3 gap-2`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`Field`}),(0,g.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,g.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`Operator`}),(0,g.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,g.jsx)(`option`,{value:`equals`,children:`Equals`}),(0,g.jsx)(`option`,{value:`contains`,children:`Contains`}),(0,g.jsx)(`option`,{value:`gt`,children:`Greater Than`}),(0,g.jsx)(`option`,{value:`lt`,children:`Less Than`}),(0,g.jsx)(`option`,{value:`between`,children:`Between`})]})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`Value`}),(0,g.jsx)(r.Input,{className:`h-8 text-sm`,value:String(e.value),onChange:n=>E(t,{...e,value:n.target.value})})]})]}),(0,g.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,g.jsx)(a.Trash2,{className:`h-4 w-4`})})]},t)),m.length===0&&(0,g.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No filters defined.`})]})]}),(0,g.jsxs)(r.TabsContent,{value:`grouping`,className:`space-y-4 mt-4`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,g.jsx)(r.Label,{children:`Grouping Rules`}),(0,g.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:D,children:[(0,g.jsx)(a.Plus,{className:`h-4 w-4 mr-2`}),`Add Group`]})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[_.map((e,t)=>(0,g.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,g.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`Field`}),(0,g.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,g.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`Sort Order`}),(0,g.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,g.jsx)(`option`,{value:`asc`,children:`Ascending`}),(0,g.jsx)(`option`,{value:`desc`,children:`Descending`})]})]})]}),(0,g.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,g.jsx)(a.Trash2,{className:`h-4 w-4`})})]},t)),_.length===0&&(0,g.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No grouping rules applied.`})]})]}),(0,g.jsxs)(r.TabsContent,{value:`sections`,className:`space-y-4 mt-4`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,g.jsx)(r.Label,{children:`Report Sections`}),(0,g.jsxs)(`div`,{className:`flex gap-2`,children:[(0,g.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`header`),children:[(0,g.jsx)(a.Plus,{className:`h-4 w-4 mr-2`}),`Header`]}),(0,g.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`chart`),children:[(0,g.jsx)(a.Plus,{className:`h-4 w-4 mr-2`}),`Chart`]}),(0,g.jsxs)(r.Button,{size:`sm`,variant:`outline`,onClick:()=>A(`table`),children:[(0,g.jsx)(a.Plus,{className:`h-4 w-4 mr-2`}),`Table`]})]})]}),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[y.map((e,t)=>(0,g.jsxs)(`div`,{className:`p-3 border rounded-lg space-y-2`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,g.jsxs)(`div`,{className:`font-medium flex items-center gap-2`,children:[(0,g.jsx)(`div`,{className:`text-xs bg-muted px-2 py-0.5 rounded uppercase`,children:e.type}),e.title]}),(0,g.jsx)(r.Button,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>j(t),children:(0,g.jsx)(a.Trash2,{className:`h-4 w-4`})})]}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`Title`}),(0,g.jsx)(r.Input,{className:`h-8 text-sm`,value:e.title||``,onChange:n=>M(t,{...e,title:n.target.value})})]}),e.type===`text`&&(0,g.jsxs)(`div`,{className:`col-span-2`,children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`Content`}),(0,g.jsx)(r.Input,{className:`h-8 text-sm`,value:e.text||``,onChange:n=>M(t,{...e,text:n.target.value})})]}),e.type===`chart`&&(0,g.jsxs)(`div`,{className:`col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded`,children:[(0,g.jsx)(`div`,{className:`col-span-2`,children:(0,g.jsx)(r.Label,{className:`text-xs font-semibold`,children:`Chart Configuration`})}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`Chart Type`}),(0,g.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=>M(t,{...e,chart:{...e.chart,type:`chart`,chartType:n.target.value}}),children:[(0,g.jsx)(`option`,{value:`bar`,children:`Bar`}),(0,g.jsx)(`option`,{value:`line`,children:`Line`}),(0,g.jsx)(`option`,{value:`area`,children:`Area`}),(0,g.jsx)(`option`,{value:`pie`,children:`Pie`})]})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`X-Axis Field`}),(0,g.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=>M(t,{...e,chart:{...e.chart,type:`chart`,xAxisField:n.target.value}}),children:[(0,g.jsx)(`option`,{value:``,children:`Select Field...`}),o.map(e=>(0,g.jsx)(`option`,{value:e.name,children:e.label||e.name},e.name)),o.length===0&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`option`,{value:`name`,children:`Name`}),(0,g.jsx)(`option`,{value:`month`,children:`Month`})]})]})]}),(0,g.jsxs)(`div`,{className:`col-span-2`,children:[(0,g.jsx)(r.Label,{className:`text-xs`,children:`Y-Axis Fields (comma separated)`}),(0,g.jsx)(r.Input,{className:`h-8 text-sm`,placeholder:`e.g. value, count`,value:e.chart?.yAxisFields?.join(`, `)||``,onChange:n=>M(t,{...e,chart:{...e.chart,type:`chart`,yAxisFields:n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}})})]})]})]})]},t)),y.length===0&&(0,g.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,g.jsx)(r.TabsContent,{value:`schedule`,className:`space-y-4 mt-4`,children:(0,g.jsx)(P,{schedule:u.schedule,onChange:e=>d({...u,schedule:e})})})]}),(0,g.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-6 pt-4 border-t`,children:[(0,g.jsx)(r.Button,{variant:`outline`,onClick:()=>{l&&console.log(`Report cancelled:`,l)},children:`Cancel`}),(0,g.jsxs)(r.Button,{onClick:()=>{console.log(`Saving report:`,u),c&&alert(`Report saved! (Handler: `+c+`)`)},children:[(0,g.jsx)(a.Save,{className:`h-4 w-4 mr-2`}),`Save Report`]})]})]})]}),s&&(0,g.jsxs)(r.Card,{className:`mt-8 border-2 border-blue-100`,children:[(0,g.jsx)(r.CardHeader,{className:`bg-blue-50/50`,children:(0,g.jsx)(r.CardTitle,{className:`text-blue-900 text-sm uppercase tracking-wide`,children:`Live Preview`})}),(0,g.jsx)(r.CardContent,{className:`pt-6`,children:(0,g.jsx)(N,{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`}]}})})]})]})},I=[{value:``,label:`None`},{value:`sum`,label:`Sum`},{value:`count`,label:`Count`},{value:`avg`,label:`Average`},{value:`min`,label:`Min`},{value:`max`,label:`Max`}];function L({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,g.jsx)(`div`,{className:`text-xs text-muted-foreground py-2`,"data-testid":`field-picker-empty`,children:`No fields available`}):(0,g.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,g.jsxs)(`div`,{className:`flex items-center gap-2 px-1 py-0.5 rounded hover:bg-muted/50 text-xs`,children:[(0,g.jsxs)(`label`,{className:`flex items-center gap-2 flex-1 cursor-pointer`,children:[(0,g.jsx)(r.Checkbox,{checked:t,onCheckedChange:()=>o(e.value),"data-testid":`field-picker-${e.value}`}),(0,g.jsx)(`span`,{className:`flex-1`,children:e.label}),e.type&&(0,g.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.type})]}),t&&(0,g.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:I.map(e=>(0,g.jsx)(`option`,{value:e.value,children:e.label},e.value))})]},e.value)})})}var R=[{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 z({availableFields:e,value:t,onChange:n}){let r=t||{},i=e=>n({...r,...e});return(0,g.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`chart-config`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`Chart type`}),(0,g.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:R.map(e=>(0,g.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),r.chartType&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`X-axis field`}),(0,g.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,g.jsx)(`option`,{value:``,children:`Select field…`}),e.map(e=>(0,g.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:`Y-axis field`}),(0,g.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,g.jsx)(`option`,{value:``,children:`Select field…`}),e.filter(e=>e.type===`number`).map(e=>(0,g.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]})]})]})}var B=[{value:`equals`,label:`=`},{value:`not_equals`,label:`≠`},{value:`greater_than`,label:`>`},{value:`less_than`,label:`<`},{value:`contains`,label:`Contains`}];function V({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,g.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`conditional-format-rules`,children:[i.map((t,n)=>(0,g.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1 border rounded bg-muted/20`,children:[(0,g.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,g.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,g.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:B.map(e=>(0,g.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,g.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,g.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,g.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,g.jsx)(a.Trash2,{className:`h-3 w-3`})})]},n)),(0,g.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,g.jsx)(a.Plus,{className:`h-3 w-3 mr-1`}),`Add Rule`]})]})}var H=[{value:`header`,label:`Header`},{value:`summary`,label:`Summary`},{value:`table`,label:`Table`},{value:`chart`,label:`Chart`},{value:`text`,label:`Text`}];function U({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,g.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`section-manager`,children:[n.map((e,t)=>(0,g.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1.5 border rounded bg-muted/20`,children:[(0,g.jsxs)(`div`,{className:`flex flex-col gap-0.5 mr-1`,children:[(0,g.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,g.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,g.jsx)(`span`,{className:`text-[9px] bg-muted px-1.5 py-0.5 rounded uppercase font-medium shrink-0`,children:e.type}),(0,g.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,g.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,g.jsx)(a.Trash2,{className:`h-3 w-3`})})]},t)),(0,g.jsx)(`div`,{className:`flex gap-1 flex-wrap`,children:H.map(e=>(0,g.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,g.jsx)(a.Plus,{className:`h-3 w-3 mr-0.5`}),e.label]},e.value))})]})}function W(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,g.jsx)(L,{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,g.jsx)(z,{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,g.jsx)(V,{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,g.jsx)(U,{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,g.jsx)(P,{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 G({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:h}=(0,r.useConfigDraft)(i,{onUpdate:o});return(0,g.jsx)(r.ConfigPanelRenderer,{open:e,onClose:t,schema:n.useMemo(()=>W(s),[s]),draft:c,isDirty:l,onFieldChange:u,onSave:()=>a(c),onDiscard:d,onUndo:f,onRedo:p,canUndo:m,canRedo:h})}async function K(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 C(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 q(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(Y),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 X(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=Q(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)}ee(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
64
- `),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function J(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 K(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function Y(e){return{name:e.name,header:e.label||e.name}}function X(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,Z(t)):$(String(e))}function Z(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 Q(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function $(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function ee(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`,_,{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`,N,{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`,F,{namespace:`report`,label:`Report Builder`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Initial Report`}]}),e.ReportBuilder=F,e.ReportConfigPanel=G,e.ReportRenderer=_,e.ReportViewer=N,e.ScheduleConfig=P,e.createScheduleTrigger=J,e.exportAsCSV=v,e.exportAsExcel=S,e.exportAsHTML=b,e.exportAsJSON=y,e.exportAsPDF=x,e.exportExcelWithFormulas=q,e.exportReport=C,e.exportWithLiveData=K,e.formatValue=k});
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});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-report",
3
- "version": "3.1.5",
3
+ "version": "3.3.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.umd.cjs",
6
6
  "module": "dist/index.js",
@@ -13,30 +13,61 @@
13
13
  }
14
14
  },
15
15
  "files": [
16
- "dist"
16
+ "dist",
17
+ "README.md",
18
+ "CHANGELOG.md",
19
+ "LICENSE"
17
20
  ],
18
21
  "dependencies": {
19
22
  "clsx": "^2.1.1",
20
- "lucide-react": "^0.577.0",
23
+ "lucide-react": "^1.8.0",
21
24
  "tailwind-merge": "^3.5.0",
22
- "@object-ui/components": "3.1.5",
23
- "@object-ui/core": "3.1.5",
24
- "@object-ui/fields": "3.1.5",
25
- "@object-ui/react": "3.1.5",
26
- "@object-ui/types": "3.1.5"
25
+ "@object-ui/components": "3.3.1",
26
+ "@object-ui/core": "3.3.1",
27
+ "@object-ui/fields": "3.3.1",
28
+ "@object-ui/react": "3.3.1",
29
+ "@object-ui/types": "3.3.1"
27
30
  },
28
31
  "peerDependencies": {
29
32
  "react": "^18.0.0",
30
33
  "react-dom": "^18.0.0"
31
34
  },
32
35
  "devDependencies": {
33
- "@types/node": "^25.5.0",
36
+ "@types/node": "^25.6.0",
34
37
  "@types/react": "19.2.14",
35
38
  "@types/react-dom": "19.2.3",
36
39
  "@vitejs/plugin-react": "^6.0.1",
37
- "vite": "^8.0.1",
40
+ "vite": "^8.0.9",
38
41
  "vite-plugin-dts": "^3.9.1",
39
- "vitest": "^4.1.0"
42
+ "vitest": "^4.1.5"
43
+ },
44
+ "description": "Report plugin for Object UI — schema-driven pivot tables, grouped aggregations and printable report layouts",
45
+ "keywords": [
46
+ "objectui",
47
+ "sdui",
48
+ "schema-driven-ui",
49
+ "react",
50
+ "tailwind",
51
+ "shadcn",
52
+ "objectstack",
53
+ "plugin",
54
+ "report",
55
+ "pivot-table",
56
+ "analytics"
57
+ ],
58
+ "license": "MIT",
59
+ "author": "ObjectStack Team <team@objectstack.ai>",
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "git+https://github.com/objectstack-ai/objectui.git",
63
+ "directory": "packages/plugin-report"
64
+ },
65
+ "bugs": {
66
+ "url": "https://github.com/objectstack-ai/objectui/issues"
67
+ },
68
+ "homepage": "https://www.objectui.org/docs/plugins/plugin-report",
69
+ "publishConfig": {
70
+ "access": "public"
40
71
  },
41
72
  "scripts": {
42
73
  "build": "vite build",