@objectstack/console 7.3.0 → 7.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/assets/{AiPendingActionsPage-BbZbWYZF.js → AiPendingActionsPage-KMQsypXx.js} +1 -1
  2. package/dist/assets/{ApiConsolePage-CxtzVvxL.js → ApiConsolePage-Bt2GOTU0.js} +1 -1
  3. package/dist/assets/{AppManagementPage-CFfnxT1t.js → AppManagementPage-D11kr33p.js} +1 -1
  4. package/dist/assets/ApprovalsInboxPage-B2HaWzLT.js +1 -0
  5. package/dist/assets/{AuditLogPage-D4FqYkQH.js → AuditLogPage-BgZmEpPe.js} +1 -1
  6. package/dist/assets/{ComponentNavView-XiNMCGMg.js → ComponentNavView-q7X3o6Ba.js} +1 -1
  7. package/dist/assets/{ConsoleFloatingChatbot-DQEWG5vB.js → ConsoleFloatingChatbot-CX7Hyegq.js} +1 -1
  8. package/dist/assets/{DeveloperHubPage-lZkmDwEj.js → DeveloperHubPage-I50zoR-V.js} +1 -1
  9. package/dist/assets/FlowRunsPage-BZfhrn_O.js +1 -0
  10. package/dist/assets/{ProfilePage-BGOg1gVa.js → ProfilePage-WwvIlqOB.js} +1 -1
  11. package/dist/assets/PublicFormsPage-CFzAVfSh.js +1 -0
  12. package/dist/assets/{RecentItemsProvider-Dt0K6V1V.js → RecentItemsProvider-VqVTd5Ra.js} +1 -1
  13. package/dist/assets/{SettingsHub-D_bBB6HI.js → SettingsHub-B2khbTUV.js} +1 -1
  14. package/dist/assets/{SettingsView-CErPIsVb.js → SettingsView-RvPByUC5.js} +1 -1
  15. package/dist/assets/{SystemHubPage-B3lD5VE8.js → SystemHubPage-DRfqpp32.js} +1 -1
  16. package/dist/assets/{data-adapter-DD2mxtaH.js → data-adapter-BI1S6gix.js} +1 -1
  17. package/dist/assets/framework-Bsl5NTfe.js +34 -0
  18. package/dist/assets/{highlighted-body-OFNGDK62-_uUbA42F.js → highlighted-body-OFNGDK62-DT9uQOp0.js} +1 -1
  19. package/dist/assets/index-7sxElnrz.js +33 -0
  20. package/dist/assets/index-ljRQeZRW.css +2 -0
  21. package/dist/assets/{infrastructure-IQKE4Vv8.js → infrastructure-CFhpdDcd.js} +1 -1
  22. package/dist/assets/mermaid-GHXKKRXX-TfKfgNtY.js +1 -0
  23. package/dist/assets/{plugin-calendar-CBSUjCse.js → plugin-calendar-DYekpDbN.js} +1 -1
  24. package/dist/assets/plugin-charts-BpgCzDOC.js +7 -0
  25. package/dist/assets/plugin-chatbot-5ZYTjB3v.js +120 -0
  26. package/dist/assets/plugin-dashboard-B9i14gqH.js +3 -0
  27. package/dist/assets/plugin-form-DLpJWJgX.js +1 -0
  28. package/dist/assets/{plugin-gantt-BM_qU02_.js → plugin-gantt-DE_BIKaH.js} +1 -1
  29. package/dist/assets/plugin-grid-BwTh0lXV.js +6 -0
  30. package/dist/assets/plugin-kanban-D6PgB3bB.js +1 -0
  31. package/dist/assets/{plugin-map-D5wjaTuu.js → plugin-map-DVKSXWRF.js} +1 -1
  32. package/dist/assets/{plugin-markdown-BS1-ubYs.js → plugin-markdown-QUM2IO7x.js} +1 -1
  33. package/dist/assets/plugin-report-CFMPQgzx.js +59 -0
  34. package/dist/assets/{plugin-timeline-DHjoax2v.js → plugin-timeline-r_gNDvzq.js} +1 -1
  35. package/dist/assets/plugin-view-DMDKwmGd.js +1 -0
  36. package/dist/assets/plugins-views-Bg7xbB79.js +4 -0
  37. package/dist/assets/{src-DftmwA5L.js → src-fYuCcOkZ.js} +1 -1
  38. package/dist/assets/{types-X_Rma6be.js → types-BDFLkf-0.js} +1 -1
  39. package/dist/assets/ui-components-De4OOQs-.js +41 -0
  40. package/dist/assets/{ui-layout-Ciu790M0.js → ui-layout-B-tX4Ipa.js} +1 -1
  41. package/dist/assets/vendor-objectstack-D6pAOWWu.js +65 -0
  42. package/dist/index.html +4 -4
  43. package/package.json +1 -1
  44. package/dist/assets/ApprovalsInboxPage-BxQZcCfd.js +0 -1
  45. package/dist/assets/FlowRunsPage-RrJ1_Gcu.js +0 -1
  46. package/dist/assets/PublicFormsPage-IlBXTnnv.js +0 -1
  47. package/dist/assets/framework-DmN5Xd7Z.js +0 -34
  48. package/dist/assets/index-3n4YIBCx.js +0 -33
  49. package/dist/assets/index-DRnsSCuD.css +0 -2
  50. package/dist/assets/mermaid-GHXKKRXX-B0LJSQUI.js +0 -1
  51. package/dist/assets/plugin-charts-C1pPCTiC.js +0 -7
  52. package/dist/assets/plugin-chatbot-BHoielbC.js +0 -120
  53. package/dist/assets/plugin-dashboard-CrU-RT7P.js +0 -3
  54. package/dist/assets/plugin-form-YkI84B6S.js +0 -1
  55. package/dist/assets/plugin-grid-C__XZwVh.js +0 -6
  56. package/dist/assets/plugin-kanban-DpM0Y5w1.js +0 -1
  57. package/dist/assets/plugin-report-ClF2T8j-.js +0 -59
  58. package/dist/assets/plugin-view-DPiRuVYV.js +0 -1
  59. package/dist/assets/plugins-views-DKbDkBwY.js +0 -4
  60. package/dist/assets/ui-components-ClOuWOoQ.js +0 -41
  61. package/dist/assets/vendor-objectstack-B5adaLmw.js +0 -65
