@objectstack/console 7.0.0 → 7.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/assets/{AiPendingActionsPage-DLWrcsds.js → AiPendingActionsPage-DfPQB-bV.js} +1 -1
- package/dist/assets/{ApiConsolePage-BIBykAYj.js → ApiConsolePage-CVt86JW9.js} +1 -1
- package/dist/assets/{AppManagementPage-BKE0rv8B.js → AppManagementPage-DuIaI8a2.js} +1 -1
- package/dist/assets/ApprovalsInboxPage-BRv2RqN4.js +1 -0
- package/dist/assets/{AuditLogPage-Bqlhi2ko.js → AuditLogPage-CDXmY4Lg.js} +1 -1
- package/dist/assets/{ComponentNavView-DBMxrUvH.js → ComponentNavView-B2VAx_8W.js} +1 -1
- package/dist/assets/{ConsoleFloatingChatbot-CBIXkoNS.js → ConsoleFloatingChatbot-c1A9X4w7.js} +1 -1
- package/dist/assets/{DeveloperHubPage-C3Ooh2Gg.js → DeveloperHubPage-E4ydudW4.js} +1 -1
- package/dist/assets/{FlowRunsPage-NjEPPv_e.js → FlowRunsPage-CF-nkx9E.js} +1 -1
- package/dist/assets/ProfilePage-4wnWye8l.js +1 -0
- package/dist/assets/PublicFormsPage-B1cdfwoQ.js +1 -0
- package/dist/assets/{SettingsHub-BTNCNbjZ.js → SettingsHub-B4d9Pn8t.js} +1 -1
- package/dist/assets/{SettingsView-BLXf7B7b.js → SettingsView-cRQBVn6H.js} +1 -1
- package/dist/assets/{SystemHubPage-CgN-8VKO.js → SystemHubPage-DIKmhwy1.js} +1 -1
- package/dist/assets/{data-adapter-Dn6-L_yI.js → data-adapter-Be-s1kWX.js} +1 -1
- package/dist/assets/{highlighted-body-OFNGDK62-Dua_6VJ2.js → highlighted-body-OFNGDK62-Dynkkk0t.js} +1 -1
- package/dist/assets/index-D7iz-IIn.js +24 -0
- package/dist/assets/index-Db8Nmh4R.css +2 -0
- package/dist/assets/mermaid-GHXKKRXX-DJsGdxYj.js +1 -0
- package/dist/assets/plugin-calendar-wl24Whh9.js +1 -0
- package/dist/assets/{plugin-charts-C11LxM1X.js → plugin-charts-Mt2y8Sdm.js} +1 -1
- package/dist/assets/{plugin-chatbot-COnH_NZC.js → plugin-chatbot-DXGXTdLU.js} +29 -29
- package/dist/assets/plugin-dashboard-DqF5vvlQ.js +3 -0
- package/dist/assets/{plugin-form-f39dp3V2.js → plugin-form-BBc-xwrZ.js} +1 -1
- package/dist/assets/plugin-gantt-scBgVq2Q.js +1 -0
- package/dist/assets/plugin-grid-u5JmW5Ui.js +6 -0
- package/dist/assets/{plugin-kanban-q2UT5MlD.js → plugin-kanban-0qj1Kr3T.js} +1 -1
- package/dist/assets/{plugin-map-C6vgk2bJ.js → plugin-map-CjA33cHV.js} +1 -1
- package/dist/assets/{plugin-markdown-DPzm2nVd.js → plugin-markdown-BPsaoDf-.js} +1 -1
- package/dist/assets/plugin-report-C35V4A8F.js +59 -0
- package/dist/assets/{plugin-timeline-lCaTr_4i.js → plugin-timeline-Bmy8v-AN.js} +1 -1
- package/dist/assets/plugin-view-tV_8MnpT.js +1 -0
- package/dist/assets/plugins-views-DM6-O61C.js +4 -0
- package/dist/assets/{src-Con14F4e.js → src-BJJhwsID.js} +1 -1
- package/dist/assets/{types-CuyLcCWX.js → types-BsFD2pPK.js} +1 -1
- package/dist/assets/{ui-components-ZN8XdmwJ.js → ui-components-DYQ4Pai7.js} +7 -7
- package/dist/assets/{ui-layout-HiDSueut.js → ui-layout-Dmw4Ab7P.js} +1 -1
- package/dist/index.html +3 -3
- package/package.json +1 -1
- package/dist/assets/ApprovalsInboxPage-D7gF2CM8.js +0 -1
- package/dist/assets/ObjectManagerListPage-DEPokJwV.js +0 -1
- package/dist/assets/ProfilePage-zYSeu2-d.js +0 -1
- package/dist/assets/PublicFormsPage-BrLPiHf1.js +0 -1
- package/dist/assets/index-Ca4KaljM.js +0 -23
- package/dist/assets/index-DsQwZDFr.css +0 -2
- package/dist/assets/mermaid-GHXKKRXX-BvEKnLTo.js +0 -1
- package/dist/assets/plugin-calendar-Dnr7itgk.js +0 -1
- package/dist/assets/plugin-dashboard-DvBectcr.js +0 -3
- package/dist/assets/plugin-gantt-7ui7uiVc.js +0 -1
- package/dist/assets/plugin-grid-DtceFt_J.js +0 -6
- package/dist/assets/plugin-report-BJM4LH87.js +0 -59
- package/dist/assets/plugin-view-b7gS6gIn.js +0 -1
- package/dist/assets/plugins-views-Dvl7pQvR.js +0 -4
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{g as n,r}from"./vendor-react-CIpZOxG3.js";import{$ as i,L as a,et as o,ut as s,z as c}from"./framework-ClI3DbWX.js";import{n as l}from"./vendor-i18n-CnFu8bdi.js";import{$ as u,At as d,Bn as f,Ci as p,Fa as m,Fn as h,Gn as g,In as _,Jn as v,Kn as y,Ln as b,Mr as x,Oo as S,Pr as C,Qn as w,Rn as T,So as E,Ti as D,Uo as O,V as k,Vn as A,Xa as j,Xn as M,Yn as N,Yo as P,bo as F,en as I,es as L,et as R,in as z,l as B,m as ee,ma as te,mr as V,nt as H,oo as ne,pi as re,qn as U,rs as ie,si as ae,ta as oe,tt as se,ui as ce,w as le,yi as ue,zn as de}from"./ui-components-DYQ4Pai7.js";import{r as fe}from"./plugin-grid-u5JmW5Ui.js";var W=e(n(),1),G=r(),pe=({schema:e})=>{let{title:t,description:n,data:r,columns:i}=e;e.chart?.type;let a=!!e.chart;return(0,G.jsxs)(y,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,G.jsxs)(N,{children:[t&&(0,G.jsx)(M,{children:t}),n&&(0,G.jsx)(v,{children:n})]}),(0,G.jsxs)(U,{className:`flex-1 overflow-auto space-y-4`,children:[a&&(()=>{let t=e.chart?.type,n=t?s.get(t):null;return n||=s.get(`chart`),n?(0,G.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,G.jsx)(n,{schema:{...e.chart,data:e.chart.data||r}})}):(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: `,t||`chart`]})})(),r&&r.length>0&&(0,G.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=s.get(`grid`)||s.get(`table`);return e?(0,G.jsx)(e,{schema:{type:`grid`,rowData:r,columnDefs:i,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:i?.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:r.map((e,t)=>(0,G.jsx)(`tr`,{className:`bg-background border-b`,children:i?.map(t=>(0,G.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function K(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function me(e,t){if(e==null)return null;let n=e instanceof Date?e:new Date(String(e));if(Number.isNaN(n.getTime()))return null;let r=n.getUTCFullYear(),i=n.getUTCMonth(),a=n.getUTCDate();switch(t){case`year`:return String(r);case`quarter`:return`${r}-Q${Math.floor(i/3)+1}`;case`month`:return`${r}-${String(i+1).padStart(2,`0`)}`;case`week`:{let e=new Date(Date.UTC(r,i,a)),t=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-t);let n=new Date(Date.UTC(e.getUTCFullYear(),0,1)),o=Math.ceil(((e.getTime()-n.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${String(o).padStart(2,`0`)}`}case`day`:return`${r}-${String(i+1).padStart(2,`0`)}-${String(a).padStart(2,`0`)}`;default:return String(e)}}function q(e,t){let n=e[t.field];return t.dateGranularity?me(n,t.dateGranularity)??`(empty)`:n==null||n===``?`(empty)`:String(n)}function J(e,t){let n={};for(let r of t){if(!r.aggregate){let t=e.find(e=>e[r.field]!=null);n[K(r)]=t?t[r.field]:null;continue}let t=e.map(e=>e[r.field]);switch(r.aggregate){case`count`:n[K(r)]=t.length;break;case`unique`:{let e=new Set;for(let n of t)n!=null&&e.add(n);n[K(r)]=e.size;break}case`sum`:{let e=0;for(let n of t)e+=Number(n)||0;n[K(r)]=e;break}case`avg`:{let e=0,i=0;for(let n of t){if(n==null||n===``)continue;let t=Number(n);Number.isNaN(t)||(e+=t,i+=1)}n[K(r)]=i===0?null:e/i;break}case`min`:{let e=null;for(let n of t){if(n==null)continue;let t=Number(n);Number.isNaN(t)||(e===null||t<e)&&(e=t)}n[K(r)]=e;break}case`max`:{let e=null;for(let n of t){if(n==null)continue;let t=Number(n);Number.isNaN(t)||(e===null||t>e)&&(e=t)}n[K(r)]=e;break}default:n[K(r)]=null}}return n}function he(e,t,n,r={},i=[]){if(t.length===0)return[];let[a,...o]=t,s=new Map;for(let t of e){let e=q(t,a),n=s.get(e);n||(n=[],s.set(e,n)),n.push(t)}let c=[];for(let[e,t]of s){let s={...r,[a.field]:e},l=[...i,e],u=J(t,n),d=o.length>0?he(t,o,n,s,l):void 0;c.push({groupKey:s,groupPath:l,values:u,count:t.length,children:d})}let l=a.sort===`desc`?-1:1;return c.sort((e,t)=>{let n=String(e.groupPath[e.groupPath.length-1]),r=String(t.groupPath[t.groupPath.length-1]);return n.localeCompare(r)*l}),typeof a.limit==`number`&&a.limit>0?c.slice(0,a.limit):c}function ge(e,t,n,r){let i=_e(e,n),a=_e(e,r),o={},s={},c={};for(let c of i){o[c.id]={};let i=ve(e,c.key,n);s[c.id]=J(i,t);for(let e of a){let n=ve(i,e.key,r);n.length!==0&&(o[c.id][e.id]=J(n,t))}}for(let n of a){let i=ve(e,n.key,r);c[n.id]=J(i,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:J(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function _e(e,t){if(t.length===0)return[{key:{},path:[],id:``}];let n=new Map;for(let r of e){let e=[],i={};for(let n of t){let t=q(r,n);e.push(t),i[n.field]=t}let a=e.join(``);n.has(a)||n.set(a,{key:i,path:e,id:a})}let r=Array.from(n.values());r.sort((e,n)=>{for(let r=0;r<t.length;r++){let i=t[r].sort===`desc`?-1:1,a=e.path[r].localeCompare(n.path[r])*i;if(a!==0)return a}return 0});let i=t[0].limit;if(typeof i==`number`&&i>0){let e=new Set;for(let t of r)e.size>=i&&!e.has(t.path[0])||e.add(t.path[0]);return r.filter(t=>e.has(t.path[0]))}return r}function ve(e,t,n){let r=Object.entries(t);if(r.length===0)return e;let i=new Map;for(let e of n)i.set(e.field,e);return e.filter(e=>{for(let[t,n]of r){let r=i.get(t);if((r?q(e,r):e[t]==null?`(null)`:String(e[t]))!==String(n))return!1}return!0})}function Y(e,t){let n={};for(let r of t){if(!r.aggregate)continue;let t=K(r),i=0,a=0,o=null,s=null;for(let n of e){let e=n[t];typeof e==`number`&&(i+=e,a+=1,(o==null||e<o)&&(o=e),(s==null||e>s)&&(s=e))}r.aggregate===`min`?n[t]=o:r.aggregate===`max`?n[t]=s:r.aggregate===`avg`?n[t]=a===0?null:i/a:n[t]=i}return n}function ye(e,t,n,r){let i=be(e,n),a=be(e,r),o={},s={},c={};for(let n of i){o[n.id]={};let r=e.filter(e=>xe(e,n.key));s[n.id]=Y(r,t);for(let e of a){let i=r.filter(t=>xe(t,e.key));if(i.length===0)continue;let a={};for(let e of t){if(!e.aggregate)continue;let t=K(e);a[t]=i[0][t]}o[n.id][e.id]=a}}for(let n of a){let r=e.filter(e=>xe(e,n.key));c[n.id]=Y(r,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:Y(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function be(e,t){if(t.length===0)return[{key:{},path:[],id:``}];let n=new Map;for(let r of e){let e=[],i={};for(let n of t){let t=r[n.field],a=t==null?`(null)`:String(t);e.push(a),i[n.field]=a}let a=e.join(``);n.has(a)||n.set(a,{key:i,path:e,id:a})}let r=Array.from(n.values());return r.sort((e,n)=>{for(let r=0;r<t.length;r++){let i=t[r].sort===`desc`?-1:1,a=e.path[r].localeCompare(n.path[r])*i;if(a!==0)return a}return 0}),r}function xe(e,t){for(let[n,r]of Object.entries(t))if((e[n]==null?`(null)`:String(e[n]))!==String(r))return!1;return!0}function X(e,t){let n=e&&Object.keys(e).length>0,r=t&&Object.keys(t).length>0;if(n&&r)return{$and:[e,t]};if(n)return e;if(r)return t}function Se(e){let t=new Set;for(let n of e.groupingsDown??[])t.add(n.field);for(let n of e.groupingsAcross??[])t.add(n.field);for(let n of e.columns??[])t.add(n.field);for(let n of e.sort??[])t.add(n.field);return Array.from(t)}function Ce(e,t,n){let r=[...e.groupingsDown??[],...e.groupingsAcross??[]],i=(e.columns??[]).filter(e=>!!e.aggregate);if(r.length===0&&i.length===0)return null;let a=r.map(e=>e.dateGranularity?{field:e.field,dateGranularity:e.dateGranularity}:e.field),o=i.map(e=>({function:e.aggregate===`unique`?`count_distinct`:e.aggregate,field:e.field,alias:K(e)})),s=X(e.filter,t),c={object:e.objectName,limit:n};return a.length>0&&(c.groupBy=a),o.length>0&&(c.aggregations=o),s&&(c.where=s),c}function we(e,t,n){for(let[r,i]of Object.entries(t)){let t=n.find(e=>e.field===r);if((t?q(e,t):String(e[r]??`(empty)`))!==String(i))return!1}return!0}var Z=[];function Te(e,t={}){let{dataSource:n,runtimeFilter:r,maxRows:i=5e3,enabled:a=!0,rows:o,preferServerAggregation:s=!0}=t,[c,l]=(0,W.useState)(o??Z),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(()=>o?!1:!!(e&&a&&n)),[m,h]=(0,W.useState)(null),g=(0,W.useRef)(0),_=(0,W.useCallback)(async()=>{if(!e||!a)return;if(o){l(o),d(!1);return}if(!n){l(Z);return}let t=++g.current;p(!0),h(null);try{let a=s?Ce(e,r,i):null;if(a&&typeof n.aggregate==`function`)try{let r=Ee(await n.aggregate(e.objectName,a));if(t!==g.current)return;l(r),d(!0);return}catch(e){typeof console<`u`&&console.warn&&console.warn(`[useReportData] dataSource.aggregate() failed, falling back to find():`,e)}if(typeof n.find!=`function`){l(Z),d(!1);return}let o=X(e.filter,r),c=Se(e),u={$top:i};o&&(u.$filter=o),c.length>0&&(u.$select=c),e.sort&&e.sort.length>0&&(u.$orderBy=e.sort.map(e=>`${e.field} ${e.direction??`asc`}`).join(`,`));let f=Ee(await n.find(e.objectName,u));if(t!==g.current)return;l(f),d(!1)}catch(e){if(t!==g.current)return;h(e instanceof Error?e:Error(String(e))),l(Z),d(!1)}finally{t===g.current&&p(!1)}},[e,a,o,n,r,i,s]);(0,W.useEffect)(()=>{_()},[_]);let{rows:v,totals:y,pivot:b}=(0,W.useMemo)(()=>{if(!e)return{rows:[],totals:{},pivot:null};let t=e.groupingsDown??[],n=e.groupingsAcross??[],r=e.columns??[],i=n.length>0;if(u){let e=[...t,...n],a=c.map(t=>{let n={},r=[];for(let i of e){let e=t[i.field];n[i.field]=e,r.push(e==null?`(null)`:String(e))}let i={...t};for(let t of e)delete i[t.field];return{groupKey:n,groupPath:r,values:i,count:1}}),o=Y(c,r),s=i?ye(c,r,t,n):null;return{rows:i&&s?s.rowHeaders.map(e=>({groupKey:e.key,groupPath:e.path,values:s.rowTotals[e.id]??{},count:1})):a,totals:o,pivot:s}}let a=i?t:[...t,...n];return{rows:a.length>0?he(c,a,r):c.map(e=>({groupKey:{},groupPath:[],values:r.length>0?J([e],r):{...e},count:1})),totals:J(c,r),pivot:i?ge(c,r,t,n):null}},[e,c,u]);return{rows:v,rawRows:c,totals:y,pivot:b,serverAggregated:u,loading:f,error:m,refetch:_,drillDown:(0,W.useCallback)(t=>{if(!e)return[];let n=[...e.groupingsDown??[],...e.groupingsAcross??[]];return c.filter(e=>we(e,t,n))},[e,c])}}function Ee(e){if(Array.isArray(e))return e;if(e&&typeof e==`object`){let t=e;if(Array.isArray(t.data))return t.data;if(Array.isArray(t.records))return t.records;if(Array.isArray(t.results))return t.results;if(Array.isArray(t.value))return t.value}return Z}function De(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function Oe(e){let t=[],n=e=>{e.children&&e.children.length>0?e.children.forEach(n):t.push(e)};return e.forEach(n),t}function ke({report:e,rows:t,labels:n}){let r=e.chart;if(!r||!r.type)return{schema:null};let i=e.groupingsDown??[],a=r.xAxis||(i.length>0?i[0]?.field:void 0);if(!a)return{schema:null,diagnostic:`chart.xAxis missing and no groupingsDown[0] to default to.`};let o=e.columns??[],s=r.yAxis,c=`count`,l=`Count`,u=!0;if(s){let e=o.find(e=>e.field===s&&e.aggregate);e?(c=De(e),l=n?.resolveColumnLabel?.(e)??(typeof e.label==`string`?e.label:`${e.aggregate}(${e.field})`),u=!1):(c=`count`,l=n?.resolveCountLabel?.(s)??`Count of ${s}`)}let d=Oe(t),f=new Map;for(let e of d){let t=e.groupKey[a];if(t===void 0)continue;let n=String(t??``),r=u?e.count:Number(e.values[c]??0),i=f.get(n);i?i.measure+=Number.isFinite(r)?r:0:f.set(n,{x:t,measure:Number.isFinite(r)?r:0})}let p=Array.from(f.values()).map(e=>{let t=n?.resolveAxisValue?.(a,e.x)??e.x??`(null)`;return{[a]:t,[c]:e.measure}});return(r.type===`pie`||r.type===`donut`||r.type===`funnel`)&&(p=[...p].sort((e,t)=>Number(t[c]??0)-Number(e[c]??0))),{schema:{type:`chart`,chartType:r.type,data:p,xAxisKey:a,series:[{dataKey:c,label:l}],title:r.title,showLegend:r.showLegend??!0,showDataLabels:r.showDataLabels??!1,className:`w-full h-[320px]`}}}function Ae(e,t,n={}){let r=X(X(e.filter,n.runtimeFilter),Object.keys(t).length>0?t:void 0);return{type:`drill`,name:`drill-${e.name}`,objectName:e.objectName,...r?{filter:r}:{},view:n.view??`list`,...n.recordId===void 0?{}:{recordId:n.recordId},openIn:n.openIn??`current`}}function je(e){return!!e&&e.type===`drill`}function Me(e){return async t=>{if(!je(t))return{success:!1,error:`drill handler invoked with non-drill action`};try{return await e.navigate({objectName:t.objectName,filter:t.filter,view:t.view,recordId:t.recordId,openIn:t.openIn}),{success:!0}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}}function Ne(e,t){return e.registerHandler(`drill`,Me(t)),()=>e.unregisterHandler(`drill`)}function Pe(e){return e?e===`unique`?`count_distinct`:e:null}function Fe(e){if(!(!e||e.length===0))return{fields:e.map(e=>({field:e.field,order:e.sort??`asc`,collapsed:!1}))}}function Ie(e){return(e.columns??[]).map(e=>{let t={field:e.field};return e.label&&(t.label=typeof e.label==`string`?e.label:String(e.label)),e.format&&(t.format=e.format),e.width&&(t.width=e.width),t})}var Le={padding:`12px 16px`,border:`1px dashed rgb(203 213 225)`,borderRadius:8,color:`rgb(100 116 139)`,fontSize:14},Re=({report:e,dataSource:t,rows:n,runtimeFilter:r,onDrillDown:i,actionRunner:o,drillView:s,drillOpenIn:c,className:u})=>{let d=e.type??`tabular`,{t:f}=l(),{fieldLabel:p,translateOptions:m}=ie(),[h,g]=W.useState(null);W.useEffect(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`||!e.objectName)return;let r=!1;return n.getObjectSchema(e.objectName).then(e=>{r||g(e??null)}).catch(()=>{}),()=>{r=!0}},[t,e.objectName]);let _=W.useCallback(t=>{if(t.label)return String(t.label);let n=h?.fields?.[t.field]?.label??t.field,r=p(e.objectName,t.field,n);return t.aggregate?`${r} · ${f(`report.aggregate.${t.aggregate}`,t.aggregate)}`:r},[h,e.objectName,p,f]),v=W.useCallback((t,n)=>{if(n==null)return;let r=h?.fields?.[t];if(!r||!(r.type===`select`||r.type===`status`)||!Array.isArray(r.options)||r.options.length===0)return;let i=m(e.objectName,t,r.options),a=String(n);for(let e of i)if(e&&e.value!==void 0&&e.value!==null&&String(e.value)===a)return e.label==null?a:String(e.label)},[h,e.objectName,m]),{rawRows:y,rows:b,totals:x,serverAggregated:S,loading:C,error:w,drillDown:T}=Te(e,{dataSource:t,rows:n,runtimeFilter:r});if(d===`matrix`||d===`joined`)return(0,G.jsxs)(`div`,{className:u,style:Le,children:[`Report type `,(0,G.jsx)(`code`,{children:d}),` is not yet supported by SpecReportGrid. It will be rendered by a dedicated component in M2 (matrix) / M3 (joined).`]});let E=W.useMemo(()=>{if(S){let t=(e.groupingsDown??[]).map(e=>({field:e.field,label:e.field.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})),n=(e.columns??[]).filter(e=>e.aggregate).map(e=>({field:K(e),label:`${(typeof e.label==`string`?e.label:null)??e.field} (${e.aggregate})`,...e.format?{format:e.format}:{}}));return{type:`object-grid`,objectName:e.objectName,columns:[...t,...n]}}let t=d===`summary`?Fe(e.groupingsDown):void 0,n=(e.columns??[]).map(e=>{let t=Pe(e.aggregate);return t?{field:e.field,type:t}:null}).filter(e=>e!==null);return{type:`object-grid`,objectName:e.objectName,columns:Ie(e),grouping:t,aggregations:n.length>0?n:void 0}},[e,d,S]),D=y,O=W.useCallback(t=>{let n=e.groupingsDown??[],a={};for(let e of n)a[e.field]=t[e.field];if(o){let t=Ae(e,a,{runtimeFilter:r,view:s,openIn:c});o.execute(t)}i&&i(a,T(a))},[o,T,c,s,i,e,r]),k=!!i||!!o,A=(e.columns??[]).filter(e=>e.aggregate),j=A.length>0&&x&&Object.keys(x).length>0,M=W.useMemo(()=>d!==`summary`||!e.chart||!e.chart.type?null:ke({report:e,rows:b,labels:{resolveColumnLabel:_,resolveCountLabel:t=>{let n=h?.fields?.[t]?.label??t;return`${p(e.objectName,t,n)} · ${f(`report.aggregate.count`,`Count`)}`},resolveAxisValue:v}}).schema,[e,b,d,_,v,h,p,f]);return(0,G.jsxs)(`div`,{className:u,"data-testid":`spec-report-grid`,"aria-busy":C||void 0,children:[w?(0,G.jsx)(`div`,{role:`alert`,style:{...Le,color:`rgb(190 18 60)`},children:w.message}):null,j?(0,G.jsxs)(`div`,{"data-testid":`spec-report-totals`,className:`mb-3 flex flex-wrap items-baseline gap-x-6 gap-y-1 rounded-md border bg-muted/40 px-3 py-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:f(`report.totals`,`Totals`)}),A.map(e=>{let t=K(e),n=x[t],r=_(e),i=typeof n==`number`?n.toLocaleString(void 0,{maximumFractionDigits:2}):String(n??`—`);return(0,G.jsxs)(`span`,{"data-testid":`spec-report-total-${t}`,className:`inline-flex items-baseline gap-1.5`,children:[(0,G.jsxs)(`span`,{className:`text-muted-foreground`,children:[r,`:`]}),(0,G.jsx)(`span`,{className:`font-mono font-medium tabular-nums`,children:i})]},t)})]}):null,M?(0,G.jsx)(`div`,{className:`mb-4`,"data-testid":`spec-report-chart`,children:(0,G.jsx)(a,{schema:M})}):null,(0,G.jsx)(fe,{schema:E,data:D,dataSource:t,onRowClick:k?O:void 0})]})};Re.displayName=`SpecReportGrid`;var ze=`—`;function Be(e){return e==null?ze:typeof e==`number`?e.toLocaleString():String(e)}function Ve(e,t,n){if(e==null||e===``||e===`(null)`)return n;let r=t?.options;if(r){let t=r.get(e);if(t!==void 0&&t!==``)return t}return e}function He({header:e,groupings:t,metaByField:n,fallback:r,emptyLabel:i}){return e.path.length===0?(0,G.jsx)(G.Fragment,{children:r}):(0,G.jsx)(G.Fragment,{children:e.path.map((e,r)=>{let a=t[r]?.field;return Ve(e,a?n.get(a):void 0,i)}).join(` / `)})}var Ue=({report:e,dataSource:t,rows:n,runtimeFilter:r,onCellClick:i,actionRunner:a,drillView:o,drillOpenIn:s,className:c,emptyCellText:u=ze})=>{let{pivot:d,loading:f,error:p}=Te(e,{dataSource:t,rows:n,runtimeFilter:r}),m=e.columns??[],h=m.length>1,{fieldLabel:g,translateOptions:_}=ie(),{t:v}=l(),y=v(`report.emptyLabel`,`(Empty)`),b=v(`report.allLabel`,`(All)`),[x,S]=W.useState(null);W.useEffect(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`||!e.objectName)return;let r=!1;return n.getObjectSchema(e.objectName).then(e=>{r||S(e??null)}).catch(()=>{}),()=>{r=!0}},[t,e.objectName]);let C=e.groupingsDown??[],w=e.groupingsAcross??[],T=W.useMemo(()=>{let t=new Map,n=x?.fields??{},r=[...C,...w];for(let i of r){let r=n[i.field],a=r?.label??i.field,o=g(e.objectName,i.field,a),s=r?.type===`select`||r?.type===`status`,c;if(s&&Array.isArray(r?.options)&&r.options.length>0){let t=_(e.objectName,i.field,r.options);c=new Map;for(let e of t)e&&e.value!==void 0&&e.value!==null&&c.set(String(e.value),e.label==null?String(e.value):String(e.label))}t.set(i.field,{fieldLabel:o,options:c})}return t},[x,C,w,e.objectName,g,_]),E=W.useMemo(()=>{let t=new Map,n=x?.fields??{};for(let r of m){let i=K(r);if(r.label){t.set(i,String(r.label));continue}let a=n[r.field]?.label??r.field,o=g(e.objectName,r.field,a);if(r.aggregate){let e=v(`report.aggregate.${r.aggregate}`,r.aggregate);t.set(i,`${o} · ${e}`)}else t.set(i,o)}return t},[m,x,e.objectName,g,v]),D=W.useCallback((t,n,c)=>{let l={...t.key,...n.key};if(a){let t=Ae(e,l,{runtimeFilter:r,view:o,openIn:s});a.execute(t)}i&&i({rowKey:t.key,colKey:n.key,combinedKey:l,values:c})},[a,s,o,i,e,r]);if(p)return(0,G.jsx)(`div`,{className:L(`rounded-md border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive`,c),role:`alert`,"data-testid":`matrix-error`,children:v(`report.failedToLoad`,`Failed to load matrix: {{message}}`,{message:p.message})});if(!d)return(0,G.jsx)(`div`,{className:L(`rounded-md border border-dashed border-border bg-muted/30 px-4 py-6 text-center text-sm text-muted-foreground`,c),"aria-busy":f||void 0,"data-testid":`matrix-empty`,children:f?v(`report.loading`,`Loading…`):v(`report.needsAcross`,"Matrix report requires at least one `groupingsAcross` field.")});let O=!!i||!!a,k=C.map(e=>T.get(e.field)?.fieldLabel??e.field).join(` / `)||v(`report.rowsLabel`,`Row`),A=w.map(e=>T.get(e.field)?.fieldLabel??e.field).join(` / `)||v(`report.columnsLabel`,`Column`),j=m.length>0?K(m[0]):null,M=0;if(j)for(let e of d.rowHeaders)for(let t of d.colHeaders){let n=d.cells[e.id]?.[t.id]?.[j];typeof n==`number`&&n>M&&(M=n)}let N=e=>{if(!j||M<=0||!e)return 0;let t=e[j];return typeof t!=`number`||t<=0?0:Math.min(1,t/M)};return(0,G.jsx)(`div`,{className:L(`overflow-auto rounded-lg border border-border bg-card shadow-sm`,c),"data-testid":`matrix-renderer`,"aria-busy":f||void 0,children:(0,G.jsxs)(`table`,{role:`table`,className:`w-full border-separate border-spacing-0 text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsxs)(`th`,{scope:`col`,className:L(`sticky left-0 top-0 z-30 border-b border-r border-border bg-muted/60`,`px-3 py-2 text-left text-xs font-semibold uppercase tracking-wide text-muted-foreground`),"aria-label":`${k} \u2192 ${A}`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground/70`,children:k}),(0,G.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`\\`}),(0,G.jsx)(`span`,{className:`text-foreground/80`,children:A})]}),d.colHeaders.map(e=>(0,G.jsx)(`th`,{scope:`col`,className:`sticky top-0 z-20 whitespace-nowrap border-b border-border bg-muted/60 px-3 py-2 text-right text-xs font-semibold text-foreground`,children:(0,G.jsx)(He,{header:e,groupings:w,metaByField:T,fallback:b,emptyLabel:y})},`col-${e.id}`)),(0,G.jsx)(`th`,{scope:`col`,className:`sticky top-0 z-20 whitespace-nowrap border-b border-l border-border bg-muted px-3 py-2 text-right text-xs font-semibold uppercase tracking-wide text-foreground`,children:v(`report.rowTotal`,`Row Total`)})]})}),(0,G.jsx)(`tbody`,{children:d.rowHeaders.map((e,t)=>(0,G.jsxs)(`tr`,{className:`group`,children:[(0,G.jsx)(`th`,{scope:`row`,className:L(`sticky left-0 z-10 whitespace-nowrap border-b border-r border-border bg-card px-3 py-2 text-left text-sm font-medium text-foreground`,`group-hover:bg-muted/50`,t===0&&`border-t-0`),children:(0,G.jsx)(He,{header:e,groupings:C,metaByField:T,fallback:b,emptyLabel:y})}),d.colHeaders.map(t=>{let n=d.cells[e.id]?.[t.id],r=!n,i=N(n);return(0,G.jsx)(`td`,{className:L(`border-b border-border px-3 py-2 text-right tabular-nums transition-colors`,r?`text-muted-foreground/40`:`text-foreground`,O&&!r&&`cursor-pointer hover:outline hover:outline-2 hover:-outline-offset-2 hover:outline-primary/50`,`group-hover:bg-muted/30`),style:i>0?{backgroundColor:`rgba(59, 130, 246, ${.06+i*.28})`}:void 0,onClick:O&&!r?()=>D(e,t,n):void 0,"data-row":e.id,"data-col":t.id,children:r?u:We(m,n,h,E)},`cell-${e.id}-${t.id}`)}),(0,G.jsx)(`td`,{className:L(`border-b border-l border-border bg-muted/40 px-3 py-2 text-right text-sm font-semibold tabular-nums text-foreground`,`group-hover:bg-muted/60`),children:We(m,d.rowTotals[e.id]??{},h,E)})]},`row-${e.id}`))}),(0,G.jsx)(`tfoot`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`row`,className:`sticky left-0 z-10 whitespace-nowrap border-t-2 border-r border-border bg-muted px-3 py-2 text-left text-xs font-semibold uppercase tracking-wide text-foreground`,children:v(`report.columnTotal`,`Column Total`)}),d.colHeaders.map(e=>(0,G.jsx)(`td`,{className:`border-t-2 border-border bg-muted/40 px-3 py-2 text-right text-sm font-semibold tabular-nums text-foreground`,children:We(m,d.colTotals[e.id]??{},h,E)},`coltotal-${e.id}`)),(0,G.jsx)(`td`,{className:`border-l border-t-2 border-border bg-primary/10 px-3 py-2 text-right text-sm font-bold tabular-nums text-foreground`,children:We(m,d.grandTotal,h,E)})]})})]})})};function We(e,t,n,r){return e.length?n?(0,G.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:e.map(e=>{let n=K(e);return(0,G.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r?.get(n)??e.label??n}),(0,G.jsx)(`span`,{className:`tabular-nums`,children:Be(t[n])})]},n)})}):Be(t[K(e[0])]):ze}function Ge(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function Ke(e,t){if(!t||Object.keys(t).length===0)return e;let n=X(t,e.filter);return{...e,filter:n}}var qe=({report:e,dataSource:t,runtimeFilter:n,actionRunner:r,drillView:a,drillOpenIn:o,className:s,renderBlock:c})=>{if(!i(e))return(0,G.jsxs)(`div`,{className:s,"data-testid":`joined-report-invalid`,style:{color:`var(--color-destructive, #b91c1c)`,fontSize:13,padding:12},children:[`JoinedReportRenderer requires a report with `,(0,G.jsx)(`code`,{children:`type: 'joined'`}),` and a `,(0,G.jsx)(`code`,{children:`blocks`}),` array.`]});let l=e.blocks??[],u=e.filter,d=e.objectName;return(0,G.jsx)(`div`,{className:s,"data-testid":`joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:l.map((e,i)=>{let s=e.objectName??d??``,l=Ke({...e,objectName:s,type:e.type??`tabular`,columns:e.columns??[]},u),f=Ge(e.label,e.name),p=e.description?Ge(e.description,``):``,m=e.name??`block-${i}`,h=(0,G.jsxs)(`section`,{"data-testid":`joined-report-block`,"data-block-id":m,style:{display:`flex`,flexDirection:`column`,gap:8,border:`1px solid var(--color-border, #e4e4e7)`,borderRadius:8,padding:16,background:`var(--color-card, #ffffff)`},children:[(0,G.jsxs)(`header`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,G.jsx)(`h3`,{style:{margin:0,fontSize:16,fontWeight:600},children:f}),p?(0,G.jsx)(`p`,{style:{margin:0,fontSize:13,color:`var(--color-muted-foreground, #71717a)`},children:p}):null]}),(0,G.jsx)(Ye,{schema:l,dataSource:t,runtimeFilter:n,actionRunner:r,drillView:a,drillOpenIn:o})]},m);return c?c(e,i,h):h})})},Je={border:`1px dashed var(--color-border, #d4d4d8)`,borderRadius:8,padding:16,color:`var(--color-muted-foreground, #71717a)`,background:`var(--color-muted, #f4f4f5)`,fontSize:13},Ye=e=>{let{dataSource:t,rows:n,runtimeFilter:r,actionRunner:a,drillView:s,drillOpenIn:l,className:u}=e,d=W.useContext(c),f=t??d?.dataSource,p=e.schema;if(p&&typeof p==`object`&&p.type===`spec-report`&&p.report&&typeof p.report==`object`&&(p=p.report),o(p)){let e=p.type??`tabular`;return e===`matrix`?(0,G.jsx)(Ue,{report:p,dataSource:f,rows:n,runtimeFilter:r,actionRunner:a,drillView:s,drillOpenIn:l,className:u}):e===`joined`?i(p)?(0,G.jsx)(qe,{report:p,dataSource:f,runtimeFilter:r,actionRunner:a,drillView:s,drillOpenIn:l,className:u}):(0,G.jsxs)(`div`,{className:u,style:Je,"data-testid":`report-joined-placeholder`,children:[`Joined report (`,(0,G.jsx)(`code`,{children:p.name}),`) is missing a `,(0,G.jsx)(`code`,{children:`blocks`}),` array.`]}):(0,G.jsx)(Re,{report:p,dataSource:f,rows:n,runtimeFilter:r,actionRunner:a,drillView:s,drillOpenIn:l,className:u})}return(0,G.jsx)(pe,{schema:p})};function Xe(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=nt(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
|
|
2
|
+
`))?`"${n.replace(/"/g,`""`)}"`:n??``}));at([...n?.includeHeaders===!1?[]:[i.join(`,`)],...a.map(e=>e.join(`,`))].join(`
|
|
3
|
+
`),n?.filename||`${e.title||`report`}.csv`,`text/csv`)}function Ze(e,t,n){let r={title:e.title,description:e.description,generatedAt:new Date().toISOString(),data:t};at(JSON.stringify(r,null,2),n?.filename||`${e.title||`report`}.json`,`application/json`)}function Qe(e,t,n){let r=e.fields||[],i=it(n?.orientation),a=rt(n?.pageSize);at(`<!DOCTYPE html>
|
|
4
|
+
<html>
|
|
5
|
+
<head>
|
|
6
|
+
<meta charset="utf-8">
|
|
7
|
+
<title>${Q(e.title||`Report`)}</title>
|
|
8
|
+
<style>
|
|
9
|
+
@page { size: ${a} ${i}; margin: 20mm; }
|
|
10
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
|
|
11
|
+
h1 { font-size: 24px; margin-bottom: 8px; }
|
|
12
|
+
.description { color: #666; margin-bottom: 24px; }
|
|
13
|
+
.meta { color: #999; font-size: 12px; margin-bottom: 16px; }
|
|
14
|
+
table { width: 100%; border-collapse: collapse; margin-top: 16px; }
|
|
15
|
+
th { background: #f5f5f5; text-align: left; padding: 8px 12px; border: 1px solid #ddd; font-weight: 600; }
|
|
16
|
+
td { padding: 8px 12px; border: 1px solid #ddd; }
|
|
17
|
+
tr:nth-child(even) { background: #fafafa; }
|
|
18
|
+
</style>
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<h1>${Q(e.title||`Report`)}</h1>
|
|
22
|
+
${e.description?`<p class="description">${Q(e.description)}</p>`:``}
|
|
23
|
+
<p class="meta">Generated: ${new Date().toLocaleString()}</p>
|
|
24
|
+
<table>
|
|
25
|
+
<thead><tr>${r.map(e=>`<th>${Q(e.label||e.name)}</th>`).join(``)}</tr></thead>
|
|
26
|
+
<tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${Q(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
|
|
27
|
+
</table>
|
|
28
|
+
</body>
|
|
29
|
+
</html>`,n?.filename||`${e.title||`report`}.html`,`text/html`)}function $e(e,t,n){let r=e.fields||[],i=it(n?.orientation),a=rt(n?.pageSize),o=window.open(``,`_blank`);if(!o){Qe(e,t,{...n,format:`html`,filename:n?.filename?.replace(/\.pdf$/,`.html`)||`${e.title||`report`}.html`});return}o.document.write(`<!DOCTYPE html>
|
|
30
|
+
<html>
|
|
31
|
+
<head>
|
|
32
|
+
<meta charset="utf-8">
|
|
33
|
+
<title>${Q(e.title||`Report`)}</title>
|
|
34
|
+
<style>
|
|
35
|
+
@page { size: ${a} ${i}; margin: 20mm; }
|
|
36
|
+
@media print { .no-print { display: none; } }
|
|
37
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
|
|
38
|
+
h1 { font-size: 24px; margin-bottom: 8px; }
|
|
39
|
+
.description { color: #666; margin-bottom: 24px; }
|
|
40
|
+
.meta { color: #999; font-size: 12px; margin-bottom: 16px; }
|
|
41
|
+
table { width: 100%; border-collapse: collapse; margin-top: 16px; }
|
|
42
|
+
th { background: #f5f5f5; text-align: left; padding: 8px 12px; border: 1px solid #ddd; font-weight: 600; }
|
|
43
|
+
td { padding: 8px 12px; border: 1px solid #ddd; }
|
|
44
|
+
tr:nth-child(even) { background: #fafafa; }
|
|
45
|
+
</style>
|
|
46
|
+
</head>
|
|
47
|
+
<body>
|
|
48
|
+
<h1>${Q(e.title||`Report`)}</h1>
|
|
49
|
+
${e.description?`<p class="description">${Q(e.description)}</p>`:``}
|
|
50
|
+
<p class="meta">Generated: ${new Date().toLocaleString()}</p>
|
|
51
|
+
<table>
|
|
52
|
+
<thead><tr>${r.map(e=>`<th>${Q(e.label||e.name)}</th>`).join(``)}</tr></thead>
|
|
53
|
+
<tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${Q(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
|
|
54
|
+
</table>
|
|
55
|
+
</body>
|
|
56
|
+
</html>`),o.document.close(),o.onload=()=>{o.print()}}function et(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=nt(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
|
|
57
|
+
`)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));at(``+[...n?.includeHeaders===!1?[]:[i.join(` `)],...a.map(e=>e.join(` `))].join(`
|
|
58
|
+
`),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function tt(e,t,n,r){switch(e){case`csv`:Xe(t,n,r);break;case`json`:Ze(t,n,r);break;case`html`:Qe(t,n,r);break;case`pdf`:$e(t,n,r);break;case`excel`:et(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function Q(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function nt(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 rt(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function it(e){return e===`landscape`?`landscape`:`portrait`}function at(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 ot(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||st(e))return ct(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 st(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function ct(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 lt(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 ut=({schema:e,onRefresh:t})=>{let{report:n,data:r,showToolbar:i=!0,allowExport:o=!0,allowPrint:c=!0,loading:l=!1}=e,u=e=>{if(!n){console.warn(`ReportViewer: Cannot export, no report defined`);return}tt(e,n,r||[],n.exportConfigs?.[e])},f=()=>{window.print()},m=()=>{t?.()},h=(e,t)=>{if(!r)return 0;let n=r.map(t=>Number(t[e])||0);switch(t){case`count`:return r.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``}},g=(e,t)=>{let r=n?.conditionalFormatting;if(!(!r||!Array.isArray(r)))for(let n of r){if(n.field!==e)continue;let r=String(t??``),i=String(n.value??``),a=!1;switch(n.operator){case`equals`:a=r===i;break;case`not_equals`:a=r!==i;break;case`contains`:a=r.includes(i);break;case`greater_than`:a=Number(t)>Number(n.value);break;case`less_than`:a=Number(t)<Number(n.value);break}if(a){let e={};return n.backgroundColor&&(e.backgroundColor=n.backgroundColor),n.textColor&&(e.color=n.textColor),e}}},_=(e,t)=>{if(e==null||e===``)return``;if(t.renderAs===`badge`&&(!t.type||t.type===`string`||t.type===`text`))return(0,G.jsx)(w,{className:t.colorMap?.[String(e)]||``,children:String(e)});if(t.aggregation)return ot(e,t);if(t.type){let n={...t};return t.colorMap&&!n.options&&(n.options=Object.entries(t.colorMap).map(([e,t])=>({value:e,label:e,color:t}))),(0,G.jsx)(B(ee(n)),{value:e,field:n})}return ot(e,t)};return n?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[i&&(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:n.title}),n.description&&(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.description})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n.refreshInterval&&(0,G.jsxs)(V,{variant:`outline`,size:`sm`,onClick:m,children:[(0,G.jsx)(ue,{className:`h-4 w-4 mr-2`}),`Refresh`]}),c&&(0,G.jsxs)(V,{variant:`outline`,size:`sm`,onClick:f,children:[(0,G.jsx)(p,{className:`h-4 w-4 mr-2`}),`Print`]}),o&&n.showExportButtons&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsxs)(V,{variant:`outline`,size:`sm`,onClick:()=>u(`pdf`),children:[(0,G.jsx)(j,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,G.jsxs)(V,{variant:`outline`,size:`sm`,onClick:()=>u(`excel`),children:[(0,G.jsx)(j,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,G.jsxs)(V,{variant:`outline`,size:`sm`,onClick:()=>u(`csv`),children:[(0,G.jsx)(j,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,G.jsxs)(y,{children:[(0,G.jsxs)(N,{children:[!i&&n.title&&(0,G.jsx)(M,{children:n.title}),!i&&n.description&&(0,G.jsx)(v,{children:n.description})]}),(0,G.jsxs)(U,{className:`space-y-6`,children:[l&&(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)(y,{children:(0,G.jsxs)(U,{className:`p-4 space-y-2`,children:[(0,G.jsx)(d,{className:`h-4 w-20`}),(0,G.jsx)(d,{className:`h-8 w-28`})]})},e))}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(d,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,G.jsx)(d,{className:`h-8 w-full`},e))]})]}),!l&&n.sections?.map((e,t)=>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:n.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,G.jsx)(y,{children:(0,G.jsxs)(U,{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:ot(h(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,G.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let t=e.chart.type,n=!!e.chart.chartType;!t&&n&&(t=`chart`),t&&s.get(t)||(t=`chart`);let i=t===`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)(a,{schema:{...e.chart,type:t,...i,data:r||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=lt(r||[],n.groupBy||[]);return t?t.map(t=>(0,G.jsxs)(W.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:g(e.name,t[e.name]),children:_(t[e.name],e)},n))},n))]},t.key)):r?.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:g(e.name,t[e.name]),children:_(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)(a,{schema:e.content})]},t)),!n.sections&&r&&r.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:n.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:r.map((e,t)=>(0,G.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:n.fields?.map((t,n)=>(0,G.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:g(t.name,e[t.name]),children:_(e[t.name],t)},n))},t))})]})})]})]})]}):(0,G.jsx)(y,{children:(0,G.jsx)(U,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})},dt=({schedule:e,onChange:t})=>{let[n,r]=(0,W.useState)(e||{enabled:!1,frequency:`weekly`,time:`09:00`,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:[`pdf`]}),i=e=>{let i={...n,...e};r(i),t?.(i)};return(0,G.jsxs)(y,{children:[(0,G.jsx)(N,{children:(0,G.jsxs)(M,{className:`flex items-center gap-2`,children:[(0,G.jsx)(S,{className:`h-5 w-5`}),`Schedule Configuration`]})}),(0,G.jsxs)(U,{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:n.enabled||!1,onChange:e=>i({enabled:e.target.checked}),className:`rounded`}),(0,G.jsx)(z,{htmlFor:`schedule-enabled`,children:`Enable Scheduled Report`})]}),n.enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(z,{children:`Frequency`}),(0,G.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:n.frequency||`weekly`,onChange:e=>i({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))})]}),n.frequency===`weekly`&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(z,{children:`Day of Week`}),(0,G.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:n.dayOfWeek??1,onChange:e=>i({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))})]}),n.frequency===`monthly`&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(z,{children:`Day of Month`}),(0,G.jsx)(I,{type:`number`,min:1,max:31,value:n.dayOfMonth??1,onChange:e=>i({dayOfMonth:Number(e.target.value)})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(z,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ne,{className:`h-4 w-4`}),`Time`]}),(0,G.jsx)(I,{type:`time`,value:n.time||`09:00`,onChange:e=>i({time:e.target.value})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(z,{children:`Timezone`}),(0,G.jsx)(I,{value:n.timezone||``,onChange:e=>i({timezone:e.target.value}),placeholder:`e.g. America/New_York`})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(z,{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:n.formats?.includes(e.value)||!1,onChange:t=>{let r=n.formats||[];i({formats:t.target.checked?[...r,e.value]:r.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)(z,{className:`flex items-center gap-2`,children:[(0,G.jsx)(oe,{className:`h-4 w-4`}),`Email Recipients`]}),(0,G.jsx)(I,{placeholder:`email1@example.com, email2@example.com`,value:n.recipients?.join(`, `)||``,onChange:e=>i({recipients:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(z,{children:`Email Subject`}),(0,G.jsx)(I,{value:n.subject||``,onChange:e=>i({subject:e.target.value}),placeholder:`Scheduled Report: {report_title}`})]})]})]})]})},ft=({schema:e})=>{let{report:t,dataSources:n=[],availableFields:r=[],showPreview:i=!0,onSave:a,onCancel:o}=e,[s,c]=(0,W.useState)(t||{type:`report`,title:`New Report`,fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[l,d]=(0,W.useState)(s.fields||[]),[f,p]=(0,W.useState)(s.filters||[]),[h,g]=(0,W.useState)(s.groupBy||[]),[_,b]=(0,W.useState)(s.sections||[]),x=()=>{if(r.length>0&&l.length<r.length){let e=r.find(e=>!l.some(t=>t.name===e.name));if(e){let t=[...l,e];d(t),c({...s,fields:t})}}},w=e=>{let t=l.filter((t,n)=>n!==e);d(t),c({...s,fields:t})},T=(e,t)=>{let n=[...l];n[e]=t,d(n),c({...s,fields:n})},E=()=>{let e={field:r[0]?.name||``,operator:`equals`,value:``},t=[...f,e];p(t),c({...s,filters:t})},O=e=>{let t=f.filter((t,n)=>n!==e);p(t),c({...s,filters:t})},k=(e,t)=>{let n=[...f];n[e]=t,p(n),c({...s,filters:n})},A=()=>{let e={field:r[0]?.name||``,sort:`asc`},t=[...h,e];g(t),c({...s,groupBy:t})},j=e=>{let t=h.filter((t,n)=>n!==e);g(t),c({...s,groupBy:t})},P=(e,t)=>{let n=[...h];n[e]=t,g(n),c({...s,groupBy:n})},F=e=>{let t={type:e,title:`New ${e} Section`},n=[..._,t];b(n),c({...s,sections:n})},L=e=>{let t=_.filter((t,n)=>n!==e);b(t),c({...s,sections:t})},B=(e,t)=>{let n=[..._];n[e]=t,b(n),c({...s,sections:n})};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(y,{children:[(0,G.jsxs)(N,{children:[(0,G.jsx)(M,{children:`Report Builder`}),(0,G.jsx)(v,{children:`Configure your report settings, fields, filters, and sections`})]}),(0,G.jsxs)(U,{children:[(0,G.jsxs)(u,{defaultValue:`basic`,className:`w-full`,children:[(0,G.jsxs)(se,{className:`grid w-full grid-cols-6`,children:[(0,G.jsxs)(H,{value:`basic`,children:[(0,G.jsx)(ae,{className:`h-4 w-4 mr-2`}),`Basic`]}),(0,G.jsxs)(H,{value:`fields`,children:[(0,G.jsx)(te,{className:`h-4 w-4 mr-2`}),`Fields`]}),(0,G.jsxs)(H,{value:`filters`,children:[(0,G.jsx)(m,{className:`h-4 w-4 mr-2`}),`Filters`]}),(0,G.jsxs)(H,{value:`grouping`,children:[(0,G.jsx)(te,{className:`h-4 w-4 mr-2`}),`Group By`]}),(0,G.jsxs)(H,{value:`sections`,children:[(0,G.jsx)(te,{className:`h-4 w-4 mr-2`}),`Sections`]}),(0,G.jsxs)(H,{value:`schedule`,children:[(0,G.jsx)(S,{className:`h-4 w-4 mr-2`}),`Schedule`]})]}),(0,G.jsx)(R,{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)(z,{htmlFor:`report-title`,children:`Report Title`}),(0,G.jsx)(I,{id:`report-title`,value:s.title||``,onChange:e=>c({...s,title:e.target.value}),placeholder:`Enter report title`})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(z,{htmlFor:`report-description`,children:`Description`}),(0,G.jsx)(I,{id:`report-description`,value:s.description||``,onChange:e=>c({...s,description:e.target.value}),placeholder:`Enter report description`})]}),n.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(z,{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`}),n.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)(z,{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:s.showExportButtons||!1,onChange:e=>c({...s,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:s.showPrintButton||!1,onChange:e=>c({...s,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)(z,{htmlFor:`export-format`,children:`Default Export Format`}),(0,G.jsxs)(`select`,{id:`export-format`,className:`w-full border rounded-md p-2`,value:s.defaultExportFormat||`pdf`,onChange:e=>c({...s,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,{value:`fields`,className:`space-y-4 mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(z,{children:`Report Fields`}),(0,G.jsxs)(V,{size:`sm`,variant:`outline`,onClick:x,disabled:l.length>=r.length,children:[(0,G.jsx)(D,{className:`h-4 w-4 mr-2`}),`Add Field`]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[l.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)(z,{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)(z,{className:`text-xs`,children:`Label`}),(0,G.jsx)(I,{className:`h-8 text-sm`,value:e.label||e.name,onChange:n=>T(t,{...e,label:n.target.value})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(z,{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=>T(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)(V,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>w(t),children:(0,G.jsx)(C,{className:`h-4 w-4`})})})]})},t)),l.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,{value:`filters`,className:`space-y-4 mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(z,{children:`Report Filters`}),(0,G.jsxs)(V,{size:`sm`,variant:`outline`,onClick:E,children:[(0,G.jsx)(D,{className:`h-4 w-4 mr-2`}),`Add Filter`]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[f.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)(z,{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:r.map((e,t)=>(0,G.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(z,{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=>k(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)(z,{className:`text-xs`,children:`Value`}),(0,G.jsx)(I,{className:`h-8 text-sm`,value:String(e.value),onChange:n=>k(t,{...e,value:n.target.value})})]})]}),(0,G.jsx)(V,{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)(C,{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 filters defined.`})]})]}),(0,G.jsxs)(R,{value:`grouping`,className:`space-y-4 mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(z,{children:`Grouping Rules`}),(0,G.jsxs)(V,{size:`sm`,variant:`outline`,onClick:A,children:[(0,G.jsx)(D,{className:`h-4 w-4 mr-2`}),`Add Group`]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[h.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)(z,{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=>P(t,{...e,field:n.target.value}),children:r.map((e,t)=>(0,G.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(z,{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=>P(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)(V,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>j(t),children:(0,G.jsx)(C,{className:`h-4 w-4`})})]},t)),h.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,{value:`sections`,className:`space-y-4 mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(z,{children:`Report Sections`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(V,{size:`sm`,variant:`outline`,onClick:()=>F(`header`),children:[(0,G.jsx)(D,{className:`h-4 w-4 mr-2`}),`Header`]}),(0,G.jsxs)(V,{size:`sm`,variant:`outline`,onClick:()=>F(`chart`),children:[(0,G.jsx)(D,{className:`h-4 w-4 mr-2`}),`Chart`]}),(0,G.jsxs)(V,{size:`sm`,variant:`outline`,onClick:()=>F(`table`),children:[(0,G.jsx)(D,{className:`h-4 w-4 mr-2`}),`Table`]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[_.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)(V,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>L(t),children:(0,G.jsx)(C,{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)(z,{className:`text-xs`,children:`Title`}),(0,G.jsx)(I,{className:`h-8 text-sm`,value:e.title||``,onChange:n=>B(t,{...e,title:n.target.value})})]}),e.type===`text`&&(0,G.jsxs)(`div`,{className:`col-span-2`,children:[(0,G.jsx)(z,{className:`text-xs`,children:`Content`}),(0,G.jsx)(I,{className:`h-8 text-sm`,value:e.text||``,onChange:n=>B(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)(z,{className:`text-xs font-semibold`,children:`Chart Configuration`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(z,{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=>B(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)(z,{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=>B(t,{...e,chart:{...e.chart,type:`chart`,xAxisField:n.target.value}}),children:[(0,G.jsx)(`option`,{value:``,children:`Select Field...`}),r.map(e=>(0,G.jsx)(`option`,{value:e.name,children:e.label||e.name},e.name)),r.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)(z,{className:`text-xs`,children:`Y-Axis Fields (comma separated)`}),(0,G.jsx)(I,{className:`h-8 text-sm`,placeholder:`e.g. value, count`,value:e.chart?.yAxisFields?.join(`, `)||``,onChange:n=>B(t,{...e,chart:{...e.chart,type:`chart`,yAxisFields:n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}})})]})]})]})]},t)),_.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,{value:`schedule`,className:`space-y-4 mt-4`,children:(0,G.jsx)(dt,{schedule:s.schedule,onChange:e=>c({...s,schedule:e})})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-6 pt-4 border-t`,children:[(0,G.jsx)(V,{variant:`outline`,onClick:()=>{o&&console.log(`Report cancelled:`,o)},children:`Cancel`}),(0,G.jsxs)(V,{onClick:()=>{console.log(`Saving report:`,s),a&&alert(`Report saved! (Handler: `+a+`)`)},children:[(0,G.jsx)(re,{className:`h-4 w-4 mr-2`}),`Save Report`]})]})]})]}),i&&(0,G.jsxs)(y,{className:`mt-8 border-2 border-blue-100`,children:[(0,G.jsx)(N,{className:`bg-blue-50/50`,children:(0,G.jsx)(M,{className:`text-blue-900 text-sm uppercase tracking-wide`,children:`Live Preview`})}),(0,G.jsx)(U,{className:`pt-6`,children:(0,G.jsx)(ut,{schema:{type:`report-viewer`,report:{...s,fields:l,filters:f,groupBy:h,sections:_},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`}]}})})]})]})},pt=[`tabular`,`summary`,`matrix`];function mt(e){let t=e.length+1,n=new Set(e.map(e=>e.name).filter(Boolean)),r=`block_${t}`;for(;n.has(r);)t+=1,r=`block_${t}`;return{name:r,type:`tabular`,columns:[]}}function ht(e){return typeof e.label==`string`?e.label:e.label&&typeof e.label==`object`?e.label.default??``:``}function gt(e){return typeof e.description==`string`?e.description:e.description&&typeof e.description==`object`?e.description.default??``:``}function _t({block:e,index:t,total:n,availableFields:r,t:i,duplicateName:a,onChange:o,onRemove:s,onMove:c}){let[l,u]=W.useState(t===0),d=e.type??`tabular`,f=d===`summary`,p=d===`matrix`,m=f||p,h=!e.name||!e.name.trim(),g=h||a,_=t=>o({...e,...t});return(0,G.jsxs)(`div`,{className:`border rounded-md bg-card text-card-foreground`,"data-testid":`joined-block-${t}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 p-1.5 border-b bg-muted/30`,children:[(0,G.jsx)(V,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 shrink-0`,onClick:()=>u(e=>!e),"aria-label":l?`Collapse block`:`Expand block`,"aria-expanded":l,"data-testid":`joined-block-toggle-${t}`,children:l?(0,G.jsx)(E,{className:`h-3.5 w-3.5`}):(0,G.jsx)(F,{className:`h-3.5 w-3.5`})}),(0,G.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background flex-1 min-w-0 ${g?`border-destructive`:``}`,value:e.name??``,onChange:e=>_({name:e.target.value}),placeholder:i(`report.editor.blockNamePlaceholder`),"aria-label":i(`report.editor.blockName`),"aria-invalid":g,"data-testid":`joined-block-name-${t}`}),(0,G.jsx)(`select`,{className:`h-6 text-xs border rounded px-1 bg-background shrink-0`,value:d,onChange:e=>_({type:e.target.value}),"aria-label":i(`report.editor.type`),"data-testid":`joined-block-type-${t}`,children:pt.map(e=>(0,G.jsx)(`option`,{value:e,children:i(`report.editor.type${e.charAt(0).toUpperCase()}${e.slice(1)}`)},e))}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-0.5 shrink-0`,children:[(0,G.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===0,onClick:()=>c(-1),"aria-label":`Move block up`,children:(0,G.jsx)(O,{className:`h-2.5 w-2.5`})}),(0,G.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===n-1,onClick:()=>c(1),"aria-label":`Move block down`,children:(0,G.jsx)(P,{className:`h-2.5 w-2.5`})})]}),(0,G.jsx)(V,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 shrink-0 text-destructive hover:text-destructive`,onClick:s,"aria-label":i(`report.editor.removeBlock`),"data-testid":`joined-block-remove-${t}`,children:(0,G.jsx)(C,{className:`h-3 w-3`})})]}),g&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 text-[10px] text-destructive bg-destructive/5 border-b`,children:[(0,G.jsx)(x,{className:`h-3 w-3`}),i(h?`report.editor.validationBlockNameRequired`:`report.editor.validationBlockNameDuplicate`)]}),l&&(0,G.jsxs)(`div`,{className:`p-2 space-y-2 text-xs`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.blockLabel`)}),(0,G.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background`,value:ht(e),onChange:e=>_({label:e.target.value||void 0}),placeholder:i(`report.editor.blockLabelPlaceholder`),"data-testid":`joined-block-label-${t}`})]}),(0,G.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.objectName`)}),(0,G.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background`,value:e.objectName??``,onChange:e=>_({objectName:e.target.value||void 0}),placeholder:i(`report.editor.objectNamePlaceholder`),"data-testid":`joined-block-object-${t}`})]})]}),(0,G.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.blockDescription`)}),(0,G.jsx)(`textarea`,{className:`text-xs border rounded px-1.5 py-1 bg-background resize-y min-h-[2rem]`,rows:2,value:gt(e),onChange:e=>_({description:e.target.value||void 0}),placeholder:i(`report.editor.blockDescriptionPlaceholder`),"data-testid":`joined-block-description-${t}`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.columns`)}),(0,G.jsx)(It,{availableFields:r,value:e.columns,onChange:e=>_({columns:e}),t:i})]}),(f||p)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.rows`)}),(0,G.jsx)(Lt,{availableFields:r,value:e.groupingsDown,onChange:e=>_({groupingsDown:e}),t:i})]}),p&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.columnsAxis`)}),(0,G.jsx)(Lt,{availableFields:r,value:e.groupingsAcross,onChange:e=>_({groupingsAcross:e}),t:i})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.filters`)}),(0,G.jsx)(kt,{availableFields:r,value:e.filter,onChange:e=>_({filter:e}),t:i})]}),m&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.chart`)}),(0,G.jsx)(Rt,{availableFields:r,columns:Ft(e.columns),value:e.chart,onChange:e=>_({chart:e}),t:i})]})]})]})}function vt(e){return Array.isArray(e)?e.map(e=>{let t=e??{};return{name:t.name??``,type:t.type??`tabular`,columns:Array.isArray(t.columns)?t.columns:[],...t}}):[]}function yt({value:e,onChange:t,availableFields:n,getFieldsForObject:r,containerObjectName:i,t:a}){let o=vt(e),s=e=>r?r(e.objectName??i)??n:n,c={};for(let e of o)e.name&&(c[e.name]=(c[e.name]??0)+1);let l=(e,n)=>{t(o.map((t,r)=>r===e?n:t))},u=e=>{t(o.filter((t,n)=>n!==e))},d=(e,n)=>{let r=e+n;if(r<0||r>=o.length)return;let i=[...o];[i[e],i[r]]=[i[r],i[e]],t(i)};return(0,G.jsxs)(`div`,{className:`space-y-2`,"data-testid":`joined-blocks-editor`,children:[o.length===0&&(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic px-1`,children:a(`report.editor.validationJoinedNeedsBlocks`)}),o.map((e,t)=>(0,G.jsx)(_t,{block:e,index:t,total:o.length,availableFields:s(e),t:a,duplicateName:!!e.name&&(c[e.name]??0)>1,onChange:e=>l(t,e),onRemove:()=>u(t),onMove:e=>d(t,e)},t)),(0,G.jsxs)(V,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 text-xs w-full`,onClick:()=>{t([...o,mt(o)])},"data-testid":`joined-block-add`,children:[(0,G.jsx)(D,{className:`h-3 w-3 mr-1`}),a(`report.editor.addBlock`)]})]})}function bt(e,t){let n=[];if(!Array.isArray(e)||e.length===0)return n.push(t(`report.editor.validationJoinedNeedsBlocks`)),n;let r=new Map,i=!1,a=!1,o=!1;for(let t of e){let e=t??{};if(!e.name||!String(e.name).trim())i=!0;else{let t=(r.get(e.name)??0)+1;r.set(e.name,t),t===2&&(a=!0)}(!Array.isArray(e.columns)||e.columns.length===0)&&(o=!0)}return i&&n.push(t(`report.editor.validationBlockNameRequired`)),a&&n.push(t(`report.editor.validationBlockNameDuplicate`)),o&&n.push(t(`report.editor.validationBlockNeedsColumns`)),n}var xt={$eq:`equals`,$ne:`notEquals`,$gt:`greaterThan`,$gte:`greaterOrEqual`,$lt:`lessThan`,$lte:`lessOrEqual`,$in:`in`,$nin:`notIn`,$contains:`contains`,$notContains:`notContains`,$exists:`isNotEmpty`},St={equals:`$eq`,notEquals:`$ne`,greaterThan:`$gt`,greaterOrEqual:`$gte`,lessThan:`$lt`,lessOrEqual:`$lte`,in:`$in`,notIn:`$nin`,contains:`$contains`,notContains:`$notContains`},Ct=()=>({id:`root`,logic:`and`,conditions:[]});function wt(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function $(){return Math.random().toString(36).slice(2,10)}function Tt(e,t){if(typeof t!=`object`||!t||Array.isArray(t))return[{id:$(),field:e,operator:Array.isArray(t)?`in`:`equals`,value:t}];let n=[];for(let[r,i]of Object.entries(t)){if(r===`$exists`){n.push({id:$(),field:e,operator:i===!1?`isEmpty`:`isNotEmpty`,value:``});continue}if(r===`$null`){n.push({id:$(),field:e,operator:i===!1?`isNotEmpty`:`isEmpty`,value:``});continue}let t=xt[r];if(!t||wt(i)&&`$field`in i)return null;n.push({id:$(),field:e,operator:t,value:i})}return n.length>0?n:null}function Et(e){if(e==null)return{group:Ct(),complex:!1};if(!wt(e))return{group:Ct(),complex:!0};let t=Object.keys(e);if(t.length===1&&(t[0]===`$and`||t[0]===`$or`)){let n=t[0]===`$or`?`or`:`and`,r=e[t[0]];if(!Array.isArray(r))return{group:Ct(),complex:!0};let i=[],a=!1;for(let e of r){if(!wt(e)){a=!0;continue}if(Object.keys(e).some(e=>e===`$and`||e===`$or`||e===`$not`)){a=!0;continue}for(let[t,n]of Object.entries(e)){let e=Tt(t,n);e?i.push(...e):a=!0}}return{group:{id:`root`,logic:n,conditions:i},complex:a}}if(t.includes(`$not`)||t.includes(`$and`)||t.includes(`$or`))return{group:Ct(),complex:!0};let n=[],r=!1;for(let[t,i]of Object.entries(e)){let e=Tt(t,i);e?n.push(...e):r=!0}return{group:{id:`root`,logic:`and`,conditions:n},complex:r}}function Dt(e){if(!e||!Array.isArray(e.conditions)||e.conditions.length===0)return;let t=e.conditions.filter(e=>e.field).map(e=>Ot(e));if(t.length!==0)return t.length===1?t[0]:{[e.logic===`or`?`$or`:`$and`]:t}}function Ot(e){let{field:t,operator:n,value:r}=e;if(n===`isEmpty`)return{[t]:{$exists:!1}};if(n===`isNotEmpty`)return{[t]:{$exists:!0}};if(n===`equals`)return{[t]:r};let i=St[n];return i?{[t]:{[i]:r}}:{[t]:r}}function kt({availableFields:e,value:t,onChange:n,t:r}){let i=W.useMemo(()=>JSON.stringify(t??null),[t]),a=W.useMemo(()=>Et(t),[i]),[o,s]=W.useState(a.group),c=W.useRef(i);W.useEffect(()=>{c.current!==i&&(s(a.group),c.current=i)},[i,a.group]);let l=e=>{s(e);let t=Dt(e);c.current=JSON.stringify(t??null),n(t)};if(a.complex)return(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-2 rounded border border-amber-300 bg-amber-50 text-amber-900 text-[11px]`,children:[(0,G.jsx)(x,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:r(`report.editor.filtersComplex`)})]});let u=()=>{l({...o,conditions:[...o.conditions,{id:$(),field:e[0]?.value??``,operator:`equals`,value:``}]})},d=e=>{l({...o,conditions:o.conditions.filter(t=>t.id!==e)})},f=(e,t)=>{l({...o,conditions:o.conditions.map(n=>n.id===e?{...n,...t}:n)})},p=[{value:`equals`,label:`=`},{value:`notEquals`,label:`≠`},{value:`greaterThan`,label:`>`},{value:`greaterOrEqual`,label:`≥`},{value:`lessThan`,label:`<`},{value:`lessOrEqual`,label:`≤`},{value:`contains`,label:r(`report.editor.opContains`,`contains`)},{value:`in`,label:`in`},{value:`notIn`,label:`not in`},{value:`isEmpty`,label:r(`report.editor.opIsEmpty`,`is empty`)},{value:`isNotEmpty`,label:r(`report.editor.opIsNotEmpty`,`is not empty`)}];return(0,G.jsxs)(`div`,{className:`space-y-1.5 py-1`,"data-testid":`spec-filter-adapter`,children:[o.conditions.length>1&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,G.jsx)(`span`,{children:r(`report.editor.combineLogic`,`Combine with`)}),(0,G.jsxs)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background`,value:o.logic,onChange:e=>l({...o,logic:e.target.value}),"data-testid":`filter-logic-select`,children:[(0,G.jsx)(`option`,{value:`and`,children:`AND`}),(0,G.jsx)(`option`,{value:`or`,children:`OR`})]})]}),o.conditions.map(t=>(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 min-w-0`,value:t.field,onChange:e=>f(t.id,{field:e.target.value}),"data-testid":`filter-field-${t.id}`,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-20 shrink-0`,value:t.operator,onChange:e=>f(t.id,{operator:e.target.value}),"data-testid":`filter-op-${t.id}`,children:p.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))}),t.operator!==`isEmpty`&&t.operator!==`isNotEmpty`&&(0,G.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-24 shrink-0`,value:Array.isArray(t.value)?t.value.join(`,`):(t.value??``).toString(),placeholder:`value`,onChange:e=>{let n=e.target.value,r=t.operator===`in`||t.operator===`notIn`?n.split(`,`).map(e=>e.trim()).filter(Boolean):n;f(t.id,{value:r})},"data-testid":`filter-value-${t.id}`}),(0,G.jsx)(V,{type:`button`,size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0 shrink-0`,onClick:()=>d(t.id),"data-testid":`filter-remove-${t.id}`,children:(0,G.jsx)(C,{className:`h-3 w-3`})})]},t.id)),(0,G.jsxs)(V,{type:`button`,size:`sm`,variant:`outline`,className:`h-6 text-[10px] w-full`,onClick:u,disabled:e.length===0,"data-testid":`filter-add`,children:[(0,G.jsx)(D,{className:`h-3 w-3 mr-1`}),r(`report.editor.addCondition`,`Add condition`)]})]})}var At=new Set([`date`,`datetime`,`time`]),jt=new Set([`number`,`currency`,`percent`,`rating`,`integer`]);function Mt({availableFields:e,selectedValues:t,onAdd:n,t:r,triggerLabel:i,title:a,description:o,testIdPrefix:s=`field-picker`,singleSelect:c=!1,commitOnSelect:l=!1,disabled:u=!1,triggerClassName:d,trigger:p}){let[m,v]=W.useState(!1),[y,x]=W.useState(``),[S,C]=W.useState(new Set),w=W.useMemo(()=>new Set(t),[t]);W.useEffect(()=>{m&&(x(``),C(new Set))},[m]);let E=y.trim().toLowerCase(),O=e.filter(e=>!w.has(e.value)),k=E?O.filter(e=>e.label.toLowerCase().includes(E)||e.value.toLowerCase().includes(E)):O,j=e=>{if(c&&l){n([e]),v(!1);return}C(t=>{let n=new Set(c?[]:t);return t.has(e)?n.delete(e):n.add(e),n})},M=()=>{if(S.size===0){v(!1);return}n(O.map(e=>e.value).filter(e=>S.has(e))),v(!1)},N=()=>{v(!1)},P=e.length===0,F=!P&&O.length===0,I=i??r(`report.editor.addColumns`,`Add fields`),L=a??r(`report.editor.fieldPickerTitle`,`Select fields`),R=o??r(`report.editor.fieldPickerDescription`,`Pick one or more fields to add. Use the search box to narrow the list.`);return(0,G.jsxs)(h,{open:m,onOpenChange:v,children:[(0,G.jsx)(A,{asChild:!0,children:p??(0,G.jsxs)(V,{type:`button`,variant:`outline`,size:`sm`,className:d??`h-8 gap-1.5`,disabled:u||P||F,"data-testid":`${s}-trigger`,children:[(0,G.jsx)(D,{className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{children:I})]})}),(0,G.jsxs)(_,{className:`sm:max-w-md max-w-[92vw] gap-3`,"data-testid":`${s}-dialog`,children:[(0,G.jsxs)(de,{children:[(0,G.jsx)(f,{children:L}),(0,G.jsx)(b,{children:R})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(ce,{className:`pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,G.jsx)(`input`,{type:`text`,className:`h-9 w-full text-sm border rounded pl-7 pr-2 bg-background`,placeholder:r(`report.editor.searchFields`,`Search fields…`),value:y,onChange:e=>x(e.target.value),"data-testid":`${s}-search`,autoFocus:!0})]}),(0,G.jsxs)(`div`,{className:`text-[11px] text-muted-foreground flex items-center justify-between`,children:[(0,G.jsxs)(`span`,{children:[k.length,`/`,O.length,S.size>0?` · ${r(`report.editor.fieldPickerSelected`,`{n} selected`).replace(`{n}`,String(S.size))}`:``]}),S.size>0&&(0,G.jsx)(`button`,{type:`button`,className:`text-[11px] underline-offset-2 hover:underline text-muted-foreground`,onClick:()=>C(new Set),"data-testid":`${s}-clear`,children:r(`report.editor.fieldPickerClear`,`Clear selection`)})]}),(0,G.jsx)(`div`,{className:`max-h-72 overflow-auto border rounded bg-background/40 p-1 space-y-0.5`,"data-testid":`${s}-list`,children:P?(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noFields`,`No fields available — pick a data source first.`)}):F?(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noFieldsAvailable`,`All fields already added.`)}):k.length===0?(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noMatchingFields`,`No fields match your search.`)}):k.map(e=>{let t=S.has(e.value);return(0,G.jsxs)(`label`,{className:`flex items-center gap-2 px-2 py-1.5 rounded hover:bg-muted/50 text-sm cursor-pointer`,"data-testid":`${s}-row-${e.value}`,children:[(0,G.jsx)(g,{checked:t,onCheckedChange:()=>j(e.value),"data-testid":`${s}-toggle-${e.value}`}),(0,G.jsx)(`span`,{className:`flex-1 truncate`,title:e.label,children:e.label}),e.type&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:e.type})]},e.value)})}),!(c&&l)&&(0,G.jsxs)(T,{className:`gap-2 sm:gap-2`,children:[(0,G.jsx)(V,{type:`button`,variant:`ghost`,size:`sm`,onClick:N,"data-testid":`${s}-cancel`,children:r(`common.cancel`,`Cancel`)}),(0,G.jsx)(V,{type:`button`,size:`sm`,onClick:M,disabled:S.size===0,"data-testid":`${s}-confirm`,children:S.size>0?r(`report.editor.fieldPickerAddN`,`Add {n}`).replace(`{n}`,String(S.size)):r(`report.editor.fieldPickerAdd`,`Add`)})]})]})]})}function Nt(e){return[{value:``,label:e(`report.editor.noneOption`)},{value:`sum`,label:e(`report.aggregate.sum`)},{value:`count`,label:e(`report.aggregate.count`)},{value:`unique`,label:e(`report.aggregate.countDistinct`)},{value:`avg`,label:e(`report.aggregate.avg`)},{value:`min`,label:e(`report.aggregate.min`)},{value:`max`,label:e(`report.aggregate.max`)}]}function Pt(e){return[{value:``,label:e(`report.editor.formatAuto`,`Auto`)},{value:`currency`,label:e(`report.editor.formatCurrency`,`Currency`)},{value:`percent`,label:e(`report.editor.formatPercent`,`Percent`)},{value:`integer`,label:e(`report.editor.formatInteger`,`Integer`)},{value:`date`,label:e(`report.editor.formatDate`,`Date`)},{value:`datetime`,label:e(`report.editor.formatDatetime`,`Date & time`)}]}function Ft(e){return Array.isArray(e)?e.map(e=>typeof e==`string`?{field:e,label:e,type:`string`}:{field:e.field||e.name||e.value,label:e.label,type:e.type||`string`,aggregate:e.aggregate??e.aggregation,format:e.format}):[]}function It({availableFields:e,value:t,onChange:n,t:r}){let i=Ft(t),a=new Set(i.map(e=>e.field)),o=Nt(r),s=Pt(r),c=t=>{if(t.length===0)return;let r=t.filter(e=>!a.has(e)).map(t=>{let n=e.find(e=>e.value===t);return{field:t,label:n?.label,type:n?.type||`string`}});r.length!==0&&n([...i,...r])},l=e=>{n(i.filter(t=>t.field!==e))},u=(e,t)=>{n(i.map(n=>n.field===e?{...n,...t}:n))},d=(e,t)=>{let r=[...i],a=e+t;a<0||a>=r.length||([r[e],r[a]]=[r[a],r[e]],n(r))};return e.length===0?(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground py-2`,"data-testid":`columns-editor-empty`,children:r(`report.editor.noFields`,`No fields available — pick a data source first.`)}):(0,G.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`columns-editor`,children:[i.length>0&&(0,G.jsx)(`div`,{className:`space-y-1.5`,"data-testid":`columns-selected`,children:i.map((t,n)=>{let a=e.find(e=>e.value===t.field);return(0,G.jsxs)(`div`,{className:`grid grid-cols-[auto_1fr_auto] gap-1.5 p-1.5 border rounded bg-muted/30 text-xs`,"data-testid":`column-row-${t.field}`,children:[(0,G.jsxs)(`div`,{className:`row-span-2 flex flex-col items-center justify-center gap-0.5`,children:[(0,G.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===0,onClick:()=>d(n,-1),"aria-label":`Move up`,"data-testid":`column-up-${t.field}`,children:(0,G.jsx)(O,{className:`h-3 w-3`})}),(0,G.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===i.length-1,onClick:()=>d(n,1),"aria-label":`Move down`,"data-testid":`column-down-${t.field}`,children:(0,G.jsx)(P,{className:`h-3 w-3`})})]}),(0,G.jsx)(`input`,{className:`h-7 text-xs border rounded px-2 bg-background min-w-0 w-full`,value:t.label??``,placeholder:a?.label??t.field,onChange:e=>u(t.field,{label:e.target.value||void 0}),"data-testid":`column-label-${t.field}`,title:a?.label??t.field}),(0,G.jsx)(V,{type:`button`,size:`sm`,variant:`ghost`,className:`row-span-2 h-7 w-7 p-0 shrink-0 self-start`,onClick:()=>l(t.field),"data-testid":`column-remove-${t.field}`,"aria-label":`Remove column`,children:(0,G.jsx)(C,{className:`h-3.5 w-3.5`})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,G.jsxs)(`label`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wide`,children:r(`report.editor.aggregateColumn`,`Aggregate`)}),(0,G.jsx)(`select`,{className:`h-7 text-xs border rounded px-1 bg-background w-full min-w-0`,value:t.aggregate??``,onChange:e=>u(t.field,{aggregate:e.target.value===``?void 0:e.target.value}),"data-testid":`column-agg-${t.field}`,children:o.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,G.jsxs)(`label`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wide`,children:r(`report.editor.formatColumn`,`Format`)}),(0,G.jsx)(`select`,{className:`h-7 text-xs border rounded px-1 bg-background w-full min-w-0`,value:t.format??``,onChange:e=>u(t.field,{format:e.target.value===``?void 0:e.target.value}),"data-testid":`column-fmt-${t.field}`,children:s.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]})]},t.field)})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i.length>0?r(`report.editor.columnsCount`,`{n} column(s) selected`).replace(`{n}`,String(i.length)):r(`report.editor.columnsEmpty`,`No columns selected yet.`)}),(0,G.jsx)(Mt,{availableFields:e,selectedValues:i.map(e=>e.field),onAdd:c,t:r,testIdPrefix:`columns-picker`,triggerLabel:r(`report.editor.addColumns`,`Add fields`)})]})]})}function Lt({availableFields:e,value:t,onChange:n,t:r,testIdPrefix:i=`grouping`}){let a=Array.isArray(t)?t.map(e=>({field:e.field??``,sortOrder:e.sortOrder??e.sort??`asc`,dateGranularity:e.dateGranularity})):[],o=[{value:``,label:r(`report.editor.dateGranularityNone`)},{value:`day`,label:r(`report.editor.day`)},{value:`week`,label:r(`report.editor.week`)},{value:`month`,label:r(`report.editor.month`)},{value:`quarter`,label:r(`report.editor.quarter`)},{value:`year`,label:r(`report.editor.year`)}],s=a.map(e=>e.field).filter(Boolean),c=e=>{n(a.filter((t,n)=>n!==e))},l=(e,t)=>{n(a.map((n,r)=>r===e?{...n,...t}:n))},u=(e,t)=>{let r=[...a],i=e+t;i<0||i>=r.length||([r[e],r[i]]=[r[i],r[e]],n(r))},d=e=>{if(e.length===0)return;let t=e.map(e=>({field:e,sortOrder:`asc`}));n([...a,...t])},f=(t,n)=>{let r=n[0];if(!r)return;let i=e.find(e=>e.value===r);l(t,{field:r,dateGranularity:i&&At.has(i.type??``)?a[t]?.dateGranularity:void 0})};return(0,G.jsxs)(`div`,{className:`space-y-1.5 py-1`,"data-testid":`${i}s-builder`,children:[a.map((t,n)=>{let d=e.find(e=>e.value===t.field),p=d&&At.has(d.type??``),m=d?.label??t.field??r(`report.editor.fieldPickerEmpty`,`(pick field)`);return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 p-1.5 border rounded bg-muted/20 text-xs`,"data-testid":`${i}-row-${n}`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-0.5 shrink-0`,children:[(0,G.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===0,onClick:()=>u(n,-1),"aria-label":`Move up`,"data-testid":`${i}-up-${n}`,children:(0,G.jsx)(O,{className:`h-3 w-3`})}),(0,G.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===a.length-1,onClick:()=>u(n,1),"aria-label":`Move down`,"data-testid":`${i}-down-${n}`,children:(0,G.jsx)(P,{className:`h-3 w-3`})})]}),(0,G.jsx)(Mt,{availableFields:e,selectedValues:s.filter(e=>e!==t.field),onAdd:e=>f(n,e),t:r,singleSelect:!0,commitOnSelect:!0,testIdPrefix:`${i}-field-picker-${n}`,title:r(`report.editor.fieldPickerChangeTitle`,`Change field`),trigger:(0,G.jsxs)(`button`,{type:`button`,className:`h-7 flex-1 min-w-0 text-left text-xs border rounded px-2 bg-background hover:bg-muted/40 inline-flex items-center justify-between gap-1.5`,"data-testid":`${i}-field-${n}`,title:m,children:[(0,G.jsx)(`span`,{className:`truncate`,children:m}),(0,G.jsx)(E,{className:`h-3 w-3 text-muted-foreground shrink-0`})]})}),(0,G.jsxs)(`select`,{className:`h-7 text-xs border rounded px-1.5 bg-background w-20 shrink-0`,value:t.sortOrder??`asc`,onChange:e=>l(n,{sortOrder:e.target.value}),"data-testid":`${i}-sort-${n}`,children:[(0,G.jsx)(`option`,{value:`asc`,children:r(`report.editor.sortAsc`)}),(0,G.jsx)(`option`,{value:`desc`,children:r(`report.editor.sortDesc`)})]}),p&&(0,G.jsx)(`select`,{className:`h-7 text-xs border rounded px-1.5 bg-background w-24 shrink-0`,value:t.dateGranularity??``,onChange:e=>l(n,{dateGranularity:e.target.value||void 0}),"data-testid":`${i}-granularity-${n}`,children:o.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,G.jsx)(V,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 shrink-0`,onClick:()=>c(n),"aria-label":`Remove grouping`,"data-testid":`${i}-remove-${n}`,children:(0,G.jsx)(C,{className:`h-3.5 w-3.5`})})]},n)}),(0,G.jsx)(Mt,{availableFields:e,selectedValues:s,onAdd:d,t:r,singleSelect:!0,commitOnSelect:!0,testIdPrefix:`${i}-add-picker`,triggerLabel:r(`report.editor.addGrouping`),title:r(`report.editor.fieldPickerAddGroupingTitle`,`Add grouping`),triggerClassName:`h-8 w-full justify-center gap-1.5`})]})}function Rt({availableFields:e,columns:t,value:n,onChange:r,t:i}){let a=n||{},o=a.type??a.chartType??``,s=a.xAxis??a.xAxisField??``,c=a.yAxis??a.yAxisFields?.[0]??``,l=e=>{let t={...a,...e};if(`type`in e&&delete t.chartType,`xAxis`in e&&delete t.xAxisField,`yAxis`in e&&delete t.yAxisFields,!e.type&&e.type===``)return r(void 0);r(t)},u=()=>r(void 0),d=[{value:``,label:i(`report.editor.chartNone`)},{value:`bar`,label:i(`report.editor.chartBar`)},{value:`line`,label:i(`report.editor.chartLine`)},{value:`area`,label:i(`report.editor.chartArea`)},{value:`pie`,label:i(`report.editor.chartPie`)},{value:`donut`,label:i(`report.editor.chartDonut`)},{value:`funnel`,label:i(`report.editor.chartFunnel`)}],f=t.filter(e=>e.aggregate).map(e=>e.field),p=e.filter(e=>jt.has(e.type??``)).map(e=>e.value),m=new Set([...f,...p]),h=e.filter(e=>m.has(e.value));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:i(`report.editor.chartType`)}),(0,G.jsx)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:o,onChange:e=>{let t=e.target.value;t?l({type:t}):u()},"data-testid":`chart-type-select`,children:d.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),o&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartTitle`)}),(0,G.jsx)(`input`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:a.title??``,placeholder:i(`report.editor.chartTitlePlaceholder`),onChange:e=>l({title:e.target.value||void 0}),"data-testid":`chart-title`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartXAxis`)}),(0,G.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:s,onChange:e=>l({xAxis:e.target.value||void 0}),"data-testid":`chart-x-field`,children:[(0,G.jsx)(`option`,{value:``,children:`—`}),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:i(`report.editor.chartYAxis`)}),(0,G.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:c,onChange:e=>l({yAxis:e.target.value||void 0}),"data-testid":`chart-y-field`,children:[(0,G.jsx)(`option`,{value:``,children:`—`}),(h.length>0?h:e).map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,G.jsx)(g,{checked:a.showLegend!==!1,onCheckedChange:e=>l({showLegend:e===!0}),"data-testid":`chart-show-legend`}),(0,G.jsx)(`span`,{children:i(`report.editor.chartShowLegend`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,G.jsx)(g,{checked:!!a.showDataLabels,onCheckedChange:e=>l({showDataLabels:e===!0}),"data-testid":`chart-show-data-labels`}),(0,G.jsx)(`span`,{children:i(`report.editor.chartShowDataLabels`)})]})]})]})}function zt(e,t,n){let r=e=>e.type===`summary`,i=e=>e.type===`matrix`,a=e=>e.type===`summary`||e.type===`matrix`,o=[{key:`basic`,title:t(`report.editor.basic`),fields:[{key:`label`,label:t(`report.editor.title`),type:`input`,placeholder:t(`report.editor.titlePlaceholder`)},{key:`description`,label:t(`report.editor.description`),type:`textarea`,placeholder:t(`report.editor.descriptionPlaceholder`)},{key:`type`,label:t(`report.editor.type`),type:`select`,defaultValue:`tabular`,options:[{value:`tabular`,label:t(`report.editor.typeTabular`)},{value:`summary`,label:t(`report.editor.typeSummary`)},{value:`matrix`,label:t(`report.editor.typeMatrix`)},{value:`joined`,label:t(`report.editor.typeJoined`)}],helpText:t(`report.editor.typeHelp`)}]},{key:`data`,title:t(`report.editor.data`),collapsible:!0,fields:[{key:`objectName`,label:t(`report.editor.objectName`),type:`input`,placeholder:t(`report.editor.objectNamePlaceholder`),helpText:t(`report.editor.objectNameHelp`)},{key:`limit`,label:t(`report.editor.limit`),type:`input`,placeholder:t(`report.editor.limitPlaceholder`)}]},{key:`rows`,title:t(`report.editor.rows`),collapsible:!0,hint:t(`report.editor.rowsHint`),visibleWhen:e=>r(e)||i(e),fields:[{key:`groupingsDown`,label:t(`report.editor.grouping`),type:`custom`,render:(n,r)=>(0,G.jsx)(Lt,{availableFields:e,value:n,onChange:r,t,testIdPrefix:`rows-grouping`})}]},{key:`columnsAxis`,title:t(`report.editor.columnsAxis`),collapsible:!0,hint:t(`report.editor.columnsAxisHint`),visibleWhen:e=>i(e),fields:[{key:`groupingsAcross`,label:t(`report.editor.grouping`),type:`custom`,render:(n,r)=>(0,G.jsx)(Lt,{availableFields:e,value:n,onChange:r,t,testIdPrefix:`cols-grouping`})}]},{key:`tabular-columns`,title:t(`report.editor.columns`),collapsible:!0,hint:t(`report.editor.columnsHint`),visibleWhen:e=>e.type!==`joined`&&!r(e)&&!i(e),fields:[{key:`columns`,label:t(`report.editor.columns`),type:`custom`,render:(n,r)=>(0,G.jsx)(It,{availableFields:e,value:n,onChange:r,t})}]},{key:`values`,title:t(`report.editor.values`),collapsible:!0,hint:t(`report.editor.valuesHint`),visibleWhen:e=>r(e)||i(e),fields:[{key:`columns`,label:t(`report.editor.values`),type:`custom`,render:(n,r)=>(0,G.jsx)(It,{availableFields:e,value:n,onChange:r,t})}]},{key:`filters`,title:t(`report.editor.filters`),collapsible:!0,hint:t(`report.editor.filtersHint`),visibleWhen:e=>e.type!==`joined`,fields:[{key:`filter`,label:t(`report.editor.filters`),type:`custom`,render:(n,r)=>(0,G.jsx)(kt,{availableFields:e,value:n,onChange:r,t})}]},{key:`blocks`,title:t(`report.editor.blocks`),collapsible:!0,hint:t(`report.editor.blocksHint`),visibleWhen:e=>e.type===`joined`,fields:[{key:`blocks`,label:t(`report.editor.blocks`),type:`custom`,render:(r,i,a)=>(0,G.jsx)(yt,{value:r,onChange:i,availableFields:e,getFieldsForObject:n,containerObjectName:a?.objectName,t})}]},{key:`chart`,title:t(`report.editor.chart`),collapsible:!0,defaultCollapsed:!0,hint:t(`report.editor.chartHint`),visibleWhen:e=>a(e),fields:[{key:`chart`,label:t(`report.editor.chart`),type:`custom`,render:(n,r,i)=>(0,G.jsx)(Rt,{availableFields:e,columns:Ft(i.columns),value:n,onChange:r,t})}]}];return{breadcrumb:[t(`report.editor.breadcrumb`,`Configuration`)],sections:o}}function Bt(e,t){let n=[],r=e.type??`tabular`,i=Array.isArray(e.groupingsDown)?e.groupingsDown.length:0,a=Array.isArray(e.groupingsAcross)?e.groupingsAcross.length:0,o=Array.isArray(e.columns)?e.columns.length:0;if(e.objectName||n.push({level:o>0?`error`:`warning`,message:t(`report.editor.validationNeedsObject`)}),r===`matrix`&&(i===0||a===0)&&n.push({level:`error`,message:t(`report.editor.validationMatrixNeedsRowsCols`)}),r===`summary`&&i===0&&n.push({level:`error`,message:t(`report.editor.validationSummaryNeedsRows`)}),r===`joined`)for(let r of bt(e.blocks,t))n.push({level:`error`,message:r});return n}function Vt({problems:e}){return e.length===0?null:(0,G.jsx)(`div`,{className:`space-y-1 p-2 border-b`,"data-testid":`report-validation-banner`,children:e.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] rounded px-2 py-1 `+(e.level===`error`?`bg-red-50 border border-red-200 text-red-900`:`bg-amber-50 border border-amber-200 text-amber-900`),children:[(0,G.jsx)(x,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:e.message})]},t))})}function Ht({open:e,onClose:t,config:n,onSave:r,onFieldChange:i,availableFields:a,getFieldsForObject:o}){let{t:s}=l(),c=W.useCallback((e,t,n)=>t===void 0?s(e,n):s(e,{defaultValue:t,...n||{}}),[s]),u=a??[],d=W.useMemo(()=>zt(u,c,o),[u,c,o]),{draft:f,isDirty:p,updateField:m,discard:h}=le(W.useMemo(()=>n??{},[n])),g=W.useCallback((e,t)=>{m(e,t),i?.(e,t,{...f,[e]:t})},[m,i,f]),_=W.useCallback(()=>{r(f),t()},[f,r,t]),v=W.useMemo(()=>Bt(f,c),[f,c]);return e?(0,G.jsx)(k,{open:e,onClose:t,schema:d,draft:f,isDirty:p,onFieldChange:g,onSave:_,onDiscard:h,headerExtra:(0,G.jsx)(Vt,{problems:v}),style:{"--config-panel-width":`440px`}}):null}async function Ut(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 tt(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 Wt(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(Kt),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 qt(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=Yt(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)}Zt(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
|
|
59
|
+
`),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function Gt(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 Ut(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function Kt(e){return{name:e.name,header:e.label||e.name}}function qt(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,Jt(t)):Xt(String(e))}function Jt(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 Yt(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function Xt(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function Zt(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)}var Qt=t({JoinedBlocksEditor:()=>yt,JoinedReportRenderer:()=>qe,LegacyReportRenderer:()=>pe,MatrixRenderer:()=>Ue,ReportBuilder:()=>ft,ReportConfigPanel:()=>Ht,ReportRenderer:()=>Ye,ReportViewer:()=>ut,ScheduleConfig:()=>dt,SpecReportGrid:()=>Re,aggregateRows:()=>J,bucketDate:()=>me,buildAggregateQuery:()=>Ce,buildDrillAction:()=>Ae,collectFields:()=>Se,columnKey:()=>K,createDrillHandler:()=>Me,createScheduleTrigger:()=>Gt,exportAsCSV:()=>Xe,exportAsExcel:()=>et,exportAsHTML:()=>Qe,exportAsJSON:()=>Ze,exportAsPDF:()=>$e,exportExcelWithFormulas:()=>Wt,exportReport:()=>tt,exportWithLiveData:()=>Ut,formatValue:()=>ot,groupAndAggregate:()=>he,groupingValue:()=>q,isDrillAction:()=>je,mergeFilters:()=>X,pivotRows:()=>ge,registerDrillHandler:()=>Ne,useReportData:()=>Te,validateJoinedBlocks:()=>bt});s.register(`report`,Ye,{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`}]}),s.register(`spec-report`,Ye,{namespace:`report`,label:`Spec Report`,category:`Report`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`},{name:`type`,type:`string`,label:`Report Type`}]}),s.register(`report-viewer`,ut,{namespace:`report`,label:`Report Viewer`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Report Definition`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`}]}),s.register(`report-builder`,ft,{namespace:`report`,label:`Report Builder`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Initial Report`}]});export{Qt as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{g as n,r}from"./vendor-react-CIpZOxG3.js";import{_ as i,m as a,r as o}from"./vendor-objectstack-CwZ3saTl.js";import{H as s,M as c,V as l,at as u,ot as d,r as f,ut as p}from"./framework-ClI3DbWX.js";import{$o as m,N as h,Qo as g,Zo as _}from"./ui-components-ZN8XdmwJ.js";import{n as v}from"./vendor-ui-utils-D3GsyZyi.js";import{a as y}from"./plugin-grid-DtceFt_J.js";var b=e(n(),1),x=r(),S=10080*60*1e3;function C(e){let t=e.flatMap(e=>(e.items||[]).flatMap(e=>[e.startDate,e.endDate])),n=Math.min(...t.map(e=>new Date(e).getTime())),r=Math.max(...t.map(e=>new Date(e).getTime()));return{minDate:new Date(n).toISOString().split(`T`)[0],maxDate:new Date(r).toISOString().split(`T`)[0]}}function w(e,t,n,r){let i=new Date(e).getTime(),a=new Date(t).getTime(),o=new Date(n).getTime(),s=new Date(r).getTime()-o,c=i-o,l=a-i;return{start:c/s*100,width:l/s*100}}function T(e,t){let n=new Date(e);return t===`short`?n.toLocaleDateString():t===`long`?n.toLocaleDateString(`en-US`,{year:`numeric`,month:`long`,day:`numeric`}):n.toISOString().split(`T`)[0]}function E({label:e,color:t}){let n=t?{backgroundColor:`${t}22`,color:t,borderColor:`${t}55`}:void 0;return(0,x.jsx)(`span`,{className:_(`inline-flex items-center rounded-full border px-2 py-0.5 text-xs font-medium`,!t&&`bg-muted text-muted-foreground border-transparent`),style:n,children:e})}function D(e){let t=[];for(let n of e){let e=n.group==null?``:String(n.group),r=t[t.length-1];r&&r.key===e?r.items.push(n):t.push({key:e,items:[n]})}return t}var O=({schema:e,className:t,...n})=>{let{variant:r=`vertical`,items:i=[],dateFormat:a=`short`,onItemClick:o}=e;if(r===`vertical`){let e=D(i),r=e.some(e=>e.key!==``),s=(e,t)=>{let n=e.color?{backgroundColor:`${e.color}33`,borderColor:e.color}:void 0,r=e.time?T(e.time,a):e.startDate?T(e.startDate,a):``,i=e.endDate&&e.endDate!==e.startDate?T(e.endDate,a):``,s=Array.isArray(e.meta)?e.meta:[];return(0,x.jsxs)(I,{density:`compact`,className:_(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,x.jsx)(R,{variant:e.color?`default`:e.variant||`default`,style:n,children:e.icon&&(0,x.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,x.jsxs)(z,{children:[(r||i)&&(0,x.jsxs)(V,{dateTime:e.time||e.startDate,className:`!mb-1 text-xs`,children:[r,i&&(0,x.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[` → `,i]})]}),e.title&&(0,x.jsx)(B,{className:`text-sm sm:text-base mb-1`,children:e.title}),s.length>0&&(0,x.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1 mb-1`,children:s.map(e=>(0,x.jsx)(E,{label:e.label,color:e.color},e.key))}),e.description&&(0,x.jsx)(H,{className:`text-sm text-muted-foreground line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&g(e.content)]})]},t)};return r?(0,x.jsx)(`div`,{className:_(`px-4 sm:px-6 py-2`,t),...n,children:e.map((e,t)=>(0,x.jsxs)(`section`,{className:`mb-4`,children:[(0,x.jsxs)(`header`,{className:`sticky top-0 z-10 -mx-4 sm:-mx-6 px-4 sm:px-6 py-1.5 backdrop-blur bg-background/90 text-xs font-semibold uppercase tracking-wide text-muted-foreground border-b`,children:[(0,x.jsx)(`span`,{children:e.key}),(0,x.jsx)(`span`,{className:`ml-2 text-muted-foreground/60 font-normal normal-case`,children:e.items.length})]}),(0,x.jsx)(P,{className:`mt-3`,children:e.items.map((e,n)=>s(e,`${t}-${n}`))})]},`${e.key}-${t}`))}):(0,x.jsx)(P,{className:t,...n,children:i.map((e,t)=>s(e,t))})}if(r===`horizontal`)return(0,x.jsx)(U,{className:_(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:i.map((e,t)=>(0,x.jsxs)(W,{className:_(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,x.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,x.jsx)(R,{variant:e.variant||`default`,children:e.icon&&(0,x.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,x.jsxs)(`div`,{className:`mt-4 text-center`,children:[e.time&&(0,x.jsx)(V,{dateTime:e.time,children:T(e.time,a)}),e.title&&(0,x.jsx)(B,{children:e.title}),e.description&&(0,x.jsx)(H,{className:`text-center line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&g(e.content)]})]}),t<i.length-1&&(0,x.jsx)(`div`,{className:`absolute left-full w-16 border-t-2 border-gray-200 top-3`})]},t))});if(r===`gantt`){let r=C(i),s=e.minDate||r.minDate,c=e.maxDate||r.maxDate,l=e.timeScale||`month`,u=(()=>{let e=[],t=new Date(s),n=new Date(c);if(l===`month`){let r=new Date(t);for(;r<=n;)e.push(r.toLocaleDateString(`en-US`,{month:`short`,year:`numeric`})),r.setMonth(r.getMonth()+1)}else if(l===`week`){let r=new Date(t);for(;r<=n;)e.push(`Week ${Math.ceil((r.getTime()-t.getTime())/S)+1}`),r.setDate(r.getDate()+7)}else if(l===`day`){let r=new Date(t);for(;r<=n;)e.push(r.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})),r.setDate(r.getDate()+1)}return e})();return(0,x.jsxs)(G,{className:_(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:[(0,x.jsxs)(K,{children:[(0,x.jsx)(q,{className:`flex items-center px-2 sm:px-4 py-2 sm:py-3`,children:(0,x.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:e.rowLabel||`Items`})}),(0,x.jsx)(J,{children:(0,x.jsx)(`div`,{className:`flex h-full`,children:u.map((e,t)=>(0,x.jsx)(`div`,{className:`flex-1 px-1 sm:px-2 py-2 sm:py-3 border-r text-xs font-medium text-center`,children:e},t))})})]}),(0,x.jsx)(`div`,{children:(0,x.jsxs)(`div`,{className:`flex`,children:[(0,x.jsx)(q,{children:i.map((e,t)=>(0,x.jsx)(Y,{children:(0,x.jsx)(X,{title:e.label,className:`truncate`,children:e.label})},t))}),(0,x.jsx)(J,{className:`relative`,children:i.map((e,t)=>(0,x.jsx)(Y,{className:`relative`,children:(e.items||[]).map((n,r)=>{let i=w(n.startDate,n.endDate,s,c);return(0,x.jsx)(Z,{start:i.start,width:i.width,variant:n.variant||`default`,onClick:()=>o?.(n,e,t,r),title:`${n.title||``}\n${T(n.startDate,a)} - ${T(n.endDate,a)}`,children:(0,x.jsx)(Q,{children:n.title})},r)})},t))})]})})]})}return null};p.register(`timeline`,O,{namespace:`plugin-timeline`,label:`Timeline`,category:`data-display`,inputs:[{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],label:`Timeline Variant`,defaultValue:`vertical`},{name:`items`,type:`array`,label:`Timeline Items`,description:`For vertical/horizontal: Array of { time, title, description, variant, icon, content }. For gantt: Array of { label, items: [{ title, startDate, endDate, variant }] }`},{name:`dateFormat`,type:`enum`,enum:[`short`,`long`,`iso`],label:`Date Format`,defaultValue:`short`},{name:`timeScale`,type:`enum`,enum:[`day`,`week`,`month`],label:`Time Scale (Gantt only)`,defaultValue:`month`},{name:`rowLabel`,type:`string`,label:`Row Label (Gantt only)`,defaultValue:`Items`},{name:`minDate`,type:`string`,label:`Min Date (Gantt only)`,description:`Override auto-calculated min date (YYYY-MM-DD)`},{name:`maxDate`,type:`string`,label:`Max Date (Gantt only)`,description:`Override auto-calculated max date (YYYY-MM-DD)`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{variant:`vertical`,dateFormat:`short`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`,icon:`🚀`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`,icon:`🎨`},{time:`2024-03-15`,title:`Beta Release`,description:`Released beta version to testers`,variant:`warning`,icon:`⚡`},{time:`2024-04-01`,title:`Launch`,description:`Official product launch`,variant:`success`,icon:`🎉`}]},examples:{vertical:{variant:`vertical`,dateFormat:`long`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`}]},horizontal:{variant:`horizontal`,dateFormat:`short`,items:[{time:`2024-01-01`,title:`Q1`,description:`First quarter`,variant:`default`},{time:`2024-04-01`,title:`Q2`,description:`Second quarter`,variant:`info`},{time:`2024-07-01`,title:`Q3`,description:`Third quarter`,variant:`warning`},{time:`2024-10-01`,title:`Q4`,description:`Fourth quarter`,variant:`success`}]},gantt:{variant:`gantt`,dateFormat:`short`,timeScale:`month`,rowLabel:`Projects`,items:[{label:`Backend Development`,items:[{title:`API Design`,startDate:`2024-01-01`,endDate:`2024-01-31`,variant:`success`},{title:`Implementation`,startDate:`2024-02-01`,endDate:`2024-03-31`,variant:`info`}]},{label:`Frontend Development`,items:[{title:`UI Design`,startDate:`2024-01-15`,endDate:`2024-02-15`,variant:`warning`},{title:`Component Dev`,startDate:`2024-02-15`,endDate:`2024-04-15`,variant:`default`}]},{label:`Testing`,items:[{title:`QA Phase`,startDate:`2024-03-01`,endDate:`2024-04-30`,variant:`danger`}]}]}}});var k={"timeline.bucket.overdue":`Overdue`,"timeline.bucket.today":`Today`,"timeline.bucket.tomorrow":`Tomorrow`,"timeline.bucket.thisWeek":`This week`,"timeline.bucket.nextWeek":`Next week`,"timeline.bucket.later":`Later`,"timeline.bucket.noDate":`No date`,"timeline.bucket.unassigned":`Unassigned`,"timeline.relative.today":`Today`,"timeline.relative.tomorrow":`Tomorrow`,"timeline.relative.yesterday":`Yesterday`,"timeline.relative.inDays":`In {{n}} days`,"timeline.relative.daysAgo":`{{n}} days ago`},A=`timeline.bucket.today`;function j(e,t){let n=k[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}function ee(){try{let e=f();return e.t(A)===A?{t:j}:{t:e.t}}catch{return{t:j}}}function te(){try{return m()}catch{return{fieldOptionLabel:(e,t,n,r)=>r,translateOptions:(e,t,n)=>n,fieldLabel:(e,t,n)=>n}}}var ne=a({mapping:a({title:i().optional(),date:i().optional(),description:i().optional(),variant:i().optional()}).optional(),objectName:i().optional(),titleField:i().optional(),dateField:i().optional(),startDateField:i().optional(),endDateField:i().optional(),descriptionField:i().optional(),groupByField:i().optional(),colorField:i().optional(),scale:o([`hour`,`day`,`week`,`month`,`quarter`,`year`]).optional()}),M=({schema:e,dataSource:t,className:n,onRowClick:r,onItemClick:i,...a})=>{let[o,s]=(0,b.useState)([]),[f,p]=(0,b.useState)(()=>{let t=Array.isArray(e.items)&&e.items.length>0,n=Array.isArray(a.data)&&a.data.length>0;return!t&&!n&&!!e.objectName}),[m,g]=(0,b.useState)(null),[_,v]=(0,b.useState)(0),[S,C]=(0,b.useState)(null),w=e.timeline;(0,b.useEffect)(()=>{let t=ne.safeParse(e);t.success||console.warn(`[ObjectTimeline] Invalid timeline configuration:`,t.error.format())},[e]);let T=l(e.bind);(0,b.useEffect)(()=>{let n=!0;return(async()=>{if(!(!t||typeof t.getObjectSchema!=`function`||!e.objectName))try{let r=await t.getObjectSchema(e.objectName);n&&C(r)}catch(e){console.warn(`Failed to fetch object def for ObjectTimeline`,e)}})(),()=>{n=!1}},[e.objectName,t]),(0,b.useEffect)(()=>{e.objectName&&!T&&!e.items&&!a.data?(async()=>{if(!t||typeof t.find!=`function`||!e.objectName){p(!1);return}p(!0);try{let n=u(S?.fields);s(d(await t.find(e.objectName,{options:{$top:100},...n.length>0?{$expand:n}:{}})))}catch(e){console.error(e),g(e)}finally{p(!1)}})():p(!1)},[e.objectName,t,T,e.items,a.data,_,S]);let E=a.data||T||o,{t:D}=ee(),{fieldOptionLabel:k}=te(),A=w?.titleField??e.mapping?.title??e.titleField??`name`,j=w?.startDateField??e.mapping?.date??e.startDateField??e.dateField??`date`,M=w?.endDateField??e.endDateField??j,N=e.mapping?.description??e.descriptionField??`description`,P=e.mapping?.variant??`variant`,F=w?.groupByField??e.groupByField,I=w?.colorField??e.colorField,L=(0,b.useMemo)(()=>{if(e.items)return e.items;if(!E||!Array.isArray(E))return[];let t=S?.fields??{},n=e.objectName||``,r=e=>{if(!e||!t[e]?.options)return{};let n={};for(let r of t[e].options)r&&r.value!=null&&(n[String(r.value)]=r);return n},i=r(I),a=Array.isArray(w?.metaFields)?w.metaFields.filter(e=>typeof e==`string`&&e):[`status`,`priority`].filter(e=>t[e]),o={};for(let e of a)o[e]=r(e);let s=e=>{if(e==null||e===``)return;let t=i[String(e)];if(t?.color)return String(t.color);let n=String(e);if(/^#([0-9a-f]{3}){1,2}$/i.test(n)||n.startsWith(`rgb`)||n.startsWith(`hsl`))return n},c=(e,t,r)=>{if(t==null||t===``)return null;let i=r[String(t)];return{label:i?.label?k(n,e,String(t),i.label):String(t),color:i?.color}},l=E.map(e=>{let t=e[j],r=e[M],i=I?e[I]:void 0,l=F?e[F]:void 0,u=[];if(n)for(let t of a){let n=c(t,e[t],o[t]||{});n&&u.push({key:t,label:n.label,color:n.color})}return{title:e[A],time:t,startDate:t,endDate:r,description:e[N],variant:e[P]||`default`,color:s(i),group:l,meta:u,_data:e}});l.sort((e,t)=>(e.startDate?new Date(e.startDate).getTime():1/0)-(t.startDate?new Date(t.startDate).getTime():1/0));let u=new Date,d=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime(),f=d(u),p=864e5,m=f-(u.getDay()+6)%7*p+7*p,h=m+7*p,g=e=>{if(!e)return D(`timeline.bucket.noDate`);let t=d(new Date(e));return Number.isNaN(t)?D(`timeline.bucket.noDate`):t<f?D(`timeline.bucket.overdue`):t===f?D(`timeline.bucket.today`):t===f+p?D(`timeline.bucket.tomorrow`):D(t<m?`timeline.bucket.thisWeek`:t<h?`timeline.bucket.nextWeek`:`timeline.bucket.later`)};if(F&&!l.every(e=>e.group==null||e.group===``)){let e=r(F);return l.map(t=>{let n=c(F,t.group,e);return{...t,group:n?n.label:t.group!=null&&t.group!==``?String(t.group):D(`timeline.bucket.unassigned`)}})}return l.map(e=>({...e,group:g(e.startDate)}))},[e.items,E,S,e.objectName,A,j,M,N,P,I,F,D,k]),{ref:R,isRefreshing:z,pullDistance:B}=y({onRefresh:(0,b.useCallback)(async()=>{v(e=>e+1)},[]),enabled:!!e.objectName&&!!t}),V=c({navigation:e.navigation,objectName:e.objectName,onRowClick:r??i}),H=w?.scale??e.scale,U={...e,items:L||[],className:n||e.className,...H?{timeScale:H}:{},onItemClick:e=>{let t=e._data||e;V.handleClick(t),i?.(t)}};return m?(0,x.jsxs)(`div`,{className:`p-4 text-destructive`,"data-testid":`timeline-error`,role:`alert`,children:[`Error loading timeline: `,m.message]}):f&&(!L||L.length===0)?(0,x.jsxs)(`div`,{className:`flex flex-col h-full min-h-[200px] p-4 gap-3`,"data-testid":`timeline-loading`,role:`status`,"aria-live":`polite`,"aria-busy":`true`,children:[(0,x.jsx)(`span`,{className:`sr-only`,children:`Loading timeline…`}),[0,1,2,3].map(e=>(0,x.jsxs)(`div`,{className:`flex items-start gap-3`,style:{opacity:Math.max(.3,1-e*.18)},children:[(0,x.jsx)(`div`,{className:`h-3 w-3 rounded-full bg-muted/70 animate-pulse mt-1.5 shrink-0`}),(0,x.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,x.jsx)(`div`,{className:`h-4 w-1/3 rounded bg-muted/70 animate-pulse`}),(0,x.jsx)(`div`,{className:`h-3 w-2/3 rounded bg-muted/50 animate-pulse`})]})]},e))]}):(0,x.jsxs)(`div`,{ref:R,className:`relative overflow-auto h-full min-w-0`,children:[B>0&&(0,x.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:B},children:z?`Refreshing…`:`Pull to refresh`}),(0,x.jsx)(O,{schema:U}),V.isOverlay&&(0,x.jsx)(h,{...V,title:`Timeline Item`,children:e=>(0,x.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,x.jsxs)(`div`,{className:`flex flex-col`,children:[(0,x.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,x.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})},N=t({ObjectTimeline:()=>M,ObjectTimelineRenderer:()=>$,Timeline:()=>P,TimelineContent:()=>z,TimelineDescription:()=>H,TimelineGantt:()=>G,TimelineGanttBar:()=>Z,TimelineGanttBarContent:()=>Q,TimelineGanttGrid:()=>J,TimelineGanttHeader:()=>K,TimelineGanttLabel:()=>X,TimelineGanttRow:()=>Y,TimelineGanttRowLabels:()=>q,TimelineHorizontal:()=>U,TimelineHorizontalItem:()=>W,TimelineItem:()=>I,TimelineMarker:()=>R,TimelineRenderer:()=>O,TimelineTime:()=>V,TimelineTitle:()=>B,timelineItemVariants:()=>F,timelineMarkerVariants:()=>L}),P=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`ol`,{ref:n,className:_(`relative ml-3 border-l border-gray-200`,e),...t}));P.displayName=`Timeline`;var F=v(`ml-6`,{variants:{density:{default:`mb-10`,compact:`mb-3`,comfortable:`mb-6`}},defaultVariants:{density:`default`}}),I=b.forwardRef(({className:e,density:t,...n},r)=>(0,x.jsx)(`li`,{ref:r,className:_(F({density:t}),e),...n}));I.displayName=`TimelineItem`;var L=v(`absolute -left-3 w-6 h-6 rounded-full border-2 flex items-center justify-center`,{variants:{variant:{default:`bg-blue-200 border-blue-400`,success:`bg-emerald-200 border-emerald-500`,warning:`bg-amber-200 border-amber-500`,danger:`bg-red-200 border-red-500`,info:`bg-purple-200 border-purple-500`,todo:`bg-slate-200 border-slate-400`,"in-progress":`bg-blue-200 border-blue-500`,done:`bg-emerald-200 border-emerald-500`}},defaultVariants:{variant:`default`}}),R=b.forwardRef(({className:e,variant:t=`default`,...n},r)=>(0,x.jsx)(`div`,{ref:r,className:_(L({variant:t}),e),...n}));R.displayName=`TimelineMarker`;var z=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:e,...t}));z.displayName=`TimelineContent`;var B=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`h3`,{ref:n,className:_(`font-semibold text-lg mb-1`,e),...t}));B.displayName=`TimelineTitle`;var V=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`time`,{ref:n,className:_(`text-sm font-normal text-gray-500 mb-2 block`,e),...t}));V.displayName=`TimelineTime`;var H=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`p`,{ref:n,className:_(`text-base text-gray-700`,e),...t}));H.displayName=`TimelineDescription`;var U=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:_(`relative flex overflow-x-auto py-8`,e),...t}));U.displayName=`TimelineHorizontal`;var W=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:_(`shrink-0 w-64 relative`,e),...t}));W.displayName=`TimelineHorizontalItem`;var G=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:_(`relative w-full border rounded-lg overflow-hidden`,e),...t}));G.displayName=`TimelineGantt`;var K=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:_(`flex border-b bg-gray-50`,e),...t}));K.displayName=`TimelineGanttHeader`;var q=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:_(`w-48 border-r bg-white`,e),...t}));q.displayName=`TimelineGanttRowLabels`;var J=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:_(`flex-1 overflow-x-auto`,e),...t}));J.displayName=`TimelineGanttGrid`;var Y=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:_(`flex items-center border-b min-h-12`,e),...t}));Y.displayName=`TimelineGanttRow`;var X=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:_(`px-4 py-2 font-medium text-sm truncate`,e),...t}));X.displayName=`TimelineGanttLabel`;var Z=b.forwardRef(({className:e,start:t=0,width:n=100,variant:r=`default`,...i},a)=>(0,x.jsx)(`div`,{ref:a,className:_(`absolute h-8 rounded-md transition-colors cursor-pointer`,{default:`bg-blue-500 hover:bg-blue-600`,success:`bg-green-500 hover:bg-green-600`,warning:`bg-yellow-500 hover:bg-yellow-600`,danger:`bg-red-500 hover:bg-red-600`,info:`bg-purple-500 hover:bg-purple-600`}[r],e),style:{left:`${t}%`,width:`${n}%`},...i}));Z.displayName=`TimelineGanttBar`;var Q=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:_(`px-2 py-1 text-white text-xs font-medium truncate`,e),...t}));Q.displayName=`TimelineGanttBarContent`;var $=({schema:e,...t})=>{let{dataSource:n}=s()||{};return(0,x.jsx)(M,{schema:e,dataSource:n,...t})};p.register(`object-timeline`,$,{namespace:`plugin-timeline`,label:`Object Timeline`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],defaultValue:`vertical`}]}),p.register(`timeline`,$,{namespace:`view`,label:`Timeline View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],defaultValue:`vertical`}]});export{N as t};
|
|
1
|
+
import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{g as n,r}from"./vendor-react-CIpZOxG3.js";import{_ as i,m as a,r as o}from"./vendor-objectstack-CwZ3saTl.js";import{H as s,M as c,V as l,at as u,ot as d,r as f,ut as p}from"./framework-ClI3DbWX.js";import{N as m,es as h,ns as g,ts as _}from"./ui-components-DYQ4Pai7.js";import{n as v}from"./vendor-ui-utils-D3GsyZyi.js";import{a as y}from"./plugin-grid-u5JmW5Ui.js";var b=e(n(),1),x=r(),S=10080*60*1e3;function C(e){let t=e.flatMap(e=>(e.items||[]).flatMap(e=>[e.startDate,e.endDate])),n=Math.min(...t.map(e=>new Date(e).getTime())),r=Math.max(...t.map(e=>new Date(e).getTime()));return{minDate:new Date(n).toISOString().split(`T`)[0],maxDate:new Date(r).toISOString().split(`T`)[0]}}function w(e,t,n,r){let i=new Date(e).getTime(),a=new Date(t).getTime(),o=new Date(n).getTime(),s=new Date(r).getTime()-o,c=i-o,l=a-i;return{start:c/s*100,width:l/s*100}}function T(e,t){let n=new Date(e);return t===`short`?n.toLocaleDateString():t===`long`?n.toLocaleDateString(`en-US`,{year:`numeric`,month:`long`,day:`numeric`}):n.toISOString().split(`T`)[0]}function E({label:e,color:t}){let n=t?{backgroundColor:`${t}22`,color:t,borderColor:`${t}55`}:void 0;return(0,x.jsx)(`span`,{className:h(`inline-flex items-center rounded-full border px-2 py-0.5 text-xs font-medium`,!t&&`bg-muted text-muted-foreground border-transparent`),style:n,children:e})}function D(e){let t=[];for(let n of e){let e=n.group==null?``:String(n.group),r=t[t.length-1];r&&r.key===e?r.items.push(n):t.push({key:e,items:[n]})}return t}var O=({schema:e,className:t,...n})=>{let{variant:r=`vertical`,items:i=[],dateFormat:a=`short`,onItemClick:o}=e;if(r===`vertical`){let e=D(i),r=e.some(e=>e.key!==``),s=(e,t)=>{let n=e.color?{backgroundColor:`${e.color}33`,borderColor:e.color}:void 0,r=e.time?T(e.time,a):e.startDate?T(e.startDate,a):``,i=e.endDate&&e.endDate!==e.startDate?T(e.endDate,a):``,s=Array.isArray(e.meta)?e.meta:[];return(0,x.jsxs)(I,{density:`compact`,className:h(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,x.jsx)(R,{variant:e.color?`default`:e.variant||`default`,style:n,children:e.icon&&(0,x.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,x.jsxs)(z,{children:[(r||i)&&(0,x.jsxs)(V,{dateTime:e.time||e.startDate,className:`!mb-1 text-xs`,children:[r,i&&(0,x.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[` → `,i]})]}),e.title&&(0,x.jsx)(B,{className:`text-sm sm:text-base mb-1`,children:e.title}),s.length>0&&(0,x.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1 mb-1`,children:s.map(e=>(0,x.jsx)(E,{label:e.label,color:e.color},e.key))}),e.description&&(0,x.jsx)(H,{className:`text-sm text-muted-foreground line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&_(e.content)]})]},t)};return r?(0,x.jsx)(`div`,{className:h(`px-4 sm:px-6 py-2`,t),...n,children:e.map((e,t)=>(0,x.jsxs)(`section`,{className:`mb-4`,children:[(0,x.jsxs)(`header`,{className:`sticky top-0 z-10 -mx-4 sm:-mx-6 px-4 sm:px-6 py-1.5 backdrop-blur bg-background/90 text-xs font-semibold uppercase tracking-wide text-muted-foreground border-b`,children:[(0,x.jsx)(`span`,{children:e.key}),(0,x.jsx)(`span`,{className:`ml-2 text-muted-foreground/60 font-normal normal-case`,children:e.items.length})]}),(0,x.jsx)(P,{className:`mt-3`,children:e.items.map((e,n)=>s(e,`${t}-${n}`))})]},`${e.key}-${t}`))}):(0,x.jsx)(P,{className:t,...n,children:i.map((e,t)=>s(e,t))})}if(r===`horizontal`)return(0,x.jsx)(U,{className:h(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:i.map((e,t)=>(0,x.jsxs)(W,{className:h(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,x.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,x.jsx)(R,{variant:e.variant||`default`,children:e.icon&&(0,x.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,x.jsxs)(`div`,{className:`mt-4 text-center`,children:[e.time&&(0,x.jsx)(V,{dateTime:e.time,children:T(e.time,a)}),e.title&&(0,x.jsx)(B,{children:e.title}),e.description&&(0,x.jsx)(H,{className:`text-center line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&_(e.content)]})]}),t<i.length-1&&(0,x.jsx)(`div`,{className:`absolute left-full w-16 border-t-2 border-gray-200 top-3`})]},t))});if(r===`gantt`){let r=C(i),s=e.minDate||r.minDate,c=e.maxDate||r.maxDate,l=e.timeScale||`month`,u=(()=>{let e=[],t=new Date(s),n=new Date(c);if(l===`month`){let r=new Date(t);for(;r<=n;)e.push(r.toLocaleDateString(`en-US`,{month:`short`,year:`numeric`})),r.setMonth(r.getMonth()+1)}else if(l===`week`){let r=new Date(t);for(;r<=n;)e.push(`Week ${Math.ceil((r.getTime()-t.getTime())/S)+1}`),r.setDate(r.getDate()+7)}else if(l===`day`){let r=new Date(t);for(;r<=n;)e.push(r.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})),r.setDate(r.getDate()+1)}return e})();return(0,x.jsxs)(G,{className:h(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:[(0,x.jsxs)(K,{children:[(0,x.jsx)(q,{className:`flex items-center px-2 sm:px-4 py-2 sm:py-3`,children:(0,x.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:e.rowLabel||`Items`})}),(0,x.jsx)(J,{children:(0,x.jsx)(`div`,{className:`flex h-full`,children:u.map((e,t)=>(0,x.jsx)(`div`,{className:`flex-1 px-1 sm:px-2 py-2 sm:py-3 border-r text-xs font-medium text-center`,children:e},t))})})]}),(0,x.jsx)(`div`,{children:(0,x.jsxs)(`div`,{className:`flex`,children:[(0,x.jsx)(q,{children:i.map((e,t)=>(0,x.jsx)(Y,{children:(0,x.jsx)(X,{title:e.label,className:`truncate`,children:e.label})},t))}),(0,x.jsx)(J,{className:`relative`,children:i.map((e,t)=>(0,x.jsx)(Y,{className:`relative`,children:(e.items||[]).map((n,r)=>{let i=w(n.startDate,n.endDate,s,c);return(0,x.jsx)(Z,{start:i.start,width:i.width,variant:n.variant||`default`,onClick:()=>o?.(n,e,t,r),title:`${n.title||``}\n${T(n.startDate,a)} - ${T(n.endDate,a)}`,children:(0,x.jsx)(Q,{children:n.title})},r)})},t))})]})})]})}return null};p.register(`timeline`,O,{namespace:`plugin-timeline`,label:`Timeline`,category:`data-display`,inputs:[{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],label:`Timeline Variant`,defaultValue:`vertical`},{name:`items`,type:`array`,label:`Timeline Items`,description:`For vertical/horizontal: Array of { time, title, description, variant, icon, content }. For gantt: Array of { label, items: [{ title, startDate, endDate, variant }] }`},{name:`dateFormat`,type:`enum`,enum:[`short`,`long`,`iso`],label:`Date Format`,defaultValue:`short`},{name:`timeScale`,type:`enum`,enum:[`day`,`week`,`month`],label:`Time Scale (Gantt only)`,defaultValue:`month`},{name:`rowLabel`,type:`string`,label:`Row Label (Gantt only)`,defaultValue:`Items`},{name:`minDate`,type:`string`,label:`Min Date (Gantt only)`,description:`Override auto-calculated min date (YYYY-MM-DD)`},{name:`maxDate`,type:`string`,label:`Max Date (Gantt only)`,description:`Override auto-calculated max date (YYYY-MM-DD)`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{variant:`vertical`,dateFormat:`short`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`,icon:`🚀`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`,icon:`🎨`},{time:`2024-03-15`,title:`Beta Release`,description:`Released beta version to testers`,variant:`warning`,icon:`⚡`},{time:`2024-04-01`,title:`Launch`,description:`Official product launch`,variant:`success`,icon:`🎉`}]},examples:{vertical:{variant:`vertical`,dateFormat:`long`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`}]},horizontal:{variant:`horizontal`,dateFormat:`short`,items:[{time:`2024-01-01`,title:`Q1`,description:`First quarter`,variant:`default`},{time:`2024-04-01`,title:`Q2`,description:`Second quarter`,variant:`info`},{time:`2024-07-01`,title:`Q3`,description:`Third quarter`,variant:`warning`},{time:`2024-10-01`,title:`Q4`,description:`Fourth quarter`,variant:`success`}]},gantt:{variant:`gantt`,dateFormat:`short`,timeScale:`month`,rowLabel:`Projects`,items:[{label:`Backend Development`,items:[{title:`API Design`,startDate:`2024-01-01`,endDate:`2024-01-31`,variant:`success`},{title:`Implementation`,startDate:`2024-02-01`,endDate:`2024-03-31`,variant:`info`}]},{label:`Frontend Development`,items:[{title:`UI Design`,startDate:`2024-01-15`,endDate:`2024-02-15`,variant:`warning`},{title:`Component Dev`,startDate:`2024-02-15`,endDate:`2024-04-15`,variant:`default`}]},{label:`Testing`,items:[{title:`QA Phase`,startDate:`2024-03-01`,endDate:`2024-04-30`,variant:`danger`}]}]}}});var k={"timeline.bucket.overdue":`Overdue`,"timeline.bucket.today":`Today`,"timeline.bucket.tomorrow":`Tomorrow`,"timeline.bucket.thisWeek":`This week`,"timeline.bucket.nextWeek":`Next week`,"timeline.bucket.later":`Later`,"timeline.bucket.noDate":`No date`,"timeline.bucket.unassigned":`Unassigned`,"timeline.relative.today":`Today`,"timeline.relative.tomorrow":`Tomorrow`,"timeline.relative.yesterday":`Yesterday`,"timeline.relative.inDays":`In {{n}} days`,"timeline.relative.daysAgo":`{{n}} days ago`},A=`timeline.bucket.today`;function j(e,t){let n=k[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}function ee(){try{let e=f();return e.t(A)===A?{t:j}:{t:e.t}}catch{return{t:j}}}function te(){try{return g()}catch{return{fieldOptionLabel:(e,t,n,r)=>r,translateOptions:(e,t,n)=>n,fieldLabel:(e,t,n)=>n}}}var ne=a({mapping:a({title:i().optional(),date:i().optional(),description:i().optional(),variant:i().optional()}).optional(),objectName:i().optional(),titleField:i().optional(),dateField:i().optional(),startDateField:i().optional(),endDateField:i().optional(),descriptionField:i().optional(),groupByField:i().optional(),colorField:i().optional(),scale:o([`hour`,`day`,`week`,`month`,`quarter`,`year`]).optional()}),M=({schema:e,dataSource:t,className:n,onRowClick:r,onItemClick:i,...a})=>{let[o,s]=(0,b.useState)([]),[f,p]=(0,b.useState)(()=>{let t=Array.isArray(e.items)&&e.items.length>0,n=Array.isArray(a.data)&&a.data.length>0;return!t&&!n&&!!e.objectName}),[h,g]=(0,b.useState)(null),[_,v]=(0,b.useState)(0),[S,C]=(0,b.useState)(null),w=e.timeline;(0,b.useEffect)(()=>{let t=ne.safeParse(e);t.success||console.warn(`[ObjectTimeline] Invalid timeline configuration:`,t.error.format())},[e]);let T=l(e.bind);(0,b.useEffect)(()=>{let n=!0;return(async()=>{if(!(!t||typeof t.getObjectSchema!=`function`||!e.objectName))try{let r=await t.getObjectSchema(e.objectName);n&&C(r)}catch(e){console.warn(`Failed to fetch object def for ObjectTimeline`,e)}})(),()=>{n=!1}},[e.objectName,t]),(0,b.useEffect)(()=>{e.objectName&&!T&&!e.items&&!a.data?(async()=>{if(!t||typeof t.find!=`function`||!e.objectName){p(!1);return}p(!0);try{let n=u(S?.fields);s(d(await t.find(e.objectName,{options:{$top:100},...n.length>0?{$expand:n}:{}})))}catch(e){console.error(e),g(e)}finally{p(!1)}})():p(!1)},[e.objectName,t,T,e.items,a.data,_,S]);let E=a.data||T||o,{t:D}=ee(),{fieldOptionLabel:k}=te(),A=w?.titleField??e.mapping?.title??e.titleField??`name`,j=w?.startDateField??e.mapping?.date??e.startDateField??e.dateField??`date`,M=w?.endDateField??e.endDateField??j,N=e.mapping?.description??e.descriptionField??`description`,P=e.mapping?.variant??`variant`,F=w?.groupByField??e.groupByField,I=w?.colorField??e.colorField,L=(0,b.useMemo)(()=>{if(e.items)return e.items;if(!E||!Array.isArray(E))return[];let t=S?.fields??{},n=e.objectName||``,r=e=>{if(!e||!t[e]?.options)return{};let n={};for(let r of t[e].options)r&&r.value!=null&&(n[String(r.value)]=r);return n},i=r(I),a=Array.isArray(w?.metaFields)?w.metaFields.filter(e=>typeof e==`string`&&e):[`status`,`priority`].filter(e=>t[e]),o={};for(let e of a)o[e]=r(e);let s=e=>{if(e==null||e===``)return;let t=i[String(e)];if(t?.color)return String(t.color);let n=String(e);if(/^#([0-9a-f]{3}){1,2}$/i.test(n)||n.startsWith(`rgb`)||n.startsWith(`hsl`))return n},c=(e,t,r)=>{if(t==null||t===``)return null;let i=r[String(t)];return{label:i?.label?k(n,e,String(t),i.label):String(t),color:i?.color}},l=E.map(e=>{let t=e[j],r=e[M],i=I?e[I]:void 0,l=F?e[F]:void 0,u=[];if(n)for(let t of a){let n=c(t,e[t],o[t]||{});n&&u.push({key:t,label:n.label,color:n.color})}return{title:e[A],time:t,startDate:t,endDate:r,description:e[N],variant:e[P]||`default`,color:s(i),group:l,meta:u,_data:e}});l.sort((e,t)=>(e.startDate?new Date(e.startDate).getTime():1/0)-(t.startDate?new Date(t.startDate).getTime():1/0));let u=new Date,d=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime(),f=d(u),p=864e5,m=f-(u.getDay()+6)%7*p+7*p,h=m+7*p,g=e=>{if(!e)return D(`timeline.bucket.noDate`);let t=d(new Date(e));return Number.isNaN(t)?D(`timeline.bucket.noDate`):t<f?D(`timeline.bucket.overdue`):t===f?D(`timeline.bucket.today`):t===f+p?D(`timeline.bucket.tomorrow`):D(t<m?`timeline.bucket.thisWeek`:t<h?`timeline.bucket.nextWeek`:`timeline.bucket.later`)};if(F&&!l.every(e=>e.group==null||e.group===``)){let e=r(F);return l.map(t=>{let n=c(F,t.group,e);return{...t,group:n?n.label:t.group!=null&&t.group!==``?String(t.group):D(`timeline.bucket.unassigned`)}})}return l.map(e=>({...e,group:g(e.startDate)}))},[e.items,E,S,e.objectName,A,j,M,N,P,I,F,D,k]),{ref:R,isRefreshing:z,pullDistance:B}=y({onRefresh:(0,b.useCallback)(async()=>{v(e=>e+1)},[]),enabled:!!e.objectName&&!!t}),V=c({navigation:e.navigation,objectName:e.objectName,onRowClick:r??i}),H=w?.scale??e.scale,U={...e,items:L||[],className:n||e.className,...H?{timeScale:H}:{},onItemClick:e=>{let t=e._data||e;V.handleClick(t),i?.(t)}};return h?(0,x.jsxs)(`div`,{className:`p-4 text-destructive`,"data-testid":`timeline-error`,role:`alert`,children:[`Error loading timeline: `,h.message]}):f&&(!L||L.length===0)?(0,x.jsxs)(`div`,{className:`flex flex-col h-full min-h-[200px] p-4 gap-3`,"data-testid":`timeline-loading`,role:`status`,"aria-live":`polite`,"aria-busy":`true`,children:[(0,x.jsx)(`span`,{className:`sr-only`,children:`Loading timeline…`}),[0,1,2,3].map(e=>(0,x.jsxs)(`div`,{className:`flex items-start gap-3`,style:{opacity:Math.max(.3,1-e*.18)},children:[(0,x.jsx)(`div`,{className:`h-3 w-3 rounded-full bg-muted/70 animate-pulse mt-1.5 shrink-0`}),(0,x.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,x.jsx)(`div`,{className:`h-4 w-1/3 rounded bg-muted/70 animate-pulse`}),(0,x.jsx)(`div`,{className:`h-3 w-2/3 rounded bg-muted/50 animate-pulse`})]})]},e))]}):(0,x.jsxs)(`div`,{ref:R,className:`relative overflow-auto h-full min-w-0`,children:[B>0&&(0,x.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:B},children:z?`Refreshing…`:`Pull to refresh`}),(0,x.jsx)(O,{schema:U}),V.isOverlay&&(0,x.jsx)(m,{...V,title:`Timeline Item`,children:e=>(0,x.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,x.jsxs)(`div`,{className:`flex flex-col`,children:[(0,x.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,x.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})},N=t({ObjectTimeline:()=>M,ObjectTimelineRenderer:()=>$,Timeline:()=>P,TimelineContent:()=>z,TimelineDescription:()=>H,TimelineGantt:()=>G,TimelineGanttBar:()=>Z,TimelineGanttBarContent:()=>Q,TimelineGanttGrid:()=>J,TimelineGanttHeader:()=>K,TimelineGanttLabel:()=>X,TimelineGanttRow:()=>Y,TimelineGanttRowLabels:()=>q,TimelineHorizontal:()=>U,TimelineHorizontalItem:()=>W,TimelineItem:()=>I,TimelineMarker:()=>R,TimelineRenderer:()=>O,TimelineTime:()=>V,TimelineTitle:()=>B,timelineItemVariants:()=>F,timelineMarkerVariants:()=>L}),P=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`ol`,{ref:n,className:h(`relative ml-3 border-l border-gray-200`,e),...t}));P.displayName=`Timeline`;var F=v(`ml-6`,{variants:{density:{default:`mb-10`,compact:`mb-3`,comfortable:`mb-6`}},defaultVariants:{density:`default`}}),I=b.forwardRef(({className:e,density:t,...n},r)=>(0,x.jsx)(`li`,{ref:r,className:h(F({density:t}),e),...n}));I.displayName=`TimelineItem`;var L=v(`absolute -left-3 w-6 h-6 rounded-full border-2 flex items-center justify-center`,{variants:{variant:{default:`bg-blue-200 border-blue-400`,success:`bg-emerald-200 border-emerald-500`,warning:`bg-amber-200 border-amber-500`,danger:`bg-red-200 border-red-500`,info:`bg-purple-200 border-purple-500`,todo:`bg-slate-200 border-slate-400`,"in-progress":`bg-blue-200 border-blue-500`,done:`bg-emerald-200 border-emerald-500`}},defaultVariants:{variant:`default`}}),R=b.forwardRef(({className:e,variant:t=`default`,...n},r)=>(0,x.jsx)(`div`,{ref:r,className:h(L({variant:t}),e),...n}));R.displayName=`TimelineMarker`;var z=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:e,...t}));z.displayName=`TimelineContent`;var B=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`h3`,{ref:n,className:h(`font-semibold text-lg mb-1`,e),...t}));B.displayName=`TimelineTitle`;var V=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`time`,{ref:n,className:h(`text-sm font-normal text-gray-500 mb-2 block`,e),...t}));V.displayName=`TimelineTime`;var H=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`p`,{ref:n,className:h(`text-base text-gray-700`,e),...t}));H.displayName=`TimelineDescription`;var U=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:h(`relative flex overflow-x-auto py-8`,e),...t}));U.displayName=`TimelineHorizontal`;var W=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:h(`shrink-0 w-64 relative`,e),...t}));W.displayName=`TimelineHorizontalItem`;var G=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:h(`relative w-full border rounded-lg overflow-hidden`,e),...t}));G.displayName=`TimelineGantt`;var K=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:h(`flex border-b bg-gray-50`,e),...t}));K.displayName=`TimelineGanttHeader`;var q=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:h(`w-48 border-r bg-white`,e),...t}));q.displayName=`TimelineGanttRowLabels`;var J=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:h(`flex-1 overflow-x-auto`,e),...t}));J.displayName=`TimelineGanttGrid`;var Y=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:h(`flex items-center border-b min-h-12`,e),...t}));Y.displayName=`TimelineGanttRow`;var X=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:h(`px-4 py-2 font-medium text-sm truncate`,e),...t}));X.displayName=`TimelineGanttLabel`;var Z=b.forwardRef(({className:e,start:t=0,width:n=100,variant:r=`default`,...i},a)=>(0,x.jsx)(`div`,{ref:a,className:h(`absolute h-8 rounded-md transition-colors cursor-pointer`,{default:`bg-blue-500 hover:bg-blue-600`,success:`bg-green-500 hover:bg-green-600`,warning:`bg-yellow-500 hover:bg-yellow-600`,danger:`bg-red-500 hover:bg-red-600`,info:`bg-purple-500 hover:bg-purple-600`}[r],e),style:{left:`${t}%`,width:`${n}%`},...i}));Z.displayName=`TimelineGanttBar`;var Q=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:h(`px-2 py-1 text-white text-xs font-medium truncate`,e),...t}));Q.displayName=`TimelineGanttBarContent`;var $=({schema:e,...t})=>{let{dataSource:n}=s()||{};return(0,x.jsx)(M,{schema:e,dataSource:n,...t})};p.register(`object-timeline`,$,{namespace:`plugin-timeline`,label:`Object Timeline`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],defaultValue:`vertical`}]}),p.register(`timeline`,$,{namespace:`view`,label:`Timeline View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],defaultValue:`vertical`}]});export{N as t};
|