@object-ui/plugin-report 3.0.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(k,M){typeof exports=="object"&&typeof module<"u"?M(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"],M):(k=typeof globalThis<"u"?globalThis:k||self,M(k.ObjectUIPluginReport={},k.ObjectUICore,k.React,k.ObjectUIComponents,k.ObjectUIReact,k.lucideReact))})(this,function(k,M,U,s,oe,N){"use strict";function ye(r){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(i,t,o.get?o:{enumerable:!0,get:()=>r[t]})}}return i.default=r,Object.freeze(i)}const Ne=ye(U);var K={exports:{}},q={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var de;function Ce(){if(de)return q;de=1;var r=Symbol.for("react.transitional.element"),i=Symbol.for("react.fragment");function t(o,c,b){var h=null;if(b!==void 0&&(h=""+b),c.key!==void 0&&(h=""+c.key),"key"in c){b={};for(var a in c)a!=="key"&&(b[a]=c[a])}else b=c;return c=b.ref,{$$typeof:r,type:o,key:h,ref:c!==void 0?c:null,props:b}}return q.Fragment=i,q.jsx=t,q.jsxs=t,q}var Y={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,20 +14,20 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
17
|
+
*/var ce;function we(){return ce||(ce=1,process.env.NODE_ENV!=="production"&&function(){function r(n){if(n==null)return null;if(typeof n=="function")return n.$$typeof===W?null:n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case m:return"Fragment";case S:return"Profiler";case C:return"StrictMode";case O:return"Suspense";case L:return"SuspenseList";case I:return"Activity"}if(typeof n=="object")switch(typeof n.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),n.$$typeof){case T:return"Portal";case v:return n.displayName||"Context";case y:return(n._context.displayName||"Context")+".Consumer";case A:var g=n.render;return n=n.displayName,n||(n=g.displayName||g.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case D:return g=n.displayName||null,g!==null?g:r(n.type)||"Memo";case B:g=n._payload,n=n._init;try{return r(n(g))}catch{}}return null}function i(n){return""+n}function t(n){try{i(n);var g=!1}catch{g=!0}if(g){g=console;var R=g.error,F=typeof Symbol=="function"&&Symbol.toStringTag&&n[Symbol.toStringTag]||n.constructor.name||"Object";return R.call(g,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",F),i(n)}}function o(n){if(n===m)return"<>";if(typeof n=="object"&&n!==null&&n.$$typeof===B)return"<...>";try{var g=r(n);return g?"<"+g+">":"<...>"}catch{return"<...>"}}function c(){var n=V.A;return n===null?null:n.getOwner()}function b(){return Error("react-stack-top-frame")}function h(n){if(Z.call(n,"key")){var g=Object.getOwnPropertyDescriptor(n,"key").get;if(g&&g.isReactWarning)return!1}return n.key!==void 0}function a(n,g){function R(){x||(x=!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)",g))}R.isReactWarning=!0,Object.defineProperty(n,"key",{get:R,configurable:!0})}function d(){var n=r(this.type);return f[n]||(f[n]=!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.")),n=this.props.ref,n!==void 0?n:null}function l(n,g,R,F,Q,ne){var _=R.ref;return n={$$typeof:$,type:n,key:g,props:R,_owner:F},(_!==void 0?_:null)!==null?Object.defineProperty(n,"ref",{enumerable:!1,get:d}):Object.defineProperty(n,"ref",{enumerable:!1,value:null}),n._store={},Object.defineProperty(n._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(n,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(n,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:Q}),Object.defineProperty(n,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:ne}),Object.freeze&&(Object.freeze(n.props),Object.freeze(n)),n}function p(n,g,R,F,Q,ne){var _=g.children;if(_!==void 0)if(F)if(se(_)){for(F=0;F<_.length;F++)j(_[F]);Object.freeze&&Object.freeze(_)}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 j(_);if(Z.call(g,"key")){_=r(n);var G=Object.keys(g).filter(function(Ye){return Ye!=="key"});F=0<G.length?"{key: someKey, "+G.join(": ..., ")+": ...}":"{key: someKey}",J[_+F]||(G=0<G.length?"{"+G.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
18
|
let props = %s;
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,
|
|
23
|
-
`))?`"${
|
|
24
|
-
`);
|
|
22
|
+
<%s key={someKey} {...props} />`,F,_,G,_),J[_+F]=!0)}if(_=null,R!==void 0&&(t(R),_=""+R),h(g)&&(t(g.key),_=""+g.key),"key"in g){R={};for(var ie in g)ie!=="key"&&(R[ie]=g[ie])}else R=g;return _&&a(R,typeof n=="function"?n.displayName||n.name||"Unknown":n),l(n,_,R,c(),Q,ne)}function j(n){E(n)?n._store&&(n._store.validated=1):typeof n=="object"&&n!==null&&n.$$typeof===B&&(n._payload.status==="fulfilled"?E(n._payload.value)&&n._payload.value._store&&(n._payload.value._store.validated=1):n._store&&(n._store.validated=1))}function E(n){return typeof n=="object"&&n!==null&&n.$$typeof===$}var w=U,$=Symbol.for("react.transitional.element"),T=Symbol.for("react.portal"),m=Symbol.for("react.fragment"),C=Symbol.for("react.strict_mode"),S=Symbol.for("react.profiler"),y=Symbol.for("react.consumer"),v=Symbol.for("react.context"),A=Symbol.for("react.forward_ref"),O=Symbol.for("react.suspense"),L=Symbol.for("react.suspense_list"),D=Symbol.for("react.memo"),B=Symbol.for("react.lazy"),I=Symbol.for("react.activity"),W=Symbol.for("react.client.reference"),V=w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Z=Object.prototype.hasOwnProperty,se=Array.isArray,u=console.createTask?console.createTask:function(){return null};w={react_stack_bottom_frame:function(n){return n()}};var x,f={},P=w.react_stack_bottom_frame.bind(w,b)(),H=u(o(b)),J={};Y.Fragment=m,Y.jsx=function(n,g,R){var F=1e4>V.recentlyCreatedOwnerStacks++;return p(n,g,R,!1,F?Error("react-stack-top-frame"):P,F?u(o(n)):H)},Y.jsxs=function(n,g,R){var F=1e4>V.recentlyCreatedOwnerStacks++;return p(n,g,R,!0,F?Error("react-stack-top-frame"):P,F?u(o(n)):H)}}()),Y}process.env.NODE_ENV==="production"?K.exports=Ce():K.exports=we();var e=K.exports;const ue=({schema:r})=>{var d;const{title:i,description:t,data:o,columns:c}=r;(d=r.chart)!=null&&d.type;const b=!!r.chart,a=!(process.env.NODE_ENV==="test");return e.jsxs(s.Card,{className:`h-full flex flex-col ${r.className||""}`,children:[e.jsxs(s.CardHeader,{children:[i&&e.jsx(s.CardTitle,{children:i}),t&&e.jsx(s.CardDescription,{children:t})]}),e.jsxs(s.CardContent,{className:"flex-1 overflow-auto space-y-4",children:[b&&(()=>{var j;const l=(j=r.chart)==null?void 0:j.type;let p=l?M.ComponentRegistry.get(l):null;return p||(p=M.ComponentRegistry.get("chart")),p?e.jsx("div",{className:"min-h-[300px] border rounded-lg p-4 bg-background/50",children:e.jsx(p,{schema:{...r.chart,data:r.chart.data||o}})}):e.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: ",l||"chart"]})})(),o&&o.length>0&&e.jsx("div",{className:"border rounded-lg",children:(()=>{const l=a?M.ComponentRegistry.get("aggrid")||M.ComponentRegistry.get("table"):null;return l?e.jsx(l,{schema:{type:"aggrid",rowData:o,columnDefs:c,domLayout:"autoHeight"}}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm text-left",children:[e.jsx("thead",{className:"text-xs uppercase bg-muted",children:e.jsx("tr",{children:c==null?void 0:c.map(p=>e.jsx("th",{className:"px-6 py-3",children:p.headerName||p.label||p.field},p.field))})}),e.jsx("tbody",{children:o.map((p,j)=>e.jsx("tr",{className:"bg-background border-b",children:c==null?void 0:c.map(E=>e.jsx("td",{className:"px-6 py-4",children:p[E.field]},E.field))},j))})]})})})()})]})]})};function he(r,i,t){const o=r.fields||[],c=o.map(a=>a.label||a.name),b=i.map(a=>o.map(d=>{let l=a[d.name];return l=be(l),typeof l=="string"&&(l.includes(",")||l.includes('"')||l.includes(`
|
|
23
|
+
`))?`"${l.replace(/"/g,'""')}"`:l??""})),h=[...(t==null?void 0:t.includeHeaders)!==!1?[c.join(",")]:[],...b.map(a=>a.join(","))].join(`
|
|
24
|
+
`);X(h,(t==null?void 0:t.filename)||`${r.title||"report"}.csv`,"text/csv")}function me(r,i,t){const o={title:r.title,description:r.description,generatedAt:new Date().toISOString(),data:i},c=JSON.stringify(o,null,2);X(c,(t==null?void 0:t.filename)||`${r.title||"report"}.json`,"application/json")}function ee(r,i,t){const o=r.fields||[],c=ge(t==null?void 0:t.orientation),b=fe(t==null?void 0:t.pageSize),h=`<!DOCTYPE html>
|
|
25
25
|
<html>
|
|
26
26
|
<head>
|
|
27
27
|
<meta charset="utf-8">
|
|
28
|
-
<title>${
|
|
28
|
+
<title>${z(r.title||"Report")}</title>
|
|
29
29
|
<style>
|
|
30
|
-
@page { size: ${
|
|
30
|
+
@page { size: ${b} ${c}; margin: 20mm; }
|
|
31
31
|
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
|
|
32
32
|
h1 { font-size: 24px; margin-bottom: 8px; }
|
|
33
33
|
.description { color: #666; margin-bottom: 24px; }
|
|
@@ -39,21 +39,21 @@ React keys must be passed directly to JSX without using spread:
|
|
|
39
39
|
</style>
|
|
40
40
|
</head>
|
|
41
41
|
<body>
|
|
42
|
-
<h1>${
|
|
43
|
-
${
|
|
42
|
+
<h1>${z(r.title||"Report")}</h1>
|
|
43
|
+
${r.description?`<p class="description">${z(r.description)}</p>`:""}
|
|
44
44
|
<p class="meta">Generated: ${new Date().toLocaleString()}</p>
|
|
45
45
|
<table>
|
|
46
|
-
<thead><tr>${
|
|
47
|
-
<tbody>${
|
|
46
|
+
<thead><tr>${o.map(a=>`<th>${z(a.label||a.name)}</th>`).join("")}</tr></thead>
|
|
47
|
+
<tbody>${i.map(a=>`<tr>${o.map(d=>`<td>${z(String(a[d.name]??""))}</td>`).join("")}</tr>`).join("")}</tbody>
|
|
48
48
|
</table>
|
|
49
49
|
</body>
|
|
50
|
-
</html>`;
|
|
50
|
+
</html>`;X(h,(t==null?void 0:t.filename)||`${r.title||"report"}.html`,"text/html")}function pe(r,i,t){var a;const o=r.fields||[],c=ge(t==null?void 0:t.orientation),b=fe(t==null?void 0:t.pageSize),h=window.open("","_blank");if(!h){const d={...t,filename:((a=t==null?void 0:t.filename)==null?void 0:a.replace(/\.pdf$/,".html"))||`${r.title||"report"}.html`};ee(r,i,d);return}h.document.write(`<!DOCTYPE html>
|
|
51
51
|
<html>
|
|
52
52
|
<head>
|
|
53
53
|
<meta charset="utf-8">
|
|
54
|
-
<title>${
|
|
54
|
+
<title>${z(r.title||"Report")}</title>
|
|
55
55
|
<style>
|
|
56
|
-
@page { size: ${
|
|
56
|
+
@page { size: ${b} ${c}; margin: 20mm; }
|
|
57
57
|
@media print { .no-print { display: none; } }
|
|
58
58
|
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
|
|
59
59
|
h1 { font-size: 24px; margin-bottom: 8px; }
|
|
@@ -66,15 +66,15 @@ ${s.description?`<p class="description">${O(s.description)}</p>`:""}
|
|
|
66
66
|
</style>
|
|
67
67
|
</head>
|
|
68
68
|
<body>
|
|
69
|
-
<h1>${
|
|
70
|
-
${
|
|
69
|
+
<h1>${z(r.title||"Report")}</h1>
|
|
70
|
+
${r.description?`<p class="description">${z(r.description)}</p>`:""}
|
|
71
71
|
<p class="meta">Generated: ${new Date().toLocaleString()}</p>
|
|
72
72
|
<table>
|
|
73
|
-
<thead><tr>${
|
|
74
|
-
<tbody>${
|
|
73
|
+
<thead><tr>${o.map(d=>`<th>${z(d.label||d.name)}</th>`).join("")}</tr></thead>
|
|
74
|
+
<tbody>${i.map(d=>`<tr>${o.map(l=>`<td>${z(String(d[l.name]??""))}</td>`).join("")}</tr>`).join("")}</tbody>
|
|
75
75
|
</table>
|
|
76
76
|
</body>
|
|
77
|
-
</html>`),
|
|
78
|
-
`)||
|
|
79
|
-
`);J(j,(a==null?void 0:a.filename)||`${s.title||"report"}.tsv`,"text/tab-separated-values")}function ee(s,d,a,c){switch(s){case"csv":oe(d,a,c);break;case"json":ue(d,a,c);break;case"html":K(d,a,c);break;case"pdf":he(d,a,c);break;case"excel":me(d,a,c);break;default:console.warn(`Unsupported export format: ${s}`)}}function O(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function xe(s){if(typeof s=="string"&&s.length>0){const d=s.charAt(0);if(d==="="||d==="+"||d==="-"||d==="@"||d==="|")return` ${s}`}return s}function pe(s){return["A4","A3","Letter","Legal"].includes(s||"")?s:"A4"}function fe(s){return s==="landscape"?"landscape":"portrait"}function J(s,d,a){const c=new Blob([s],{type:`${a};charset=utf-8`}),u=URL.createObjectURL(c),p=document.createElement("a");p.href=u,p.download=d,document.body.appendChild(p),p.click(),document.body.removeChild(p),URL.revokeObjectURL(u)}const te=({schema:s,onRefresh:d})=>{var E,S;const{report:a,data:c,showToolbar:u=!0,allowExport:p=!0,allowPrint:j=!0,loading:i=!1}=s,x=m=>{var v;if(!a){console.warn("ReportViewer: Cannot export, no report defined");return}ee(m,a,c||[],(v=a.exportConfigs)==null?void 0:v[m])},n=()=>{window.print()},b=()=>{d==null||d()},y=(m,v)=>{if(!c)return 0;const N=c.map(k=>Number(k[m])||0);switch(v){case"count":return c.length;case"sum":return N.reduce((k,g)=>k+g,0);case"avg":return N.length>0?(N.reduce((k,g)=>k+g,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""}};return a?e.jsxs("div",{className:"space-y-4",children:[u&&e.jsxs("div",{className:"flex items-center justify-between gap-2 p-4 bg-card rounded-lg border",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:a.title}),a.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:a.description})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a.refreshInterval&&e.jsxs(r.Button,{variant:"outline",size:"sm",onClick:b,children:[e.jsx(w.RefreshCw,{className:"h-4 w-4 mr-2"}),"Refresh"]}),j&&e.jsxs(r.Button,{variant:"outline",size:"sm",onClick:n,children:[e.jsx(w.Printer,{className:"h-4 w-4 mr-2"}),"Print"]}),p&&a.showExportButtons&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(r.Button,{variant:"outline",size:"sm",onClick:()=>x("pdf"),children:[e.jsx(w.Download,{className:"h-4 w-4 mr-2"}),"PDF"]}),e.jsxs(r.Button,{variant:"outline",size:"sm",onClick:()=>x("excel"),children:[e.jsx(w.Download,{className:"h-4 w-4 mr-2"}),"Excel"]}),e.jsxs(r.Button,{variant:"outline",size:"sm",onClick:()=>x("csv"),children:[e.jsx(w.Download,{className:"h-4 w-4 mr-2"}),"CSV"]})]})]})]}),e.jsxs(r.Card,{children:[e.jsxs(r.CardHeader,{children:[!u&&a.title&&e.jsx(r.CardTitle,{children:a.title}),!u&&a.description&&e.jsx(r.CardDescription,{children:a.description})]}),e.jsxs(r.CardContent,{className:"space-y-6",children:[i&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading report data..."}),!i&&((E=a.sections)==null?void 0:E.map((m,v)=>{var N,k;return m.visible===!1?null:e.jsxs("div",{className:"space-y-2",children:[m.title&&e.jsx("h3",{className:"text-lg font-semibold border-b pb-2",children:m.title}),m.type==="header"&&m.title&&e.jsx("div",{className:"text-2xl font-bold py-4",children:m.title}),m.type==="summary"&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:(N=a.fields)==null?void 0:N.filter(g=>g.showInSummary).map((g,L)=>e.jsx(r.Card,{children:e.jsxs(r.CardContent,{className:"p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:g.label||g.name}),e.jsx("div",{className:"text-2xl font-bold",children:y(g.name,g.aggregation)})]})},L))}),m.type==="chart"&&m.chart&&e.jsx("div",{className:"min-h-[300px]",children:(()=>{let g=m.chart.type;const L=!!m.chart.chartType;!g&&L&&(g="chart"),g&&!!_.ComponentRegistry.get(g)||(g="chart");const P=g==="chart"?{xAxisKey:m.chart.xAxisKey||m.chart.xAxisField||"name",series:m.chart.series||(m.chart.yAxisFields?m.chart.yAxisFields.map(Y=>({dataKey:Y})):[]),chartType:m.chart.chartType||"bar"}:{},V={...m.chart,type:g,...P,data:c||m.chart.data,className:m.chart.className||"w-full h-[350px]"};return e.jsx(ne.SchemaRenderer,{schema:V})})()}),m.type==="table"&&e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted",children:e.jsx("tr",{children:(k=m.columns)==null?void 0:k.map((g,L)=>e.jsx("th",{className:"px-4 py-2 text-left font-medium",children:g.label||g.name},L))})}),e.jsx("tbody",{children:c==null?void 0:c.map((g,L)=>{var D;return e.jsx("tr",{className:"border-t",children:(D=m.columns)==null?void 0:D.map((I,P)=>e.jsx("td",{className:"px-4 py-2",children:g[I.name]},P))},L)})})]})}),m.type==="text"&&m.text&&e.jsx("div",{className:"prose max-w-none",children:e.jsx("p",{children:m.text})}),m.type==="page-break"&&e.jsx("div",{className:"border-t-2 border-dashed my-8 print:page-break-after-always"}),m.content&&e.jsx(ne.SchemaRenderer,{schema:m.content})]},v)})),!a.sections&&c&&c.length>0&&e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted",children:e.jsx("tr",{children:(S=a.fields)==null?void 0:S.map((m,v)=>e.jsx("th",{className:"px-4 py-2 text-left font-medium",children:m.label||m.name},v))})}),e.jsx("tbody",{children:c.map((m,v)=>{var N;return e.jsx("tr",{className:"border-t",children:(N=a.fields)==null?void 0:N.map((k,g)=>e.jsx("td",{className:"px-4 py-2",children:m[k.name]},g))},v)})})]})})]})]})]}):e.jsx(r.Card,{children:e.jsx(r.CardContent,{className:"p-8 text-center text-muted-foreground",children:"No report to display"})})},je=({schedule:s,onChange:d})=>{var x;const[a,c]=B.useState(s||{enabled:!1,frequency:"weekly",time:"09:00",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:["pdf"]}),u=n=>{const b={...a,...n};c(b),d==null||d(b)},p=[{value:"once",label:"Once"},{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"monthly",label:"Monthly"},{value:"quarterly",label:"Quarterly"},{value:"yearly",label:"Yearly"}],j=[{value:"pdf",label:"PDF"},{value:"excel",label:"Excel"},{value:"csv",label:"CSV"},{value:"html",label:"HTML"}],i=[{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"}];return e.jsxs(r.Card,{children:[e.jsx(r.CardHeader,{children:e.jsxs(r.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(w.Calendar,{className:"h-5 w-5"}),"Schedule Configuration"]})}),e.jsxs(r.CardContent,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"schedule-enabled",checked:a.enabled||!1,onChange:n=>u({enabled:n.target.checked}),className:"rounded"}),e.jsx(r.Label,{htmlFor:"schedule-enabled",children:"Enable Scheduled Report"})]}),a.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Frequency"}),e.jsx("select",{className:"w-full border rounded-md p-2 bg-background",value:a.frequency||"weekly",onChange:n=>u({frequency:n.target.value}),children:p.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))})]}),a.frequency==="weekly"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Day of Week"}),e.jsx("select",{className:"w-full border rounded-md p-2 bg-background",value:a.dayOfWeek??1,onChange:n=>u({dayOfWeek:Number(n.target.value)}),children:i.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))})]}),a.frequency==="monthly"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Day of Month"}),e.jsx(r.Input,{type:"number",min:1,max:31,value:a.dayOfMonth??1,onChange:n=>u({dayOfMonth:Number(n.target.value)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(r.Label,{className:"flex items-center gap-2",children:[e.jsx(w.Clock,{className:"h-4 w-4"}),"Time"]}),e.jsx(r.Input,{type:"time",value:a.time||"09:00",onChange:n=>u({time:n.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Timezone"}),e.jsx(r.Input,{value:a.timezone||"",onChange:n=>u({timezone:n.target.value}),placeholder:"e.g. America/New_York"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Export Formats"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:j.map(n=>{var b;return e.jsxs("label",{className:"flex items-center gap-1.5 px-3 py-1.5 border rounded-md cursor-pointer hover:bg-muted/50",children:[e.jsx("input",{type:"checkbox",checked:((b=a.formats)==null?void 0:b.includes(n.value))||!1,onChange:y=>{const E=a.formats||[];u({formats:y.target.checked?[...E,n.value]:E.filter(S=>S!==n.value)})},className:"rounded"}),e.jsx("span",{className:"text-sm",children:n.label})]},n.value)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(r.Label,{className:"flex items-center gap-2",children:[e.jsx(w.Mail,{className:"h-4 w-4"}),"Email Recipients"]}),e.jsx(r.Input,{placeholder:"email1@example.com, email2@example.com",value:((x=a.recipients)==null?void 0:x.join(", "))||"",onChange:n=>u({recipients:n.target.value.split(",").map(b=>b.trim()).filter(Boolean)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Email Subject"}),e.jsx(r.Input,{value:a.subject||"",onChange:n=>u({subject:n.target.value}),placeholder:"Scheduled Report: {report_title}"})]})]})]})]})},be=({schema:s})=>{const{report:d,dataSources:a=[],availableFields:c=[],showPreview:u=!0,onSave:p,onCancel:j}=s,[i,x]=B.useState(d||{type:"report",title:"New Report",fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[n,b]=B.useState(i.fields||[]),[y,E]=B.useState(i.filters||[]),[S,m]=B.useState(i.groupBy||[]),[v,N]=B.useState(i.sections||[]),k=()=>{if(c.length>0&&n.length<c.length){const l=c.find(o=>!n.some(h=>h.name===o.name));if(l){const o=[...n,l];b(o),x({...i,fields:o})}}},g=l=>{const o=n.filter((h,A)=>A!==l);b(o),x({...i,fields:o})},L=(l,o)=>{const h=[...n];h[l]=o,b(h),x({...i,fields:h})},D=()=>{var h;const l={field:((h=c[0])==null?void 0:h.name)||"",operator:"equals",value:""},o=[...y,l];E(o),x({...i,filters:o})},I=l=>{const o=y.filter((h,A)=>A!==l);E(o),x({...i,filters:o})},P=(l,o)=>{const h=[...y];h[l]=o,E(h),x({...i,filters:h})},V=()=>{var h;const l={field:((h=c[0])==null?void 0:h.name)||"",sort:"asc"},o=[...S,l];m(o),x({...i,groupBy:o})},Y=l=>{const o=S.filter((h,A)=>A!==l);m(o),x({...i,groupBy:o})},z=(l,o)=>{const h=[...S];h[l]=o,m(h),x({...i,groupBy:h})},W=l=>{const o={type:l,title:`New ${l} Section`},h=[...v,o];N(h),x({...i,sections:h})},ae=l=>{const o=v.filter((h,A)=>A!==l);N(o),x({...i,sections:o})},$=(l,o)=>{const h=[...v];h[l]=o,N(h),x({...i,sections:h})},X=()=>{console.log("Saving report:",i),p&&alert("Report saved! (Handler: "+p+")")},re=()=>{j&&console.log("Report cancelled:",j)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(r.Card,{children:[e.jsxs(r.CardHeader,{children:[e.jsx(r.CardTitle,{children:"Report Builder"}),e.jsx(r.CardDescription,{children:"Configure your report settings, fields, filters, and sections"})]}),e.jsxs(r.CardContent,{children:[e.jsxs(r.Tabs,{defaultValue:"basic",className:"w-full",children:[e.jsxs(r.TabsList,{className:"grid w-full grid-cols-6",children:[e.jsxs(r.TabsTrigger,{value:"basic",children:[e.jsx(w.Settings,{className:"h-4 w-4 mr-2"}),"Basic"]}),e.jsxs(r.TabsTrigger,{value:"fields",children:[e.jsx(w.Layers,{className:"h-4 w-4 mr-2"}),"Fields"]}),e.jsxs(r.TabsTrigger,{value:"filters",children:[e.jsx(w.Filter,{className:"h-4 w-4 mr-2"}),"Filters"]}),e.jsxs(r.TabsTrigger,{value:"grouping",children:[e.jsx(w.Layers,{className:"h-4 w-4 mr-2"}),"Group By"]}),e.jsxs(r.TabsTrigger,{value:"sections",children:[e.jsx(w.Layers,{className:"h-4 w-4 mr-2"}),"Sections"]}),e.jsxs(r.TabsTrigger,{value:"schedule",children:[e.jsx(w.Calendar,{className:"h-4 w-4 mr-2"}),"Schedule"]})]}),e.jsx(r.TabsContent,{value:"basic",className:"space-y-4 mt-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{htmlFor:"report-title",children:"Report Title"}),e.jsx(r.Input,{id:"report-title",value:i.title||"",onChange:l=>x({...i,title:l.target.value}),placeholder:"Enter report title"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{htmlFor:"report-description",children:"Description"}),e.jsx(r.Input,{id:"report-description",value:i.description||"",onChange:l=>x({...i,description:l.target.value}),placeholder:"Enter report description"})]}),a.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Data Source"}),e.jsxs("select",{className:"w-full border rounded-md p-2",children:[e.jsx("option",{value:"",children:"Select a data source"}),a.map((l,o)=>e.jsxs("option",{value:o,children:["Data Source ",o+1]},o))]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{children:"Export Options"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:i.showExportButtons||!1,onChange:l=>x({...i,showExportButtons:l.target.checked})}),e.jsx("span",{className:"text-sm",children:"Show Export Buttons"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:i.showPrintButton||!1,onChange:l=>x({...i,showPrintButton:l.target.checked})}),e.jsx("span",{className:"text-sm",children:"Show Print Button"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r.Label,{htmlFor:"export-format",children:"Default Export Format"}),e.jsxs("select",{id:"export-format",className:"w-full border rounded-md p-2",value:i.defaultExportFormat||"pdf",onChange:l=>x({...i,defaultExportFormat:l.target.value}),children:[e.jsx("option",{value:"pdf",children:"PDF"}),e.jsx("option",{value:"excel",children:"Excel"}),e.jsx("option",{value:"csv",children:"CSV"}),e.jsx("option",{value:"json",children:"JSON"}),e.jsx("option",{value:"html",children:"HTML"})]})]})]})}),e.jsxs(r.TabsContent,{value:"fields",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{children:"Report Fields"}),e.jsxs(r.Button,{size:"sm",variant:"outline",onClick:k,disabled:n.length>=c.length,children:[e.jsx(w.Plus,{className:"h-4 w-4 mr-2"}),"Add Field"]})]}),e.jsxs("div",{className:"space-y-2",children:[n.map((l,o)=>e.jsx("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:e.jsxs("div",{className:"flex-1 grid grid-cols-4 gap-2",children:[e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Field Name"}),e.jsx("div",{className:"text-sm font-medium",children:l.name})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Label"}),e.jsx(r.Input,{className:"h-8 text-sm",value:l.label||l.name,onChange:h=>L(o,{...l,label:h.target.value})})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Aggregation"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:l.aggregation||"",onChange:h=>L(o,{...l,aggregation:h.target.value}),children:[e.jsx("option",{value:"",children:"None"}),e.jsx("option",{value:"sum",children:"Sum"}),e.jsx("option",{value:"count",children:"Count"}),e.jsx("option",{value:"avg",children:"Average"}),e.jsx("option",{value:"min",children:"Min"}),e.jsx("option",{value:"max",children:"Max"})]})]}),e.jsx("div",{className:"flex items-end justify-end",children:e.jsx(r.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50",onClick:()=>g(o),children:e.jsx(w.Trash2,{className:"h-4 w-4"})})})]})},o)),n.length===0&&e.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.'})]})]}),e.jsxs(r.TabsContent,{value:"filters",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{children:"Report Filters"}),e.jsxs(r.Button,{size:"sm",variant:"outline",onClick:D,children:[e.jsx(w.Plus,{className:"h-4 w-4 mr-2"}),"Add Filter"]})]}),e.jsxs("div",{className:"space-y-2",children:[y.map((l,o)=>e.jsxs("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Field"}),e.jsx("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:l.field,onChange:h=>P(o,{...l,field:h.target.value}),children:c.map((h,A)=>e.jsx("option",{value:h.name,children:h.label||h.name},A))})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Operator"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:l.operator,onChange:h=>P(o,{...l,operator:h.target.value}),children:[e.jsx("option",{value:"equals",children:"Equals"}),e.jsx("option",{value:"contains",children:"Contains"}),e.jsx("option",{value:"gt",children:"Greater Than"}),e.jsx("option",{value:"lt",children:"Less Than"}),e.jsx("option",{value:"between",children:"Between"})]})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Value"}),e.jsx(r.Input,{className:"h-8 text-sm",value:String(l.value),onChange:h=>P(o,{...l,value:h.target.value})})]})]}),e.jsx(r.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50 self-end",onClick:()=>I(o),children:e.jsx(w.Trash2,{className:"h-4 w-4"})})]},o)),y.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No filters defined."})]})]}),e.jsxs(r.TabsContent,{value:"grouping",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{children:"Grouping Rules"}),e.jsxs(r.Button,{size:"sm",variant:"outline",onClick:V,children:[e.jsx(w.Plus,{className:"h-4 w-4 mr-2"}),"Add Group"]})]}),e.jsxs("div",{className:"space-y-2",children:[S.map((l,o)=>e.jsxs("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Field"}),e.jsx("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:l.field,onChange:h=>z(o,{...l,field:h.target.value}),children:c.map((h,A)=>e.jsx("option",{value:h.name,children:h.label||h.name},A))})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Sort Order"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:l.sort||"asc",onChange:h=>z(o,{...l,sort:h.target.value}),children:[e.jsx("option",{value:"asc",children:"Ascending"}),e.jsx("option",{value:"desc",children:"Descending"})]})]})]}),e.jsx(r.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50 self-end",onClick:()=>Y(o),children:e.jsx(w.Trash2,{className:"h-4 w-4"})})]},o)),S.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No grouping rules applied."})]})]}),e.jsxs(r.TabsContent,{value:"sections",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{children:"Report Sections"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(r.Button,{size:"sm",variant:"outline",onClick:()=>W("header"),children:[e.jsx(w.Plus,{className:"h-4 w-4 mr-2"}),"Header"]}),e.jsxs(r.Button,{size:"sm",variant:"outline",onClick:()=>W("chart"),children:[e.jsx(w.Plus,{className:"h-4 w-4 mr-2"}),"Chart"]}),e.jsxs(r.Button,{size:"sm",variant:"outline",onClick:()=>W("table"),children:[e.jsx(w.Plus,{className:"h-4 w-4 mr-2"}),"Table"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[v.map((l,o)=>{var h,A,q,H;return e.jsxs("div",{className:"p-3 border rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2",children:[e.jsx("div",{className:"text-xs bg-muted px-2 py-0.5 rounded uppercase",children:l.type}),l.title]}),e.jsx(r.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50",onClick:()=>ae(o),children:e.jsx(w.Trash2,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Title"}),e.jsx(r.Input,{className:"h-8 text-sm",value:l.title||"",onChange:t=>$(o,{...l,title:t.target.value})})]}),l.type==="text"&&e.jsxs("div",{className:"col-span-2",children:[e.jsx(r.Label,{className:"text-xs",children:"Content"}),e.jsx(r.Input,{className:"h-8 text-sm",value:l.text||"",onChange:t=>$(o,{...l,text:t.target.value})})]}),l.type==="chart"&&e.jsxs("div",{className:"col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded",children:[e.jsx("div",{className:"col-span-2",children:e.jsx(r.Label,{className:"text-xs font-semibold",children:"Chart Configuration"})}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"Chart Type"}),e.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:((h=l.chart)==null?void 0:h.chartType)||"bar",onChange:t=>$(o,{...l,chart:{...l.chart,type:"chart",chartType:t.target.value}}),children:[e.jsx("option",{value:"bar",children:"Bar"}),e.jsx("option",{value:"line",children:"Line"}),e.jsx("option",{value:"area",children:"Area"}),e.jsx("option",{value:"pie",children:"Pie"})]})]}),e.jsxs("div",{children:[e.jsx(r.Label,{className:"text-xs",children:"X-Axis Field"}),e.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:((A=l.chart)==null?void 0:A.xAxisField)||"",onChange:t=>$(o,{...l,chart:{...l.chart,type:"chart",xAxisField:t.target.value}}),children:[e.jsx("option",{value:"",children:"Select Field..."}),c.map(t=>e.jsx("option",{value:t.name,children:t.label||t.name},t.name)),c.length===0&&e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"name",children:"Name"}),e.jsx("option",{value:"month",children:"Month"})]})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(r.Label,{className:"text-xs",children:"Y-Axis Fields (comma separated)"}),e.jsx(r.Input,{className:"h-8 text-sm",placeholder:"e.g. value, count",value:((H=(q=l.chart)==null?void 0:q.yAxisFields)==null?void 0:H.join(", "))||"",onChange:t=>$(o,{...l,chart:{...l.chart,type:"chart",yAxisFields:t.target.value.split(",").map(f=>f.trim()).filter(Boolean)}})})]})]})]})]},o)}),v.length===0&&e.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."})]})]}),e.jsx(r.TabsContent,{value:"schedule",className:"space-y-4 mt-4",children:e.jsx(je,{schedule:i.schedule,onChange:l=>x({...i,schedule:l})})})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 mt-6 pt-4 border-t",children:[e.jsx(r.Button,{variant:"outline",onClick:re,children:"Cancel"}),e.jsxs(r.Button,{onClick:X,children:[e.jsx(w.Save,{className:"h-4 w-4 mr-2"}),"Save Report"]})]})]})]}),u&&e.jsxs(r.Card,{className:"mt-8 border-2 border-blue-100",children:[e.jsx(r.CardHeader,{className:"bg-blue-50/50",children:e.jsx(r.CardTitle,{className:"text-blue-900 text-sm uppercase tracking-wide",children:"Live Preview"})}),e.jsx(r.CardContent,{className:"pt-6",children:e.jsx(te,{schema:{type:"report-viewer",report:{...i,fields:n,filters:y,groupBy:S,sections:v},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"}]}})})]})]})};async function ve(s,d){var x;const{dataSource:a,resource:c,queryParams:u,format:p,exportConfig:j}=d,i=p||s.defaultExportFormat||"pdf";try{const b=(await a.find(c,u)).data||[],y={format:i,...(x=s.exportConfigs)==null?void 0:x[i],...j};return ee(i,s,b,y),{success:!0,recordCount:b.length,format:i}}catch(n){return{success:!1,recordCount:0,format:i,error:n.message}}}function Ne(s,d,a={}){const{columns:c,filename:u,includeAggregationRow:p=!1}=a,j=c||(s.fields||[]).map(Ce),i=j.map(y=>y.header),x=d.map((y,E)=>j.map(S=>{if(S.formula)return S.formula.replace(/\{ROW\}/g,String(E+2));const m=y[S.name];return Se(m,S.numberFormat)}));if(p&&d.length>0){const y=j.map((E,S)=>{const m=(s.fields||[]).find(v=>v.name===E.name);if(m!=null&&m.aggregation){const v=ke(S),N=2,k=d.length+1;switch(m.aggregation){case"sum":return`=SUM(${v}${N}:${v}${k})`;case"avg":return`=AVERAGE(${v}${N}:${v}${k})`;case"count":return`=COUNTA(${v}${N}:${v}${k})`;case"min":return`=MIN(${v}${N}:${v}${k})`;case"max":return`=MAX(${v}${N}:${v}${k})`;default:return""}}return""});x.push(y)}const n="\uFEFF"+[i.join(" "),...x.map(y=>y.join(" "))].join(`
|
|
80
|
-
`),
|
|
77
|
+
</html>`),h.document.close(),h.onload=()=>{h.print()}}function xe(r,i,t){const o=r.fields||[],c=o.map(a=>a.label||a.name),b=i.map(a=>o.map(d=>{let l=a[d.name];return l=be(l),typeof l=="string"&&(l.includes(",")||l.includes('"')||l.includes(`
|
|
78
|
+
`)||l.includes(" "))?`"${l.replace(/"/g,'""')}"`:l??""})),h="\uFEFF"+[...(t==null?void 0:t.includeHeaders)!==!1?[c.join(" ")]:[],...b.map(a=>a.join(" "))].join(`
|
|
79
|
+
`);X(h,(t==null?void 0:t.filename)||`${r.title||"report"}.tsv`,"text/tab-separated-values")}function te(r,i,t,o){switch(r){case"csv":he(i,t,o);break;case"json":me(i,t,o);break;case"html":ee(i,t,o);break;case"pdf":pe(i,t,o);break;case"excel":xe(i,t,o);break;default:console.warn(`Unsupported export format: ${r}`)}}function z(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function be(r){if(typeof r=="string"&&r.length>0){const i=r.charAt(0);if(i==="="||i==="+"||i==="-"||i==="@"||i==="|")return` ${r}`}return r}function fe(r){return["A4","A3","Letter","Legal"].includes(r||"")?r:"A4"}function ge(r){return r==="landscape"?"landscape":"portrait"}function X(r,i,t){const o=new Blob([r],{type:`${t};charset=utf-8`}),c=URL.createObjectURL(o),b=document.createElement("a");b.href=c,b.download=i,document.body.appendChild(b),b.click(),document.body.removeChild(b),URL.revokeObjectURL(c)}function ae(r,i){if(r==null||r==="")return"";const t=i==null?void 0:i.type,o=i==null?void 0:i.format;if(t==="date"||o==="date"||ke(r))return Se(r);if(t==="number"||typeof r=="number"){const c=typeof r=="number"?r:Number(r);return isNaN(c)?String(r):o==="currency"||o==="currency_cny"?`¥${c.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:0})}`:o==="currency_usd"?`$${c.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:0})}`:o==="percent"?`${c.toLocaleString("en-US",{minimumFractionDigits:1,maximumFractionDigits:1})}%`:c.toLocaleString("en-US")}return String(r)}function ke(r){return typeof r!="string"?!1:/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(r)}function Se(r){try{const i=new Date(r);if(isNaN(i.getTime()))return String(r);const t=i.getFullYear(),o=String(i.getMonth()+1).padStart(2,"0"),c=String(i.getDate()).padStart(2,"0");return`${t}-${o}-${c}`}catch{return String(r)}}function Te(r,i){if(!i||i.length===0||!r||r.length===0)return null;const t=i[0],o=t.field,c=new Map;for(const a of r){const d=String(a[o]??"(empty)");c.has(d)||c.set(d,[]),c.get(d).push(a)}const b=[];for(const[a,d]of c)b.push({key:a,label:`${t.label||o}: ${a}`,rows:d});const h=t.sort==="desc"?-1:1;return b.sort((a,d)=>a.key.localeCompare(d.key)*h),b}const re=({schema:r,onRefresh:i})=>{var $,T;const{report:t,data:o,showToolbar:c=!0,allowExport:b=!0,allowPrint:h=!0,loading:a=!1}=r,d=m=>{var C;if(!t){console.warn("ReportViewer: Cannot export, no report defined");return}te(m,t,o||[],(C=t.exportConfigs)==null?void 0:C[m])},l=()=>{window.print()},p=()=>{i==null||i()},j=(m,C)=>{if(!o)return 0;const S=o.map(y=>Number(y[m])||0);switch(C){case"count":return o.length;case"sum":return S.reduce((y,v)=>y+v,0);case"avg":return S.length>0?(S.reduce((y,v)=>y+v,0)/S.length).toFixed(2):0;case"min":return S.length>0?Math.min(...S):0;case"max":return S.length>0?Math.max(...S):0;default:return""}},E=(m,C)=>{const S=t==null?void 0:t.conditionalFormatting;if(!(!S||!Array.isArray(S)))for(const y of S){if(y.field!==m)continue;const v=String(C??""),A=String(y.value??"");let O=!1;switch(y.operator){case"equals":O=v===A;break;case"not_equals":O=v!==A;break;case"contains":O=v.includes(A);break;case"greater_than":O=Number(C)>Number(y.value);break;case"less_than":O=Number(C)<Number(y.value);break}if(O){const L={};return y.backgroundColor&&(L.backgroundColor=y.backgroundColor),y.textColor&&(L.color=y.textColor),L}}},w=(m,C)=>{var S;if(m==null||m==="")return"";if(C.renderAs==="badge"){const y=((S=C.colorMap)==null?void 0:S[String(m)])||"";return e.jsx(s.Badge,{className:y,children:String(m)})}return ae(m,C)};return t?e.jsxs("div",{className:"space-y-4",children:[c&&e.jsxs("div",{className:"flex items-center justify-between gap-2 p-4 bg-card rounded-lg border",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:t.title}),t.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t.description})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.refreshInterval&&e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:p,children:[e.jsx(N.RefreshCw,{className:"h-4 w-4 mr-2"}),"Refresh"]}),h&&e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:l,children:[e.jsx(N.Printer,{className:"h-4 w-4 mr-2"}),"Print"]}),b&&t.showExportButtons&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:()=>d("pdf"),children:[e.jsx(N.Download,{className:"h-4 w-4 mr-2"}),"PDF"]}),e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:()=>d("excel"),children:[e.jsx(N.Download,{className:"h-4 w-4 mr-2"}),"Excel"]}),e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:()=>d("csv"),children:[e.jsx(N.Download,{className:"h-4 w-4 mr-2"}),"CSV"]})]})]})]}),e.jsxs(s.Card,{children:[e.jsxs(s.CardHeader,{children:[!c&&t.title&&e.jsx(s.CardTitle,{children:t.title}),!c&&t.description&&e.jsx(s.CardDescription,{children:t.description})]}),e.jsxs(s.CardContent,{className:"space-y-6",children:[a&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[1,2,3].map(m=>e.jsx(s.Card,{children:e.jsxs(s.CardContent,{className:"p-4 space-y-2",children:[e.jsx(s.Skeleton,{className:"h-4 w-20"}),e.jsx(s.Skeleton,{className:"h-8 w-28"})]})},m))}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Skeleton,{className:"h-10 w-full"}),[1,2,3,4,5].map(m=>e.jsx(s.Skeleton,{className:"h-8 w-full"},m))]})]}),!a&&(($=t.sections)==null?void 0:$.map((m,C)=>{var S,y;return m.visible===!1?null:e.jsxs("div",{className:"space-y-2",children:[m.title&&m.type!=="header"&&e.jsx("h3",{className:"text-lg font-semibold border-b pb-2",children:m.title}),m.type==="header"&&m.title&&e.jsx("div",{className:"text-2xl font-bold py-4",children:m.title}),m.type==="summary"&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:(S=t.fields)==null?void 0:S.filter(v=>v.showInSummary).map((v,A)=>e.jsx(s.Card,{children:e.jsxs(s.CardContent,{className:"p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:v.label||v.name}),e.jsx("div",{className:"text-2xl font-bold",children:ae(j(v.name,v.aggregation),v)})]})},A))}),m.type==="chart"&&m.chart&&e.jsx("div",{className:"min-h-[300px]",children:(()=>{let v=m.chart.type;const A=!!m.chart.chartType;!v&&A&&(v="chart"),v&&!!M.ComponentRegistry.get(v)||(v="chart");const D=v==="chart"?{xAxisKey:m.chart.xAxisKey||m.chart.xAxisField||"name",series:m.chart.series||(m.chart.yAxisFields?m.chart.yAxisFields.map(I=>({dataKey:I})):[]),chartType:m.chart.chartType||"bar"}:{},B={...m.chart,type:v,...D,data:o||m.chart.data,className:m.chart.className||"w-full h-[350px]"};return e.jsx(oe.SchemaRenderer,{schema:B})})()}),m.type==="table"&&e.jsx("div",{className:"border rounded-lg overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm min-w-[600px]",children:[e.jsx("thead",{className:"bg-muted",children:e.jsx("tr",{children:(y=m.columns)==null?void 0:y.map((v,A)=>e.jsx("th",{className:`px-4 py-2 font-medium ${v.type==="number"?"text-right":"text-left"}`,children:v.label||v.name},A))})}),e.jsx("tbody",{children:(()=>{const v=Te(o||[],t.groupBy||[]);return v?v.map(A=>{var O;return e.jsxs(U.Fragment,{children:[e.jsx("tr",{className:"bg-muted/60",children:e.jsxs("td",{colSpan:((O=m.columns)==null?void 0:O.length)||1,className:"px-4 py-2 font-semibold text-sm",children:[A.label," (",A.rows.length,")"]})}),A.rows.map((L,D)=>{var B;return e.jsx("tr",{className:"border-t hover:bg-muted/50 even:bg-muted/20",children:(B=m.columns)==null?void 0:B.map((I,W)=>e.jsx("td",{className:`px-4 py-2 ${I.type==="number"?"text-right tabular-nums":""}`,style:E(I.name,L[I.name]),children:w(L[I.name],I)},W))},D)})]},A.key)}):o==null?void 0:o.map((A,O)=>{var L;return e.jsx("tr",{className:"border-t hover:bg-muted/50 even:bg-muted/20",children:(L=m.columns)==null?void 0:L.map((D,B)=>e.jsx("td",{className:`px-4 py-2 ${D.type==="number"?"text-right tabular-nums":""}`,style:E(D.name,A[D.name]),children:w(A[D.name],D)},B))},O)})})()})]})}),m.type==="text"&&m.text&&e.jsx("div",{className:"prose max-w-none",children:e.jsx("p",{children:m.text})}),m.type==="page-break"&&e.jsx("div",{className:"border-t-2 border-dashed my-8 print:page-break-after-always"}),m.content&&e.jsx(oe.SchemaRenderer,{schema:m.content})]},C)})),!t.sections&&o&&o.length>0&&e.jsx("div",{className:"border rounded-lg overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm min-w-[600px]",children:[e.jsx("thead",{className:"bg-muted",children:e.jsx("tr",{children:(T=t.fields)==null?void 0:T.map((m,C)=>e.jsx("th",{className:`px-4 py-2 font-medium ${m.type==="number"?"text-right":"text-left"}`,children:m.label||m.name},C))})}),e.jsx("tbody",{children:o.map((m,C)=>{var S;return e.jsx("tr",{className:"border-t hover:bg-muted/50 even:bg-muted/20",children:(S=t.fields)==null?void 0:S.map((y,v)=>e.jsx("td",{className:`px-4 py-2 ${y.type==="number"?"text-right tabular-nums":""}`,style:E(y.name,m[y.name]),children:w(m[y.name],y)},v))},C)})})]})})]})]})]}):e.jsx(s.Card,{children:e.jsx(s.CardContent,{className:"p-8 text-center text-muted-foreground",children:"No report to display"})})},le=({schedule:r,onChange:i})=>{var d;const[t,o]=U.useState(r||{enabled:!1,frequency:"weekly",time:"09:00",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:["pdf"]}),c=l=>{const p={...t,...l};o(p),i==null||i(p)},b=[{value:"once",label:"Once"},{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"monthly",label:"Monthly"},{value:"quarterly",label:"Quarterly"},{value:"yearly",label:"Yearly"}],h=[{value:"pdf",label:"PDF"},{value:"excel",label:"Excel"},{value:"csv",label:"CSV"},{value:"html",label:"HTML"}],a=[{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"}];return e.jsxs(s.Card,{children:[e.jsx(s.CardHeader,{children:e.jsxs(s.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(N.Calendar,{className:"h-5 w-5"}),"Schedule Configuration"]})}),e.jsxs(s.CardContent,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"schedule-enabled",checked:t.enabled||!1,onChange:l=>c({enabled:l.target.checked}),className:"rounded"}),e.jsx(s.Label,{htmlFor:"schedule-enabled",children:"Enable Scheduled Report"})]}),t.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Frequency"}),e.jsx("select",{className:"w-full border rounded-md p-2 bg-background",value:t.frequency||"weekly",onChange:l=>c({frequency:l.target.value}),children:b.map(l=>e.jsx("option",{value:l.value,children:l.label},l.value))})]}),t.frequency==="weekly"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Day of Week"}),e.jsx("select",{className:"w-full border rounded-md p-2 bg-background",value:t.dayOfWeek??1,onChange:l=>c({dayOfWeek:Number(l.target.value)}),children:a.map(l=>e.jsx("option",{value:l.value,children:l.label},l.value))})]}),t.frequency==="monthly"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Day of Month"}),e.jsx(s.Input,{type:"number",min:1,max:31,value:t.dayOfMonth??1,onChange:l=>c({dayOfMonth:Number(l.target.value)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{className:"flex items-center gap-2",children:[e.jsx(N.Clock,{className:"h-4 w-4"}),"Time"]}),e.jsx(s.Input,{type:"time",value:t.time||"09:00",onChange:l=>c({time:l.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Timezone"}),e.jsx(s.Input,{value:t.timezone||"",onChange:l=>c({timezone:l.target.value}),placeholder:"e.g. America/New_York"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Export Formats"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:h.map(l=>{var p;return e.jsxs("label",{className:"flex items-center gap-1.5 px-3 py-1.5 border rounded-md cursor-pointer hover:bg-muted/50",children:[e.jsx("input",{type:"checkbox",checked:((p=t.formats)==null?void 0:p.includes(l.value))||!1,onChange:j=>{const E=t.formats||[];c({formats:j.target.checked?[...E,l.value]:E.filter(w=>w!==l.value)})},className:"rounded"}),e.jsx("span",{className:"text-sm",children:l.label})]},l.value)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{className:"flex items-center gap-2",children:[e.jsx(N.Mail,{className:"h-4 w-4"}),"Email Recipients"]}),e.jsx(s.Input,{placeholder:"email1@example.com, email2@example.com",value:((d=t.recipients)==null?void 0:d.join(", "))||"",onChange:l=>c({recipients:l.target.value.split(",").map(p=>p.trim()).filter(Boolean)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Email Subject"}),e.jsx(s.Input,{value:t.subject||"",onChange:l=>c({subject:l.target.value}),placeholder:"Scheduled Report: {report_title}"})]})]})]})]})},ve=({schema:r})=>{const{report:i,dataSources:t=[],availableFields:o=[],showPreview:c=!0,onSave:b,onCancel:h}=r,[a,d]=U.useState(i||{type:"report",title:"New Report",fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[l,p]=U.useState(a.fields||[]),[j,E]=U.useState(a.filters||[]),[w,$]=U.useState(a.groupBy||[]),[T,m]=U.useState(a.sections||[]),C=()=>{if(o.length>0&&l.length<o.length){const u=o.find(x=>!l.some(f=>f.name===x.name));if(u){const x=[...l,u];p(x),d({...a,fields:x})}}},S=u=>{const x=l.filter((f,P)=>P!==u);p(x),d({...a,fields:x})},y=(u,x)=>{const f=[...l];f[u]=x,p(f),d({...a,fields:f})},v=()=>{var f;const u={field:((f=o[0])==null?void 0:f.name)||"",operator:"equals",value:""},x=[...j,u];E(x),d({...a,filters:x})},A=u=>{const x=j.filter((f,P)=>P!==u);E(x),d({...a,filters:x})},O=(u,x)=>{const f=[...j];f[u]=x,E(f),d({...a,filters:f})},L=()=>{var f;const u={field:((f=o[0])==null?void 0:f.name)||"",sort:"asc"},x=[...w,u];$(x),d({...a,groupBy:x})},D=u=>{const x=w.filter((f,P)=>P!==u);$(x),d({...a,groupBy:x})},B=(u,x)=>{const f=[...w];f[u]=x,$(f),d({...a,groupBy:f})},I=u=>{const x={type:u,title:`New ${u} Section`},f=[...T,x];m(f),d({...a,sections:f})},W=u=>{const x=T.filter((f,P)=>P!==u);m(x),d({...a,sections:x})},V=(u,x)=>{const f=[...T];f[u]=x,m(f),d({...a,sections:f})},Z=()=>{console.log("Saving report:",a),b&&alert("Report saved! (Handler: "+b+")")},se=()=>{h&&console.log("Report cancelled:",h)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(s.Card,{children:[e.jsxs(s.CardHeader,{children:[e.jsx(s.CardTitle,{children:"Report Builder"}),e.jsx(s.CardDescription,{children:"Configure your report settings, fields, filters, and sections"})]}),e.jsxs(s.CardContent,{children:[e.jsxs(s.Tabs,{defaultValue:"basic",className:"w-full",children:[e.jsxs(s.TabsList,{className:"grid w-full grid-cols-6",children:[e.jsxs(s.TabsTrigger,{value:"basic",children:[e.jsx(N.Settings,{className:"h-4 w-4 mr-2"}),"Basic"]}),e.jsxs(s.TabsTrigger,{value:"fields",children:[e.jsx(N.Layers,{className:"h-4 w-4 mr-2"}),"Fields"]}),e.jsxs(s.TabsTrigger,{value:"filters",children:[e.jsx(N.Filter,{className:"h-4 w-4 mr-2"}),"Filters"]}),e.jsxs(s.TabsTrigger,{value:"grouping",children:[e.jsx(N.Layers,{className:"h-4 w-4 mr-2"}),"Group By"]}),e.jsxs(s.TabsTrigger,{value:"sections",children:[e.jsx(N.Layers,{className:"h-4 w-4 mr-2"}),"Sections"]}),e.jsxs(s.TabsTrigger,{value:"schedule",children:[e.jsx(N.Calendar,{className:"h-4 w-4 mr-2"}),"Schedule"]})]}),e.jsx(s.TabsContent,{value:"basic",className:"space-y-4 mt-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"report-title",children:"Report Title"}),e.jsx(s.Input,{id:"report-title",value:a.title||"",onChange:u=>d({...a,title:u.target.value}),placeholder:"Enter report title"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"report-description",children:"Description"}),e.jsx(s.Input,{id:"report-description",value:a.description||"",onChange:u=>d({...a,description:u.target.value}),placeholder:"Enter report description"})]}),t.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Data Source"}),e.jsxs("select",{className:"w-full border rounded-md p-2",children:[e.jsx("option",{value:"",children:"Select a data source"}),t.map((u,x)=>e.jsxs("option",{value:x,children:["Data Source ",x+1]},x))]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Export Options"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:a.showExportButtons||!1,onChange:u=>d({...a,showExportButtons:u.target.checked})}),e.jsx("span",{className:"text-sm",children:"Show Export Buttons"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:a.showPrintButton||!1,onChange:u=>d({...a,showPrintButton:u.target.checked})}),e.jsx("span",{className:"text-sm",children:"Show Print Button"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"export-format",children:"Default Export Format"}),e.jsxs("select",{id:"export-format",className:"w-full border rounded-md p-2",value:a.defaultExportFormat||"pdf",onChange:u=>d({...a,defaultExportFormat:u.target.value}),children:[e.jsx("option",{value:"pdf",children:"PDF"}),e.jsx("option",{value:"excel",children:"Excel"}),e.jsx("option",{value:"csv",children:"CSV"}),e.jsx("option",{value:"json",children:"JSON"}),e.jsx("option",{value:"html",children:"HTML"})]})]})]})}),e.jsxs(s.TabsContent,{value:"fields",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Report Fields"}),e.jsxs(s.Button,{size:"sm",variant:"outline",onClick:C,disabled:l.length>=o.length,children:[e.jsx(N.Plus,{className:"h-4 w-4 mr-2"}),"Add Field"]})]}),e.jsxs("div",{className:"space-y-2",children:[l.map((u,x)=>e.jsx("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:e.jsxs("div",{className:"flex-1 grid grid-cols-4 gap-2",children:[e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Field Name"}),e.jsx("div",{className:"text-sm font-medium",children:u.name})]}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Label"}),e.jsx(s.Input,{className:"h-8 text-sm",value:u.label||u.name,onChange:f=>y(x,{...u,label:f.target.value})})]}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Aggregation"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:u.aggregation||"",onChange:f=>y(x,{...u,aggregation:f.target.value}),children:[e.jsx("option",{value:"",children:"None"}),e.jsx("option",{value:"sum",children:"Sum"}),e.jsx("option",{value:"count",children:"Count"}),e.jsx("option",{value:"avg",children:"Average"}),e.jsx("option",{value:"min",children:"Min"}),e.jsx("option",{value:"max",children:"Max"})]})]}),e.jsx("div",{className:"flex items-end justify-end",children:e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50",onClick:()=>S(x),children:e.jsx(N.Trash2,{className:"h-4 w-4"})})})]})},x)),l.length===0&&e.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.'})]})]}),e.jsxs(s.TabsContent,{value:"filters",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Report Filters"}),e.jsxs(s.Button,{size:"sm",variant:"outline",onClick:v,children:[e.jsx(N.Plus,{className:"h-4 w-4 mr-2"}),"Add Filter"]})]}),e.jsxs("div",{className:"space-y-2",children:[j.map((u,x)=>e.jsxs("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Field"}),e.jsx("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:u.field,onChange:f=>O(x,{...u,field:f.target.value}),children:o.map((f,P)=>e.jsx("option",{value:f.name,children:f.label||f.name},P))})]}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Operator"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:u.operator,onChange:f=>O(x,{...u,operator:f.target.value}),children:[e.jsx("option",{value:"equals",children:"Equals"}),e.jsx("option",{value:"contains",children:"Contains"}),e.jsx("option",{value:"gt",children:"Greater Than"}),e.jsx("option",{value:"lt",children:"Less Than"}),e.jsx("option",{value:"between",children:"Between"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Value"}),e.jsx(s.Input,{className:"h-8 text-sm",value:String(u.value),onChange:f=>O(x,{...u,value:f.target.value})})]})]}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50 self-end",onClick:()=>A(x),children:e.jsx(N.Trash2,{className:"h-4 w-4"})})]},x)),j.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No filters defined."})]})]}),e.jsxs(s.TabsContent,{value:"grouping",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Grouping Rules"}),e.jsxs(s.Button,{size:"sm",variant:"outline",onClick:L,children:[e.jsx(N.Plus,{className:"h-4 w-4 mr-2"}),"Add Group"]})]}),e.jsxs("div",{className:"space-y-2",children:[w.map((u,x)=>e.jsxs("div",{className:"flex items-center gap-2 p-3 border rounded-lg",children:[e.jsxs("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Field"}),e.jsx("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:u.field,onChange:f=>B(x,{...u,field:f.target.value}),children:o.map((f,P)=>e.jsx("option",{value:f.name,children:f.label||f.name},P))})]}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Sort Order"}),e.jsxs("select",{className:"w-full border rounded-md h-8 text-sm px-2",value:u.sort||"asc",onChange:f=>B(x,{...u,sort:f.target.value}),children:[e.jsx("option",{value:"asc",children:"Ascending"}),e.jsx("option",{value:"desc",children:"Descending"})]})]})]}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50 self-end",onClick:()=>D(x),children:e.jsx(N.Trash2,{className:"h-4 w-4"})})]},x)),w.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No grouping rules applied."})]})]}),e.jsxs(s.TabsContent,{value:"sections",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Report Sections"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(s.Button,{size:"sm",variant:"outline",onClick:()=>I("header"),children:[e.jsx(N.Plus,{className:"h-4 w-4 mr-2"}),"Header"]}),e.jsxs(s.Button,{size:"sm",variant:"outline",onClick:()=>I("chart"),children:[e.jsx(N.Plus,{className:"h-4 w-4 mr-2"}),"Chart"]}),e.jsxs(s.Button,{size:"sm",variant:"outline",onClick:()=>I("table"),children:[e.jsx(N.Plus,{className:"h-4 w-4 mr-2"}),"Table"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[T.map((u,x)=>{var f,P,H,J;return e.jsxs("div",{className:"p-3 border rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2",children:[e.jsx("div",{className:"text-xs bg-muted px-2 py-0.5 rounded uppercase",children:u.type}),u.title]}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-700 hover:bg-red-50",onClick:()=>W(x),children:e.jsx(N.Trash2,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Title"}),e.jsx(s.Input,{className:"h-8 text-sm",value:u.title||"",onChange:n=>V(x,{...u,title:n.target.value})})]}),u.type==="text"&&e.jsxs("div",{className:"col-span-2",children:[e.jsx(s.Label,{className:"text-xs",children:"Content"}),e.jsx(s.Input,{className:"h-8 text-sm",value:u.text||"",onChange:n=>V(x,{...u,text:n.target.value})})]}),u.type==="chart"&&e.jsxs("div",{className:"col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded",children:[e.jsx("div",{className:"col-span-2",children:e.jsx(s.Label,{className:"text-xs font-semibold",children:"Chart Configuration"})}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"Chart Type"}),e.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:((f=u.chart)==null?void 0:f.chartType)||"bar",onChange:n=>V(x,{...u,chart:{...u.chart,type:"chart",chartType:n.target.value}}),children:[e.jsx("option",{value:"bar",children:"Bar"}),e.jsx("option",{value:"line",children:"Line"}),e.jsx("option",{value:"area",children:"Area"}),e.jsx("option",{value:"pie",children:"Pie"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{className:"text-xs",children:"X-Axis Field"}),e.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:((P=u.chart)==null?void 0:P.xAxisField)||"",onChange:n=>V(x,{...u,chart:{...u.chart,type:"chart",xAxisField:n.target.value}}),children:[e.jsx("option",{value:"",children:"Select Field..."}),o.map(n=>e.jsx("option",{value:n.name,children:n.label||n.name},n.name)),o.length===0&&e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"name",children:"Name"}),e.jsx("option",{value:"month",children:"Month"})]})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(s.Label,{className:"text-xs",children:"Y-Axis Fields (comma separated)"}),e.jsx(s.Input,{className:"h-8 text-sm",placeholder:"e.g. value, count",value:((J=(H=u.chart)==null?void 0:H.yAxisFields)==null?void 0:J.join(", "))||"",onChange:n=>V(x,{...u,chart:{...u.chart,type:"chart",yAxisFields:n.target.value.split(",").map(g=>g.trim()).filter(Boolean)}})})]})]})]})]},x)}),T.length===0&&e.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."})]})]}),e.jsx(s.TabsContent,{value:"schedule",className:"space-y-4 mt-4",children:e.jsx(le,{schedule:a.schedule,onChange:u=>d({...a,schedule:u})})})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 mt-6 pt-4 border-t",children:[e.jsx(s.Button,{variant:"outline",onClick:se,children:"Cancel"}),e.jsxs(s.Button,{onClick:Z,children:[e.jsx(N.Save,{className:"h-4 w-4 mr-2"}),"Save Report"]})]})]})]}),c&&e.jsxs(s.Card,{className:"mt-8 border-2 border-blue-100",children:[e.jsx(s.CardHeader,{className:"bg-blue-50/50",children:e.jsx(s.CardTitle,{className:"text-blue-900 text-sm uppercase tracking-wide",children:"Live Preview"})}),e.jsx(s.CardContent,{className:"pt-6",children:e.jsx(re,{schema:{type:"report-viewer",report:{...a,fields:l,filters:j,groupBy:w,sections:T},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"}]}})})]})]})},Ee=[{value:"",label:"None"},{value:"sum",label:"Sum"},{value:"count",label:"Count"},{value:"avg",label:"Average"},{value:"min",label:"Min"},{value:"max",label:"Max"}];function Re({availableFields:r,value:i,onChange:t}){const o=Array.isArray(i)?i.map(a=>typeof a=="string"?{name:a,label:a,type:"string"}:{name:a.name||a.field||a.value,label:a.label||a.name||"",type:a.type||"string",aggregation:a.aggregation}):[],c=o.map(a=>a.name),b=a=>{const d=c.includes(a);let l;if(d)l=o.filter(p=>p.name!==a);else{const p=r.find(j=>j.value===a);l=[...o,{name:a,label:(p==null?void 0:p.label)||a,type:(p==null?void 0:p.type)||"string"}]}t(l)},h=(a,d)=>{const l=o.map(p=>p.name===a?{...p,aggregation:d||void 0,showInSummary:!!d}:p);t(l)};return r.length===0?e.jsx("div",{className:"text-xs text-muted-foreground py-2","data-testid":"field-picker-empty",children:"No fields available"}):e.jsx("div",{className:"space-y-1 py-1","data-testid":"field-picker",children:r.map(a=>{const d=c.includes(a.value),l=o.find(p=>p.name===a.value);return e.jsxs("div",{className:"flex items-center gap-2 px-1 py-0.5 rounded hover:bg-muted/50 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 flex-1 cursor-pointer",children:[e.jsx(s.Checkbox,{checked:d,onCheckedChange:()=>b(a.value),"data-testid":`field-picker-${a.value}`}),e.jsx("span",{className:"flex-1",children:a.label}),a.type&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:a.type})]}),d&&e.jsx("select",{className:"h-5 text-[10px] border rounded px-1 bg-background",value:(l==null?void 0:l.aggregation)||"",onChange:p=>h(a.value,p.target.value),"data-testid":`field-agg-${a.value}`,children:Ee.map(p=>e.jsx("option",{value:p.value,children:p.label},p.value))})]},a.value)})})}const Ae=[{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 Fe({availableFields:r,value:i,onChange:t}){var b;const o=i||{},c=h=>t({...o,...h});return e.jsxs("div",{className:"space-y-2 py-1","data-testid":"chart-config",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-muted-foreground",children:"Chart type"}),e.jsx("select",{className:"w-full h-7 text-xs border rounded px-2 bg-background",value:o.chartType||"",onChange:h=>c({chartType:h.target.value||void 0}),"data-testid":"chart-type-select",children:Ae.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))})]}),o.chartType&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-muted-foreground",children:"X-axis field"}),e.jsxs("select",{className:"w-full h-7 text-xs border rounded px-2 bg-background",value:o.xAxisField||"",onChange:h=>c({xAxisField:h.target.value||void 0}),"data-testid":"chart-x-field",children:[e.jsx("option",{value:"",children:"Select field…"}),r.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-muted-foreground",children:"Y-axis field"}),e.jsxs("select",{className:"w-full h-7 text-xs border rounded px-2 bg-background",value:((b=o.yAxisFields)==null?void 0:b[0])||"",onChange:h=>c({yAxisFields:h.target.value?[h.target.value]:[]}),"data-testid":"chart-y-field",children:[e.jsx("option",{value:"",children:"Select field…"}),r.filter(h=>h.type==="number").map(h=>e.jsx("option",{value:h.value,children:h.label},h.value))]})]})]})]})}const _e=[{value:"equals",label:"="},{value:"not_equals",label:"≠"},{value:"greater_than",label:">"},{value:"less_than",label:"<"},{value:"contains",label:"Contains"}];function $e({availableFields:r,value:i,onChange:t}){const o=Array.isArray(i)?i:[],c=()=>{var a;t([...o,{field:((a=r[0])==null?void 0:a.value)||"",operator:"equals",value:"",backgroundColor:"#fef9c3",textColor:""}])},b=a=>{t(o.filter((d,l)=>l!==a))},h=(a,d)=>{t(o.map((l,p)=>p===a?{...l,...d}:l))};return e.jsxs("div",{className:"space-y-2 py-1","data-testid":"conditional-format-rules",children:[o.map((a,d)=>e.jsxs("div",{className:"flex items-center gap-1 text-[10px] p-1 border rounded bg-muted/20",children:[e.jsx("select",{className:"h-5 text-[10px] border rounded px-1 bg-background flex-1",value:a.field,onChange:l=>h(d,{field:l.target.value}),"data-testid":`cf-rule-field-${d}`,children:r.map(l=>e.jsx("option",{value:l.value,children:l.label},l.value))}),e.jsx("select",{className:"h-5 text-[10px] border rounded px-1 bg-background w-12",value:a.operator,onChange:l=>h(d,{operator:l.target.value}),children:_e.map(l=>e.jsx("option",{value:l.value,children:l.label},l.value))}),e.jsx("input",{className:"h-5 text-[10px] border rounded px-1 bg-background w-16",value:a.value,placeholder:"value",onChange:l=>h(d,{value:l.target.value}),"data-testid":`cf-rule-value-${d}`}),e.jsx("input",{type:"color",className:"h-5 w-5 rounded border cursor-pointer",value:a.backgroundColor||"#fef9c3",onChange:l=>h(d,{backgroundColor:l.target.value}),title:"Background color"}),e.jsx(s.Button,{type:"button",size:"sm",variant:"ghost",className:"h-5 w-5 p-0",onClick:()=>b(d),"data-testid":`cf-rule-remove-${d}`,children:e.jsx(N.Trash2,{className:"h-3 w-3"})})]},d)),e.jsxs(s.Button,{type:"button",size:"sm",variant:"outline",className:"h-6 text-[10px] w-full",onClick:c,"data-testid":"cf-add-rule",children:[e.jsx(N.Plus,{className:"h-3 w-3 mr-1"}),"Add Rule"]})]})}const Oe=[{value:"header",label:"Header"},{value:"summary",label:"Summary"},{value:"table",label:"Table"},{value:"chart",label:"Chart"},{value:"text",label:"Text"}];function Pe({value:r,onChange:i}){const t=Array.isArray(r)?r:[],o=a=>{i([...t,{type:a,title:`New ${a}`,visible:!0}])},c=a=>{i(t.filter((d,l)=>l!==a))},b=(a,d)=>{i(t.map((l,p)=>p===a?{...l,...d}:l))},h=(a,d)=>{const l=a+d;if(l<0||l>=t.length)return;const p=[...t];[p[a],p[l]]=[p[l],p[a]],i(p)};return e.jsxs("div",{className:"space-y-2 py-1","data-testid":"section-manager",children:[t.map((a,d)=>e.jsxs("div",{className:"flex items-center gap-1 text-[10px] p-1.5 border rounded bg-muted/20",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 mr-1",children:[e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground disabled:opacity-30",disabled:d===0,onClick:()=>h(d,-1),"data-testid":`section-up-${d}`,children:"▲"}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground disabled:opacity-30",disabled:d===t.length-1,onClick:()=>h(d,1),"data-testid":`section-down-${d}`,children:"▼"})]}),e.jsx("span",{className:"text-[9px] bg-muted px-1.5 py-0.5 rounded uppercase font-medium shrink-0",children:a.type}),e.jsx("input",{className:"h-5 text-[10px] border rounded px-1 bg-background flex-1 min-w-0",value:a.title||"",placeholder:"Section title",onChange:l=>b(d,{title:l.target.value}),"data-testid":`section-title-${d}`}),e.jsx(s.Button,{type:"button",size:"sm",variant:"ghost",className:"h-5 w-5 p-0 shrink-0",onClick:()=>c(d),"data-testid":`section-remove-${d}`,children:e.jsx(N.Trash2,{className:"h-3 w-3"})})]},d)),e.jsx("div",{className:"flex gap-1 flex-wrap",children:Oe.map(a=>e.jsxs(s.Button,{type:"button",size:"sm",variant:"outline",className:"h-6 text-[10px]",onClick:()=>o(a.value),"data-testid":`section-add-${a.value}`,children:[e.jsx(N.Plus,{className:"h-3 w-3 mr-0.5"}),a.label]},a.value))})]})}function Le(r=[]){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:(i,t)=>e.jsx(Re,{availableFields:r,value:i,onChange:t})}]},{key:"filters",title:"Filters",collapsible:!0,hint:"Define filter conditions for the report data",fields:[{key:"filters",label:"Conditions",type:"filter",fields:r}]},{key:"groupBy",title:"Group By",collapsible:!0,hint:"Group report data and compute aggregations",fields:[{key:"groupBy",label:"Grouping",type:"sort",fields:r}]},{key:"chart",title:"Chart",collapsible:!0,hint:"Add a chart visualization to the report",fields:[{key:"chartConfig",label:"Chart",type:"custom",render:(i,t)=>e.jsx(Fe,{availableFields:r,value:i,onChange:t})}]},{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:(i,t)=>e.jsx($e,{availableFields:r,value:i,onChange:t})}]},{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:(i,t)=>e.jsx(Pe,{value:i,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:(i,t)=>e.jsx(le,{schedule:i,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 De({open:r,onClose:i,config:t,onSave:o,onFieldChange:c,availableFields:b}){const{draft:h,isDirty:a,updateField:d,discard:l,undo:p,redo:j,canUndo:E,canRedo:w}=s.useConfigDraft(t,{onUpdate:c}),$=Ne.useMemo(()=>Le(b),[b]);return e.jsx(s.ConfigPanelRenderer,{open:r,onClose:i,schema:$,draft:h,isDirty:a,onFieldChange:d,onSave:()=>o(h),onDiscard:l,onUndo:p,onRedo:j,canUndo:E,canRedo:w})}async function je(r,i){var d;const{dataSource:t,resource:o,queryParams:c,format:b,exportConfig:h}=i,a=b||r.defaultExportFormat||"pdf";try{const p=(await t.find(o,c)).data||[],j={format:a,...(d=r.exportConfigs)==null?void 0:d[a],...h};return te(a,r,p,j),{success:!0,recordCount:p.length,format:a}}catch(l){return{success:!1,recordCount:0,format:a,error:l.message}}}function Be(r,i,t={}){const{columns:o,filename:c,includeAggregationRow:b=!1}=t,h=o||(r.fields||[]).map(Me),a=h.map(j=>j.header),d=i.map((j,E)=>h.map(w=>{if(w.formula)return w.formula.replace(/\{ROW\}/g,String(E+2));const $=j[w.name];return ze($,w.numberFormat)}));if(b&&i.length>0){const j=h.map((E,w)=>{const $=(r.fields||[]).find(T=>T.name===E.name);if($!=null&&$.aggregation){const T=Ve(w),m=2,C=i.length+1;switch($.aggregation){case"sum":return`=SUM(${T}${m}:${T}${C})`;case"avg":return`=AVERAGE(${T}${m}:${T}${C})`;case"count":return`=COUNTA(${T}${m}:${T}${C})`;case"min":return`=MIN(${T}${m}:${T}${C})`;case"max":return`=MAX(${T}${m}:${T}${C})`;default:return""}}return""});d.push(j)}const l="\uFEFF"+[a.join(" "),...d.map(j=>j.join(" "))].join(`
|
|
80
|
+
`),p=c||`${r.title||"report"}.tsv`;qe(l,p,"text/tab-separated-values")}function Ie(r,i,t,o){return async()=>{const c=r.schedule;if(!(c!=null&&c.enabled))return[];const b=c.formats||[r.defaultExportFormat||"pdf"],h=[];for(const a of b){const d=await je(r,{dataSource:i,resource:t,format:a});h.push(d)}return o(r,c),h}}function Me(r){return{name:r.name,header:r.label||r.name}}function ze(r,i){return r==null?"":typeof r=="number"&&i?r.toLocaleString("en-US",Ue(i)):Ge(String(r))}function Ue(r){if(r.includes("%"))return{style:"percent",minimumFractionDigits:0};const i=(r.match(/0/g)||[]).length;return{minimumFractionDigits:Math.max(0,i-1),maximumFractionDigits:Math.max(0,i-1)}}function Ve(r){let i="",t=r;for(;t>=0;)i=String.fromCharCode(t%26+65)+i,t=Math.floor(t/26)-1;return i}function Ge(r){if(r.length>0){const i=r.charAt(0);if(i==="="||i==="+"||i==="-"||i==="@"||i==="|")return`'${r}`}return r}function qe(r,i,t){const o=new Blob([r],{type:`${t};charset=utf-8`}),c=URL.createObjectURL(o),b=document.createElement("a");b.href=c,b.download=i,document.body.appendChild(b),b.click(),document.body.removeChild(b),URL.revokeObjectURL(c)}M.ComponentRegistry.register("report",ue,{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"}]}),M.ComponentRegistry.register("report-viewer",re,{namespace:"report",label:"Report Viewer",category:"Report",inputs:[{name:"report",type:"code",label:"Report Definition"},{name:"showToolbar",type:"boolean",label:"Show Toolbar"}]}),M.ComponentRegistry.register("report-builder",ve,{namespace:"report",label:"Report Builder",category:"Report",inputs:[{name:"report",type:"code",label:"Initial Report"}]}),k.ReportBuilder=ve,k.ReportConfigPanel=De,k.ReportRenderer=ue,k.ReportViewer=re,k.ScheduleConfig=le,k.createScheduleTrigger=Ie,k.exportAsCSV=he,k.exportAsExcel=xe,k.exportAsHTML=ee,k.exportAsJSON=me,k.exportAsPDF=pe,k.exportExcelWithFormulas=Be,k.exportReport=te,k.exportWithLiveData=je,k.formatValue=ae,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export type AvailableField = {
|
|
9
|
+
value: string;
|
|
10
|
+
label: string;
|
|
11
|
+
type?: string;
|
|
12
|
+
options?: Array<{
|
|
13
|
+
value: string;
|
|
14
|
+
label: string;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
export interface ReportConfigPanelProps {
|
|
18
|
+
/** Whether the panel is open */
|
|
19
|
+
open: boolean;
|
|
20
|
+
/** Close handler */
|
|
21
|
+
onClose: () => void;
|
|
22
|
+
/** Initial / committed report configuration */
|
|
23
|
+
config: Record<string, any>;
|
|
24
|
+
/** Persist the updated config */
|
|
25
|
+
onSave: (config: Record<string, any>) => void;
|
|
26
|
+
/** Optional live-update callback */
|
|
27
|
+
onFieldChange?: (field: string, value: any) => void;
|
|
28
|
+
/** Available fields for filter/sort sub-editors */
|
|
29
|
+
availableFields?: AvailableField[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* ReportConfigPanel — Schema-driven configuration panel for reports.
|
|
33
|
+
*
|
|
34
|
+
* Built entirely on the generic ConfigPanelRenderer + useConfigDraft,
|
|
35
|
+
* mirroring the DashboardConfigPanel pattern so that report configuration
|
|
36
|
+
* uses the same schema-driven approach as all other view types.
|
|
37
|
+
*/
|
|
38
|
+
export declare function ReportConfigPanel({ open, onClose, config, onSave, onFieldChange, availableFields, }: ReportConfigPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReportField } from '../../types/src';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Format a cell value based on the field definition.
|
|
5
|
+
* Handles number (with thousand separators), currency, percent, and date formatting.
|
|
6
|
+
*/
|
|
7
|
+
export declare function formatValue(value: any, field?: ReportField): string;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { ReportRenderer } from './ReportRenderer';
|
|
2
2
|
import { ReportViewer } from './ReportViewer';
|
|
3
3
|
import { ReportBuilder } from './ReportBuilder';
|
|
4
|
+
import { ReportConfigPanel } from './ReportConfigPanel';
|
|
4
5
|
|
|
5
|
-
export { ReportRenderer, ReportViewer, ReportBuilder };
|
|
6
|
+
export { ReportRenderer, ReportViewer, ReportBuilder, ReportConfigPanel };
|
|
7
|
+
export type { AvailableField } from './ReportConfigPanel';
|
|
8
|
+
export { formatValue } from './formatValue';
|
|
6
9
|
export { exportReport, exportAsCSV, exportAsJSON, exportAsHTML, exportAsPDF, exportAsExcel } from './ReportExportEngine';
|
|
7
10
|
export { ScheduleConfig } from './ScheduleConfig';
|
|
8
11
|
export { exportWithLiveData, exportExcelWithFormulas, createScheduleTrigger, } from './LiveReportExporter';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-report",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.umd.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -17,21 +17,21 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"clsx": "^2.1.1",
|
|
20
|
-
"lucide-react": "^0.
|
|
21
|
-
"tailwind-merge": "^
|
|
22
|
-
"@object-ui/components": "3.0
|
|
23
|
-
"@object-ui/core": "3.0
|
|
24
|
-
"@object-ui/fields": "3.0
|
|
25
|
-
"@object-ui/react": "3.0
|
|
26
|
-
"@object-ui/types": "3.0
|
|
20
|
+
"lucide-react": "^0.576.0",
|
|
21
|
+
"tailwind-merge": "^3.5.0",
|
|
22
|
+
"@object-ui/components": "3.1.0",
|
|
23
|
+
"@object-ui/core": "3.1.0",
|
|
24
|
+
"@object-ui/fields": "3.1.0",
|
|
25
|
+
"@object-ui/react": "3.1.0",
|
|
26
|
+
"@object-ui/types": "3.1.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "^18.0.0",
|
|
30
30
|
"react-dom": "^18.0.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^25.
|
|
34
|
-
"@types/react": "19.2.
|
|
33
|
+
"@types/node": "^25.3.3",
|
|
34
|
+
"@types/react": "19.2.14",
|
|
35
35
|
"@types/react-dom": "19.2.3",
|
|
36
36
|
"@vitejs/plugin-react": "^5.1.4",
|
|
37
37
|
"vite": "^5.4.21",
|