@@ -0,0 +1,59 @@
1
+ import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{r as n,y as r}from"./vendor-react-CyVA1SE-.js";import{B as i,R as a,dt as o,et as s,tt as c}from"./framework-Bsl5NTfe.js";import{n as l}from"./vendor-i18n-DPyFo2xM.js";import{$ as u,Ai as d,At as f,Bn as p,Bo as m,Do as h,Fi as g,Fn as _,Gn as v,Ia as y,In as b,Jn as x,Kn as S,Ks as C,Ln as w,Lr as T,Ms as E,Pr as D,Qn as O,Ri as k,Rn as A,Rs as j,Sa as M,Us as N,V as P,Vn as ee,Xn as F,Yn as I,ao as te,en as L,et as R,hi as ne,in as z,is as re,l as ie,m as ae,mr as B,ms as oe,ns as se,nt as V,qn as H,tt as ce,vi as le,w as ue,xi as de,zn as fe}from"./ui-components-De4OOQs-.js";import{r as pe}from"./plugin-grid-BwTh0lXV.js";var U=e(r(),1),W=n(),me=({schema:e})=>{let{title:t,description:n,data:r,columns:i}=e;e.chart?.type;let a=!!e.chart;return(0,W.jsxs)(S,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,W.jsxs)(I,{children:[t&&(0,W.jsx)(F,{children:t}),n&&(0,W.jsx)(x,{children:n})]}),(0,W.jsxs)(H,{className:`flex-1 overflow-auto space-y-4`,children:[a&&(()=>{let t=e.chart?.type,n=t?o.get(t):null;return n||=o.get(`chart`),n?(0,W.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,W.jsx)(n,{schema:{...e.chart,data:e.chart.data||r}})}):(0,W.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,W.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=o.get(`grid`)||o.get(`table`);return e?(0,W.jsx)(e,{schema:{type:`grid`,rowData:r,columnDefs:i,domLayout:`autoHeight`}}):(0,W.jsx)(`div`,{className:`overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,W.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,W.jsx)(`tr`,{children:i?.map(e=>(0,W.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,W.jsx)(`tbody`,{children:r.map((e,t)=>(0,W.jsx)(`tr`,{className:`bg-background border-b`,children:i?.map(t=>(0,W.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function G(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function he(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 K(e,t){let n=e[t.field];return t.dateGranularity?he(n,t.dateGranularity)??`(empty)`:n==null||n===``?`(empty)`:String(n)}function q(e,t){let n={};for(let r of t){if(!r.aggregate){let t=e.find(e=>e[r.field]!=null);n[G(r)]=t?t[r.field]:null;continue}let t=e.map(e=>e[r.field]);switch(r.aggregate){case`count`:n[G(r)]=t.length;break;case`unique`:{let e=new Set;for(let n of t)n!=null&&e.add(n);n[G(r)]=e.size;break}case`sum`:{let e=0;for(let n of t)e+=Number(n)||0;n[G(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[G(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[G(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[G(r)]=e;break}default:n[G(r)]=null}}return n}function ge(e,t,n,r={},i=[]){if(t.length===0)return[];let[a,...o]=t,s=new Map;for(let t of e){let e=K(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=q(t,n),d=o.length>0?ge(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 _e(e,t,n,r){let i=ve(e,n),a=ve(e,r),o={},s={},c={};for(let c of i){o[c.id]={};let i=ye(e,c.key,n);s[c.id]=q(i,t);for(let e of a){let n=ye(i,e.key,r);n.length!==0&&(o[c.id][e.id]=q(n,t))}}for(let n of a){let i=ye(e,n.key,r);c[n.id]=q(i,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:q(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function ve(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=K(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 ye(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?K(e,r):e[t]==null?`(null)`:String(e[t]))!==String(n))return!1}return!0})}function be(e,t){let n={};for(let r of t){if(!r.aggregate)continue;let t=G(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 xe(e,t,n,r){let i=Se(e,n),a=Se(e,r),o={},s={},c={};for(let n of i){o[n.id]={};let r=e.filter(e=>Ce(e,n.key));s[n.id]=be(r,t);for(let e of a){let i=r.filter(t=>Ce(t,e.key));if(i.length===0)continue;let a={};for(let e of t){if(!e.aggregate)continue;let t=G(e);a[t]=i[0][t]}o[n.id][e.id]=a}}for(let n of a){let r=e.filter(e=>Ce(e,n.key));c[n.id]=be(r,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:be(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function Se(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 Ce(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 J(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 we(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 Te(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:G(e)})),s=J(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 Ee(e,t,n){for(let[r,i]of Object.entries(t)){let t=n.find(e=>e.field===r);if((t?K(e,t):String(e[r]??`(empty)`))!==String(i))return!1}return!0}var Y=[];function De(e,t={}){let{dataSource:n,runtimeFilter:r,maxRows:i=5e3,enabled:a=!0,rows:o,preferServerAggregation:s=!0}=t,[c,l]=(0,U.useState)(o??Y),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(()=>o?!1:!!(e&&a&&n)),[m,h]=(0,U.useState)(null),g=(0,U.useRef)(0),_=(0,U.useCallback)(async()=>{if(!e||!a)return;if(o){l(o),d(!1);return}if(!n){l(Y);return}let t=++g.current;p(!0),h(null);try{let a=s?Te(e,r,i):null;if(a&&typeof n.aggregate==`function`)try{let r=Oe(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(Y),d(!1);return}let o=J(e.filter,r),c=we(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=Oe(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(Y),d(!1)}finally{t===g.current&&p(!1)}},[e,a,o,n,r,i,s]);(0,U.useEffect)(()=>{_()},[_]);let{rows:v,totals:y,pivot:b}=(0,U.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=be(c,r),s=i?xe(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?ge(c,a,r):c.map(e=>({groupKey:{},groupPath:[],values:r.length>0?q([e],r):{...e},count:1})),totals:q(c,r),pivot:i?_e(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,U.useCallback)(t=>{if(!e)return[];let n=[...e.groupingsDown??[],...e.groupingsAcross??[]];return c.filter(e=>Ee(e,t,n))},[e,c])}}function Oe(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 Y}function ke(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function Ae(e){let t=[],n=e=>{e.children&&e.children.length>0?e.children.forEach(n):t.push(e)};return e.forEach(n),t}function je({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=ke(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=Ae(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 Me(e,t,n={}){let r=J(J(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 Ne(e){return!!e&&e.type===`drill`}function Pe(e){return async t=>{if(!Ne(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 Fe(e,t){return e.registerHandler(`drill`,Pe(t)),()=>e.unregisterHandler(`drill`)}function Ie(e){return e?e===`unique`?`count_distinct`:e:null}function Le(e){if(!(!e||e.length===0))return{fields:e.map(e=>({field:e.field,order:e.sort??`asc`,collapsed:!1}))}}function Re(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 ze={padding:`12px 16px`,border:`1px dashed rgb(203 213 225)`,borderRadius:8,color:`rgb(100 116 139)`,fontSize:14},Be=({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}=C(),[h,g]=U.useState(null);U.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 _=U.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=U.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:w,error:T,drillDown:E}=De(e,{dataSource:t,rows:n,runtimeFilter:r});if(d===`matrix`||d===`joined`)return(0,W.jsxs)(`div`,{className:u,style:ze,children:[`Report type `,(0,W.jsx)(`code`,{children:d}),` is not yet supported by SpecReportGrid. It will be rendered by a dedicated component in M2 (matrix) / M3 (joined).`]});let D=U.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:G(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`?Le(e.groupingsDown):void 0,n=(e.columns??[]).map(e=>{let t=Ie(e.aggregate);return t?{field:e.field,type:t}:null}).filter(e=>e!==null);return{type:`object-grid`,objectName:e.objectName,columns:Re(e),grouping:t,aggregations:n.length>0?n:void 0}},[e,d,S]),O=y,k=U.useCallback(t=>{let n=e.groupingsDown??[],a={};for(let e of n)a[e.field]=t[e.field];if(o){let t=Me(e,a,{runtimeFilter:r,view:s,openIn:c});o.execute(t)}i&&i(a,E(a))},[o,E,c,s,i,e,r]),A=!!i||!!o,j=(e.columns??[]).filter(e=>e.aggregate),M=j.length>0&&x&&Object.keys(x).length>0,N=U.useMemo(()=>d!==`summary`||!e.chart||!e.chart.type?null:je({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,W.jsxs)(`div`,{className:u,"data-testid":`spec-report-grid`,"aria-busy":w||void 0,children:[T?(0,W.jsx)(`div`,{role:`alert`,style:{...ze,color:`rgb(190 18 60)`},children:T.message}):null,M?(0,W.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,W.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:f(`report.totals`,`Totals`)}),j.map(e=>{let t=G(e),n=x[t],r=_(e),i=typeof n==`number`?n.toLocaleString(void 0,{maximumFractionDigits:2}):String(n??`—`);return(0,W.jsxs)(`span`,{"data-testid":`spec-report-total-${t}`,className:`inline-flex items-baseline gap-1.5`,children:[(0,W.jsxs)(`span`,{className:`text-muted-foreground`,children:[r,`:`]}),(0,W.jsx)(`span`,{className:`font-mono font-medium tabular-nums`,children:i})]},t)})]}):null,N?(0,W.jsx)(`div`,{className:`mb-4`,"data-testid":`spec-report-chart`,children:(0,W.jsx)(a,{schema:N})}):null,(0,W.jsx)(pe,{schema:D,data:O,dataSource:t,onRowClick:A?k:void 0})]})};Be.displayName=`SpecReportGrid`;var Ve=`—`;function He(e){return e==null?Ve:typeof e==`number`?e.toLocaleString():String(e)}function Ue(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 We({header:e,groupings:t,metaByField:n,fallback:r,emptyLabel:i}){return e.path.length===0?(0,W.jsx)(W.Fragment,{children:r}):(0,W.jsx)(W.Fragment,{children:e.path.map((e,r)=>{let a=t[r]?.field;return Ue(e,a?n.get(a):void 0,i)}).join(` / `)})}var Ge=({report:e,dataSource:t,rows:n,runtimeFilter:r,onCellClick:i,actionRunner:a,drillView:o,drillOpenIn:s,className:c,emptyCellText:u=Ve})=>{let{pivot:d,loading:f,error:p}=De(e,{dataSource:t,rows:n,runtimeFilter:r}),m=e.columns??[],h=m.length>1,{fieldLabel:g,translateOptions:_}=C(),{t:v}=l(),y=v(`report.emptyLabel`,`(Empty)`),b=v(`report.allLabel`,`(All)`),[x,S]=U.useState(null);U.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 w=e.groupingsDown??[],T=e.groupingsAcross??[],E=U.useMemo(()=>{let t=new Map,n=x?.fields??{},r=[...w,...T];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,w,T,e.objectName,g,_]),D=U.useMemo(()=>{let t=new Map,n=x?.fields??{};for(let r of m){let i=G(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]),O=U.useCallback((t,n,c)=>{let l={...t.key,...n.key};if(a){let t=Me(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,W.jsx)(`div`,{className:N(`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,W.jsx)(`div`,{className:N(`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 k=!!i||!!a,A=w.map(e=>E.get(e.field)?.fieldLabel??e.field).join(` / `)||v(`report.rowsLabel`,`Row`),j=T.map(e=>E.get(e.field)?.fieldLabel??e.field).join(` / `)||v(`report.columnsLabel`,`Column`),M=m.length>0?G(m[0]):null,P=0;if(M)for(let e of d.rowHeaders)for(let t of d.colHeaders){let n=d.cells[e.id]?.[t.id]?.[M];typeof n==`number`&&n>P&&(P=n)}let ee=e=>{if(!M||P<=0||!e)return 0;let t=e[M];return typeof t!=`number`||t<=0?0:Math.min(1,t/P)};return(0,W.jsx)(`div`,{className:N(`overflow-auto rounded-lg border border-border bg-card shadow-sm`,c),"data-testid":`matrix-renderer`,"aria-busy":f||void 0,children:(0,W.jsxs)(`table`,{role:`table`,className:`w-full border-separate border-spacing-0 text-sm`,children:[(0,W.jsx)(`thead`,{children:(0,W.jsxs)(`tr`,{children:[(0,W.jsxs)(`th`,{scope:`col`,className:N(`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":`${A} \u2192 ${j}`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground/70`,children:A}),(0,W.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`\\`}),(0,W.jsx)(`span`,{className:`text-foreground/80`,children:j})]}),d.colHeaders.map(e=>(0,W.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,W.jsx)(We,{header:e,groupings:T,metaByField:E,fallback:b,emptyLabel:y})},`col-${e.id}`)),(0,W.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,W.jsx)(`tbody`,{children:d.rowHeaders.map((e,t)=>(0,W.jsxs)(`tr`,{className:`group`,children:[(0,W.jsx)(`th`,{scope:`row`,className:N(`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,W.jsx)(We,{header:e,groupings:w,metaByField:E,fallback:b,emptyLabel:y})}),d.colHeaders.map(t=>{let n=d.cells[e.id]?.[t.id],r=!n,i=ee(n);return(0,W.jsx)(`td`,{className:N(`border-b border-border px-3 py-2 text-right tabular-nums transition-colors`,r?`text-muted-foreground/40`:`text-foreground`,k&&!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:k&&!r?()=>O(e,t,n):void 0,"data-row":e.id,"data-col":t.id,children:r?u:X(m,n,h,D)},`cell-${e.id}-${t.id}`)}),(0,W.jsx)(`td`,{className:N(`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:X(m,d.rowTotals[e.id]??{},h,D)})]},`row-${e.id}`))}),(0,W.jsx)(`tfoot`,{children:(0,W.jsxs)(`tr`,{children:[(0,W.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,W.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:X(m,d.colTotals[e.id]??{},h,D)},`coltotal-${e.id}`)),(0,W.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:X(m,d.grandTotal,h,D)})]})})]})})};function X(e,t,n,r){return e.length?n?(0,W.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:e.map(e=>{let n=G(e);return(0,W.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r?.get(n)??e.label??n}),(0,W.jsx)(`span`,{className:`tabular-nums`,children:He(t[n])})]},n)})}):He(t[G(e[0])]):Ve}function Ke(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function qe(e,t){if(!t||Object.keys(t).length===0)return e;let n=J(t,e.filter);return{...e,filter:n}}var Je=({report:e,dataSource:t,runtimeFilter:n,actionRunner:r,drillView:i,drillOpenIn:a,className:o,renderBlock:c})=>{if(!s(e))return(0,W.jsxs)(`div`,{className:o,"data-testid":`joined-report-invalid`,style:{color:`var(--color-destructive, #b91c1c)`,fontSize:13,padding:12},children:[`JoinedReportRenderer requires a report with `,(0,W.jsx)(`code`,{children:`type: 'joined'`}),` and a `,(0,W.jsx)(`code`,{children:`blocks`}),` array.`]});let l=e.blocks??[],u=e.filter,d=e.objectName;return(0,W.jsx)(`div`,{className:o,"data-testid":`joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:l.map((e,o)=>{let s=e.objectName??d??``,l=qe({...e,objectName:s,type:e.type??`tabular`,columns:e.columns??[]},u),f=Ke(e.label,e.name),p=e.description?Ke(e.description,``):``,m=e.name??`block-${o}`,h=(0,W.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,W.jsxs)(`header`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,W.jsx)(`h3`,{style:{margin:0,fontSize:16,fontWeight:600},children:f}),p?(0,W.jsx)(`p`,{style:{margin:0,fontSize:13,color:`var(--color-muted-foreground, #71717a)`},children:p}):null]}),(0,W.jsx)(Z,{schema:l,dataSource:t,runtimeFilter:n,actionRunner:r,drillView:i,drillOpenIn:a})]},m);return c?c(e,o,h):h})})},Ye={border:`1px dashed var(--color-border, #d4d4d8)`,borderRadius:8,padding:16,color:`var(--color-muted-foreground, #71717a)`,background:`var(--color-muted, #f4f4f5)`,fontSize:13},Z=e=>{let{dataSource:t,rows:n,runtimeFilter:r,actionRunner:a,drillView:o,drillOpenIn:l,className:u}=e,d=U.useContext(i),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),c(p)){let e=p.type??`tabular`;return e===`matrix`?(0,W.jsx)(Ge,{report:p,dataSource:f,rows:n,runtimeFilter:r,actionRunner:a,drillView:o,drillOpenIn:l,className:u}):e===`joined`?s(p)?(0,W.jsx)(Je,{report:p,dataSource:f,runtimeFilter:r,actionRunner:a,drillView:o,drillOpenIn:l,className:u}):(0,W.jsxs)(`div`,{className:u,style:Ye,"data-testid":`report-joined-placeholder`,children:[`Joined report (`,(0,W.jsx)(`code`,{children:p.name}),`) is missing a `,(0,W.jsx)(`code`,{children:`blocks`}),` array.`]}):(0,W.jsx)(Be,{report:p,dataSource:f,rows:n,runtimeFilter:r,actionRunner:a,drillView:o,drillOpenIn:l,className:u})}return(0,W.jsx)(me,{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,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`)}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:s=!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])},p=()=>{window.print()},m=()=>{t?.()},_=(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``}},v=(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}}},y=(e,t)=>{if(e==null||e===``)return``;if(t.renderAs===`badge`&&(!t.type||t.type===`string`||t.type===`text`))return(0,W.jsx)(O,{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,W.jsx)(ie(ae(n)),{value:e,field:n})}return ot(e,t)};return n?(0,W.jsxs)(`div`,{className:`space-y-4`,children:[i&&(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold`,children:n.title}),n.description&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.description})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n.refreshInterval&&(0,W.jsxs)(B,{variant:`outline`,size:`sm`,onClick:m,children:[(0,W.jsx)(d,{className:`h-4 w-4 mr-2`}),`Refresh`]}),c&&(0,W.jsxs)(B,{variant:`outline`,size:`sm`,onClick:p,children:[(0,W.jsx)(g,{className:`h-4 w-4 mr-2`}),`Print`]}),s&&n.showExportButtons&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,W.jsxs)(B,{variant:`outline`,size:`sm`,onClick:()=>u(`pdf`),children:[(0,W.jsx)(h,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,W.jsxs)(B,{variant:`outline`,size:`sm`,onClick:()=>u(`excel`),children:[(0,W.jsx)(h,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,W.jsxs)(B,{variant:`outline`,size:`sm`,onClick:()=>u(`csv`),children:[(0,W.jsx)(h,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,W.jsxs)(S,{children:[(0,W.jsxs)(I,{children:[!i&&n.title&&(0,W.jsx)(F,{children:n.title}),!i&&n.description&&(0,W.jsx)(x,{children:n.description})]}),(0,W.jsxs)(H,{className:`space-y-6`,children:[l&&(0,W.jsxs)(`div`,{className:`space-y-6`,children:[(0,W.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,W.jsx)(S,{children:(0,W.jsxs)(H,{className:`p-4 space-y-2`,children:[(0,W.jsx)(f,{className:`h-4 w-20`}),(0,W.jsx)(f,{className:`h-8 w-28`})]})},e))}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(f,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,W.jsx)(f,{className:`h-8 w-full`},e))]})]}),!l&&n.sections?.map((e,t)=>e.visible===!1?null:(0,W.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,W.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,W.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,W.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:n.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,W.jsx)(S,{children:(0,W.jsxs)(H,{className:`p-4`,children:[(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,W.jsx)(`div`,{className:`text-2xl font-bold`,children:ot(_(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,W.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let t=e.chart.type,n=!!e.chart.chartType;!t&&n&&(t=`chart`),t&&o.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,W.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,W.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,W.jsx)(`thead`,{className:`bg-muted`,children:(0,W.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,W.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,W.jsx)(`tbody`,{children:(()=>{let t=lt(r||[],n.groupBy||[]);return t?t.map(t=>(0,W.jsxs)(U.Fragment,{children:[(0,W.jsx)(`tr`,{className:`bg-muted/60`,children:(0,W.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,W.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,W.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:v(e.name,t[e.name]),children:y(t[e.name],e)},n))},n))]},t.key)):r?.map((t,n)=>(0,W.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,W.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:v(e.name,t[e.name]),children:y(t[e.name],e)},n))},n))})()})]})}),e.type===`text`&&e.text&&(0,W.jsx)(`div`,{className:`prose max-w-none`,children:(0,W.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,W.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,W.jsx)(a,{schema:e.content})]},t)),!n.sections&&r&&r.length>0&&(0,W.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,W.jsx)(`thead`,{className:`bg-muted`,children:(0,W.jsx)(`tr`,{children:n.fields?.map((e,t)=>(0,W.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,W.jsx)(`tbody`,{children:r.map((e,t)=>(0,W.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:n.fields?.map((t,n)=>(0,W.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:v(t.name,e[t.name]),children:y(e[t.name],t)},n))},t))})]})})]})]})]}):(0,W.jsx)(S,{children:(0,W.jsx)(H,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})},dt=({schedule:e,onChange:t})=>{let[n,r]=(0,U.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,W.jsxs)(S,{children:[(0,W.jsx)(I,{children:(0,W.jsxs)(F,{className:`flex items-center gap-2`,children:[(0,W.jsx)(oe,{className:`h-5 w-5`}),`Schedule Configuration`]})}),(0,W.jsxs)(H,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`checkbox`,id:`schedule-enabled`,checked:n.enabled||!1,onChange:e=>i({enabled:e.target.checked}),className:`rounded`}),(0,W.jsx)(z,{htmlFor:`schedule-enabled`,children:`Enable Scheduled Report`})]}),n.enabled&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Frequency`}),(0,W.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,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),n.frequency===`weekly`&&(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Day of Week`}),(0,W.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,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),n.frequency===`monthly`&&(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Day of Month`}),(0,W.jsx)(L,{type:`number`,min:1,max:31,value:n.dayOfMonth??1,onChange:e=>i({dayOfMonth:Number(e.target.value)})})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(z,{className:`flex items-center gap-2`,children:[(0,W.jsx)(m,{className:`h-4 w-4`}),`Time`]}),(0,W.jsx)(L,{type:`time`,value:n.time||`09:00`,onChange:e=>i({time:e.target.value})})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Timezone`}),(0,W.jsx)(L,{value:n.timezone||``,onChange:e=>i({timezone:e.target.value}),placeholder:`e.g. America/New_York`})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Export Formats`}),(0,W.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,W.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,W.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,W.jsx)(`span`,{className:`text-sm`,children:e.label})]},e.value))})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(z,{className:`flex items-center gap-2`,children:[(0,W.jsx)(M,{className:`h-4 w-4`}),`Email Recipients`]}),(0,W.jsx)(L,{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,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Email Subject`}),(0,W.jsx)(L,{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,U.useState)(t||{type:`report`,title:`New Report`,fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[l,d]=(0,U.useState)(s.fields||[]),[f,p]=(0,U.useState)(s.filters||[]),[m,h]=(0,U.useState)(s.groupBy||[]),[g,_]=(0,U.useState)(s.sections||[]),v=()=>{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})}}},b=e=>{let t=l.filter((t,n)=>n!==e);d(t),c({...s,fields:t})},C=(e,t)=>{let n=[...l];n[e]=t,d(n),c({...s,fields:n})},w=()=>{let e={field:r[0]?.name||``,operator:`equals`,value:``},t=[...f,e];p(t),c({...s,filters:t})},E=e=>{let t=f.filter((t,n)=>n!==e);p(t),c({...s,filters:t})},D=(e,t)=>{let n=[...f];n[e]=t,p(n),c({...s,filters:n})},O=()=>{let e={field:r[0]?.name||``,sort:`asc`},t=[...m,e];h(t),c({...s,groupBy:t})},A=e=>{let t=m.filter((t,n)=>n!==e);h(t),c({...s,groupBy:t})},j=(e,t)=>{let n=[...m];n[e]=t,h(n),c({...s,groupBy:n})},M=e=>{let t={type:e,title:`New ${e} Section`},n=[...g,t];_(n),c({...s,sections:n})},N=e=>{let t=g.filter((t,n)=>n!==e);_(t),c({...s,sections:t})},P=(e,t)=>{let n=[...g];n[e]=t,_(n),c({...s,sections:n})};return(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(S,{children:[(0,W.jsxs)(I,{children:[(0,W.jsx)(F,{children:`Report Builder`}),(0,W.jsx)(x,{children:`Configure your report settings, fields, filters, and sections`})]}),(0,W.jsxs)(H,{children:[(0,W.jsxs)(u,{defaultValue:`basic`,className:`w-full`,children:[(0,W.jsxs)(ce,{className:`grid w-full grid-cols-6`,children:[(0,W.jsxs)(V,{value:`basic`,children:[(0,W.jsx)(ne,{className:`h-4 w-4 mr-2`}),`Basic`]}),(0,W.jsxs)(V,{value:`fields`,children:[(0,W.jsx)(y,{className:`h-4 w-4 mr-2`}),`Fields`]}),(0,W.jsxs)(V,{value:`filters`,children:[(0,W.jsx)(te,{className:`h-4 w-4 mr-2`}),`Filters`]}),(0,W.jsxs)(V,{value:`grouping`,children:[(0,W.jsx)(y,{className:`h-4 w-4 mr-2`}),`Group By`]}),(0,W.jsxs)(V,{value:`sections`,children:[(0,W.jsx)(y,{className:`h-4 w-4 mr-2`}),`Sections`]}),(0,W.jsxs)(V,{value:`schedule`,children:[(0,W.jsx)(oe,{className:`h-4 w-4 mr-2`}),`Schedule`]})]}),(0,W.jsx)(R,{value:`basic`,className:`space-y-4 mt-4`,children:(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{htmlFor:`report-title`,children:`Report Title`}),(0,W.jsx)(L,{id:`report-title`,value:s.title||``,onChange:e=>c({...s,title:e.target.value}),placeholder:`Enter report title`})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{htmlFor:`report-description`,children:`Description`}),(0,W.jsx)(L,{id:`report-description`,value:s.description||``,onChange:e=>c({...s,description:e.target.value}),placeholder:`Enter report description`})]}),n.length>0&&(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Data Source`}),(0,W.jsxs)(`select`,{className:`w-full border rounded-md p-2`,children:[(0,W.jsx)(`option`,{value:``,children:`Select a data source`}),n.map((e,t)=>(0,W.jsxs)(`option`,{value:t,children:[`Data Source `,t+1]},t))]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{children:`Export Options`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,W.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:s.showExportButtons||!1,onChange:e=>c({...s,showExportButtons:e.target.checked})}),(0,W.jsx)(`span`,{className:`text-sm`,children:`Show Export Buttons`})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:s.showPrintButton||!1,onChange:e=>c({...s,showPrintButton:e.target.checked})}),(0,W.jsx)(`span`,{className:`text-sm`,children:`Show Print Button`})]})]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(z,{htmlFor:`export-format`,children:`Default Export Format`}),(0,W.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,W.jsx)(`option`,{value:`pdf`,children:`PDF`}),(0,W.jsx)(`option`,{value:`excel`,children:`Excel`}),(0,W.jsx)(`option`,{value:`csv`,children:`CSV`}),(0,W.jsx)(`option`,{value:`json`,children:`JSON`}),(0,W.jsx)(`option`,{value:`html`,children:`HTML`})]})]})]})}),(0,W.jsxs)(R,{value:`fields`,className:`space-y-4 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(z,{children:`Report Fields`}),(0,W.jsxs)(B,{size:`sm`,variant:`outline`,onClick:v,disabled:l.length>=r.length,children:[(0,W.jsx)(k,{className:`h-4 w-4 mr-2`}),`Add Field`]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[l.map((e,t)=>(0,W.jsx)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:(0,W.jsxs)(`div`,{className:`flex-1 grid grid-cols-4 gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Field Name`}),(0,W.jsx)(`div`,{className:`text-sm font-medium`,children:e.name})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Label`}),(0,W.jsx)(L,{className:`h-8 text-sm`,value:e.label||e.name,onChange:n=>C(t,{...e,label:n.target.value})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Aggregation`}),(0,W.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.aggregation||``,onChange:n=>C(t,{...e,aggregation:n.target.value}),children:[(0,W.jsx)(`option`,{value:``,children:`None`}),(0,W.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,W.jsx)(`option`,{value:`count`,children:`Count`}),(0,W.jsx)(`option`,{value:`avg`,children:`Average`}),(0,W.jsx)(`option`,{value:`min`,children:`Min`}),(0,W.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,W.jsx)(`div`,{className:`flex items-end justify-end`,children:(0,W.jsx)(B,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>b(t),children:(0,W.jsx)(T,{className:`h-4 w-4`})})})]})},t)),l.length===0&&(0,W.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,W.jsxs)(R,{value:`filters`,className:`space-y-4 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(z,{children:`Report Filters`}),(0,W.jsxs)(B,{size:`sm`,variant:`outline`,onClick:w,children:[(0,W.jsx)(k,{className:`h-4 w-4 mr-2`}),`Add Filter`]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[f.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,W.jsxs)(`div`,{className:`flex-1 grid grid-cols-3 gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Field`}),(0,W.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>D(t,{...e,field:n.target.value}),children:r.map((e,t)=>(0,W.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Operator`}),(0,W.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.operator,onChange:n=>D(t,{...e,operator:n.target.value}),children:[(0,W.jsx)(`option`,{value:`equals`,children:`Equals`}),(0,W.jsx)(`option`,{value:`contains`,children:`Contains`}),(0,W.jsx)(`option`,{value:`gt`,children:`Greater Than`}),(0,W.jsx)(`option`,{value:`lt`,children:`Less Than`}),(0,W.jsx)(`option`,{value:`between`,children:`Between`})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Value`}),(0,W.jsx)(L,{className:`h-8 text-sm`,value:String(e.value),onChange:n=>D(t,{...e,value:n.target.value})})]})]}),(0,W.jsx)(B,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>E(t),children:(0,W.jsx)(T,{className:`h-4 w-4`})})]},t)),f.length===0&&(0,W.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No filters defined.`})]})]}),(0,W.jsxs)(R,{value:`grouping`,className:`space-y-4 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(z,{children:`Grouping Rules`}),(0,W.jsxs)(B,{size:`sm`,variant:`outline`,onClick:O,children:[(0,W.jsx)(k,{className:`h-4 w-4 mr-2`}),`Add Group`]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[m.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,W.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Field`}),(0,W.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>j(t,{...e,field:n.target.value}),children:r.map((e,t)=>(0,W.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Sort Order`}),(0,W.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.sort||`asc`,onChange:n=>j(t,{...e,sort:n.target.value}),children:[(0,W.jsx)(`option`,{value:`asc`,children:`Ascending`}),(0,W.jsx)(`option`,{value:`desc`,children:`Descending`})]})]})]}),(0,W.jsx)(B,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>A(t),children:(0,W.jsx)(T,{className:`h-4 w-4`})})]},t)),m.length===0&&(0,W.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No grouping rules applied.`})]})]}),(0,W.jsxs)(R,{value:`sections`,className:`space-y-4 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(z,{children:`Report Sections`}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(B,{size:`sm`,variant:`outline`,onClick:()=>M(`header`),children:[(0,W.jsx)(k,{className:`h-4 w-4 mr-2`}),`Header`]}),(0,W.jsxs)(B,{size:`sm`,variant:`outline`,onClick:()=>M(`chart`),children:[(0,W.jsx)(k,{className:`h-4 w-4 mr-2`}),`Chart`]}),(0,W.jsxs)(B,{size:`sm`,variant:`outline`,onClick:()=>M(`table`),children:[(0,W.jsx)(k,{className:`h-4 w-4 mr-2`}),`Table`]})]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[g.map((e,t)=>(0,W.jsxs)(`div`,{className:`p-3 border rounded-lg space-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{className:`font-medium flex items-center gap-2`,children:[(0,W.jsx)(`div`,{className:`text-xs bg-muted px-2 py-0.5 rounded uppercase`,children:e.type}),e.title]}),(0,W.jsx)(B,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>N(t),children:(0,W.jsx)(T,{className:`h-4 w-4`})})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Title`}),(0,W.jsx)(L,{className:`h-8 text-sm`,value:e.title||``,onChange:n=>P(t,{...e,title:n.target.value})})]}),e.type===`text`&&(0,W.jsxs)(`div`,{className:`col-span-2`,children:[(0,W.jsx)(z,{className:`text-xs`,children:`Content`}),(0,W.jsx)(L,{className:`h-8 text-sm`,value:e.text||``,onChange:n=>P(t,{...e,text:n.target.value})})]}),e.type===`chart`&&(0,W.jsxs)(`div`,{className:`col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded`,children:[(0,W.jsx)(`div`,{className:`col-span-2`,children:(0,W.jsx)(z,{className:`text-xs font-semibold`,children:`Chart Configuration`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`Chart Type`}),(0,W.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.chartType||`bar`,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,chartType:n.target.value}}),children:[(0,W.jsx)(`option`,{value:`bar`,children:`Bar`}),(0,W.jsx)(`option`,{value:`line`,children:`Line`}),(0,W.jsx)(`option`,{value:`area`,children:`Area`}),(0,W.jsx)(`option`,{value:`pie`,children:`Pie`})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(z,{className:`text-xs`,children:`X-Axis Field`}),(0,W.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.xAxisField||``,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,xAxisField:n.target.value}}),children:[(0,W.jsx)(`option`,{value:``,children:`Select Field...`}),r.map(e=>(0,W.jsx)(`option`,{value:e.name,children:e.label||e.name},e.name)),r.length===0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`option`,{value:`name`,children:`Name`}),(0,W.jsx)(`option`,{value:`month`,children:`Month`})]})]})]}),(0,W.jsxs)(`div`,{className:`col-span-2`,children:[(0,W.jsx)(z,{className:`text-xs`,children:`Y-Axis Fields (comma separated)`}),(0,W.jsx)(L,{className:`h-8 text-sm`,placeholder:`e.g. value, count`,value:e.chart?.yAxisFields?.join(`, `)||``,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,yAxisFields:n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}})})]})]})]})]},t)),g.length===0&&(0,W.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,W.jsx)(R,{value:`schedule`,className:`space-y-4 mt-4`,children:(0,W.jsx)(dt,{schedule:s.schedule,onChange:e=>c({...s,schedule:e})})})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-6 pt-4 border-t`,children:[(0,W.jsx)(B,{variant:`outline`,onClick:()=>{o&&console.log(`Report cancelled:`,o)},children:`Cancel`}),(0,W.jsxs)(B,{onClick:()=>{console.log(`Saving report:`,s),a&&alert(`Report saved! (Handler: `+a+`)`)},children:[(0,W.jsx)(de,{className:`h-4 w-4 mr-2`}),`Save Report`]})]})]})]}),i&&(0,W.jsxs)(S,{className:`mt-8 border-2 border-blue-100`,children:[(0,W.jsx)(I,{className:`bg-blue-50/50`,children:(0,W.jsx)(F,{className:`text-blue-900 text-sm uppercase tracking-wide`,children:`Live Preview`})}),(0,W.jsx)(H,{className:`pt-6`,children:(0,W.jsx)(ut,{schema:{type:`report-viewer`,report:{...s,fields:l,filters:f,groupBy:m,sections:g},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]=U.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,W.jsxs)(`div`,{className:`border rounded-md bg-card text-card-foreground`,"data-testid":`joined-block-${t}`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1 p-1.5 border-b bg-muted/30`,children:[(0,W.jsx)(B,{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,W.jsx)(re,{className:`h-3.5 w-3.5`}):(0,W.jsx)(se,{className:`h-3.5 w-3.5`})}),(0,W.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,W.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,W.jsx)(`option`,{value:e,children:i(`report.editor.type${e.charAt(0).toUpperCase()}${e.slice(1)}`)},e))}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-0.5 shrink-0`,children:[(0,W.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,W.jsx)(E,{className:`h-2.5 w-2.5`})}),(0,W.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,W.jsx)(j,{className:`h-2.5 w-2.5`})})]}),(0,W.jsx)(B,{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,W.jsx)(T,{className:`h-3 w-3`})})]}),g&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 text-[10px] text-destructive bg-destructive/5 border-b`,children:[(0,W.jsx)(D,{className:`h-3 w-3`}),i(h?`report.editor.validationBlockNameRequired`:`report.editor.validationBlockNameDuplicate`)]}),l&&(0,W.jsxs)(`div`,{className:`p-2 space-y-2 text-xs`,children:[(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.blockLabel`)}),(0,W.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,W.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.objectName`)}),(0,W.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,W.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.blockDescription`)}),(0,W.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,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.columns`)}),(0,W.jsx)(It,{availableFields:r,value:e.columns,onChange:e=>_({columns:e}),t:i})]}),(f||p)&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.rows`)}),(0,W.jsx)(Lt,{availableFields:r,value:e.groupingsDown,onChange:e=>_({groupingsDown:e}),t:i})]}),p&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.columnsAxis`)}),(0,W.jsx)(Lt,{availableFields:r,value:e.groupingsAcross,onChange:e=>_({groupingsAcross:e}),t:i})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.filters`)}),(0,W.jsx)(kt,{availableFields:r,value:e.filter,onChange:e=>_({filter:e}),t:i})]}),m&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.chart`)}),(0,W.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,W.jsxs)(`div`,{className:`space-y-2`,"data-testid":`joined-blocks-editor`,children:[o.length===0&&(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic px-1`,children:a(`report.editor.validationJoinedNeedsBlocks`)}),o.map((e,t)=>(0,W.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,W.jsxs)(B,{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,W.jsx)(k,{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=U.useMemo(()=>JSON.stringify(t??null),[t]),a=U.useMemo(()=>Et(t),[i]),[o,s]=U.useState(a.group),c=U.useRef(i);U.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,W.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,W.jsx)(D,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,W.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,W.jsxs)(`div`,{className:`space-y-1.5 py-1`,"data-testid":`spec-filter-adapter`,children:[o.conditions.length>1&&(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,W.jsx)(`span`,{children:r(`report.editor.combineLogic`,`Combine with`)}),(0,W.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,W.jsx)(`option`,{value:`and`,children:`AND`}),(0,W.jsx)(`option`,{value:`or`,children:`OR`})]})]}),o.conditions.map(t=>(0,W.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1 border rounded bg-muted/20`,children:[(0,W.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,W.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,W.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,W.jsx)(`option`,{value:e.value,children:e.label},e.value))}),t.operator!==`isEmpty`&&t.operator!==`isNotEmpty`&&(0,W.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,W.jsx)(B,{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,W.jsx)(T,{className:`h-3 w-3`})})]},t.id)),(0,W.jsxs)(B,{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,W.jsx)(k,{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:f}){let[m,h]=U.useState(!1),[g,y]=U.useState(``),[x,S]=U.useState(new Set),C=U.useMemo(()=>new Set(t),[t]);U.useEffect(()=>{m&&(y(``),S(new Set))},[m]);let T=g.trim().toLowerCase(),E=e.filter(e=>!C.has(e.value)),D=T?E.filter(e=>e.label.toLowerCase().includes(T)||e.value.toLowerCase().includes(T)):E,O=e=>{if(c&&l){n([e]),h(!1);return}S(t=>{let n=new Set(c?[]:t);return t.has(e)?n.delete(e):n.add(e),n})},j=()=>{if(x.size===0){h(!1);return}n(E.map(e=>e.value).filter(e=>x.has(e))),h(!1)},M=()=>{h(!1)},N=e.length===0,P=!N&&E.length===0,F=i??r(`report.editor.addColumns`,`Add fields`),I=a??r(`report.editor.fieldPickerTitle`,`Select fields`),te=o??r(`report.editor.fieldPickerDescription`,`Pick one or more fields to add. Use the search box to narrow the list.`);return(0,W.jsxs)(_,{open:m,onOpenChange:h,children:[(0,W.jsx)(ee,{asChild:!0,children:f??(0,W.jsxs)(B,{type:`button`,variant:`outline`,size:`sm`,className:d??`h-8 gap-1.5`,disabled:u||N||P,"data-testid":`${s}-trigger`,children:[(0,W.jsx)(k,{className:`h-3.5 w-3.5`}),(0,W.jsx)(`span`,{children:F})]})}),(0,W.jsxs)(b,{className:`sm:max-w-md max-w-[92vw] gap-3`,"data-testid":`${s}-dialog`,children:[(0,W.jsxs)(fe,{children:[(0,W.jsx)(p,{children:I}),(0,W.jsx)(w,{children:te})]}),(0,W.jsxs)(`div`,{className:`relative`,children:[(0,W.jsx)(le,{className:`pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,W.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:g,onChange:e=>y(e.target.value),"data-testid":`${s}-search`,autoFocus:!0})]}),(0,W.jsxs)(`div`,{className:`text-[11px] text-muted-foreground flex items-center justify-between`,children:[(0,W.jsxs)(`span`,{children:[D.length,`/`,E.length,x.size>0?` · ${r(`report.editor.fieldPickerSelected`,`{n} selected`).replace(`{n}`,String(x.size))}`:``]}),x.size>0&&(0,W.jsx)(`button`,{type:`button`,className:`text-[11px] underline-offset-2 hover:underline text-muted-foreground`,onClick:()=>S(new Set),"data-testid":`${s}-clear`,children:r(`report.editor.fieldPickerClear`,`Clear selection`)})]}),(0,W.jsx)(`div`,{className:`max-h-72 overflow-auto border rounded bg-background/40 p-1 space-y-0.5`,"data-testid":`${s}-list`,children:N?(0,W.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.`)}):P?(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noFieldsAvailable`,`All fields already added.`)}):D.length===0?(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noMatchingFields`,`No fields match your search.`)}):D.map(e=>{let t=x.has(e.value);return(0,W.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,W.jsx)(v,{checked:t,onCheckedChange:()=>O(e.value),"data-testid":`${s}-toggle-${e.value}`}),(0,W.jsx)(`span`,{className:`flex-1 truncate`,title:e.label,children:e.label}),e.type&&(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:e.type})]},e.value)})}),!(c&&l)&&(0,W.jsxs)(A,{className:`gap-2 sm:gap-2`,children:[(0,W.jsx)(B,{type:`button`,variant:`ghost`,size:`sm`,onClick:M,"data-testid":`${s}-cancel`,children:r(`common.cancel`,`Cancel`)}),(0,W.jsx)(B,{type:`button`,size:`sm`,onClick:j,disabled:x.size===0,"data-testid":`${s}-confirm`,children:x.size>0?r(`report.editor.fieldPickerAddN`,`Add {n}`).replace(`{n}`,String(x.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,W.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,W.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`columns-editor`,children:[i.length>0&&(0,W.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,W.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,W.jsxs)(`div`,{className:`row-span-2 flex flex-col items-center justify-center gap-0.5`,children:[(0,W.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,W.jsx)(E,{className:`h-3 w-3`})}),(0,W.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,W.jsx)(j,{className:`h-3 w-3`})})]}),(0,W.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,W.jsx)(B,{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,W.jsx)(T,{className:`h-3.5 w-3.5`})}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wide`,children:r(`report.editor.aggregateColumn`,`Aggregate`)}),(0,W.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,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wide`,children:r(`report.editor.formatColumn`,`Format`)}),(0,W.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,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]})]},t.field)})}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[(0,W.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,W.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,W.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,W.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,W.jsxs)(`div`,{className:`flex flex-col gap-0.5 shrink-0`,children:[(0,W.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,W.jsx)(E,{className:`h-3 w-3`})}),(0,W.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,W.jsx)(j,{className:`h-3 w-3`})})]}),(0,W.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,W.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,W.jsx)(`span`,{className:`truncate`,children:m}),(0,W.jsx)(re,{className:`h-3 w-3 text-muted-foreground shrink-0`})]})}),(0,W.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,W.jsx)(`option`,{value:`asc`,children:r(`report.editor.sortAsc`)}),(0,W.jsx)(`option`,{value:`desc`,children:r(`report.editor.sortDesc`)})]}),p&&(0,W.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,W.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,W.jsx)(B,{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,W.jsx)(T,{className:`h-3.5 w-3.5`})})]},n)}),(0,W.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,W.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`chart-config`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartType`)}),(0,W.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,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),o&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartTitle`)}),(0,W.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,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartXAxis`)}),(0,W.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,W.jsx)(`option`,{value:``,children:`—`}),e.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartYAxis`)}),(0,W.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,W.jsx)(`option`,{value:``,children:`—`}),(h.length>0?h:e).map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,W.jsx)(v,{checked:a.showLegend!==!1,onCheckedChange:e=>l({showLegend:e===!0}),"data-testid":`chart-show-legend`}),(0,W.jsx)(`span`,{children:i(`report.editor.chartShowLegend`)})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,W.jsx)(v,{checked:!!a.showDataLabels,onCheckedChange:e=>l({showDataLabels:e===!0}),"data-testid":`chart-show-data-labels`}),(0,W.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,W.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,W.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,W.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,W.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,W.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,W.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,W.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,W.jsx)(`div`,{className:`space-y-1 p-2 border-b`,"data-testid":`report-validation-banner`,children:e.map((e,t)=>(0,W.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,W.jsx)(D,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,W.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=U.useCallback((e,t,n)=>t===void 0?s(e,n):s(e,{defaultValue:t,...n||{}}),[s]),u=a??[],d=U.useMemo(()=>zt(u,c,o),[u,c,o]),{draft:f,isDirty:p,updateField:m,discard:h}=ue(U.useMemo(()=>n??{},[n])),g=U.useCallback((e,t)=>{m(e,t),i?.(e,t,{...f,[e]:t})},[m,i,f]),_=U.useCallback(()=>{r(f),t()},[f,r,t]),v=U.useMemo(()=>Bt(f,c),[f,c]);return e?(0,W.jsx)(P,{open:e,onClose:t,schema:d,draft:f,isDirty:p,onFieldChange:g,onSave:_,onDiscard:h,headerExtra:(0,W.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:()=>Je,LegacyReportRenderer:()=>me,MatrixRenderer:()=>Ge,ReportBuilder:()=>ft,ReportConfigPanel:()=>Ht,ReportRenderer:()=>Z,ReportViewer:()=>ut,ScheduleConfig:()=>dt,SpecReportGrid:()=>Be,aggregateRows:()=>q,bucketDate:()=>he,buildAggregateQuery:()=>Te,buildDrillAction:()=>Me,collectFields:()=>we,columnKey:()=>G,createDrillHandler:()=>Pe,createScheduleTrigger:()=>Gt,exportAsCSV:()=>Xe,exportAsExcel:()=>et,exportAsHTML:()=>Qe,exportAsJSON:()=>Ze,exportAsPDF:()=>$e,exportExcelWithFormulas:()=>Wt,exportReport:()=>tt,exportWithLiveData:()=>Ut,formatValue:()=>ot,groupAndAggregate:()=>ge,groupingValue:()=>K,isDrillAction:()=>Ne,mergeFilters:()=>J,pivotRows:()=>_e,registerDrillHandler:()=>Fe,useReportData:()=>De,validateJoinedBlocks:()=>bt});o.register(`report`,Z,{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`}]}),o.register(`spec-report`,Z,{namespace:`report`,label:`Spec Report`,category:`Report`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`},{name:`type`,type:`string`,label:`Report Type`}]}),o.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`}]}),o.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{r as n,y as r}from"./vendor-react-CyVA1SE-.js";import{O as i,T as a,m as o}from"./vendor-objectstack-B5adaLmw.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-DmN5Xd7Z.js";import{Hs as m,N as h,Us as g,Ws as _}from"./ui-components-ClOuWOoQ.js";import{n as v}from"./vendor-ui-utils-BbOuugky.js";import{a as ee}from"./plugin-grid-C__XZwVh.js";var y=e(r(),1),b=n(),x=10080*60*1e3;function S(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 C(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 w(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 T({label:e,color:t}){let n=t?{backgroundColor:`${t}22`,color:t,borderColor:`${t}55`}:void 0;return(0,b.jsx)(`span`,{className:m(`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 E(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 D=({schema:e,className:t,...n})=>{let{variant:r=`vertical`,items:i=[],dateFormat:a=`short`,onItemClick:o}=e;if(r===`vertical`){let e=E(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?w(e.time,a):e.startDate?w(e.startDate,a):``,i=e.endDate&&e.endDate!==e.startDate?w(e.endDate,a):``,s=Array.isArray(e.meta)?e.meta:[];return(0,b.jsxs)(I,{density:`compact`,className:m(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,b.jsx)(R,{variant:e.color?`default`:e.variant||`default`,style:n,children:e.icon&&(0,b.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,b.jsxs)(z,{children:[(r||i)&&(0,b.jsxs)(V,{dateTime:e.time||e.startDate,className:`!mb-1 text-xs`,children:[r,i&&(0,b.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[` → `,i]})]}),e.title&&(0,b.jsx)(B,{className:`text-sm sm:text-base mb-1`,children:e.title}),s.length>0&&(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1 mb-1`,children:s.map(e=>(0,b.jsx)(T,{label:e.label,color:e.color},e.key))}),e.description&&(0,b.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,b.jsx)(`div`,{className:m(`px-4 sm:px-6 py-2`,t),...n,children:e.map((e,t)=>(0,b.jsxs)(`section`,{className:`mb-4`,children:[(0,b.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,b.jsx)(`span`,{children:e.key}),(0,b.jsx)(`span`,{className:`ml-2 text-muted-foreground/60 font-normal normal-case`,children:e.items.length})]}),(0,b.jsx)(P,{className:`mt-3`,children:e.items.map((e,n)=>s(e,`${t}-${n}`))})]},`${e.key}-${t}`))}):(0,b.jsx)(P,{className:t,...n,children:i.map((e,t)=>s(e,t))})}if(r===`horizontal`)return(0,b.jsx)(U,{className:m(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:i.map((e,t)=>(0,b.jsxs)(W,{className:m(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,b.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,b.jsx)(R,{variant:e.variant||`default`,children:e.icon&&(0,b.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,b.jsxs)(`div`,{className:`mt-4 text-center`,children:[e.time&&(0,b.jsx)(V,{dateTime:e.time,children:w(e.time,a)}),e.title&&(0,b.jsx)(B,{children:e.title}),e.description&&(0,b.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,b.jsx)(`div`,{className:`absolute left-full w-16 border-t-2 border-gray-200 top-3`})]},t))});if(r===`gantt`){let r=S(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())/x)+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,b.jsxs)(G,{className:m(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:[(0,b.jsxs)(K,{children:[(0,b.jsx)(q,{className:`flex items-center px-2 sm:px-4 py-2 sm:py-3`,children:(0,b.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:e.rowLabel||`Items`})}),(0,b.jsx)(J,{children:(0,b.jsx)(`div`,{className:`flex h-full`,children:u.map((e,t)=>(0,b.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,b.jsx)(`div`,{children:(0,b.jsxs)(`div`,{className:`flex`,children:[(0,b.jsx)(q,{children:i.map((e,t)=>(0,b.jsx)(Y,{children:(0,b.jsx)(X,{title:e.label,className:`truncate`,children:e.label})},t))}),(0,b.jsx)(J,{className:`relative`,children:i.map((e,t)=>(0,b.jsx)(Y,{className:`relative`,children:(e.items||[]).map((n,r)=>{let i=C(n.startDate,n.endDate,s,c);return(0,b.jsx)(Z,{start:i.start,width:i.width,variant:n.variant||`default`,onClick:()=>o?.(n,e,t,r),title:`${n.title||``}\n${w(n.startDate,a)} - ${w(n.endDate,a)}`,children:(0,b.jsx)(Q,{children:n.title})},r)})},t))})]})})]})}return null};p.register(`timeline`,D,{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 O={"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`},k=`timeline.bucket.today`;function A(e,t){let n=O[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}function j(){try{let e=f();return e.t(k)===k?{t:A}:{t:e.t}}catch{return{t:A}}}function te(){try{return _()}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,y.useState)([]),[f,p]=(0,y.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,y.useState)(null),[_,v]=(0,y.useState)(0),[x,S]=(0,y.useState)(null),C=e.timeline;(0,y.useEffect)(()=>{let t=ne.safeParse(e);t.success||console.warn(`[ObjectTimeline] Invalid timeline configuration:`,t.error.format())},[e]);let w=l(e.bind);(0,y.useEffect)(()=>{let n=!0;return(async()=>{if(!(!t||typeof t.getObjectSchema!=`function`||!e.objectName))try{let r=await t.getObjectSchema(e.objectName);n&&S(r)}catch(e){console.warn(`Failed to fetch object def for ObjectTimeline`,e)}})(),()=>{n=!1}},[e.objectName,t]),(0,y.useEffect)(()=>{e.objectName&&!w&&!e.items&&!a.data?(async()=>{if(!t||typeof t.find!=`function`||!e.objectName){p(!1);return}p(!0);try{let n=u(x?.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,w,e.items,a.data,_,x]);let T=a.data||w||o,{t:E}=j(),{fieldOptionLabel:O}=te(),k=C?.titleField??e.mapping?.title??e.titleField??`name`,A=C?.startDateField??e.mapping?.date??e.startDateField??e.dateField??`date`,M=C?.endDateField??e.endDateField??A,N=e.mapping?.description??e.descriptionField??`description`,P=e.mapping?.variant??`variant`,F=C?.groupByField??e.groupByField,I=C?.colorField??e.colorField,L=(0,y.useMemo)(()=>{if(e.items)return e.items;if(!T||!Array.isArray(T))return[];let t=x?.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(C?.metaFields)?C.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?O(n,e,String(t),i.label):String(t),color:i?.color}},l=T.map(e=>{let t=e[A],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[k],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 E(`timeline.bucket.noDate`);let t=d(new Date(e));return Number.isNaN(t)?E(`timeline.bucket.noDate`):t<f?E(`timeline.bucket.overdue`):t===f?E(`timeline.bucket.today`):t===f+p?E(`timeline.bucket.tomorrow`):E(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):E(`timeline.bucket.unassigned`)}})}return l.map(e=>({...e,group:g(e.startDate)}))},[e.items,T,x,e.objectName,k,A,M,N,P,I,F,E,O]),{ref:R,isRefreshing:z,pullDistance:B}=ee({onRefresh:(0,y.useCallback)(async()=>{v(e=>e+1)},[]),enabled:!!e.objectName&&!!t}),V=c({navigation:e.navigation,objectName:e.objectName,onRowClick:r??i}),H=C?.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,b.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,b.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,b.jsx)(`span`,{className:`sr-only`,children:`Loading timeline…`}),[0,1,2,3].map(e=>(0,b.jsxs)(`div`,{className:`flex items-start gap-3`,style:{opacity:Math.max(.3,1-e*.18)},children:[(0,b.jsx)(`div`,{className:`h-3 w-3 rounded-full bg-muted/70 animate-pulse mt-1.5 shrink-0`}),(0,b.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,b.jsx)(`div`,{className:`h-4 w-1/3 rounded bg-muted/70 animate-pulse`}),(0,b.jsx)(`div`,{className:`h-3 w-2/3 rounded bg-muted/50 animate-pulse`})]})]},e))]}):(0,b.jsxs)(`div`,{ref:R,className:`relative overflow-auto h-full min-w-0`,children:[B>0&&(0,b.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:B},children:z?`Refreshing…`:`Pull to refresh`}),(0,b.jsx)(D,{schema:U}),V.isOverlay&&(0,b.jsx)(h,{...V,title:`Timeline Item`,children:e=>(0,b.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,b.jsxs)(`div`,{className:`flex flex-col`,children:[(0,b.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,b.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:()=>D,TimelineTime:()=>V,TimelineTitle:()=>B,timelineItemVariants:()=>F,timelineMarkerVariants:()=>L}),P=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`ol`,{ref:n,className:m(`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=y.forwardRef(({className:e,density:t,...n},r)=>(0,b.jsx)(`li`,{ref:r,className:m(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=y.forwardRef(({className:e,variant:t=`default`,...n},r)=>(0,b.jsx)(`div`,{ref:r,className:m(L({variant:t}),e),...n}));R.displayName=`TimelineMarker`;var z=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:e,...t}));z.displayName=`TimelineContent`;var B=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`h3`,{ref:n,className:m(`font-semibold text-lg mb-1`,e),...t}));B.displayName=`TimelineTitle`;var V=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`time`,{ref:n,className:m(`text-sm font-normal text-gray-500 mb-2 block`,e),...t}));V.displayName=`TimelineTime`;var H=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`p`,{ref:n,className:m(`text-base text-gray-700`,e),...t}));H.displayName=`TimelineDescription`;var U=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:m(`relative flex overflow-x-auto py-8`,e),...t}));U.displayName=`TimelineHorizontal`;var W=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:m(`shrink-0 w-64 relative`,e),...t}));W.displayName=`TimelineHorizontalItem`;var G=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:m(`relative w-full border rounded-lg overflow-hidden`,e),...t}));G.displayName=`TimelineGantt`;var K=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:m(`flex border-b bg-gray-50`,e),...t}));K.displayName=`TimelineGanttHeader`;var q=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:m(`w-48 border-r bg-white`,e),...t}));q.displayName=`TimelineGanttRowLabels`;var J=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:m(`flex-1 overflow-x-auto`,e),...t}));J.displayName=`TimelineGanttGrid`;var Y=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:m(`flex items-center border-b min-h-12`,e),...t}));Y.displayName=`TimelineGanttRow`;var X=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:m(`px-4 py-2 font-medium text-sm truncate`,e),...t}));X.displayName=`TimelineGanttLabel`;var Z=y.forwardRef(({className:e,start:t=0,width:n=100,variant:r=`default`,...i},a)=>(0,b.jsx)(`div`,{ref:a,className:m(`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=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:m(`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,b.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{r as n,y as r}from"./vendor-react-CyVA1SE-.js";import{O as i,T as a,m as o}from"./vendor-objectstack-D6pAOWWu.js";import{H as s,N as c,U as l,dt as u,ot as d,r as f,st as p}from"./framework-Bsl5NTfe.js";import{Gs as m,N as h,Us as g,Ws as _}from"./ui-components-De4OOQs-.js";import{n as v}from"./vendor-ui-utils-BbOuugky.js";import{a as ee}from"./plugin-grid-BwTh0lXV.js";var y=e(r(),1),b=n(),x=10080*60*1e3;function S(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 C(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 w(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 T({label:e,color:t}){let n=t?{backgroundColor:`${t}22`,color:t,borderColor:`${t}55`}:void 0;return(0,b.jsx)(`span`,{className:g(`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 E(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 D=({schema:e,className:t,...n})=>{let{variant:r=`vertical`,items:i=[],dateFormat:a=`short`,onItemClick:o}=e;if(r===`vertical`){let e=E(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?w(e.time,a):e.startDate?w(e.startDate,a):``,i=e.endDate&&e.endDate!==e.startDate?w(e.endDate,a):``,s=Array.isArray(e.meta)?e.meta:[];return(0,b.jsxs)(I,{density:`compact`,className:g(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,b.jsx)(R,{variant:e.color?`default`:e.variant||`default`,style:n,children:e.icon&&(0,b.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,b.jsxs)(z,{children:[(r||i)&&(0,b.jsxs)(V,{dateTime:e.time||e.startDate,className:`!mb-1 text-xs`,children:[r,i&&(0,b.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[` → `,i]})]}),e.title&&(0,b.jsx)(B,{className:`text-sm sm:text-base mb-1`,children:e.title}),s.length>0&&(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1 mb-1`,children:s.map(e=>(0,b.jsx)(T,{label:e.label,color:e.color},e.key))}),e.description&&(0,b.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,b.jsx)(`div`,{className:g(`px-4 sm:px-6 py-2`,t),...n,children:e.map((e,t)=>(0,b.jsxs)(`section`,{className:`mb-4`,children:[(0,b.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,b.jsx)(`span`,{children:e.key}),(0,b.jsx)(`span`,{className:`ml-2 text-muted-foreground/60 font-normal normal-case`,children:e.items.length})]}),(0,b.jsx)(P,{className:`mt-3`,children:e.items.map((e,n)=>s(e,`${t}-${n}`))})]},`${e.key}-${t}`))}):(0,b.jsx)(P,{className:t,...n,children:i.map((e,t)=>s(e,t))})}if(r===`horizontal`)return(0,b.jsx)(U,{className:g(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:i.map((e,t)=>(0,b.jsxs)(W,{className:g(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,b.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,b.jsx)(R,{variant:e.variant||`default`,children:e.icon&&(0,b.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,b.jsxs)(`div`,{className:`mt-4 text-center`,children:[e.time&&(0,b.jsx)(V,{dateTime:e.time,children:w(e.time,a)}),e.title&&(0,b.jsx)(B,{children:e.title}),e.description&&(0,b.jsx)(H,{className:`text-center line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&_(e.content)]})]}),t<i.length-1&&(0,b.jsx)(`div`,{className:`absolute left-full w-16 border-t-2 border-gray-200 top-3`})]},t))});if(r===`gantt`){let r=S(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())/x)+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,b.jsxs)(G,{className:g(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:[(0,b.jsxs)(K,{children:[(0,b.jsx)(q,{className:`flex items-center px-2 sm:px-4 py-2 sm:py-3`,children:(0,b.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:e.rowLabel||`Items`})}),(0,b.jsx)(J,{children:(0,b.jsx)(`div`,{className:`flex h-full`,children:u.map((e,t)=>(0,b.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,b.jsx)(`div`,{children:(0,b.jsxs)(`div`,{className:`flex`,children:[(0,b.jsx)(q,{children:i.map((e,t)=>(0,b.jsx)(Y,{children:(0,b.jsx)(X,{title:e.label,className:`truncate`,children:e.label})},t))}),(0,b.jsx)(J,{className:`relative`,children:i.map((e,t)=>(0,b.jsx)(Y,{className:`relative`,children:(e.items||[]).map((n,r)=>{let i=C(n.startDate,n.endDate,s,c);return(0,b.jsx)(Z,{start:i.start,width:i.width,variant:n.variant||`default`,onClick:()=>o?.(n,e,t,r),title:`${n.title||``}\n${w(n.startDate,a)} - ${w(n.endDate,a)}`,children:(0,b.jsx)(Q,{children:n.title})},r)})},t))})]})})]})}return null};u.register(`timeline`,D,{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 O={"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`},k=`timeline.bucket.today`;function A(e,t){let n=O[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}function j(){try{let e=f();return e.t(k)===k?{t:A}:{t:e.t}}catch{return{t:A}}}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,l]=(0,y.useState)([]),[u,f]=(0,y.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,y.useState)(null),[_,v]=(0,y.useState)(0),[x,S]=(0,y.useState)(null),C=e.timeline;(0,y.useEffect)(()=>{let t=ne.safeParse(e);t.success||console.warn(`[ObjectTimeline] Invalid timeline configuration:`,t.error.format())},[e]);let w=s(e.bind);(0,y.useEffect)(()=>{let n=!0;return(async()=>{if(!(!t||typeof t.getObjectSchema!=`function`||!e.objectName))try{let r=await t.getObjectSchema(e.objectName);n&&S(r)}catch(e){console.warn(`Failed to fetch object def for ObjectTimeline`,e)}})(),()=>{n=!1}},[e.objectName,t]),(0,y.useEffect)(()=>{e.objectName&&!w&&!e.items&&!a.data?(async()=>{if(!t||typeof t.find!=`function`||!e.objectName){f(!1);return}f(!0);try{let n=d(x?.fields);l(p(await t.find(e.objectName,{options:{$top:100},...n.length>0?{$expand:n}:{}})))}catch(e){console.error(e),g(e)}finally{f(!1)}})():f(!1)},[e.objectName,t,w,e.items,a.data,_,x]);let T=a.data||w||o,{t:E}=j(),{fieldOptionLabel:O}=te(),k=C?.titleField??e.mapping?.title??e.titleField??`name`,A=C?.startDateField??e.mapping?.date??e.startDateField??e.dateField??`date`,M=C?.endDateField??e.endDateField??A,N=e.mapping?.description??e.descriptionField??`description`,P=e.mapping?.variant??`variant`,F=C?.groupByField??e.groupByField,I=C?.colorField??e.colorField,L=(0,y.useMemo)(()=>{if(e.items)return e.items;if(!T||!Array.isArray(T))return[];let t=x?.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(C?.metaFields)?C.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?O(n,e,String(t),i.label):String(t),color:i?.color}},l=T.map(e=>{let t=e[A],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[k],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 E(`timeline.bucket.noDate`);let t=d(new Date(e));return Number.isNaN(t)?E(`timeline.bucket.noDate`):t<f?E(`timeline.bucket.overdue`):t===f?E(`timeline.bucket.today`):t===f+p?E(`timeline.bucket.tomorrow`):E(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):E(`timeline.bucket.unassigned`)}})}return l.map(e=>({...e,group:g(e.startDate)}))},[e.items,T,x,e.objectName,k,A,M,N,P,I,F,E,O]),{ref:R,isRefreshing:z,pullDistance:B}=ee({onRefresh:(0,y.useCallback)(async()=>{v(e=>e+1)},[]),enabled:!!e.objectName&&!!t}),V=c({navigation:e.navigation,objectName:e.objectName,onRowClick:r??i}),H=C?.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,b.jsxs)(`div`,{className:`p-4 text-destructive`,"data-testid":`timeline-error`,role:`alert`,children:[`Error loading timeline: `,m.message]}):u&&(!L||L.length===0)?(0,b.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,b.jsx)(`span`,{className:`sr-only`,children:`Loading timeline…`}),[0,1,2,3].map(e=>(0,b.jsxs)(`div`,{className:`flex items-start gap-3`,style:{opacity:Math.max(.3,1-e*.18)},children:[(0,b.jsx)(`div`,{className:`h-3 w-3 rounded-full bg-muted/70 animate-pulse mt-1.5 shrink-0`}),(0,b.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,b.jsx)(`div`,{className:`h-4 w-1/3 rounded bg-muted/70 animate-pulse`}),(0,b.jsx)(`div`,{className:`h-3 w-2/3 rounded bg-muted/50 animate-pulse`})]})]},e))]}):(0,b.jsxs)(`div`,{ref:R,className:`relative overflow-auto h-full min-w-0`,children:[B>0&&(0,b.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:B},children:z?`Refreshing…`:`Pull to refresh`}),(0,b.jsx)(D,{schema:U}),V.isOverlay&&(0,b.jsx)(h,{...V,title:`Timeline Item`,children:e=>(0,b.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,b.jsxs)(`div`,{className:`flex flex-col`,children:[(0,b.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,b.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:()=>D,TimelineTime:()=>V,TimelineTitle:()=>B,timelineItemVariants:()=>F,timelineMarkerVariants:()=>L}),P=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`ol`,{ref:n,className:g(`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=y.forwardRef(({className:e,density:t,...n},r)=>(0,b.jsx)(`li`,{ref:r,className:g(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=y.forwardRef(({className:e,variant:t=`default`,...n},r)=>(0,b.jsx)(`div`,{ref:r,className:g(L({variant:t}),e),...n}));R.displayName=`TimelineMarker`;var z=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:e,...t}));z.displayName=`TimelineContent`;var B=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`h3`,{ref:n,className:g(`font-semibold text-lg mb-1`,e),...t}));B.displayName=`TimelineTitle`;var V=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`time`,{ref:n,className:g(`text-sm font-normal text-gray-500 mb-2 block`,e),...t}));V.displayName=`TimelineTime`;var H=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`p`,{ref:n,className:g(`text-base text-gray-700`,e),...t}));H.displayName=`TimelineDescription`;var U=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:g(`relative flex overflow-x-auto py-8`,e),...t}));U.displayName=`TimelineHorizontal`;var W=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:g(`shrink-0 w-64 relative`,e),...t}));W.displayName=`TimelineHorizontalItem`;var G=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:g(`relative w-full border rounded-lg overflow-hidden`,e),...t}));G.displayName=`TimelineGantt`;var K=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:g(`flex border-b bg-gray-50`,e),...t}));K.displayName=`TimelineGanttHeader`;var q=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:g(`w-48 border-r bg-white`,e),...t}));q.displayName=`TimelineGanttRowLabels`;var J=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:g(`flex-1 overflow-x-auto`,e),...t}));J.displayName=`TimelineGanttGrid`;var Y=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:g(`flex items-center border-b min-h-12`,e),...t}));Y.displayName=`TimelineGanttRow`;var X=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:g(`px-4 py-2 font-medium text-sm truncate`,e),...t}));X.displayName=`TimelineGanttLabel`;var Z=y.forwardRef(({className:e,start:t=0,width:n=100,variant:r=`default`,...i},a)=>(0,b.jsx)(`div`,{ref:a,className:g(`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=y.forwardRef(({className:e,...t},n)=>(0,b.jsx)(`div`,{ref:n,className:g(`px-2 py-1 text-white text-xs font-medium truncate`,e),...t}));Q.displayName=`TimelineGanttBarContent`;var $=({schema:e,...t})=>{let{dataSource:n}=l()||{};return(0,b.jsx)(M,{schema:e,dataSource:n,...t})};u.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`}]}),u.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};