@objectstack/console 8.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/assets/{AiPendingActionsPage-DvOWhD7g.js → AiPendingActionsPage-B9iWZUDQ.js} +1 -1
  2. package/dist/assets/{ApiConsolePage-Vl1bVDlg.js → ApiConsolePage-DJYUA73f.js} +1 -1
  3. package/dist/assets/AppManagementPage-DPljSpdo.js +1 -0
  4. package/dist/assets/{ApprovalsInboxPage-k11JteOF.js → ApprovalsInboxPage-Be6DrS7X.js} +1 -1
  5. package/dist/assets/{AuditLogPage-BAgbEbjd.js → AuditLogPage-DWQl9my4.js} +1 -1
  6. package/dist/assets/{ComponentNavView-Cu9EpRhc.js → ComponentNavView-BlNdGi6O.js} +1 -1
  7. package/dist/assets/ConsoleFloatingChatbot-DWHDGm6C.js +1 -0
  8. package/dist/assets/DeveloperHubPage-D7pt27Ji.js +1 -0
  9. package/dist/assets/FlowRunsPage-sdTkbx5s.js +1 -0
  10. package/dist/assets/{IntegrationsPage-DlDdz6C1.js → IntegrationsPage-CHg7ApBe.js} +2 -2
  11. package/dist/assets/{MonacoImpl-D8XcOOYC.js → MonacoImpl-BsJjT9SV.js} +1 -1
  12. package/dist/assets/{ProfilePage-DmAxKVba.js → ProfilePage-D7kxyCKj.js} +1 -1
  13. package/dist/assets/PublicFormsPage-DbMqDQiv.js +1 -0
  14. package/dist/assets/{RecentItemsProvider-PPHUem2M.js → RecentItemsProvider-DiJIrHwK.js} +1 -1
  15. package/dist/assets/{SettingsHub-CQQPAWJE.js → SettingsHub-DerOpof3.js} +1 -1
  16. package/dist/assets/SettingsView-BNq6smI8.js +1 -0
  17. package/dist/assets/SystemHubPage-D-J4FeqY.js +1 -0
  18. package/dist/assets/data-adapter-DlR5JXpU.js +1 -0
  19. package/dist/assets/{dist-BG5mNWi0.js → dist-DYcwLEm6.js} +1 -1
  20. package/dist/assets/{framework-D2TAXBd8.js → framework-DoGxClbR.js} +6 -6
  21. package/dist/assets/{highlighted-body-OFNGDK62-lqS5G44w.js → highlighted-body-OFNGDK62-Bu5WidAv.js} +1 -1
  22. package/dist/assets/index-CJppnf0b.css +2 -0
  23. package/dist/assets/index-DMV3FQgO.js +32 -0
  24. package/dist/assets/infrastructure-CxityHZF.js +3 -0
  25. package/dist/assets/mergeServerFields-DL5isEen.js +7 -0
  26. package/dist/assets/mermaid-GHXKKRXX-BAcku4Xs.js +1 -0
  27. package/dist/assets/plugin-calendar-DSFbexMB.js +1 -0
  28. package/dist/assets/plugin-charts-BjUzf65B.js +7 -0
  29. package/dist/assets/plugin-chatbot-DUla2_T9.js +120 -0
  30. package/dist/assets/plugin-dashboard-DbPGiGy-.js +5 -0
  31. package/dist/assets/plugin-form-CcC4fdyJ.js +1 -0
  32. package/dist/assets/{plugin-gantt-C4jqziXn.js → plugin-gantt-CEW8O7uB.js} +1 -1
  33. package/dist/assets/plugin-grid-BiWgglXK.js +6 -0
  34. package/dist/assets/plugin-kanban-C_GfAMzI.js +1 -0
  35. package/dist/assets/plugin-map-Bt30Mxn6.js +1 -0
  36. package/dist/assets/plugin-markdown-tayYSGF3.js +7 -0
  37. package/dist/assets/plugin-report-qca5M0OZ.js +59 -0
  38. package/dist/assets/{plugin-timeline-C7Y4YBw6.js → plugin-timeline-DZoFKL82.js} +1 -1
  39. package/dist/assets/plugin-view-Ei4BPIYk.js +1 -0
  40. package/dist/assets/plugins-views-BtLnemvB.js +4 -0
  41. package/dist/assets/runtime-config-ir5bt3TX.js +1 -0
  42. package/dist/assets/{src-DSLdt1DW.js → src-DOKKicsm.js} +1 -1
  43. package/dist/assets/{types-Bxt1180l.js → types-TLjbGkho.js} +1 -1
  44. package/dist/assets/ui-components-DeXgqLMc.js +42 -0
  45. package/dist/assets/{ui-layout-C7asUpWR.js → ui-layout-CvIgXgRF.js} +1 -1
  46. package/dist/assets/vendor-charts-DAigH0Ti.js +39 -0
  47. package/dist/assets/{vendor-dndkit-Ds4hJT77.js → vendor-dndkit-DMFEUxSy.js} +1 -1
  48. package/dist/assets/{vendor-i18n-D22Ua8-0.js → vendor-i18n-CdF5ccW5.js} +1 -1
  49. package/dist/assets/{vendor-icons-core-XrvLM9sL.js → vendor-icons-core-C_yMA5lO.js} +1 -1
  50. package/dist/assets/{vendor-markdown-CW3B88C8.js → vendor-markdown-C9mPywRm.js} +2 -2
  51. package/dist/assets/vendor-objectstack-B2q1QmZh.js +102 -0
  52. package/dist/assets/vendor-radix-CSVEhP0L.js +56 -0
  53. package/dist/assets/vendor-react-DR370ovB.js +11 -0
  54. package/dist/assets/vendor-sentry-Cv_7Tgs6.js +501 -0
  55. package/dist/assets/{vendor-ui-utils-CjuGfYLJ.js → vendor-ui-utils-rQOI1gAo.js} +1 -1
  56. package/dist/index.html +6 -6
  57. package/package.json +1 -1
  58. package/dist/assets/AppManagementPage-xylPiZXY.js +0 -1
  59. package/dist/assets/ConsoleFloatingChatbot-Bmrpz8kU.js +0 -1
  60. package/dist/assets/DeveloperHubPage-D0U8y334.js +0 -1
  61. package/dist/assets/FlowRunsPage-Bct8RGca.js +0 -1
  62. package/dist/assets/PublicFormsPage-DqmgJlHM.js +0 -1
  63. package/dist/assets/SettingsView-DYZF-4ez.js +0 -1
  64. package/dist/assets/SystemHubPage-c5n8TmAu.js +0 -1
  65. package/dist/assets/data-adapter-BEUY_KBa.js +0 -1
  66. package/dist/assets/index-BULCH_rU.js +0 -32
  67. package/dist/assets/index-TbUZx7_1.css +0 -2
  68. package/dist/assets/infrastructure-ai8_U_pI.js +0 -3
  69. package/dist/assets/mermaid-GHXKKRXX-9CQJi3nm.js +0 -1
  70. package/dist/assets/plugin-calendar-BJ7fznUX.js +0 -1
  71. package/dist/assets/plugin-charts-wMrfjY7-.js +0 -7
  72. package/dist/assets/plugin-chatbot-BbT-Zj0J.js +0 -120
  73. package/dist/assets/plugin-dashboard-PAzWRr0S.js +0 -3
  74. package/dist/assets/plugin-form-BCa4rKi8.js +0 -1
  75. package/dist/assets/plugin-grid-B3Vr31vQ.js +0 -6
  76. package/dist/assets/plugin-kanban-C45siRfB.js +0 -1
  77. package/dist/assets/plugin-map-BB0oqbKR.js +0 -1
  78. package/dist/assets/plugin-markdown-BD_OCMP4.js +0 -7
  79. package/dist/assets/plugin-report-DbF7QhyW.js +0 -59
  80. package/dist/assets/plugin-view-13J1AT1r.js +0 -1
  81. package/dist/assets/plugins-views-BfPWuVqp.js +0 -4
  82. package/dist/assets/ui-components-Df6BGPWS.js +0 -42
  83. package/dist/assets/useMetadata-C-bbpJVP.js +0 -7
  84. package/dist/assets/vendor-charts-4buVt82U.js +0 -39
  85. package/dist/assets/vendor-objectstack-b2m3JVRu.js +0 -83
  86. package/dist/assets/vendor-radix-Bzf7fki-.js +0 -56
  87. package/dist/assets/vendor-react-BMpe6Iqg.js +0 -13
  88. package/dist/assets/vendor-sentry-BreXt3n4.js +0 -501
@@ -0,0 +1,59 @@
1
+ import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,t as r}from"./vendor-react-DR370ovB.js";import{B as i,H as a,mt as o,nt as s,rt as c}from"./framework-DoGxClbR.js";import{n as l}from"./vendor-i18n-CdF5ccW5.js";import{At as u,Bn as d,Ca as f,Cs as p,Da as m,Fn as h,Fr as g,Gn as _,H as v,Ii as y,In as b,Jn as x,Kn as S,Ko as C,La as w,Ln as T,Mo as E,Qn as D,Qs as O,Rn as k,Rr as A,Si as j,T as M,Vn as N,Vs as P,Xn as F,Yn as I,Yr as ee,ds as te,en as L,et as ne,gi as re,in as R,ji as ie,l as ae,m as oe,mr as z,nt as se,ps as ce,qn as B,qs as le,rt as V,so as ue,tc as de,tt as H,yi as fe,zi as U,zn as pe}from"./ui-components-DeXgqLMc.js";import{r as me}from"./plugin-grid-BiWgglXK.js";var W=e(n(),1),G=r(),he=({schema:e})=>{let{title:t,description:n,data:r,columns:i}=e;e.chart?.type;let a=!!e.chart;return(0,G.jsxs)(S,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,G.jsxs)(I,{children:[t&&(0,G.jsx)(F,{children:t}),n&&(0,G.jsx)(x,{children:n})]}),(0,G.jsxs)(B,{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,G.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,G.jsx)(n,{schema:{...e.chart,data:e.chart.data||r}})}):(0,G.jsxs)(`div`,{className:`min-h-[100px] border rounded-md p-4 bg-muted/20 text-muted-foreground flex items-center justify-center`,children:[`Unknown component type: `,t||`chart`]})})(),r&&r.length>0&&(0,G.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=o.get(`grid`)||o.get(`table`);return e?(0,G.jsx)(e,{schema:{type:`grid`,rowData:r,columnDefs:i,domLayout:`autoHeight`}}):(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,G.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,G.jsx)(`tr`,{children:i?.map(e=>(0,G.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,G.jsx)(`tbody`,{children:r.map((e,t)=>(0,G.jsx)(`tr`,{className:`bg-background border-b`,children:i?.map(t=>(0,G.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function K(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function ge(e,t){if(e==null)return null;let n=e instanceof Date?e:new Date(String(e));if(Number.isNaN(n.getTime()))return null;let r=n.getUTCFullYear(),i=n.getUTCMonth(),a=n.getUTCDate();switch(t){case`year`:return String(r);case`quarter`:return`${r}-Q${Math.floor(i/3)+1}`;case`month`:return`${r}-${String(i+1).padStart(2,`0`)}`;case`week`:{let e=new Date(Date.UTC(r,i,a)),t=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-t);let n=new Date(Date.UTC(e.getUTCFullYear(),0,1)),o=Math.ceil(((e.getTime()-n.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${String(o).padStart(2,`0`)}`}case`day`:return`${r}-${String(i+1).padStart(2,`0`)}-${String(a).padStart(2,`0`)}`;default:return String(e)}}function q(e,t){let n=e[t.field];return t.dateGranularity?ge(n,t.dateGranularity)??`(empty)`:n==null||n===``?`(empty)`:String(n)}function J(e,t){let n={};for(let r of t){if(!r.aggregate){let t=e.find(e=>e[r.field]!=null);n[K(r)]=t?t[r.field]:null;continue}let t=e.map(e=>e[r.field]);switch(r.aggregate){case`count`:n[K(r)]=t.length;break;case`unique`:{let e=new Set;for(let n of t)n!=null&&e.add(n);n[K(r)]=e.size;break}case`sum`:{let e=0;for(let n of t)e+=Number(n)||0;n[K(r)]=e;break}case`avg`:{let e=0,i=0;for(let n of t){if(n==null||n===``)continue;let t=Number(n);Number.isNaN(t)||(e+=t,i+=1)}n[K(r)]=i===0?null:e/i;break}case`min`:{let e=null;for(let n of t){if(n==null)continue;let t=Number(n);Number.isNaN(t)||(e===null||t<e)&&(e=t)}n[K(r)]=e;break}case`max`:{let e=null;for(let n of t){if(n==null)continue;let t=Number(n);Number.isNaN(t)||(e===null||t>e)&&(e=t)}n[K(r)]=e;break}default:n[K(r)]=null}}return n}function _e(e,t,n,r={},i=[]){if(t.length===0)return[];let[a,...o]=t,s=new Map;for(let t of e){let e=q(t,a),n=s.get(e);n||(n=[],s.set(e,n)),n.push(t)}let c=[];for(let[e,t]of s){let s={...r,[a.field]:e},l=[...i,e],u=J(t,n),d=o.length>0?_e(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 ve(e,t,n,r){let i=ye(e,n),a=ye(e,r),o={},s={},c={};for(let c of i){o[c.id]={};let i=be(e,c.key,n);s[c.id]=J(i,t);for(let e of a){let n=be(i,e.key,r);n.length!==0&&(o[c.id][e.id]=J(n,t))}}for(let n of a){let i=be(e,n.key,r);c[n.id]=J(i,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:J(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function ye(e,t){if(t.length===0)return[{key:{},path:[],id:``}];let n=new Map;for(let r of e){let e=[],i={};for(let n of t){let t=q(r,n);e.push(t),i[n.field]=t}let a=e.join(``);n.has(a)||n.set(a,{key:i,path:e,id:a})}let r=Array.from(n.values());r.sort((e,n)=>{for(let r=0;r<t.length;r++){let i=t[r].sort===`desc`?-1:1,a=e.path[r].localeCompare(n.path[r])*i;if(a!==0)return a}return 0});let i=t[0].limit;if(typeof i==`number`&&i>0){let e=new Set;for(let t of r)e.size>=i&&!e.has(t.path[0])||e.add(t.path[0]);return r.filter(t=>e.has(t.path[0]))}return r}function be(e,t,n){let r=Object.entries(t);if(r.length===0)return e;let i=new Map;for(let e of n)i.set(e.field,e);return e.filter(e=>{for(let[t,n]of r){let r=i.get(t);if((r?q(e,r):e[t]==null?`(null)`:String(e[t]))!==String(n))return!1}return!0})}function Y(e,t){let n={};for(let r of t){if(!r.aggregate)continue;let t=K(r),i=0,a=0,o=null,s=null;for(let n of e){let e=n[t];typeof e==`number`&&(i+=e,a+=1,(o==null||e<o)&&(o=e),(s==null||e>s)&&(s=e))}r.aggregate===`min`?n[t]=o:r.aggregate===`max`?n[t]=s:r.aggregate===`avg`?n[t]=a===0?null:i/a:n[t]=i}return n}function 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]=Y(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=K(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]=Y(r,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:Y(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function 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 X(e,t){let n=e&&Object.keys(e).length>0,r=t&&Object.keys(t).length>0;if(n&&r)return{$and:[e,t]};if(n)return e;if(r)return t}function 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:K(e)})),s=X(e.filter,t),c={object:e.objectName,limit:n};return a.length>0&&(c.groupBy=a),o.length>0&&(c.aggregations=o),s&&(c.where=s),c}function Ee(e,t,n){for(let[r,i]of Object.entries(t)){let t=n.find(e=>e.field===r);if((t?q(e,t):String(e[r]??`(empty)`))!==String(i))return!1}return!0}var Z=[];function De(e,t={}){let{dataSource:n,runtimeFilter:r,maxRows:i=5e3,enabled:a=!0,rows:o,preferServerAggregation:s=!0}=t,[c,l]=(0,W.useState)(o??Z),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(()=>o?!1:!!(e&&a&&n)),[m,h]=(0,W.useState)(null),g=(0,W.useRef)(0),_=(0,W.useCallback)(async()=>{if(!e||!a)return;if(o){l(o),d(!1);return}if(!n){l(Z);return}let t=++g.current;p(!0),h(null);try{let a=s?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(Z),d(!1);return}let o=X(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(Z),d(!1)}finally{t===g.current&&p(!1)}},[e,a,o,n,r,i,s]);(0,W.useEffect)(()=>{_()},[_]);let{rows:v,totals:y,pivot:b}=(0,W.useMemo)(()=>{if(!e)return{rows:[],totals:{},pivot:null};let t=e.groupingsDown??[],n=e.groupingsAcross??[],r=e.columns??[],i=n.length>0;if(u){let e=[...t,...n],a=c.map(t=>{let n={},r=[];for(let i of e){let e=t[i.field];n[i.field]=e,r.push(e==null?`(null)`:String(e))}let i={...t};for(let t of e)delete i[t.field];return{groupKey:n,groupPath:r,values:i,count:1}}),o=Y(c,r),s=i?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?_e(c,a,r):c.map(e=>({groupKey:{},groupPath:[],values:r.length>0?J([e],r):{...e},count:1})),totals:J(c,r),pivot:i?ve(c,r,t,n):null}},[e,c,u]);return{rows:v,rawRows:c,totals:y,pivot:b,serverAggregated:u,loading:f,error:m,refetch:_,drillDown:(0,W.useCallback)(t=>{if(!e)return[];let n=[...e.groupingsDown??[],...e.groupingsAcross??[]];return c.filter(e=>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 Z}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=X(X(e.filter,n.runtimeFilter),Object.keys(t).length>0?t:void 0);return{type:`drill`,name:`drill-${e.name}`,objectName:e.objectName,...r?{filter:r}:{},view:n.view??`list`,...n.recordId===void 0?{}:{recordId:n.recordId},openIn:n.openIn??`current`}}function 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:a,actionRunner:o,drillView:s,drillOpenIn:c,className:u})=>{let d=e.type??`tabular`,{t:f}=l(),{fieldLabel:p,translateOptions:m}=de(),[h,g]=W.useState(null);W.useEffect(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`||!e.objectName)return;let r=!1;return n.getObjectSchema(e.objectName).then(e=>{r||g(e??null)}).catch(()=>{}),()=>{r=!0}},[t,e.objectName]);let _=W.useCallback(t=>{if(t.label)return String(t.label);let n=h?.fields?.[t.field]?.label??t.field,r=p(e.objectName,t.field,n);return t.aggregate?`${r} · ${f(`report.aggregate.${t.aggregate}`,t.aggregate)}`:r},[h,e.objectName,p,f]),v=W.useCallback((t,n)=>{if(n==null)return;let r=h?.fields?.[t];if(!r||!(r.type===`select`||r.type===`status`)||!Array.isArray(r.options)||r.options.length===0)return;let i=m(e.objectName,t,r.options),a=String(n);for(let e of i)if(e&&e.value!==void 0&&e.value!==null&&String(e.value)===a)return e.label==null?a:String(e.label)},[h,e.objectName,m]),{rawRows:y,rows:b,totals:x,serverAggregated:S,loading:C,error:w,drillDown:T}=De(e,{dataSource:t,rows:n,runtimeFilter:r});if(d===`matrix`||d===`joined`)return(0,G.jsxs)(`div`,{className:u,style:ze,children:[`Report type `,(0,G.jsx)(`code`,{children:d}),` is not yet supported by SpecReportGrid. It will be rendered by a dedicated component in M2 (matrix) / M3 (joined).`]});let E=W.useMemo(()=>{if(S){let t=(e.groupingsDown??[]).map(e=>({field:e.field,label:e.field.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})),n=(e.columns??[]).filter(e=>e.aggregate).map(e=>({field:K(e),label:`${(typeof e.label==`string`?e.label:null)??e.field} (${e.aggregate})`,...e.format?{format:e.format}:{}}));return{type:`object-grid`,objectName:e.objectName,columns:[...t,...n]}}let t=d===`summary`?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]),D=y,O=W.useCallback(t=>{let n=e.groupingsDown??[],i={};for(let e of n)i[e.field]=t[e.field];if(o){let t=Me(e,i,{runtimeFilter:r,view:s,openIn:c});o.execute(t)}a&&a(i,T(i))},[o,T,c,s,a,e,r]),k=!!a||!!o,A=(e.columns??[]).filter(e=>e.aggregate),j=A.length>0&&x&&Object.keys(x).length>0,M=W.useMemo(()=>d!==`summary`||!e.chart||!e.chart.type?null: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,G.jsxs)(`div`,{className:u,"data-testid":`spec-report-grid`,"aria-busy":C||void 0,children:[w?(0,G.jsx)(`div`,{role:`alert`,style:{...ze,color:`rgb(190 18 60)`},children:w.message}):null,j?(0,G.jsxs)(`div`,{"data-testid":`spec-report-totals`,className:`mb-3 flex flex-wrap items-baseline gap-x-6 gap-y-1 rounded-md border bg-muted/40 px-3 py-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:f(`report.totals`,`Totals`)}),A.map(e=>{let t=K(e),n=x[t],r=_(e),i=typeof n==`number`?n.toLocaleString(void 0,{maximumFractionDigits:2}):String(n??`—`);return(0,G.jsxs)(`span`,{"data-testid":`spec-report-total-${t}`,className:`inline-flex items-baseline gap-1.5`,children:[(0,G.jsxs)(`span`,{className:`text-muted-foreground`,children:[r,`:`]}),(0,G.jsx)(`span`,{className:`font-mono font-medium tabular-nums`,children:i})]},t)})]}):null,M?(0,G.jsx)(`div`,{className:`mb-4`,"data-testid":`spec-report-chart`,children:(0,G.jsx)(i,{schema:M})}):null,(0,G.jsx)(me,{schema:E,data:D,dataSource:t,onRowClick:k?O: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,G.jsx)(G.Fragment,{children:r}):(0,G.jsx)(G.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:_}=de(),{t:v}=l(),y=v(`report.emptyLabel`,`(Empty)`),b=v(`report.allLabel`,`(All)`),[x,S]=W.useState(null);W.useEffect(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`||!e.objectName)return;let r=!1;return n.getObjectSchema(e.objectName).then(e=>{r||S(e??null)}).catch(()=>{}),()=>{r=!0}},[t,e.objectName]);let C=e.groupingsDown??[],w=e.groupingsAcross??[],T=W.useMemo(()=>{let t=new Map,n=x?.fields??{},r=[...C,...w];for(let i of r){let r=n[i.field],a=r?.label??i.field,o=g(e.objectName,i.field,a),s=r?.type===`select`||r?.type===`status`,c;if(s&&Array.isArray(r?.options)&&r.options.length>0){let t=_(e.objectName,i.field,r.options);c=new Map;for(let e of t)e&&e.value!==void 0&&e.value!==null&&c.set(String(e.value),e.label==null?String(e.value):String(e.label))}t.set(i.field,{fieldLabel:o,options:c})}return t},[x,C,w,e.objectName,g,_]),E=W.useMemo(()=>{let t=new Map,n=x?.fields??{};for(let r of m){let i=K(r);if(r.label){t.set(i,String(r.label));continue}let a=n[r.field]?.label??r.field,o=g(e.objectName,r.field,a);if(r.aggregate){let e=v(`report.aggregate.${r.aggregate}`,r.aggregate);t.set(i,`${o} · ${e}`)}else t.set(i,o)}return t},[m,x,e.objectName,g,v]),D=W.useCallback((t,n,c)=>{let l={...t.key,...n.key};if(a){let t=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,G.jsx)(`div`,{className:O(`rounded-md border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive`,c),role:`alert`,"data-testid":`matrix-error`,children:v(`report.failedToLoad`,`Failed to load matrix: {{message}}`,{message:p.message})});if(!d)return(0,G.jsx)(`div`,{className:O(`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=C.map(e=>T.get(e.field)?.fieldLabel??e.field).join(` / `)||v(`report.rowsLabel`,`Row`),j=w.map(e=>T.get(e.field)?.fieldLabel??e.field).join(` / `)||v(`report.columnsLabel`,`Column`),M=m.length>0?K(m[0]):null,N=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>N&&(N=n)}let P=e=>{if(!M||N<=0||!e)return 0;let t=e[M];return typeof t!=`number`||t<=0?0:Math.min(1,t/N)};return(0,G.jsx)(`div`,{className:O(`overflow-auto rounded-lg border border-border bg-card shadow-sm`,c),"data-testid":`matrix-renderer`,"aria-busy":f||void 0,children:(0,G.jsxs)(`table`,{role:`table`,className:`w-full border-separate border-spacing-0 text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsxs)(`th`,{scope:`col`,className:O(`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,G.jsx)(`span`,{className:`text-muted-foreground/70`,children:A}),(0,G.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`\\`}),(0,G.jsx)(`span`,{className:`text-foreground/80`,children:j})]}),d.colHeaders.map(e=>(0,G.jsx)(`th`,{scope:`col`,className:`sticky top-0 z-20 whitespace-nowrap border-b border-border bg-muted/60 px-3 py-2 text-right text-xs font-semibold text-foreground`,children:(0,G.jsx)(We,{header:e,groupings:w,metaByField:T,fallback:b,emptyLabel:y})},`col-${e.id}`)),(0,G.jsx)(`th`,{scope:`col`,className:`sticky top-0 z-20 whitespace-nowrap border-b border-l border-border bg-muted px-3 py-2 text-right text-xs font-semibold uppercase tracking-wide text-foreground`,children:v(`report.rowTotal`,`Row Total`)})]})}),(0,G.jsx)(`tbody`,{children:d.rowHeaders.map((e,t)=>(0,G.jsxs)(`tr`,{className:`group`,children:[(0,G.jsx)(`th`,{scope:`row`,className:O(`sticky left-0 z-10 whitespace-nowrap border-b border-r border-border bg-card px-3 py-2 text-left text-sm font-medium text-foreground`,`group-hover:bg-muted/50`,t===0&&`border-t-0`),children:(0,G.jsx)(We,{header:e,groupings:C,metaByField:T,fallback:b,emptyLabel:y})}),d.colHeaders.map(t=>{let n=d.cells[e.id]?.[t.id],r=!n,i=P(n);return(0,G.jsx)(`td`,{className:O(`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?()=>D(e,t,n):void 0,"data-row":e.id,"data-col":t.id,children:r?u:Ke(m,n,h,E)},`cell-${e.id}-${t.id}`)}),(0,G.jsx)(`td`,{className:O(`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:Ke(m,d.rowTotals[e.id]??{},h,E)})]},`row-${e.id}`))}),(0,G.jsx)(`tfoot`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`row`,className:`sticky left-0 z-10 whitespace-nowrap border-t-2 border-r border-border bg-muted px-3 py-2 text-left text-xs font-semibold uppercase tracking-wide text-foreground`,children:v(`report.columnTotal`,`Column Total`)}),d.colHeaders.map(e=>(0,G.jsx)(`td`,{className:`border-t-2 border-border bg-muted/40 px-3 py-2 text-right text-sm font-semibold tabular-nums text-foreground`,children:Ke(m,d.colTotals[e.id]??{},h,E)},`coltotal-${e.id}`)),(0,G.jsx)(`td`,{className:`border-l border-t-2 border-border bg-primary/10 px-3 py-2 text-right text-sm font-bold tabular-nums text-foreground`,children:Ke(m,d.grandTotal,h,E)})]})})]})})};function Ke(e,t,n,r){return e.length?n?(0,G.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:e.map(e=>{let n=K(e);return(0,G.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r?.get(n)??e.label??n}),(0,G.jsx)(`span`,{className:`tabular-nums`,children:He(t[n])})]},n)})}):He(t[K(e[0])]):Ve}function qe(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function Je(e,t){if(!t||Object.keys(t).length===0)return e;let n=X(t,e.filter);return{...e,filter:n}}var Ye=({report:e,dataSource:t,runtimeFilter:n,actionRunner:r,drillView:i,drillOpenIn:a,className:o,renderBlock:c})=>{if(!s(e))return(0,G.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,G.jsx)(`code`,{children:`type: 'joined'`}),` and a `,(0,G.jsx)(`code`,{children:`blocks`}),` array.`]});let l=e.blocks??[],u=e.filter,d=e.objectName;return(0,G.jsx)(`div`,{className: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=Je({...e,objectName:s,type:e.type??`tabular`,columns:e.columns??[]},u),f=qe(e.label,e.name),p=e.description?qe(e.description,``):``,m=e.name??`block-${o}`,h=(0,G.jsxs)(`section`,{"data-testid":`joined-report-block`,"data-block-id":m,style:{display:`flex`,flexDirection:`column`,gap:8,border:`1px solid var(--color-border, #e4e4e7)`,borderRadius:8,padding:16,background:`var(--color-card, #ffffff)`},children:[(0,G.jsxs)(`header`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,G.jsx)(`h3`,{style:{margin:0,fontSize:16,fontWeight:600},children:f}),p?(0,G.jsx)(`p`,{style:{margin:0,fontSize:13,color:`var(--color-muted-foreground, #71717a)`},children:p}):null]}),(0,G.jsx)(nt,{schema:l,dataSource:t,runtimeFilter:n,actionRunner:r,drillView:i,drillOpenIn:a})]},m);return c?c(e,o,h):h})})};function Xe(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.dataset==`string`&&t.dataset.length>0?!0:t.type===`joined`&&Array.isArray(t.blocks)&&t.blocks.some(e=>typeof e?.dataset==`string`)}function Ze(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function Qe(e){return e==null?`—`:typeof e==`number`?Number.isInteger(e)?String(e):e.toLocaleString(void 0,{maximumFractionDigits:2}):String(e)}function $e({dataset:e,rows:t,values:n,runtimeFilter:r,dataSource:i}){let[a,o]=W.useState({status:`idle`,rows:[]}),s=JSON.stringify(r??null),c=`${e}|${t.join(`,`)}|${n.join(`,`)}|${s}`;if(W.useEffect(()=>{let a=i;if(!a||typeof a.queryDataset!=`function`){o({status:`error`,rows:[],error:`This data source does not support dataset queries.`});return}if(!e||n.length===0){o({status:`idle`,rows:[]});return}let s=!1;return o({status:`loading`,rows:[]}),a.queryDataset(e,{dimensions:t,measures:n,...r&&Object.keys(r).length>0?{runtimeFilter:r}:{}}).then(e=>{s||o({status:`ok`,rows:Array.isArray(e?.rows)?e.rows:[]})}).catch(e=>{s||o({status:`error`,rows:[],error:String(e?.message??e)})}),()=>{s=!0}},[c]),n.length===0)return(0,G.jsxs)(`div`,{className:`flex items-center justify-center rounded-md border border-dashed bg-muted/20 p-4 text-xs text-muted-foreground`,children:[`This report binds the “`,e,`” dataset — choose at least one measure (values) to render.`]});if(a.status===`loading`||a.status===`idle`)return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,G.jsx)(m,{className:`h-4 w-4 animate-spin`}),` Running report…`]});if(a.status===`error`)return(0,G.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,G.jsx)(g,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{className:`break-words`,children:a.error})]});if(a.rows.length===0)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 rounded-md border border-dashed bg-muted/20 p-6 text-xs text-muted-foreground`,children:[(0,G.jsx)(ee,{className:`h-6 w-6`}),` The dataset returned no rows for this report’s scope.`]});let l=[...t,...n];return(0,G.jsx)(`div`,{className:`overflow-auto max-h-[70vh] rounded-md border`,children:(0,G.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,G.jsx)(`thead`,{className:`bg-muted/40`,children:(0,G.jsx)(`tr`,{children:l.map(e=>(0,G.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:e},e))})}),(0,G.jsx)(`tbody`,{children:a.rows.map((e,t)=>(0,G.jsx)(`tr`,{className:`border-t`,children:l.map(t=>(0,G.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:Qe(e[t])},t))},t))})]})})}var et=({report:e,dataSource:t,runtimeFilter:n,className:r})=>{let i=X(e.runtimeFilter??e.filter,n);return e.type===`joined`&&Array.isArray(e.blocks)?(0,G.jsx)(`div`,{className:r,"data-testid":`dataset-joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:e.blocks.map((e,n)=>{let r=X(i,e.runtimeFilter??e.filter);return(0,G.jsxs)(`section`,{"data-testid":`dataset-report-block`,"data-block-id":e.name??`block-${n}`,className:`flex flex-col gap-2 rounded-lg border bg-card p-4`,children:[(0,G.jsxs)(`header`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold`,children:Ze(e.label,e.name??`Block ${n+1}`)}),e.description?(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Ze(e.description,``)}):null]}),(0,G.jsx)($e,{dataset:String(e.dataset??``),rows:Array.isArray(e.rows)?e.rows.filter(Boolean):[],values:Array.isArray(e.values)?e.values.filter(Boolean):[],runtimeFilter:r,dataSource:t})]},e.name??`block-${n}`)})}):(0,G.jsx)(`div`,{className:r,"data-testid":`dataset-report`,"data-report-name":e.name,children:(0,G.jsx)($e,{dataset:String(e.dataset??``),rows:Array.isArray(e.rows)?e.rows.filter(Boolean):[],values:Array.isArray(e.values)?e.values.filter(Boolean):[],runtimeFilter:i,dataSource:t})})},tt={border:`1px dashed var(--color-border, #d4d4d8)`,borderRadius:8,padding:16,color:`var(--color-muted-foreground, #71717a)`,background:`var(--color-muted, #f4f4f5)`,fontSize:13},nt=e=>{let{dataSource:t,rows:n,runtimeFilter:r,actionRunner:i,drillView:o,drillOpenIn:l,className:u}=e,d=W.useContext(a),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),Xe(p))return(0,G.jsx)(et,{report:p,dataSource:f,runtimeFilter:r,className:u});if(c(p)){let e=p.type??`tabular`;return e===`matrix`?(0,G.jsx)(Ge,{report:p,dataSource:f,rows:n,runtimeFilter:r,actionRunner:i,drillView:o,drillOpenIn:l,className:u}):e===`joined`?s(p)?(0,G.jsx)(Ye,{report:p,dataSource:f,runtimeFilter:r,actionRunner:i,drillView:o,drillOpenIn:l,className:u}):(0,G.jsxs)(`div`,{className:u,style:tt,"data-testid":`report-joined-placeholder`,children:[`Joined report (`,(0,G.jsx)(`code`,{children:p.name}),`) is missing a `,(0,G.jsx)(`code`,{children:`blocks`}),` array.`]}):(0,G.jsx)(Be,{report:p,dataSource:f,rows:n,runtimeFilter:r,actionRunner:i,drillView:o,drillOpenIn:l,className:u})}return(0,G.jsx)(he,{schema:p})};function rt(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=lt(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
2
+ `))?`"${n.replace(/"/g,`""`)}"`:n??``}));ft([...n?.includeHeaders===!1?[]:[i.join(`,`)],...a.map(e=>e.join(`,`))].join(`
3
+ `),n?.filename||`${e.title||`report`}.csv`,`text/csv`)}function it(e,t,n){let r={title:e.title,description:e.description,generatedAt:new Date().toISOString(),data:t};ft(JSON.stringify(r,null,2),n?.filename||`${e.title||`report`}.json`,`application/json`)}function at(e,t,n){let r=e.fields||[],i=dt(n?.orientation),a=ut(n?.pageSize);ft(`<!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 ot(e,t,n){let r=e.fields||[],i=dt(n?.orientation),a=ut(n?.pageSize),o=window.open(``,`_blank`);if(!o){at(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 st(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=lt(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
57
+ `)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));ft(``+[...n?.includeHeaders===!1?[]:[i.join(` `)],...a.map(e=>e.join(` `))].join(`
58
+ `),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function ct(e,t,n,r){switch(e){case`csv`:rt(t,n,r);break;case`json`:it(t,n,r);break;case`html`:at(t,n,r);break;case`pdf`:ot(t,n,r);break;case`excel`:st(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 lt(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 ut(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function dt(e){return e===`landscape`?`landscape`:`portrait`}function ft(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 pt(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||mt(e))return ht(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 mt(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function ht(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 gt(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 _t=({schema:e,onRefresh:t})=>{let{report:n,data:r,showToolbar:a=!0,allowExport:s=!0,allowPrint:c=!0,loading:l=!1}=e,d=e=>{if(!n){console.warn(`ReportViewer: Cannot export, no report defined`);return}ct(e,n,r||[],n.exportConfigs?.[e])},f=()=>{window.print()},p=()=>{t?.()},m=(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``}},h=(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}}},g=(e,t)=>{if(e==null||e===``)return``;if(t.renderAs===`badge`&&(!t.type||t.type===`string`||t.type===`text`))return(0,G.jsx)(D,{className:t.colorMap?.[String(e)]||``,children:String(e)});if(t.aggregation)return pt(e,t);if(t.type){let n={...t};return t.colorMap&&!n.options&&(n.options=Object.entries(t.colorMap).map(([e,t])=>({value:e,label:e,color:t}))),(0,G.jsx)(ae(oe(n)),{value:e,field:n})}return pt(e,t)};return n?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[a&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:n.title}),n.description&&(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.description})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n.refreshInterval&&(0,G.jsxs)(z,{variant:`outline`,size:`sm`,onClick:p,children:[(0,G.jsx)(ie,{className:`h-4 w-4 mr-2`}),`Refresh`]}),c&&(0,G.jsxs)(z,{variant:`outline`,size:`sm`,onClick:f,children:[(0,G.jsx)(y,{className:`h-4 w-4 mr-2`}),`Print`]}),s&&n.showExportButtons&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>d(`pdf`),children:[(0,G.jsx)(E,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,G.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>d(`excel`),children:[(0,G.jsx)(E,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,G.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>d(`csv`),children:[(0,G.jsx)(E,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,G.jsxs)(S,{children:[(0,G.jsxs)(I,{children:[!a&&n.title&&(0,G.jsx)(F,{children:n.title}),!a&&n.description&&(0,G.jsx)(x,{children:n.description})]}),(0,G.jsxs)(B,{className:`space-y-6`,children:[l&&(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,G.jsx)(S,{children:(0,G.jsxs)(B,{className:`p-4 space-y-2`,children:[(0,G.jsx)(u,{className:`h-4 w-20`}),(0,G.jsx)(u,{className:`h-8 w-28`})]})},e))}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(u,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,G.jsx)(u,{className:`h-8 w-full`},e))]})]}),!l&&n.sections?.map((e,t)=>e.visible===!1?null:(0,G.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,G.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,G.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:n.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,G.jsx)(S,{children:(0,G.jsxs)(B,{className:`p-4`,children:[(0,G.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,G.jsx)(`div`,{className:`text-2xl font-bold`,children:pt(m(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,G.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let t=e.chart.type,n=!!e.chart.chartType;!t&&n&&(t=`chart`),t&&o.get(t)||(t=`chart`);let a=t===`chart`?{xAxisKey:e.chart.xAxisKey||e.chart.xAxisField||`name`,series:e.chart.series||(e.chart.yAxisFields?e.chart.yAxisFields.map(e=>({dataKey:e})):[]),chartType:e.chart.chartType||`bar`}:{};return(0,G.jsx)(i,{schema:{...e.chart,type:t,...a,data:r||e.chart.data,className:e.chart.className||`w-full h-[350px]`}})})()}),e.type===`table`&&(0,G.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,G.jsx)(`thead`,{className:`bg-muted`,children:(0,G.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,G.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,G.jsx)(`tbody`,{children:(()=>{let t=gt(r||[],n.groupBy||[]);return t?t.map(t=>(0,G.jsxs)(W.Fragment,{children:[(0,G.jsx)(`tr`,{className:`bg-muted/60`,children:(0,G.jsxs)(`td`,{colSpan:e.columns?.length||1,className:`px-4 py-2 font-semibold text-sm`,children:[t.label,` (`,t.rows.length,`)`]})}),t.rows.map((t,n)=>(0,G.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,G.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:h(e.name,t[e.name]),children:g(t[e.name],e)},n))},n))]},t.key)):r?.map((t,n)=>(0,G.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,G.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:h(e.name,t[e.name]),children:g(t[e.name],e)},n))},n))})()})]})}),e.type===`text`&&e.text&&(0,G.jsx)(`div`,{className:`prose max-w-none`,children:(0,G.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,G.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,G.jsx)(i,{schema:e.content})]},t)),!n.sections&&r&&r.length>0&&(0,G.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,G.jsx)(`thead`,{className:`bg-muted`,children:(0,G.jsx)(`tr`,{children:n.fields?.map((e,t)=>(0,G.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,G.jsx)(`tbody`,{children:r.map((e,t)=>(0,G.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:n.fields?.map((t,n)=>(0,G.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:h(t.name,e[t.name]),children:g(e[t.name],t)},n))},t))})]})})]})]})]}):(0,G.jsx)(S,{children:(0,G.jsx)(B,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})},vt=({schedule:e,onChange:t})=>{let[n,r]=(0,W.useState)(e||{enabled:!1,frequency:`weekly`,time:`09:00`,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:[`pdf`]}),i=e=>{let i={...n,...e};r(i),t?.(i)};return(0,G.jsxs)(S,{children:[(0,G.jsx)(I,{children:(0,G.jsxs)(F,{className:`flex items-center gap-2`,children:[(0,G.jsx)(p,{className:`h-5 w-5`}),`Schedule Configuration`]})}),(0,G.jsxs)(B,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`schedule-enabled`,checked:n.enabled||!1,onChange:e=>i({enabled:e.target.checked}),className:`rounded`}),(0,G.jsx)(R,{htmlFor:`schedule-enabled`,children:`Enable Scheduled Report`})]}),n.enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(R,{children:`Frequency`}),(0,G.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:n.frequency||`weekly`,onChange:e=>i({frequency:e.target.value}),children:[{value:`once`,label:`Once`},{value:`daily`,label:`Daily`},{value:`weekly`,label:`Weekly`},{value:`monthly`,label:`Monthly`},{value:`quarterly`,label:`Quarterly`},{value:`yearly`,label:`Yearly`}].map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),n.frequency===`weekly`&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(R,{children:`Day of Week`}),(0,G.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:n.dayOfWeek??1,onChange:e=>i({dayOfWeek:Number(e.target.value)}),children:[{value:0,label:`Sunday`},{value:1,label:`Monday`},{value:2,label:`Tuesday`},{value:3,label:`Wednesday`},{value:4,label:`Thursday`},{value:5,label:`Friday`},{value:6,label:`Saturday`}].map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),n.frequency===`monthly`&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(R,{children:`Day of Month`}),(0,G.jsx)(L,{type:`number`,min:1,max:31,value:n.dayOfMonth??1,onChange:e=>i({dayOfMonth:Number(e.target.value)})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(R,{className:`flex items-center gap-2`,children:[(0,G.jsx)(C,{className:`h-4 w-4`}),`Time`]}),(0,G.jsx)(L,{type:`time`,value:n.time||`09:00`,onChange:e=>i({time:e.target.value})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(R,{children:`Timezone`}),(0,G.jsx)(L,{value:n.timezone||``,onChange:e=>i({timezone:e.target.value}),placeholder:`e.g. America/New_York`})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(R,{children:`Export Formats`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:[{value:`pdf`,label:`PDF`},{value:`excel`,label:`Excel`},{value:`csv`,label:`CSV`},{value:`html`,label:`HTML`}].map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-1.5 px-3 py-1.5 border rounded-md cursor-pointer hover:bg-muted/50`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:n.formats?.includes(e.value)||!1,onChange:t=>{let r=n.formats||[];i({formats:t.target.checked?[...r,e.value]:r.filter(t=>t!==e.value)})},className:`rounded`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e.label})]},e.value))})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(R,{className:`flex items-center gap-2`,children:[(0,G.jsx)(f,{className:`h-4 w-4`}),`Email Recipients`]}),(0,G.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,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(R,{children:`Email Subject`}),(0,G.jsx)(L,{value:n.subject||``,onChange:e=>i({subject:e.target.value}),placeholder:`Scheduled Report: {report_title}`})]})]})]})]})},yt=({schema:e})=>{let{report:t,dataSources:n=[],availableFields:r=[],showPreview:i=!0,onSave:a,onCancel:o}=e,[s,c]=(0,W.useState)(t||{type:`report`,title:`New Report`,fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[l,u]=(0,W.useState)(s.fields||[]),[d,f]=(0,W.useState)(s.filters||[]),[m,h]=(0,W.useState)(s.groupBy||[]),[g,_]=(0,W.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];u(t),c({...s,fields:t})}}},y=e=>{let t=l.filter((t,n)=>n!==e);u(t),c({...s,fields:t})},b=(e,t)=>{let n=[...l];n[e]=t,u(n),c({...s,fields:n})},C=()=>{let e={field:r[0]?.name||``,operator:`equals`,value:``},t=[...d,e];f(t),c({...s,filters:t})},T=e=>{let t=d.filter((t,n)=>n!==e);f(t),c({...s,filters:t})},E=(e,t)=>{let n=[...d];n[e]=t,f(n),c({...s,filters:n})},D=()=>{let e={field:r[0]?.name||``,sort:`asc`},t=[...m,e];h(t),c({...s,groupBy:t})},O=e=>{let t=m.filter((t,n)=>n!==e);h(t),c({...s,groupBy:t})},k=(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,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(S,{children:[(0,G.jsxs)(I,{children:[(0,G.jsx)(F,{children:`Report Builder`}),(0,G.jsx)(x,{children:`Configure your report settings, fields, filters, and sections`})]}),(0,G.jsxs)(B,{children:[(0,G.jsxs)(ne,{defaultValue:`basic`,className:`w-full`,children:[(0,G.jsxs)(se,{className:`grid w-full grid-cols-6`,children:[(0,G.jsxs)(V,{value:`basic`,children:[(0,G.jsx)(re,{className:`h-4 w-4 mr-2`}),`Basic`]}),(0,G.jsxs)(V,{value:`fields`,children:[(0,G.jsx)(w,{className:`h-4 w-4 mr-2`}),`Fields`]}),(0,G.jsxs)(V,{value:`filters`,children:[(0,G.jsx)(ue,{className:`h-4 w-4 mr-2`}),`Filters`]}),(0,G.jsxs)(V,{value:`grouping`,children:[(0,G.jsx)(w,{className:`h-4 w-4 mr-2`}),`Group By`]}),(0,G.jsxs)(V,{value:`sections`,children:[(0,G.jsx)(w,{className:`h-4 w-4 mr-2`}),`Sections`]}),(0,G.jsxs)(V,{value:`schedule`,children:[(0,G.jsx)(p,{className:`h-4 w-4 mr-2`}),`Schedule`]})]}),(0,G.jsx)(H,{value:`basic`,className:`space-y-4 mt-4`,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(R,{htmlFor:`report-title`,children:`Report Title`}),(0,G.jsx)(L,{id:`report-title`,value:s.title||``,onChange:e=>c({...s,title:e.target.value}),placeholder:`Enter report title`})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(R,{htmlFor:`report-description`,children:`Description`}),(0,G.jsx)(L,{id:`report-description`,value:s.description||``,onChange:e=>c({...s,description:e.target.value}),placeholder:`Enter report description`})]}),n.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(R,{children:`Data Source`}),(0,G.jsxs)(`select`,{className:`w-full border rounded-md p-2`,children:[(0,G.jsx)(`option`,{value:``,children:`Select a data source`}),n.map((e,t)=>(0,G.jsxs)(`option`,{value:t,children:[`Data Source `,t+1]},t))]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(R,{children:`Export Options`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:s.showExportButtons||!1,onChange:e=>c({...s,showExportButtons:e.target.checked})}),(0,G.jsx)(`span`,{className:`text-sm`,children:`Show Export Buttons`})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:s.showPrintButton||!1,onChange:e=>c({...s,showPrintButton:e.target.checked})}),(0,G.jsx)(`span`,{className:`text-sm`,children:`Show Print Button`})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(R,{htmlFor:`export-format`,children:`Default Export Format`}),(0,G.jsxs)(`select`,{id:`export-format`,className:`w-full border rounded-md p-2`,value:s.defaultExportFormat||`pdf`,onChange:e=>c({...s,defaultExportFormat:e.target.value}),children:[(0,G.jsx)(`option`,{value:`pdf`,children:`PDF`}),(0,G.jsx)(`option`,{value:`excel`,children:`Excel`}),(0,G.jsx)(`option`,{value:`csv`,children:`CSV`}),(0,G.jsx)(`option`,{value:`json`,children:`JSON`}),(0,G.jsx)(`option`,{value:`html`,children:`HTML`})]})]})]})}),(0,G.jsxs)(H,{value:`fields`,className:`space-y-4 mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(R,{children:`Report Fields`}),(0,G.jsxs)(z,{size:`sm`,variant:`outline`,onClick:v,disabled:l.length>=r.length,children:[(0,G.jsx)(U,{className:`h-4 w-4 mr-2`}),`Add Field`]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[l.map((e,t)=>(0,G.jsx)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex-1 grid grid-cols-4 gap-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(R,{className:`text-xs`,children:`Field Name`}),(0,G.jsx)(`div`,{className:`text-sm font-medium`,children:e.name})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(R,{className:`text-xs`,children:`Label`}),(0,G.jsx)(L,{className:`h-8 text-sm`,value:e.label||e.name,onChange:n=>b(t,{...e,label:n.target.value})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(R,{className:`text-xs`,children:`Aggregation`}),(0,G.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.aggregation||``,onChange:n=>b(t,{...e,aggregation:n.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:`None`}),(0,G.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,G.jsx)(`option`,{value:`count`,children:`Count`}),(0,G.jsx)(`option`,{value:`avg`,children:`Average`}),(0,G.jsx)(`option`,{value:`min`,children:`Min`}),(0,G.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,G.jsx)(`div`,{className:`flex items-end justify-end`,children:(0,G.jsx)(z,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>y(t),children:(0,G.jsx)(A,{className:`h-4 w-4`})})})]})},t)),l.length===0&&(0,G.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No fields selected. Click "Add Field" to begin.`})]})]}),(0,G.jsxs)(H,{value:`filters`,className:`space-y-4 mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(R,{children:`Report Filters`}),(0,G.jsxs)(z,{size:`sm`,variant:`outline`,onClick:C,children:[(0,G.jsx)(U,{className:`h-4 w-4 mr-2`}),`Add Filter`]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[d.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex-1 grid grid-cols-3 gap-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(R,{className:`text-xs`,children:`Field`}),(0,G.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>E(t,{...e,field:n.target.value}),children:r.map((e,t)=>(0,G.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(R,{className:`text-xs`,children:`Operator`}),(0,G.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.operator,onChange:n=>E(t,{...e,operator:n.target.value}),children:[(0,G.jsx)(`option`,{value:`equals`,children:`Equals`}),(0,G.jsx)(`option`,{value:`contains`,children:`Contains`}),(0,G.jsx)(`option`,{value:`gt`,children:`Greater Than`}),(0,G.jsx)(`option`,{value:`lt`,children:`Less Than`}),(0,G.jsx)(`option`,{value:`between`,children:`Between`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(R,{className:`text-xs`,children:`Value`}),(0,G.jsx)(L,{className:`h-8 text-sm`,value:String(e.value),onChange:n=>E(t,{...e,value:n.target.value})})]})]}),(0,G.jsx)(z,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>T(t),children:(0,G.jsx)(A,{className:`h-4 w-4`})})]},t)),d.length===0&&(0,G.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No filters defined.`})]})]}),(0,G.jsxs)(H,{value:`grouping`,className:`space-y-4 mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(R,{children:`Grouping Rules`}),(0,G.jsxs)(z,{size:`sm`,variant:`outline`,onClick:D,children:[(0,G.jsx)(U,{className:`h-4 w-4 mr-2`}),`Add Group`]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[m.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(R,{className:`text-xs`,children:`Field`}),(0,G.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>k(t,{...e,field:n.target.value}),children:r.map((e,t)=>(0,G.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(R,{className:`text-xs`,children:`Sort Order`}),(0,G.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.sort||`asc`,onChange:n=>k(t,{...e,sort:n.target.value}),children:[(0,G.jsx)(`option`,{value:`asc`,children:`Ascending`}),(0,G.jsx)(`option`,{value:`desc`,children:`Descending`})]})]})]}),(0,G.jsx)(z,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>O(t),children:(0,G.jsx)(A,{className:`h-4 w-4`})})]},t)),m.length===0&&(0,G.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No grouping rules applied.`})]})]}),(0,G.jsxs)(H,{value:`sections`,className:`space-y-4 mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(R,{children:`Report Sections`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>M(`header`),children:[(0,G.jsx)(U,{className:`h-4 w-4 mr-2`}),`Header`]}),(0,G.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>M(`chart`),children:[(0,G.jsx)(U,{className:`h-4 w-4 mr-2`}),`Chart`]}),(0,G.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>M(`table`),children:[(0,G.jsx)(U,{className:`h-4 w-4 mr-2`}),`Table`]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[g.map((e,t)=>(0,G.jsxs)(`div`,{className:`p-3 border rounded-lg space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`font-medium flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`text-xs bg-muted px-2 py-0.5 rounded uppercase`,children:e.type}),e.title]}),(0,G.jsx)(z,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>N(t),children:(0,G.jsx)(A,{className:`h-4 w-4`})})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(R,{className:`text-xs`,children:`Title`}),(0,G.jsx)(L,{className:`h-8 text-sm`,value:e.title||``,onChange:n=>P(t,{...e,title:n.target.value})})]}),e.type===`text`&&(0,G.jsxs)(`div`,{className:`col-span-2`,children:[(0,G.jsx)(R,{className:`text-xs`,children:`Content`}),(0,G.jsx)(L,{className:`h-8 text-sm`,value:e.text||``,onChange:n=>P(t,{...e,text:n.target.value})})]}),e.type===`chart`&&(0,G.jsxs)(`div`,{className:`col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded`,children:[(0,G.jsx)(`div`,{className:`col-span-2`,children:(0,G.jsx)(R,{className:`text-xs font-semibold`,children:`Chart Configuration`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(R,{className:`text-xs`,children:`Chart Type`}),(0,G.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.chartType||`bar`,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,chartType:n.target.value}}),children:[(0,G.jsx)(`option`,{value:`bar`,children:`Bar`}),(0,G.jsx)(`option`,{value:`line`,children:`Line`}),(0,G.jsx)(`option`,{value:`area`,children:`Area`}),(0,G.jsx)(`option`,{value:`pie`,children:`Pie`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(R,{className:`text-xs`,children:`X-Axis Field`}),(0,G.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.xAxisField||``,onChange:n=>P(t,{...e,chart:{...e.chart,type:`chart`,xAxisField:n.target.value}}),children:[(0,G.jsx)(`option`,{value:``,children:`Select Field...`}),r.map(e=>(0,G.jsx)(`option`,{value:e.name,children:e.label||e.name},e.name)),r.length===0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`option`,{value:`name`,children:`Name`}),(0,G.jsx)(`option`,{value:`month`,children:`Month`})]})]})]}),(0,G.jsxs)(`div`,{className:`col-span-2`,children:[(0,G.jsx)(R,{className:`text-xs`,children:`Y-Axis Fields (comma separated)`}),(0,G.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,G.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No customized sections. The default report layout will be used.`})]})]}),(0,G.jsx)(H,{value:`schedule`,className:`space-y-4 mt-4`,children:(0,G.jsx)(vt,{schedule:s.schedule,onChange:e=>c({...s,schedule:e})})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-6 pt-4 border-t`,children:[(0,G.jsx)(z,{variant:`outline`,onClick:()=>{o&&console.log(`Report cancelled:`,o)},children:`Cancel`}),(0,G.jsxs)(z,{onClick:()=>{console.log(`Saving report:`,s),a&&alert(`Report saved! (Handler: `+a+`)`)},children:[(0,G.jsx)(j,{className:`h-4 w-4 mr-2`}),`Save Report`]})]})]})]}),i&&(0,G.jsxs)(S,{className:`mt-8 border-2 border-blue-100`,children:[(0,G.jsx)(I,{className:`bg-blue-50/50`,children:(0,G.jsx)(F,{className:`text-blue-900 text-sm uppercase tracking-wide`,children:`Live Preview`})}),(0,G.jsx)(B,{className:`pt-6`,children:(0,G.jsx)(_t,{schema:{type:`report-viewer`,report:{...s,fields:l,filters:d,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`}]}})})]})]})},bt=[`tabular`,`summary`,`matrix`];function xt(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 St(e){return typeof e.label==`string`?e.label:e.label&&typeof e.label==`object`?e.label.default??``:``}function Ct(e){return typeof e.description==`string`?e.description:e.description&&typeof e.description==`object`?e.description.default??``:``}function wt({block:e,index:t,total:n,availableFields:r,t:i,duplicateName:a,onChange:o,onRemove:s,onMove:c}){let[l,u]=W.useState(t===0),d=e.type??`tabular`,f=d===`summary`,p=d===`matrix`,m=f||p,h=!e.name||!e.name.trim(),_=h||a,v=t=>o({...e,...t});return(0,G.jsxs)(`div`,{className:`border rounded-md bg-card text-card-foreground`,"data-testid":`joined-block-${t}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 p-1.5 border-b bg-muted/30`,children:[(0,G.jsx)(z,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 shrink-0`,onClick:()=>u(e=>!e),"aria-label":l?`Collapse block`:`Expand block`,"aria-expanded":l,"data-testid":`joined-block-toggle-${t}`,children:l?(0,G.jsx)(ce,{className:`h-3.5 w-3.5`}):(0,G.jsx)(te,{className:`h-3.5 w-3.5`})}),(0,G.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background flex-1 min-w-0 ${_?`border-destructive`:``}`,value:e.name??``,onChange:e=>v({name:e.target.value}),placeholder:i(`report.editor.blockNamePlaceholder`),"aria-label":i(`report.editor.blockName`),"aria-invalid":_,"data-testid":`joined-block-name-${t}`}),(0,G.jsx)(`select`,{className:`h-6 text-xs border rounded px-1 bg-background shrink-0`,value:d,onChange:e=>v({type:e.target.value}),"aria-label":i(`report.editor.type`),"data-testid":`joined-block-type-${t}`,children:bt.map(e=>(0,G.jsx)(`option`,{value:e,children:i(`report.editor.type${e.charAt(0).toUpperCase()}${e.slice(1)}`)},e))}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-0.5 shrink-0`,children:[(0,G.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===0,onClick:()=>c(-1),"aria-label":`Move block up`,children:(0,G.jsx)(P,{className:`h-2.5 w-2.5`})}),(0,G.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===n-1,onClick:()=>c(1),"aria-label":`Move block down`,children:(0,G.jsx)(le,{className:`h-2.5 w-2.5`})})]}),(0,G.jsx)(z,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0 shrink-0 text-destructive hover:text-destructive`,onClick:s,"aria-label":i(`report.editor.removeBlock`),"data-testid":`joined-block-remove-${t}`,children:(0,G.jsx)(A,{className:`h-3 w-3`})})]}),_&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 text-[10px] text-destructive bg-destructive/5 border-b`,children:[(0,G.jsx)(g,{className:`h-3 w-3`}),i(h?`report.editor.validationBlockNameRequired`:`report.editor.validationBlockNameDuplicate`)]}),l&&(0,G.jsxs)(`div`,{className:`p-2 space-y-2 text-xs`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.blockLabel`)}),(0,G.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background`,value:St(e),onChange:e=>v({label:e.target.value||void 0}),placeholder:i(`report.editor.blockLabelPlaceholder`),"data-testid":`joined-block-label-${t}`})]}),(0,G.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.objectName`)}),(0,G.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background`,value:e.objectName??``,onChange:e=>v({objectName:e.target.value||void 0}),placeholder:i(`report.editor.objectNamePlaceholder`),"data-testid":`joined-block-object-${t}`})]})]}),(0,G.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.blockDescription`)}),(0,G.jsx)(`textarea`,{className:`text-xs border rounded px-1.5 py-1 bg-background resize-y min-h-[2rem]`,rows:2,value:Ct(e),onChange:e=>v({description:e.target.value||void 0}),placeholder:i(`report.editor.blockDescriptionPlaceholder`),"data-testid":`joined-block-description-${t}`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.columns`)}),(0,G.jsx)(Ut,{availableFields:r,value:e.columns,onChange:e=>v({columns:e}),t:i})]}),(f||p)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.rows`)}),(0,G.jsx)(Wt,{availableFields:r,value:e.groupingsDown,onChange:e=>v({groupingsDown:e}),t:i})]}),p&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.columnsAxis`)}),(0,G.jsx)(Wt,{availableFields:r,value:e.groupingsAcross,onChange:e=>v({groupingsAcross:e}),t:i})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.filters`)}),(0,G.jsx)(It,{availableFields:r,value:e.filter,onChange:e=>v({filter:e}),t:i})]}),m&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.chart`)}),(0,G.jsx)(Gt,{availableFields:r,columns:Ht(e.columns),value:e.chart,onChange:e=>v({chart:e}),t:i})]})]})]})}function Tt(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 Et({value:e,onChange:t,availableFields:n,getFieldsForObject:r,containerObjectName:i,t:a}){let o=Tt(e),s=e=>r?r(e.objectName??i)??n:n,c={};for(let e of o)e.name&&(c[e.name]=(c[e.name]??0)+1);let l=(e,n)=>{t(o.map((t,r)=>r===e?n:t))},u=e=>{t(o.filter((t,n)=>n!==e))},d=(e,n)=>{let r=e+n;if(r<0||r>=o.length)return;let i=[...o];[i[e],i[r]]=[i[r],i[e]],t(i)};return(0,G.jsxs)(`div`,{className:`space-y-2`,"data-testid":`joined-blocks-editor`,children:[o.length===0&&(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic px-1`,children:a(`report.editor.validationJoinedNeedsBlocks`)}),o.map((e,t)=>(0,G.jsx)(wt,{block:e,index:t,total:o.length,availableFields:s(e),t:a,duplicateName:!!e.name&&(c[e.name]??0)>1,onChange:e=>l(t,e),onRemove:()=>u(t),onMove:e=>d(t,e)},t)),(0,G.jsxs)(z,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 text-xs w-full`,onClick:()=>{t([...o,xt(o)])},"data-testid":`joined-block-add`,children:[(0,G.jsx)(U,{className:`h-3 w-3 mr-1`}),a(`report.editor.addBlock`)]})]})}function Dt(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 Ot={$eq:`equals`,$ne:`notEquals`,$gt:`greaterThan`,$gte:`greaterOrEqual`,$lt:`lessThan`,$lte:`lessOrEqual`,$in:`in`,$nin:`notIn`,$contains:`contains`,$notContains:`notContains`,$exists:`isNotEmpty`},kt={equals:`$eq`,notEquals:`$ne`,greaterThan:`$gt`,greaterOrEqual:`$gte`,lessThan:`$lt`,lessOrEqual:`$lte`,in:`$in`,notIn:`$nin`,contains:`$contains`,notContains:`$notContains`},At=()=>({id:`root`,logic:`and`,conditions:[]});function jt(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function $(){return Math.random().toString(36).slice(2,10)}function Mt(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=Ot[r];if(!t||jt(i)&&`$field`in i)return null;n.push({id:$(),field:e,operator:t,value:i})}return n.length>0?n:null}function Nt(e){if(e==null)return{group:At(),complex:!1};if(!jt(e))return{group:At(),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:At(),complex:!0};let i=[],a=!1;for(let e of r){if(!jt(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=Mt(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:At(),complex:!0};let n=[],r=!1;for(let[t,i]of Object.entries(e)){let e=Mt(t,i);e?n.push(...e):r=!0}return{group:{id:`root`,logic:`and`,conditions:n},complex:r}}function Pt(e){if(!e||!Array.isArray(e.conditions)||e.conditions.length===0)return;let t=e.conditions.filter(e=>e.field).map(e=>Ft(e));if(t.length!==0)return t.length===1?t[0]:{[e.logic===`or`?`$or`:`$and`]:t}}function Ft(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=kt[n];return i?{[t]:{[i]:r}}:{[t]:r}}function It({availableFields:e,value:t,onChange:n,t:r}){let i=W.useMemo(()=>JSON.stringify(t??null),[t]),a=W.useMemo(()=>Nt(t),[i]),[o,s]=W.useState(a.group),c=W.useRef(i);W.useEffect(()=>{c.current!==i&&(s(a.group),c.current=i)},[i,a.group]);let l=e=>{s(e);let t=Pt(e);c.current=JSON.stringify(t??null),n(t)};if(a.complex)return(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-2 rounded border border-amber-300 bg-amber-50 text-amber-900 text-[11px]`,children:[(0,G.jsx)(g,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:r(`report.editor.filtersComplex`)})]});let u=()=>{l({...o,conditions:[...o.conditions,{id:$(),field:e[0]?.value??``,operator:`equals`,value:``}]})},d=e=>{l({...o,conditions:o.conditions.filter(t=>t.id!==e)})},f=(e,t)=>{l({...o,conditions:o.conditions.map(n=>n.id===e?{...n,...t}:n)})},p=[{value:`equals`,label:`=`},{value:`notEquals`,label:`≠`},{value:`greaterThan`,label:`>`},{value:`greaterOrEqual`,label:`≥`},{value:`lessThan`,label:`<`},{value:`lessOrEqual`,label:`≤`},{value:`contains`,label:r(`report.editor.opContains`,`contains`)},{value:`in`,label:`in`},{value:`notIn`,label:`not in`},{value:`isEmpty`,label:r(`report.editor.opIsEmpty`,`is empty`)},{value:`isNotEmpty`,label:r(`report.editor.opIsNotEmpty`,`is not empty`)}];return(0,G.jsxs)(`div`,{className:`space-y-1.5 py-1`,"data-testid":`spec-filter-adapter`,children:[o.conditions.length>1&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,G.jsx)(`span`,{children:r(`report.editor.combineLogic`,`Combine with`)}),(0,G.jsxs)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background`,value:o.logic,onChange:e=>l({...o,logic:e.target.value}),"data-testid":`filter-logic-select`,children:[(0,G.jsx)(`option`,{value:`and`,children:`AND`}),(0,G.jsx)(`option`,{value:`or`,children:`OR`})]})]}),o.conditions.map(t=>(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1 border rounded bg-muted/20`,children:[(0,G.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background flex-1 min-w-0`,value:t.field,onChange:e=>f(t.id,{field:e.target.value}),"data-testid":`filter-field-${t.id}`,children:e.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,G.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-20 shrink-0`,value:t.operator,onChange:e=>f(t.id,{operator:e.target.value}),"data-testid":`filter-op-${t.id}`,children:p.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))}),t.operator!==`isEmpty`&&t.operator!==`isNotEmpty`&&(0,G.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-24 shrink-0`,value:Array.isArray(t.value)?t.value.join(`,`):(t.value??``).toString(),placeholder:`value`,onChange:e=>{let n=e.target.value,r=t.operator===`in`||t.operator===`notIn`?n.split(`,`).map(e=>e.trim()).filter(Boolean):n;f(t.id,{value:r})},"data-testid":`filter-value-${t.id}`}),(0,G.jsx)(z,{type:`button`,size:`sm`,variant:`ghost`,className:`h-5 w-5 p-0 shrink-0`,onClick:()=>d(t.id),"data-testid":`filter-remove-${t.id}`,children:(0,G.jsx)(A,{className:`h-3 w-3`})})]},t.id)),(0,G.jsxs)(z,{type:`button`,size:`sm`,variant:`outline`,className:`h-6 text-[10px] w-full`,onClick:u,disabled:e.length===0,"data-testid":`filter-add`,children:[(0,G.jsx)(U,{className:`h-3 w-3 mr-1`}),r(`report.editor.addCondition`,`Add condition`)]})]})}var Lt=new Set([`date`,`datetime`,`time`]),Rt=new Set([`number`,`currency`,`percent`,`rating`,`integer`]);function zt({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:f,trigger:p}){let[m,g]=W.useState(!1),[v,y]=W.useState(``),[x,S]=W.useState(new Set),C=W.useMemo(()=>new Set(t),[t]);W.useEffect(()=>{m&&(y(``),S(new Set))},[m]);let w=v.trim().toLowerCase(),E=e.filter(e=>!C.has(e.value)),D=w?E.filter(e=>e.label.toLowerCase().includes(w)||e.value.toLowerCase().includes(w)):E,O=e=>{if(c&&l){n([e]),g(!1);return}S(t=>{let n=new Set(c?[]:t);return t.has(e)?n.delete(e):n.add(e),n})},A=()=>{if(x.size===0){g(!1);return}n(E.map(e=>e.value).filter(e=>x.has(e))),g(!1)},j=()=>{g(!1)},M=e.length===0,P=!M&&E.length===0,F=i??r(`report.editor.addColumns`,`Add fields`),I=a??r(`report.editor.fieldPickerTitle`,`Select fields`),ee=o??r(`report.editor.fieldPickerDescription`,`Pick one or more fields to add. Use the search box to narrow the list.`);return(0,G.jsxs)(h,{open:m,onOpenChange:g,children:[(0,G.jsx)(N,{asChild:!0,children:p??(0,G.jsxs)(z,{type:`button`,variant:`outline`,size:`sm`,className:f??`h-8 gap-1.5`,disabled:u||M||P,"data-testid":`${s}-trigger`,children:[(0,G.jsx)(U,{className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{children:F})]})}),(0,G.jsxs)(b,{className:`sm:max-w-md max-w-[92vw] gap-3`,"data-testid":`${s}-dialog`,children:[(0,G.jsxs)(pe,{children:[(0,G.jsx)(d,{children:I}),(0,G.jsx)(T,{children:ee})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(fe,{className:`pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,G.jsx)(`input`,{type:`text`,className:`h-9 w-full text-sm border rounded pl-7 pr-2 bg-background`,placeholder:r(`report.editor.searchFields`,`Search fields…`),value:v,onChange:e=>y(e.target.value),"data-testid":`${s}-search`,autoFocus:!0})]}),(0,G.jsxs)(`div`,{className:`text-[11px] text-muted-foreground flex items-center justify-between`,children:[(0,G.jsxs)(`span`,{children:[D.length,`/`,E.length,x.size>0?` · ${r(`report.editor.fieldPickerSelected`,`{n} selected`).replace(`{n}`,String(x.size))}`:``]}),x.size>0&&(0,G.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,G.jsx)(`div`,{className:`max-h-72 overflow-auto border rounded bg-background/40 p-1 space-y-0.5`,"data-testid":`${s}-list`,children:M?(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noFields`,`No fields available — pick a data source first.`)}):P?(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noFieldsAvailable`,`All fields already added.`)}):D.length===0?(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noMatchingFields`,`No fields match your search.`)}):D.map(e=>{let t=x.has(e.value);return(0,G.jsxs)(`label`,{className:`flex items-center gap-2 px-2 py-1.5 rounded hover:bg-muted/50 text-sm cursor-pointer`,"data-testid":`${s}-row-${e.value}`,children:[(0,G.jsx)(_,{checked:t,onCheckedChange:()=>O(e.value),"data-testid":`${s}-toggle-${e.value}`}),(0,G.jsx)(`span`,{className:`flex-1 truncate`,title:e.label,children:e.label}),e.type&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:e.type})]},e.value)})}),!(c&&l)&&(0,G.jsxs)(k,{className:`gap-2 sm:gap-2`,children:[(0,G.jsx)(z,{type:`button`,variant:`ghost`,size:`sm`,onClick:j,"data-testid":`${s}-cancel`,children:r(`common.cancel`,`Cancel`)}),(0,G.jsx)(z,{type:`button`,size:`sm`,onClick:A,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 Bt(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 Vt(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 Ht(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 Ut({availableFields:e,value:t,onChange:n,t:r}){let i=Ht(t),a=new Set(i.map(e=>e.field)),o=Bt(r),s=Vt(r),c=t=>{if(t.length===0)return;let r=t.filter(e=>!a.has(e)).map(t=>{let n=e.find(e=>e.value===t);return{field:t,label:n?.label,type:n?.type||`string`}});r.length!==0&&n([...i,...r])},l=e=>{n(i.filter(t=>t.field!==e))},u=(e,t)=>{n(i.map(n=>n.field===e?{...n,...t}:n))},d=(e,t)=>{let r=[...i],a=e+t;a<0||a>=r.length||([r[e],r[a]]=[r[a],r[e]],n(r))};return e.length===0?(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground py-2`,"data-testid":`columns-editor-empty`,children:r(`report.editor.noFields`,`No fields available — pick a data source first.`)}):(0,G.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`columns-editor`,children:[i.length>0&&(0,G.jsx)(`div`,{className:`space-y-1.5`,"data-testid":`columns-selected`,children:i.map((t,n)=>{let a=e.find(e=>e.value===t.field);return(0,G.jsxs)(`div`,{className:`grid grid-cols-[auto_1fr_auto] gap-1.5 p-1.5 border rounded bg-muted/30 text-xs`,"data-testid":`column-row-${t.field}`,children:[(0,G.jsxs)(`div`,{className:`row-span-2 flex flex-col items-center justify-center gap-0.5`,children:[(0,G.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===0,onClick:()=>d(n,-1),"aria-label":`Move up`,"data-testid":`column-up-${t.field}`,children:(0,G.jsx)(P,{className:`h-3 w-3`})}),(0,G.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===i.length-1,onClick:()=>d(n,1),"aria-label":`Move down`,"data-testid":`column-down-${t.field}`,children:(0,G.jsx)(le,{className:`h-3 w-3`})})]}),(0,G.jsx)(`input`,{className:`h-7 text-xs border rounded px-2 bg-background min-w-0 w-full`,value:t.label??``,placeholder:a?.label??t.field,onChange:e=>u(t.field,{label:e.target.value||void 0}),"data-testid":`column-label-${t.field}`,title:a?.label??t.field}),(0,G.jsx)(z,{type:`button`,size:`sm`,variant:`ghost`,className:`row-span-2 h-7 w-7 p-0 shrink-0 self-start`,onClick:()=>l(t.field),"data-testid":`column-remove-${t.field}`,"aria-label":`Remove column`,children:(0,G.jsx)(A,{className:`h-3.5 w-3.5`})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,G.jsxs)(`label`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wide`,children:r(`report.editor.aggregateColumn`,`Aggregate`)}),(0,G.jsx)(`select`,{className:`h-7 text-xs border rounded px-1 bg-background w-full min-w-0`,value:t.aggregate??``,onChange:e=>u(t.field,{aggregate:e.target.value===``?void 0:e.target.value}),"data-testid":`column-agg-${t.field}`,children:o.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,G.jsxs)(`label`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wide`,children:r(`report.editor.formatColumn`,`Format`)}),(0,G.jsx)(`select`,{className:`h-7 text-xs border rounded px-1 bg-background w-full min-w-0`,value:t.format??``,onChange:e=>u(t.field,{format:e.target.value===``?void 0:e.target.value}),"data-testid":`column-fmt-${t.field}`,children:s.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]})]},t.field)})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i.length>0?r(`report.editor.columnsCount`,`{n} column(s) selected`).replace(`{n}`,String(i.length)):r(`report.editor.columnsEmpty`,`No columns selected yet.`)}),(0,G.jsx)(zt,{availableFields:e,selectedValues:i.map(e=>e.field),onAdd:c,t:r,testIdPrefix:`columns-picker`,triggerLabel:r(`report.editor.addColumns`,`Add fields`)})]})]})}function Wt({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&&Lt.has(i.type??``)?a[t]?.dateGranularity:void 0})};return(0,G.jsxs)(`div`,{className:`space-y-1.5 py-1`,"data-testid":`${i}s-builder`,children:[a.map((t,n)=>{let d=e.find(e=>e.value===t.field),p=d&&Lt.has(d.type??``),m=d?.label??t.field??r(`report.editor.fieldPickerEmpty`,`(pick field)`);return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 p-1.5 border rounded bg-muted/20 text-xs`,"data-testid":`${i}-row-${n}`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-0.5 shrink-0`,children:[(0,G.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===0,onClick:()=>u(n,-1),"aria-label":`Move up`,"data-testid":`${i}-up-${n}`,children:(0,G.jsx)(P,{className:`h-3 w-3`})}),(0,G.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===a.length-1,onClick:()=>u(n,1),"aria-label":`Move down`,"data-testid":`${i}-down-${n}`,children:(0,G.jsx)(le,{className:`h-3 w-3`})})]}),(0,G.jsx)(zt,{availableFields:e,selectedValues:s.filter(e=>e!==t.field),onAdd:e=>f(n,e),t:r,singleSelect:!0,commitOnSelect:!0,testIdPrefix:`${i}-field-picker-${n}`,title:r(`report.editor.fieldPickerChangeTitle`,`Change field`),trigger:(0,G.jsxs)(`button`,{type:`button`,className:`h-7 flex-1 min-w-0 text-left text-xs border rounded px-2 bg-background hover:bg-muted/40 inline-flex items-center justify-between gap-1.5`,"data-testid":`${i}-field-${n}`,title:m,children:[(0,G.jsx)(`span`,{className:`truncate`,children:m}),(0,G.jsx)(ce,{className:`h-3 w-3 text-muted-foreground shrink-0`})]})}),(0,G.jsxs)(`select`,{className:`h-7 text-xs border rounded px-1.5 bg-background w-20 shrink-0`,value:t.sortOrder??`asc`,onChange:e=>l(n,{sortOrder:e.target.value}),"data-testid":`${i}-sort-${n}`,children:[(0,G.jsx)(`option`,{value:`asc`,children:r(`report.editor.sortAsc`)}),(0,G.jsx)(`option`,{value:`desc`,children:r(`report.editor.sortDesc`)})]}),p&&(0,G.jsx)(`select`,{className:`h-7 text-xs border rounded px-1.5 bg-background w-24 shrink-0`,value:t.dateGranularity??``,onChange:e=>l(n,{dateGranularity:e.target.value||void 0}),"data-testid":`${i}-granularity-${n}`,children:o.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,G.jsx)(z,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 shrink-0`,onClick:()=>c(n),"aria-label":`Remove grouping`,"data-testid":`${i}-remove-${n}`,children:(0,G.jsx)(A,{className:`h-3.5 w-3.5`})})]},n)}),(0,G.jsx)(zt,{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 Gt({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=>Rt.has(e.type??``)).map(e=>e.value),m=new Set([...f,...p]),h=e.filter(e=>m.has(e.value));return(0,G.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`chart-config`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartType`)}),(0,G.jsx)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:o,onChange:e=>{let t=e.target.value;t?l({type:t}):u()},"data-testid":`chart-type-select`,children:d.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),o&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartTitle`)}),(0,G.jsx)(`input`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:a.title??``,placeholder:i(`report.editor.chartTitlePlaceholder`),onChange:e=>l({title:e.target.value||void 0}),"data-testid":`chart-title`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartXAxis`)}),(0,G.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:s,onChange:e=>l({xAxis:e.target.value||void 0}),"data-testid":`chart-x-field`,children:[(0,G.jsx)(`option`,{value:``,children:`—`}),e.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartYAxis`)}),(0,G.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:c,onChange:e=>l({yAxis:e.target.value||void 0}),"data-testid":`chart-y-field`,children:[(0,G.jsx)(`option`,{value:``,children:`—`}),(h.length>0?h:e).map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,G.jsx)(_,{checked:a.showLegend!==!1,onCheckedChange:e=>l({showLegend:e===!0}),"data-testid":`chart-show-legend`}),(0,G.jsx)(`span`,{children:i(`report.editor.chartShowLegend`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,G.jsx)(_,{checked:!!a.showDataLabels,onCheckedChange:e=>l({showDataLabels:e===!0}),"data-testid":`chart-show-data-labels`}),(0,G.jsx)(`span`,{children:i(`report.editor.chartShowDataLabels`)})]})]})]})}function Kt(e,t,n){let r=e=>e.type===`summary`,i=e=>e.type===`matrix`,a=e=>e.type===`summary`||e.type===`matrix`,o=[{key:`basic`,title:t(`report.editor.basic`),fields:[{key:`label`,label:t(`report.editor.title`),type:`input`,placeholder:t(`report.editor.titlePlaceholder`)},{key:`description`,label:t(`report.editor.description`),type:`textarea`,placeholder:t(`report.editor.descriptionPlaceholder`)},{key:`type`,label:t(`report.editor.type`),type:`select`,defaultValue:`tabular`,options:[{value:`tabular`,label:t(`report.editor.typeTabular`)},{value:`summary`,label:t(`report.editor.typeSummary`)},{value:`matrix`,label:t(`report.editor.typeMatrix`)},{value:`joined`,label:t(`report.editor.typeJoined`)}],helpText:t(`report.editor.typeHelp`)}]},{key:`data`,title:t(`report.editor.data`),collapsible:!0,fields:[{key:`objectName`,label:t(`report.editor.objectName`),type:`input`,placeholder:t(`report.editor.objectNamePlaceholder`),helpText:t(`report.editor.objectNameHelp`)},{key:`limit`,label:t(`report.editor.limit`),type:`input`,placeholder:t(`report.editor.limitPlaceholder`)}]},{key:`rows`,title:t(`report.editor.rows`),collapsible:!0,hint:t(`report.editor.rowsHint`),visibleWhen:e=>r(e)||i(e),fields:[{key:`groupingsDown`,label:t(`report.editor.grouping`),type:`custom`,render:(n,r)=>(0,G.jsx)(Wt,{availableFields:e,value:n,onChange:r,t,testIdPrefix:`rows-grouping`})}]},{key:`columnsAxis`,title:t(`report.editor.columnsAxis`),collapsible:!0,hint:t(`report.editor.columnsAxisHint`),visibleWhen:e=>i(e),fields:[{key:`groupingsAcross`,label:t(`report.editor.grouping`),type:`custom`,render:(n,r)=>(0,G.jsx)(Wt,{availableFields:e,value:n,onChange:r,t,testIdPrefix:`cols-grouping`})}]},{key:`tabular-columns`,title:t(`report.editor.columns`),collapsible:!0,hint:t(`report.editor.columnsHint`),visibleWhen:e=>e.type!==`joined`&&!r(e)&&!i(e),fields:[{key:`columns`,label:t(`report.editor.columns`),type:`custom`,render:(n,r)=>(0,G.jsx)(Ut,{availableFields:e,value:n,onChange:r,t})}]},{key:`values`,title:t(`report.editor.values`),collapsible:!0,hint:t(`report.editor.valuesHint`),visibleWhen:e=>r(e)||i(e),fields:[{key:`columns`,label:t(`report.editor.values`),type:`custom`,render:(n,r)=>(0,G.jsx)(Ut,{availableFields:e,value:n,onChange:r,t})}]},{key:`filters`,title:t(`report.editor.filters`),collapsible:!0,hint:t(`report.editor.filtersHint`),visibleWhen:e=>e.type!==`joined`,fields:[{key:`filter`,label:t(`report.editor.filters`),type:`custom`,render:(n,r)=>(0,G.jsx)(It,{availableFields:e,value:n,onChange:r,t})}]},{key:`blocks`,title:t(`report.editor.blocks`),collapsible:!0,hint:t(`report.editor.blocksHint`),visibleWhen:e=>e.type===`joined`,fields:[{key:`blocks`,label:t(`report.editor.blocks`),type:`custom`,render:(r,i,a)=>(0,G.jsx)(Et,{value:r,onChange:i,availableFields:e,getFieldsForObject:n,containerObjectName:a?.objectName,t})}]},{key:`chart`,title:t(`report.editor.chart`),collapsible:!0,defaultCollapsed:!0,hint:t(`report.editor.chartHint`),visibleWhen:e=>a(e),fields:[{key:`chart`,label:t(`report.editor.chart`),type:`custom`,render:(n,r,i)=>(0,G.jsx)(Gt,{availableFields:e,columns:Ht(i.columns),value:n,onChange:r,t})}]}];return{breadcrumb:[t(`report.editor.breadcrumb`,`Configuration`)],sections:o}}function qt(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 Dt(e.blocks,t))n.push({level:`error`,message:r});return n}function Jt({problems:e}){return e.length===0?null:(0,G.jsx)(`div`,{className:`space-y-1 p-2 border-b`,"data-testid":`report-validation-banner`,children:e.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] rounded px-2 py-1 `+(e.level===`error`?`bg-red-50 border border-red-200 text-red-900`:`bg-amber-50 border border-amber-200 text-amber-900`),children:[(0,G.jsx)(g,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:e.message})]},t))})}function Yt({open:e,onClose:t,config:n,onSave:r,onFieldChange:i,availableFields:a,getFieldsForObject:o}){let{t:s}=l(),c=W.useCallback((e,t,n)=>t===void 0?s(e,n):s(e,{defaultValue:t,...n||{}}),[s]),u=a??[],d=W.useMemo(()=>Kt(u,c,o),[u,c,o]),{draft:f,isDirty:p,updateField:m,discard:h}=M(W.useMemo(()=>n??{},[n])),g=W.useCallback((e,t)=>{m(e,t),i?.(e,t,{...f,[e]:t})},[m,i,f]),_=W.useCallback(()=>{r(f),t()},[f,r,t]),y=W.useMemo(()=>qt(f,c),[f,c]);return e?(0,G.jsx)(v,{open:e,onClose:t,schema:d,draft:f,isDirty:p,onFieldChange:g,onSave:_,onDiscard:h,headerExtra:(0,G.jsx)(Jt,{problems:y}),style:{"--config-panel-width":`440px`}}):null}async function Xt(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 ct(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 Zt(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map($t),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 en(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=nn(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)}an(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
59
+ `),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function Qt(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 Xt(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function $t(e){return{name:e.name,header:e.label||e.name}}function en(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,tn(t)):rn(String(e))}function tn(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 nn(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function rn(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function an(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 on=t({DatasetReportRenderer:()=>et,JoinedBlocksEditor:()=>Et,JoinedReportRenderer:()=>Ye,LegacyReportRenderer:()=>he,MatrixRenderer:()=>Ge,ReportBuilder:()=>yt,ReportConfigPanel:()=>Yt,ReportRenderer:()=>nt,ReportViewer:()=>_t,ScheduleConfig:()=>vt,SpecReportGrid:()=>Be,aggregateRows:()=>J,bucketDate:()=>ge,buildAggregateQuery:()=>Te,buildDrillAction:()=>Me,collectFields:()=>we,columnKey:()=>K,createDrillHandler:()=>Pe,createScheduleTrigger:()=>Qt,exportAsCSV:()=>rt,exportAsExcel:()=>st,exportAsHTML:()=>at,exportAsJSON:()=>it,exportAsPDF:()=>ot,exportExcelWithFormulas:()=>Zt,exportReport:()=>ct,exportWithLiveData:()=>Xt,formatValue:()=>pt,groupAndAggregate:()=>_e,groupingValue:()=>q,isDatasetReport:()=>Xe,isDrillAction:()=>Ne,mergeFilters:()=>X,pivotRows:()=>ve,registerDrillHandler:()=>Fe,useReportData:()=>De,validateJoinedBlocks:()=>Dt});o.register(`report`,nt,{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`,nt,{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`,_t,{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`,yt,{namespace:`report`,label:`Report Builder`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Initial Report`}]});export{on 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-BMpe6Iqg.js";import{F as i,G as a,W as o,ct as s,lt as c,pt as l,r as u}from"./framework-D2TAXBd8.js";import{M as d,k as f,v as p}from"./vendor-objectstack-b2m3JVRu.js";import{P as m,Xs as h,Ys as g,Zs as _}from"./ui-components-Df6BGPWS.js";import{i as v}from"./vendor-ui-utils-CjuGfYLJ.js";import{a as y}from"./plugin-grid-B3Vr31vQ.js";var b=e(r(),1),x=n(),S=10080*60*1e3;function C(e){let t=e.flatMap(e=>(e.items||[]).flatMap(e=>[e.startDate,e.endDate])),n=Math.min(...t.map(e=>new Date(e).getTime())),r=Math.max(...t.map(e=>new Date(e).getTime()));return{minDate:new Date(n).toISOString().split(`T`)[0],maxDate:new Date(r).toISOString().split(`T`)[0]}}function w(e,t,n,r){let i=new Date(e).getTime(),a=new Date(t).getTime(),o=new Date(n).getTime(),s=new Date(r).getTime()-o,c=i-o,l=a-i;return{start:c/s*100,width:l/s*100}}function T(e,t){let n=new Date(e);return t===`short`?n.toLocaleDateString():t===`long`?n.toLocaleDateString(`en-US`,{year:`numeric`,month:`long`,day:`numeric`}):n.toISOString().split(`T`)[0]}function E({label:e,color:t}){let n=t?{backgroundColor:`${t}22`,color:t,borderColor:`${t}55`}:void 0;return(0,x.jsx)(`span`,{className: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 D(e){let t=[];for(let n of e){let e=n.group==null?``:String(n.group),r=t[t.length-1];r&&r.key===e?r.items.push(n):t.push({key:e,items:[n]})}return t}var O=({schema:e,className:t,...n})=>{let{variant:r=`vertical`,items:i=[],dateFormat:a=`short`,onItemClick:o}=e;if(r===`vertical`){let e=D(i),r=e.some(e=>e.key!==``),s=(e,t)=>{let n=e.color?{backgroundColor:`${e.color}33`,borderColor:e.color}:void 0,r=e.time?T(e.time,a):e.startDate?T(e.startDate,a):``,i=e.endDate&&e.endDate!==e.startDate?T(e.endDate,a):``,s=Array.isArray(e.meta)?e.meta:[];return(0,x.jsxs)(I,{density:`compact`,className:g(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,x.jsx)(R,{variant:e.color?`default`:e.variant||`default`,style:n,children:e.icon&&(0,x.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,x.jsxs)(z,{children:[(r||i)&&(0,x.jsxs)(V,{dateTime:e.time||e.startDate,className:`!mb-1 text-xs`,children:[r,i&&(0,x.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[` → `,i]})]}),e.title&&(0,x.jsx)(B,{className:`text-sm sm:text-base mb-1`,children:e.title}),s.length>0&&(0,x.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1 mb-1`,children:s.map(e=>(0,x.jsx)(E,{label:e.label,color:e.color},e.key))}),e.description&&(0,x.jsx)(H,{className:`text-sm text-muted-foreground line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&h(e.content)]})]},t)};return r?(0,x.jsx)(`div`,{className:g(`px-4 sm:px-6 py-2`,t),...n,children:e.map((e,t)=>(0,x.jsxs)(`section`,{className:`mb-4`,children:[(0,x.jsxs)(`header`,{className:`sticky top-0 z-10 -mx-4 sm:-mx-6 px-4 sm:px-6 py-1.5 backdrop-blur bg-background/90 text-xs font-semibold uppercase tracking-wide text-muted-foreground border-b`,children:[(0,x.jsx)(`span`,{children:e.key}),(0,x.jsx)(`span`,{className:`ml-2 text-muted-foreground/60 font-normal normal-case`,children:e.items.length})]}),(0,x.jsx)(P,{className:`mt-3`,children:e.items.map((e,n)=>s(e,`${t}-${n}`))})]},`${e.key}-${t}`))}):(0,x.jsx)(P,{className:t,...n,children:i.map((e,t)=>s(e,t))})}if(r===`horizontal`)return(0,x.jsx)(U,{className:g(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:i.map((e,t)=>(0,x.jsxs)(W,{className:g(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,x.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,x.jsx)(R,{variant:e.variant||`default`,children:e.icon&&(0,x.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,x.jsxs)(`div`,{className:`mt-4 text-center`,children:[e.time&&(0,x.jsx)(V,{dateTime:e.time,children:T(e.time,a)}),e.title&&(0,x.jsx)(B,{children:e.title}),e.description&&(0,x.jsx)(H,{className:`text-center line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&h(e.content)]})]}),t<i.length-1&&(0,x.jsx)(`div`,{className:`absolute left-full w-16 border-t-2 border-gray-200 top-3`})]},t))});if(r===`gantt`){let r=C(i),s=e.minDate||r.minDate,c=e.maxDate||r.maxDate,l=e.timeScale||`month`,u=(()=>{let e=[],t=new Date(s),n=new Date(c);if(l===`month`){let r=new Date(t);for(;r<=n;)e.push(r.toLocaleDateString(`en-US`,{month:`short`,year:`numeric`})),r.setMonth(r.getMonth()+1)}else if(l===`week`){let r=new Date(t);for(;r<=n;)e.push(`Week ${Math.ceil((r.getTime()-t.getTime())/S)+1}`),r.setDate(r.getDate()+7)}else if(l===`day`){let r=new Date(t);for(;r<=n;)e.push(r.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})),r.setDate(r.getDate()+1)}return e})();return(0,x.jsxs)(G,{className:g(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:[(0,x.jsxs)(K,{children:[(0,x.jsx)(q,{className:`flex items-center px-2 sm:px-4 py-2 sm:py-3`,children:(0,x.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:e.rowLabel||`Items`})}),(0,x.jsx)(J,{children:(0,x.jsx)(`div`,{className:`flex h-full`,children:u.map((e,t)=>(0,x.jsx)(`div`,{className:`flex-1 px-1 sm:px-2 py-2 sm:py-3 border-r text-xs font-medium text-center`,children:e},t))})})]}),(0,x.jsx)(`div`,{children:(0,x.jsxs)(`div`,{className:`flex`,children:[(0,x.jsx)(q,{children:i.map((e,t)=>(0,x.jsx)(Y,{children:(0,x.jsx)(X,{title:e.label,className:`truncate`,children:e.label})},t))}),(0,x.jsx)(J,{className:`relative`,children:i.map((e,t)=>(0,x.jsx)(Y,{className:`relative`,children:(e.items||[]).map((n,r)=>{let i=w(n.startDate,n.endDate,s,c);return(0,x.jsx)(Z,{start:i.start,width:i.width,variant:n.variant||`default`,onClick:()=>o?.(n,e,t,r),title:`${n.title||``}\n${T(n.startDate,a)} - ${T(n.endDate,a)}`,children:(0,x.jsx)(Q,{children:n.title})},r)})},t))})]})})]})}return null};l.register(`timeline`,O,{namespace:`plugin-timeline`,label:`Timeline`,category:`data-display`,inputs:[{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],label:`Timeline Variant`,defaultValue:`vertical`},{name:`items`,type:`array`,label:`Timeline Items`,description:`For vertical/horizontal: Array of { time, title, description, variant, icon, content }. For gantt: Array of { label, items: [{ title, startDate, endDate, variant }] }`},{name:`dateFormat`,type:`enum`,enum:[`short`,`long`,`iso`],label:`Date Format`,defaultValue:`short`},{name:`timeScale`,type:`enum`,enum:[`day`,`week`,`month`],label:`Time Scale (Gantt only)`,defaultValue:`month`},{name:`rowLabel`,type:`string`,label:`Row Label (Gantt only)`,defaultValue:`Items`},{name:`minDate`,type:`string`,label:`Min Date (Gantt only)`,description:`Override auto-calculated min date (YYYY-MM-DD)`},{name:`maxDate`,type:`string`,label:`Max Date (Gantt only)`,description:`Override auto-calculated max date (YYYY-MM-DD)`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{variant:`vertical`,dateFormat:`short`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`,icon:`🚀`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`,icon:`🎨`},{time:`2024-03-15`,title:`Beta Release`,description:`Released beta version to testers`,variant:`warning`,icon:`⚡`},{time:`2024-04-01`,title:`Launch`,description:`Official product launch`,variant:`success`,icon:`🎉`}]},examples:{vertical:{variant:`vertical`,dateFormat:`long`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`}]},horizontal:{variant:`horizontal`,dateFormat:`short`,items:[{time:`2024-01-01`,title:`Q1`,description:`First quarter`,variant:`default`},{time:`2024-04-01`,title:`Q2`,description:`Second quarter`,variant:`info`},{time:`2024-07-01`,title:`Q3`,description:`Third quarter`,variant:`warning`},{time:`2024-10-01`,title:`Q4`,description:`Fourth quarter`,variant:`success`}]},gantt:{variant:`gantt`,dateFormat:`short`,timeScale:`month`,rowLabel:`Projects`,items:[{label:`Backend Development`,items:[{title:`API Design`,startDate:`2024-01-01`,endDate:`2024-01-31`,variant:`success`},{title:`Implementation`,startDate:`2024-02-01`,endDate:`2024-03-31`,variant:`info`}]},{label:`Frontend Development`,items:[{title:`UI Design`,startDate:`2024-01-15`,endDate:`2024-02-15`,variant:`warning`},{title:`Component Dev`,startDate:`2024-02-15`,endDate:`2024-04-15`,variant:`default`}]},{label:`Testing`,items:[{title:`QA Phase`,startDate:`2024-03-01`,endDate:`2024-04-30`,variant:`danger`}]}]}}});var k={"timeline.bucket.overdue":`Overdue`,"timeline.bucket.today":`Today`,"timeline.bucket.tomorrow":`Tomorrow`,"timeline.bucket.thisWeek":`This week`,"timeline.bucket.nextWeek":`Next week`,"timeline.bucket.later":`Later`,"timeline.bucket.noDate":`No date`,"timeline.bucket.unassigned":`Unassigned`,"timeline.relative.today":`Today`,"timeline.relative.tomorrow":`Tomorrow`,"timeline.relative.yesterday":`Yesterday`,"timeline.relative.inDays":`In {{n}} days`,"timeline.relative.daysAgo":`{{n}} days ago`},A=`timeline.bucket.today`;function j(e,t){let n=k[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}function ee(){try{let e=u();return e.t(A)===A?{t:j}:{t:e.t}}catch{return{t:j}}}function te(){try{return _()}catch{return{fieldOptionLabel:(e,t,n,r)=>r,translateOptions:(e,t,n)=>n,fieldLabel:(e,t,n)=>n}}}var ne=f({mapping:f({title:d().optional(),date:d().optional(),description:d().optional(),variant:d().optional()}).optional(),objectName:d().optional(),titleField:d().optional(),dateField:d().optional(),startDateField:d().optional(),endDateField:d().optional(),descriptionField:d().optional(),groupByField:d().optional(),colorField:d().optional(),scale:p([`hour`,`day`,`week`,`month`,`quarter`,`year`]).optional()}),M=({schema:e,dataSource:t,className:n,onRowClick:r,onItemClick:a,...l})=>{let[u,d]=(0,b.useState)([]),[f,p]=(0,b.useState)(()=>{let t=Array.isArray(e.items)&&e.items.length>0,n=Array.isArray(l.data)&&l.data.length>0;return!t&&!n&&!!e.objectName}),[h,g]=(0,b.useState)(null),[_,v]=(0,b.useState)(0),[S,C]=(0,b.useState)(null),w=e.timeline;(0,b.useEffect)(()=>{let t=ne.safeParse(e);t.success||console.warn(`[ObjectTimeline] Invalid timeline configuration:`,t.error.format())},[e]);let T=o(e.bind);(0,b.useEffect)(()=>{let n=!0;return(async()=>{if(!(!t||typeof t.getObjectSchema!=`function`||!e.objectName))try{let r=await t.getObjectSchema(e.objectName);n&&C(r)}catch(e){console.warn(`Failed to fetch object def for ObjectTimeline`,e)}})(),()=>{n=!1}},[e.objectName,t]),(0,b.useEffect)(()=>{e.objectName&&!T&&!e.items&&!l.data?(async()=>{if(!t||typeof t.find!=`function`||!e.objectName){p(!1);return}p(!0);try{let n=s(S?.fields);d(c(await t.find(e.objectName,{options:{$top:100},...n.length>0?{$expand:n}:{}})))}catch(e){console.error(e),g(e)}finally{p(!1)}})():p(!1)},[e.objectName,t,T,e.items,l.data,_,S]);let E=l.data||T||u,{t:D}=ee(),{fieldOptionLabel:k}=te(),A=w?.titleField??e.mapping?.title??e.titleField??`name`,j=w?.startDateField??e.mapping?.date??e.startDateField??e.dateField??`date`,M=w?.endDateField??e.endDateField??j,N=e.mapping?.description??e.descriptionField??`description`,P=e.mapping?.variant??`variant`,F=w?.groupByField??e.groupByField,I=w?.colorField??e.colorField,L=(0,b.useMemo)(()=>{if(e.items)return e.items;if(!E||!Array.isArray(E))return[];let t=S?.fields??{},n=e.objectName||``,r=e=>{if(!e||!t[e]?.options)return{};let n={};for(let r of t[e].options)r&&r.value!=null&&(n[String(r.value)]=r);return n},i=r(I),a=Array.isArray(w?.metaFields)?w.metaFields.filter(e=>typeof e==`string`&&e):[`status`,`priority`].filter(e=>t[e]),o={};for(let e of a)o[e]=r(e);let s=e=>{if(e==null||e===``)return;let t=i[String(e)];if(t?.color)return String(t.color);let n=String(e);if(/^#([0-9a-f]{3}){1,2}$/i.test(n)||n.startsWith(`rgb`)||n.startsWith(`hsl`))return n},c=(e,t,r)=>{if(t==null||t===``)return null;let i=r[String(t)];return{label:i?.label?k(n,e,String(t),i.label):String(t),color:i?.color}},l=E.map(e=>{let t=e[j],r=e[M],i=I?e[I]:void 0,l=F?e[F]:void 0,u=[];if(n)for(let t of a){let n=c(t,e[t],o[t]||{});n&&u.push({key:t,label:n.label,color:n.color})}return{title:e[A],time:t,startDate:t,endDate:r,description:e[N],variant:e[P]||`default`,color:s(i),group:l,meta:u,_data:e}});l.sort((e,t)=>(e.startDate?new Date(e.startDate).getTime():1/0)-(t.startDate?new Date(t.startDate).getTime():1/0));let u=new Date,d=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime(),f=d(u),p=864e5,m=f-(u.getDay()+6)%7*p+7*p,h=m+7*p,g=e=>{if(!e)return D(`timeline.bucket.noDate`);let t=d(new Date(e));return Number.isNaN(t)?D(`timeline.bucket.noDate`):t<f?D(`timeline.bucket.overdue`):t===f?D(`timeline.bucket.today`):t===f+p?D(`timeline.bucket.tomorrow`):D(t<m?`timeline.bucket.thisWeek`:t<h?`timeline.bucket.nextWeek`:`timeline.bucket.later`)};if(F&&!l.every(e=>e.group==null||e.group===``)){let e=r(F);return l.map(t=>{let n=c(F,t.group,e);return{...t,group:n?n.label:t.group!=null&&t.group!==``?String(t.group):D(`timeline.bucket.unassigned`)}})}return l.map(e=>({...e,group:g(e.startDate)}))},[e.items,E,S,e.objectName,A,j,M,N,P,I,F,D,k]),{ref:R,isRefreshing:z,pullDistance:B}=y({onRefresh:(0,b.useCallback)(async()=>{v(e=>e+1)},[]),enabled:!!e.objectName&&!!t}),V=i({navigation:e.navigation,objectName:e.objectName,onRowClick:r??a}),H=w?.scale??e.scale,U={...e,items:L||[],className:n||e.className,...H?{timeScale:H}:{},onItemClick:e=>{let t=e._data||e;V.handleClick(t),a?.(t)}};return h?(0,x.jsxs)(`div`,{className:`p-4 text-destructive`,"data-testid":`timeline-error`,role:`alert`,children:[`Error loading timeline: `,h.message]}):f&&(!L||L.length===0)?(0,x.jsxs)(`div`,{className:`flex flex-col h-full min-h-[200px] p-4 gap-3`,"data-testid":`timeline-loading`,role:`status`,"aria-live":`polite`,"aria-busy":`true`,children:[(0,x.jsx)(`span`,{className:`sr-only`,children:`Loading timeline…`}),[0,1,2,3].map(e=>(0,x.jsxs)(`div`,{className:`flex items-start gap-3`,style:{opacity:Math.max(.3,1-e*.18)},children:[(0,x.jsx)(`div`,{className:`h-3 w-3 rounded-full bg-muted/70 animate-pulse mt-1.5 shrink-0`}),(0,x.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,x.jsx)(`div`,{className:`h-4 w-1/3 rounded bg-muted/70 animate-pulse`}),(0,x.jsx)(`div`,{className:`h-3 w-2/3 rounded bg-muted/50 animate-pulse`})]})]},e))]}):(0,x.jsxs)(`div`,{ref:R,className:`relative overflow-auto h-full min-w-0`,children:[B>0&&(0,x.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:B},children:z?`Refreshing…`:`Pull to refresh`}),(0,x.jsx)(O,{schema:U}),V.isOverlay&&(0,x.jsx)(m,{...V,title:`Timeline Item`,children:e=>(0,x.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,x.jsxs)(`div`,{className:`flex flex-col`,children:[(0,x.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,x.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})},N=t({ObjectTimeline:()=>M,ObjectTimelineRenderer:()=>$,Timeline:()=>P,TimelineContent:()=>z,TimelineDescription:()=>H,TimelineGantt:()=>G,TimelineGanttBar:()=>Z,TimelineGanttBarContent:()=>Q,TimelineGanttGrid:()=>J,TimelineGanttHeader:()=>K,TimelineGanttLabel:()=>X,TimelineGanttRow:()=>Y,TimelineGanttRowLabels:()=>q,TimelineHorizontal:()=>U,TimelineHorizontalItem:()=>W,TimelineItem:()=>I,TimelineMarker:()=>R,TimelineRenderer:()=>O,TimelineTime:()=>V,TimelineTitle:()=>B,timelineItemVariants:()=>F,timelineMarkerVariants:()=>L}),P=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`ol`,{ref:n,className: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=b.forwardRef(({className:e,density:t,...n},r)=>(0,x.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=b.forwardRef(({className:e,variant:t=`default`,...n},r)=>(0,x.jsx)(`div`,{ref:r,className:g(L({variant:t}),e),...n}));R.displayName=`TimelineMarker`;var z=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:e,...t}));z.displayName=`TimelineContent`;var B=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`h3`,{ref:n,className:g(`font-semibold text-lg mb-1`,e),...t}));B.displayName=`TimelineTitle`;var V=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`time`,{ref:n,className:g(`text-sm font-normal text-gray-500 mb-2 block`,e),...t}));V.displayName=`TimelineTime`;var H=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`p`,{ref:n,className:g(`text-base text-gray-700`,e),...t}));H.displayName=`TimelineDescription`;var U=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`relative flex overflow-x-auto py-8`,e),...t}));U.displayName=`TimelineHorizontal`;var W=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`shrink-0 w-64 relative`,e),...t}));W.displayName=`TimelineHorizontalItem`;var G=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`relative w-full border rounded-lg overflow-hidden`,e),...t}));G.displayName=`TimelineGantt`;var K=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`flex border-b bg-gray-50`,e),...t}));K.displayName=`TimelineGanttHeader`;var q=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`w-48 border-r bg-white`,e),...t}));q.displayName=`TimelineGanttRowLabels`;var J=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`flex-1 overflow-x-auto`,e),...t}));J.displayName=`TimelineGanttGrid`;var Y=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`flex items-center border-b min-h-12`,e),...t}));Y.displayName=`TimelineGanttRow`;var X=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`px-4 py-2 font-medium text-sm truncate`,e),...t}));X.displayName=`TimelineGanttLabel`;var Z=b.forwardRef(({className:e,start:t=0,width:n=100,variant:r=`default`,...i},a)=>(0,x.jsx)(`div`,{ref:a,className: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=b.forwardRef(({className:e,...t},n)=>(0,x.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}=a()||{};return(0,x.jsx)(M,{schema:e,dataSource:n,...t})};l.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`}]}),l.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{_ as n,t as r}from"./vendor-react-DR370ovB.js";import{F as i,G as a,W as o,lt as s,mt as c,r as l,ut as u}from"./framework-DoGxClbR.js";import{A as d,N as f,y as p}from"./vendor-objectstack-B2q1QmZh.js";import{$s as m,P as h,Qs as g,ec as _}from"./ui-components-DeXgqLMc.js";import{i as v}from"./vendor-ui-utils-rQOI1gAo.js";import{a as y}from"./plugin-grid-BiWgglXK.js";var b=e(n(),1),x=r(),S=10080*60*1e3;function C(e){let t=e.flatMap(e=>(e.items||[]).flatMap(e=>[e.startDate,e.endDate])),n=Math.min(...t.map(e=>new Date(e).getTime())),r=Math.max(...t.map(e=>new Date(e).getTime()));return{minDate:new Date(n).toISOString().split(`T`)[0],maxDate:new Date(r).toISOString().split(`T`)[0]}}function w(e,t,n,r){let i=new Date(e).getTime(),a=new Date(t).getTime(),o=new Date(n).getTime(),s=new Date(r).getTime()-o,c=i-o,l=a-i;return{start:c/s*100,width:l/s*100}}function T(e,t){let n=new Date(e);return t===`short`?n.toLocaleDateString():t===`long`?n.toLocaleDateString(`en-US`,{year:`numeric`,month:`long`,day:`numeric`}):n.toISOString().split(`T`)[0]}function E({label:e,color:t}){let n=t?{backgroundColor:`${t}22`,color:t,borderColor:`${t}55`}:void 0;return(0,x.jsx)(`span`,{className: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 D(e){let t=[];for(let n of e){let e=n.group==null?``:String(n.group),r=t[t.length-1];r&&r.key===e?r.items.push(n):t.push({key:e,items:[n]})}return t}var O=({schema:e,className:t,...n})=>{let{variant:r=`vertical`,items:i=[],dateFormat:a=`short`,onItemClick:o}=e;if(r===`vertical`){let e=D(i),r=e.some(e=>e.key!==``),s=(e,t)=>{let n=e.color?{backgroundColor:`${e.color}33`,borderColor:e.color}:void 0,r=e.time?T(e.time,a):e.startDate?T(e.startDate,a):``,i=e.endDate&&e.endDate!==e.startDate?T(e.endDate,a):``,s=Array.isArray(e.meta)?e.meta:[];return(0,x.jsxs)(I,{density:`compact`,className:g(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,x.jsx)(R,{variant:e.color?`default`:e.variant||`default`,style:n,children:e.icon&&(0,x.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,x.jsxs)(z,{children:[(r||i)&&(0,x.jsxs)(V,{dateTime:e.time||e.startDate,className:`!mb-1 text-xs`,children:[r,i&&(0,x.jsxs)(`span`,{className:`text-muted-foreground/70`,children:[` → `,i]})]}),e.title&&(0,x.jsx)(B,{className:`text-sm sm:text-base mb-1`,children:e.title}),s.length>0&&(0,x.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1 mb-1`,children:s.map(e=>(0,x.jsx)(E,{label:e.label,color:e.color},e.key))}),e.description&&(0,x.jsx)(H,{className:`text-sm text-muted-foreground line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&m(e.content)]})]},t)};return r?(0,x.jsx)(`div`,{className:g(`px-4 sm:px-6 py-2`,t),...n,children:e.map((e,t)=>(0,x.jsxs)(`section`,{className:`mb-4`,children:[(0,x.jsxs)(`header`,{className:`sticky top-0 z-10 -mx-4 sm:-mx-6 px-4 sm:px-6 py-1.5 backdrop-blur bg-background/90 text-xs font-semibold uppercase tracking-wide text-muted-foreground border-b`,children:[(0,x.jsx)(`span`,{children:e.key}),(0,x.jsx)(`span`,{className:`ml-2 text-muted-foreground/60 font-normal normal-case`,children:e.items.length})]}),(0,x.jsx)(P,{className:`mt-3`,children:e.items.map((e,n)=>s(e,`${t}-${n}`))})]},`${e.key}-${t}`))}):(0,x.jsx)(P,{className:t,...n,children:i.map((e,t)=>s(e,t))})}if(r===`horizontal`)return(0,x.jsx)(U,{className:g(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:i.map((e,t)=>(0,x.jsxs)(W,{className:g(e.className,o&&`cursor-pointer`),onClick:()=>o?.(e),children:[(0,x.jsxs)(`div`,{className:`flex flex-col items-center`,children:[(0,x.jsx)(R,{variant:e.variant||`default`,children:e.icon&&(0,x.jsx)(`span`,{className:`text-xs`,children:e.icon})}),(0,x.jsxs)(`div`,{className:`mt-4 text-center`,children:[e.time&&(0,x.jsx)(V,{dateTime:e.time,children:T(e.time,a)}),e.title&&(0,x.jsx)(B,{children:e.title}),e.description&&(0,x.jsx)(H,{className:`text-center line-clamp-2 sm:line-clamp-none`,children:e.description}),e.content&&m(e.content)]})]}),t<i.length-1&&(0,x.jsx)(`div`,{className:`absolute left-full w-16 border-t-2 border-gray-200 top-3`})]},t))});if(r===`gantt`){let r=C(i),s=e.minDate||r.minDate,c=e.maxDate||r.maxDate,l=e.timeScale||`month`,u=(()=>{let e=[],t=new Date(s),n=new Date(c);if(l===`month`){let r=new Date(t);for(;r<=n;)e.push(r.toLocaleDateString(`en-US`,{month:`short`,year:`numeric`})),r.setMonth(r.getMonth()+1)}else if(l===`week`){let r=new Date(t);for(;r<=n;)e.push(`Week ${Math.ceil((r.getTime()-t.getTime())/S)+1}`),r.setDate(r.getDate()+7)}else if(l===`day`){let r=new Date(t);for(;r<=n;)e.push(r.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})),r.setDate(r.getDate()+1)}return e})();return(0,x.jsxs)(G,{className:g(`overflow-x-auto [-webkit-overflow-scrolling:touch]`,t),...n,children:[(0,x.jsxs)(K,{children:[(0,x.jsx)(q,{className:`flex items-center px-2 sm:px-4 py-2 sm:py-3`,children:(0,x.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:e.rowLabel||`Items`})}),(0,x.jsx)(J,{children:(0,x.jsx)(`div`,{className:`flex h-full`,children:u.map((e,t)=>(0,x.jsx)(`div`,{className:`flex-1 px-1 sm:px-2 py-2 sm:py-3 border-r text-xs font-medium text-center`,children:e},t))})})]}),(0,x.jsx)(`div`,{children:(0,x.jsxs)(`div`,{className:`flex`,children:[(0,x.jsx)(q,{children:i.map((e,t)=>(0,x.jsx)(Y,{children:(0,x.jsx)(X,{title:e.label,className:`truncate`,children:e.label})},t))}),(0,x.jsx)(J,{className:`relative`,children:i.map((e,t)=>(0,x.jsx)(Y,{className:`relative`,children:(e.items||[]).map((n,r)=>{let i=w(n.startDate,n.endDate,s,c);return(0,x.jsx)(Z,{start:i.start,width:i.width,variant:n.variant||`default`,onClick:()=>o?.(n,e,t,r),title:`${n.title||``}\n${T(n.startDate,a)} - ${T(n.endDate,a)}`,children:(0,x.jsx)(Q,{children:n.title})},r)})},t))})]})})]})}return null};c.register(`timeline`,O,{namespace:`plugin-timeline`,label:`Timeline`,category:`data-display`,inputs:[{name:`variant`,type:`enum`,enum:[`vertical`,`horizontal`,`gantt`],label:`Timeline Variant`,defaultValue:`vertical`},{name:`items`,type:`array`,label:`Timeline Items`,description:`For vertical/horizontal: Array of { time, title, description, variant, icon, content }. For gantt: Array of { label, items: [{ title, startDate, endDate, variant }] }`},{name:`dateFormat`,type:`enum`,enum:[`short`,`long`,`iso`],label:`Date Format`,defaultValue:`short`},{name:`timeScale`,type:`enum`,enum:[`day`,`week`,`month`],label:`Time Scale (Gantt only)`,defaultValue:`month`},{name:`rowLabel`,type:`string`,label:`Row Label (Gantt only)`,defaultValue:`Items`},{name:`minDate`,type:`string`,label:`Min Date (Gantt only)`,description:`Override auto-calculated min date (YYYY-MM-DD)`},{name:`maxDate`,type:`string`,label:`Max Date (Gantt only)`,description:`Override auto-calculated max date (YYYY-MM-DD)`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{variant:`vertical`,dateFormat:`short`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`,icon:`🚀`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`,icon:`🎨`},{time:`2024-03-15`,title:`Beta Release`,description:`Released beta version to testers`,variant:`warning`,icon:`⚡`},{time:`2024-04-01`,title:`Launch`,description:`Official product launch`,variant:`success`,icon:`🎉`}]},examples:{vertical:{variant:`vertical`,dateFormat:`long`,items:[{time:`2024-01-15`,title:`Project Started`,description:`Kickoff meeting and initial planning`,variant:`success`},{time:`2024-02-01`,title:`First Milestone`,description:`Completed initial design phase`,variant:`info`}]},horizontal:{variant:`horizontal`,dateFormat:`short`,items:[{time:`2024-01-01`,title:`Q1`,description:`First quarter`,variant:`default`},{time:`2024-04-01`,title:`Q2`,description:`Second quarter`,variant:`info`},{time:`2024-07-01`,title:`Q3`,description:`Third quarter`,variant:`warning`},{time:`2024-10-01`,title:`Q4`,description:`Fourth quarter`,variant:`success`}]},gantt:{variant:`gantt`,dateFormat:`short`,timeScale:`month`,rowLabel:`Projects`,items:[{label:`Backend Development`,items:[{title:`API Design`,startDate:`2024-01-01`,endDate:`2024-01-31`,variant:`success`},{title:`Implementation`,startDate:`2024-02-01`,endDate:`2024-03-31`,variant:`info`}]},{label:`Frontend Development`,items:[{title:`UI Design`,startDate:`2024-01-15`,endDate:`2024-02-15`,variant:`warning`},{title:`Component Dev`,startDate:`2024-02-15`,endDate:`2024-04-15`,variant:`default`}]},{label:`Testing`,items:[{title:`QA Phase`,startDate:`2024-03-01`,endDate:`2024-04-30`,variant:`danger`}]}]}}});var k={"timeline.bucket.overdue":`Overdue`,"timeline.bucket.today":`Today`,"timeline.bucket.tomorrow":`Tomorrow`,"timeline.bucket.thisWeek":`This week`,"timeline.bucket.nextWeek":`Next week`,"timeline.bucket.later":`Later`,"timeline.bucket.noDate":`No date`,"timeline.bucket.unassigned":`Unassigned`,"timeline.relative.today":`Today`,"timeline.relative.tomorrow":`Tomorrow`,"timeline.relative.yesterday":`Yesterday`,"timeline.relative.inDays":`In {{n}} days`,"timeline.relative.daysAgo":`{{n}} days ago`},A=`timeline.bucket.today`;function j(e,t){let n=k[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}function ee(){try{let e=l();return e.t(A)===A?{t:j}:{t:e.t}}catch{return{t:j}}}function te(){try{return _()}catch{return{fieldOptionLabel:(e,t,n,r)=>r,translateOptions:(e,t,n)=>n,fieldLabel:(e,t,n)=>n}}}var ne=d({mapping:d({title:f().optional(),date:f().optional(),description:f().optional(),variant:f().optional()}).optional(),objectName:f().optional(),titleField:f().optional(),dateField:f().optional(),startDateField:f().optional(),endDateField:f().optional(),descriptionField:f().optional(),groupByField:f().optional(),colorField:f().optional(),scale:p([`hour`,`day`,`week`,`month`,`quarter`,`year`]).optional()}),M=({schema:e,dataSource:t,className:n,onRowClick:r,onItemClick:a,...c})=>{let[l,d]=(0,b.useState)([]),[f,p]=(0,b.useState)(()=>{let t=Array.isArray(e.items)&&e.items.length>0,n=Array.isArray(c.data)&&c.data.length>0;return!t&&!n&&!!e.objectName}),[m,g]=(0,b.useState)(null),[_,v]=(0,b.useState)(0),[S,C]=(0,b.useState)(null),w=e.timeline;(0,b.useEffect)(()=>{let t=ne.safeParse(e);t.success||console.warn(`[ObjectTimeline] Invalid timeline configuration:`,t.error.format())},[e]);let T=o(e.bind);(0,b.useEffect)(()=>{let n=!0;return(async()=>{if(!(!t||typeof t.getObjectSchema!=`function`||!e.objectName))try{let r=await t.getObjectSchema(e.objectName);n&&C(r)}catch(e){console.warn(`Failed to fetch object def for ObjectTimeline`,e)}})(),()=>{n=!1}},[e.objectName,t]),(0,b.useEffect)(()=>{e.objectName&&!T&&!e.items&&!c.data?(async()=>{if(!t||typeof t.find!=`function`||!e.objectName){p(!1);return}p(!0);try{let n=s(S?.fields);d(u(await t.find(e.objectName,{options:{$top:100},...n.length>0?{$expand:n}:{}})))}catch(e){console.error(e),g(e)}finally{p(!1)}})():p(!1)},[e.objectName,t,T,e.items,c.data,_,S]);let E=c.data||T||l,{t:D}=ee(),{fieldOptionLabel:k}=te(),A=w?.titleField??e.mapping?.title??e.titleField??`name`,j=w?.startDateField??e.mapping?.date??e.startDateField??e.dateField??`date`,M=w?.endDateField??e.endDateField??j,N=e.mapping?.description??e.descriptionField??`description`,P=e.mapping?.variant??`variant`,F=w?.groupByField??e.groupByField,I=w?.colorField??e.colorField,L=(0,b.useMemo)(()=>{if(e.items)return e.items;if(!E||!Array.isArray(E))return[];let t=S?.fields??{},n=e.objectName||``,r=e=>{if(!e||!t[e]?.options)return{};let n={};for(let r of t[e].options)r&&r.value!=null&&(n[String(r.value)]=r);return n},i=r(I),a=Array.isArray(w?.metaFields)?w.metaFields.filter(e=>typeof e==`string`&&e):[`status`,`priority`].filter(e=>t[e]),o={};for(let e of a)o[e]=r(e);let s=e=>{if(e==null||e===``)return;let t=i[String(e)];if(t?.color)return String(t.color);let n=String(e);if(/^#([0-9a-f]{3}){1,2}$/i.test(n)||n.startsWith(`rgb`)||n.startsWith(`hsl`))return n},c=(e,t,r)=>{if(t==null||t===``)return null;let i=r[String(t)];return{label:i?.label?k(n,e,String(t),i.label):String(t),color:i?.color}},l=E.map(e=>{let t=e[j],r=e[M],i=I?e[I]:void 0,l=F?e[F]:void 0,u=[];if(n)for(let t of a){let n=c(t,e[t],o[t]||{});n&&u.push({key:t,label:n.label,color:n.color})}return{title:e[A],time:t,startDate:t,endDate:r,description:e[N],variant:e[P]||`default`,color:s(i),group:l,meta:u,_data:e}});l.sort((e,t)=>(e.startDate?new Date(e.startDate).getTime():1/0)-(t.startDate?new Date(t.startDate).getTime():1/0));let u=new Date,d=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime(),f=d(u),p=864e5,m=f-(u.getDay()+6)%7*p+7*p,h=m+7*p,g=e=>{if(!e)return D(`timeline.bucket.noDate`);let t=d(new Date(e));return Number.isNaN(t)?D(`timeline.bucket.noDate`):t<f?D(`timeline.bucket.overdue`):t===f?D(`timeline.bucket.today`):t===f+p?D(`timeline.bucket.tomorrow`):D(t<m?`timeline.bucket.thisWeek`:t<h?`timeline.bucket.nextWeek`:`timeline.bucket.later`)};if(F&&!l.every(e=>e.group==null||e.group===``)){let e=r(F);return l.map(t=>{let n=c(F,t.group,e);return{...t,group:n?n.label:t.group!=null&&t.group!==``?String(t.group):D(`timeline.bucket.unassigned`)}})}return l.map(e=>({...e,group:g(e.startDate)}))},[e.items,E,S,e.objectName,A,j,M,N,P,I,F,D,k]),{ref:R,isRefreshing:z,pullDistance:B}=y({onRefresh:(0,b.useCallback)(async()=>{v(e=>e+1)},[]),enabled:!!e.objectName&&!!t}),V=i({navigation:e.navigation,objectName:e.objectName,onRowClick:r??a}),H=w?.scale??e.scale,U={...e,items:L||[],className:n||e.className,...H?{timeScale:H}:{},onItemClick:e=>{let t=e._data||e;V.handleClick(t),a?.(t)}};return m?(0,x.jsxs)(`div`,{className:`p-4 text-destructive`,"data-testid":`timeline-error`,role:`alert`,children:[`Error loading timeline: `,m.message]}):f&&(!L||L.length===0)?(0,x.jsxs)(`div`,{className:`flex flex-col h-full min-h-[200px] p-4 gap-3`,"data-testid":`timeline-loading`,role:`status`,"aria-live":`polite`,"aria-busy":`true`,children:[(0,x.jsx)(`span`,{className:`sr-only`,children:`Loading timeline…`}),[0,1,2,3].map(e=>(0,x.jsxs)(`div`,{className:`flex items-start gap-3`,style:{opacity:Math.max(.3,1-e*.18)},children:[(0,x.jsx)(`div`,{className:`h-3 w-3 rounded-full bg-muted/70 animate-pulse mt-1.5 shrink-0`}),(0,x.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,x.jsx)(`div`,{className:`h-4 w-1/3 rounded bg-muted/70 animate-pulse`}),(0,x.jsx)(`div`,{className:`h-3 w-2/3 rounded bg-muted/50 animate-pulse`})]})]},e))]}):(0,x.jsxs)(`div`,{ref:R,className:`relative overflow-auto h-full min-w-0`,children:[B>0&&(0,x.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:B},children:z?`Refreshing…`:`Pull to refresh`}),(0,x.jsx)(O,{schema:U}),V.isOverlay&&(0,x.jsx)(h,{...V,title:`Timeline Item`,children:e=>(0,x.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,x.jsxs)(`div`,{className:`flex flex-col`,children:[(0,x.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,x.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})},N=t({ObjectTimeline:()=>M,ObjectTimelineRenderer:()=>$,Timeline:()=>P,TimelineContent:()=>z,TimelineDescription:()=>H,TimelineGantt:()=>G,TimelineGanttBar:()=>Z,TimelineGanttBarContent:()=>Q,TimelineGanttGrid:()=>J,TimelineGanttHeader:()=>K,TimelineGanttLabel:()=>X,TimelineGanttRow:()=>Y,TimelineGanttRowLabels:()=>q,TimelineHorizontal:()=>U,TimelineHorizontalItem:()=>W,TimelineItem:()=>I,TimelineMarker:()=>R,TimelineRenderer:()=>O,TimelineTime:()=>V,TimelineTitle:()=>B,timelineItemVariants:()=>F,timelineMarkerVariants:()=>L}),P=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`ol`,{ref:n,className: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=b.forwardRef(({className:e,density:t,...n},r)=>(0,x.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=b.forwardRef(({className:e,variant:t=`default`,...n},r)=>(0,x.jsx)(`div`,{ref:r,className:g(L({variant:t}),e),...n}));R.displayName=`TimelineMarker`;var z=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:e,...t}));z.displayName=`TimelineContent`;var B=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`h3`,{ref:n,className:g(`font-semibold text-lg mb-1`,e),...t}));B.displayName=`TimelineTitle`;var V=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`time`,{ref:n,className:g(`text-sm font-normal text-gray-500 mb-2 block`,e),...t}));V.displayName=`TimelineTime`;var H=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`p`,{ref:n,className:g(`text-base text-gray-700`,e),...t}));H.displayName=`TimelineDescription`;var U=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`relative flex overflow-x-auto py-8`,e),...t}));U.displayName=`TimelineHorizontal`;var W=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`shrink-0 w-64 relative`,e),...t}));W.displayName=`TimelineHorizontalItem`;var G=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`relative w-full border rounded-lg overflow-hidden`,e),...t}));G.displayName=`TimelineGantt`;var K=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`flex border-b bg-gray-50`,e),...t}));K.displayName=`TimelineGanttHeader`;var q=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`w-48 border-r bg-white`,e),...t}));q.displayName=`TimelineGanttRowLabels`;var J=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`flex-1 overflow-x-auto`,e),...t}));J.displayName=`TimelineGanttGrid`;var Y=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`flex items-center border-b min-h-12`,e),...t}));Y.displayName=`TimelineGanttRow`;var X=b.forwardRef(({className:e,...t},n)=>(0,x.jsx)(`div`,{ref:n,className:g(`px-4 py-2 font-medium text-sm truncate`,e),...t}));X.displayName=`TimelineGanttLabel`;var Z=b.forwardRef(({className:e,start:t=0,width:n=100,variant:r=`default`,...i},a)=>(0,x.jsx)(`div`,{ref:a,className: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=b.forwardRef(({className:e,...t},n)=>(0,x.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}=a()||{};return(0,x.jsx)(M,{schema:e,dataSource:n,...t})};c.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`}]}),c.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};
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n}from"./vendor-react-DR370ovB.js";import{B as r,H as i,lt as a,mt as o,r as s}from"./framework-DoGxClbR.js";import{$a as c,$r as l,$t as u,Bn as d,Bo as f,Bt as p,Cn as m,Cs as h,Dn as g,Dt as _,Ea as v,En as y,Et as b,Fa as x,Fn as S,Ga as C,Gn as w,Hi as T,Ht as E,In as D,Jr as O,Ki as ee,Ln as k,Oa as A,Ot as j,P as M,Qn as te,Qs as N,Qt as P,Rn as ne,Rr as F,Rt as re,Si as ie,Sn as I,Tn as L,U as R,Ui as z,Us as ae,Vs as B,Vt as V,Zs as H,Zt as U,_i as W,_n as oe,ai as se,an as ce,bn as le,ci as G,cn as K,dn as ue,en as q,eo as J,et as de,fn as fe,gi as pe,gn as me,gr as he,hi as ge,hn as _e,in as ve,ka as ye,ko as be,kt as Y,mn as xe,mr as X,ms as Se,nt as Z,on as Ce,pn as we,ps as Te,rt as Ee,so as De,to as Oe,un as ke,vn as Ae,vo as je,wn as Me,xa as Ne,xn as Pe,xr as Fe,yi as Ie,yn as Le,zi as Re,zn as ze,zt as Be}from"./ui-components-DeXgqLMc.js";import{i as Ve}from"./vendor-ui-utils-rQOI1gAo.js";import{t as He}from"./plugin-form-CcC4fdyJ.js";import{_ as Ue,a as We,c as Ge,d as Ke,g as qe,h as Je,n as Ye,o as Xe,p as Ze,r as Qe,s as $e,t as et,u as tt}from"./vendor-dndkit-DMFEUxSy.js";import{r as nt}from"./plugin-grid-BiWgglXK.js";var Q=e(t(),1),$=n(),rt={list:`List`,detail:`Detail`,grid:`Grid`,kanban:`Kanban`,calendar:`Calendar`,timeline:`Timeline`,map:`Map`,gallery:`Gallery`,gantt:`Gantt`},it={list:A,detail:je,grid:J,kanban:x,calendar:h,timeline:H,map:Ne,gallery:C,gantt:se},at=Ve(`flex gap-4`,{variants:{position:{top:`flex-col`,bottom:`flex-col-reverse`,left:`flex-row`,right:`flex-row-reverse`}},defaultVariants:{position:`top`}}),ot=Ve(`w-full`,{variants:{orientation:{horizontal:`w-full`,vertical:`w-48`}},defaultVariants:{orientation:`horizontal`}}),st=Ve(`flex gap-2`,{variants:{orientation:{horizontal:`flex-row flex-wrap`,vertical:`flex-col`}},defaultVariants:{orientation:`horizontal`}}),ct=Ve(``,{variants:{orientation:{horizontal:``,vertical:`flex h-auto flex-col items-stretch`}},defaultVariants:{orientation:`horizontal`}});function lt(e){return e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}var ut={Home:`House`};function dt(e){if(!e)return null;let t=lt(e);return he[ut[t]||t]||null}function ft(e){return e.label?e.label:rt[e.type]||e.type}function pt(e){return e.icon?dt(e.icon):it[e.type]||null}function mt(e){return e.activeView?e.activeView:e.defaultView?e.defaultView:e.views?.[0]?.type}var ht={share:ge,settings:pe,duplicate:f,delete:F},gt={share:`Share`,settings:`Settings`,duplicate:`Duplicate`,delete:`Delete`},_t=({schema:e,className:t,onViewChange:n,onCreateView:i,onViewAction:a,createViewLabel:o=`Create view`,...s})=>{let c=Q.useMemo(()=>e.storageKey?e.storageKey:`view-switcher${e.id?`-${e.id}`:``}`,[e.id,e.storageKey]),[l,u]=Q.useState(()=>mt(e));Q.useEffect(()=>{if(e.activeView){u(e.activeView);return}if(e.persistPreference)try{let t=localStorage.getItem(c);if(t){let n=e.views.find(e=>e.type===t)?.type;n&&u(n)}}catch{}},[e.activeView,e.persistPreference,e.views,c]),Q.useEffect(()=>{if(!(!e.persistPreference||!l||e.activeView))try{localStorage.setItem(c,l)}catch{}},[l,e.activeView,e.persistPreference,c]);let d=Q.useCallback(t=>{n?.(t),e.onViewChange&&typeof window<`u`&&window.dispatchEvent(new CustomEvent(e.onViewChange,{detail:{view:t}}))},[n,e.onViewChange]),f=Q.useCallback(e=>{u(e),d(e)},[d]),m=l||e.views?.[0]?.type,h=m||``,g=e.views.find(e=>e.type===m)||e.views?.[0],_=e.variant||`tabs`,v=e.position||`top`,y=v===`left`||v===`right`,b=y?`vertical`:`horizontal`,x=e.viewActions&&e.viewActions.length>0?(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:e.viewActions.map((e,t)=>{let n=e.icon&&dt(e.icon)||ht[e.type];return(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>a?.(e.type,m),title:gt[e.type]||e.type,children:n?(0,$.jsx)(n,{className:`h-3.5 w-3.5`}):null},`action-${e.type}-${t}`)})}):null,S=e.allowCreateView?(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>i?.(),title:o,children:(0,$.jsx)(Re,{className:`h-3.5 w-3.5`})}):null,C=(0,$.jsxs)(`div`,{className:N(ot({orientation:b}),`flex items-center gap-1`),children:[_===`dropdown`&&(0,$.jsxs)(re,{value:h,onValueChange:e=>f(e),children:[(0,$.jsx)(V,{className:N(`w-full`,y?`h-10`:`h-9`),children:(0,$.jsx)(E,{placeholder:`Select view`})}),(0,$.jsx)(Be,{children:e.views.map((e,t)=>(0,$.jsx)(p,{value:e.type,children:ft(e)},`${e.type}-${t}`))})]}),_===`buttons`&&(0,$.jsx)(`div`,{className:N(st({orientation:b})),children:e.views.map((e,t)=>{let n=e.type===m,r=pt(e);return(0,$.jsxs)(X,{type:`button`,size:`sm`,variant:n?`secondary`:`ghost`,className:N(`justify-start gap-2`,y?`w-full`:``),onClick:()=>f(e.type),children:[r?(0,$.jsx)(r,{className:`h-4 w-4`}):null,(0,$.jsx)(`span`,{children:ft(e)})]},`${e.type}-${t}`)})}),_===`tabs`&&(0,$.jsx)(de,{value:h,onValueChange:e=>f(e),children:(0,$.jsx)(Z,{className:N(ct({orientation:b})),children:e.views.map((e,t)=>{let n=pt(e);return(0,$.jsxs)(Ee,{value:e.type,className:N(`gap-2`,y?`justify-start`:``),children:[n?(0,$.jsx)(n,{className:`h-4 w-4`}):null,(0,$.jsx)(`span`,{children:ft(e)})]},`${e.type}-${t}`)})})}),x,S]}),w=g?.schema?Array.isArray(g.schema)?(0,$.jsx)(`div`,{className:`space-y-4`,children:g.schema.map((e,t)=>(0,$.jsx)(r,{schema:e,...s},`${g.type}-${t}`))}):(0,$.jsx)(r,{schema:g.schema,...s}):null;return(0,$.jsxs)(`div`,{className:N(at({position:v}),t),children:[(0,$.jsx)(`div`,{className:N(`shrink-0`,y?`flex flex-col`:`flex`),children:C}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:w})]})},vt=r,yt=({schema:e,dataSource:t,className:n,views:r,activeViewId:i,onViewChange:o,onRowClick:s,onEdit:c,renderListView:l,toolbarAddon:u,onCreateView:f,onViewAction:p})=>{let[m,h]=(0,Q.useState)(null),g=(0,Q.useRef)(null);g.current=m;let[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(`create`),[x,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(0);(0,Q.useEffect)(()=>{if(!(!t?.onMutation||!e.objectName)&&!l)return t.onMutation(t=>{t.resource===e.objectName&&T(e=>e+1)})},[t,e.objectName,l]);let[E,O]=(0,Q.useState)([]),[ee,A]=(0,Q.useState)(!1),[j,te]=(0,Q.useState)({}),[P,ne]=(0,Q.useState)([]),F=e.listViews,re=F!=null&&Object.keys(F).length>0,[ie,I]=(0,Q.useState)(()=>e.defaultListView&&F?.[e.defaultListView]?e.defaultListView:F&&Object.keys(F)[0]||``),L=(0,Q.useMemo)(()=>!re||!ie?null:F[ie]||null,[re,ie,F]),R=(0,Q.useMemo)(()=>r&&r.length>0?r:null,[r]),z=R!=null&&R.length>0,ae=i||R?.[0]?.id,B=R?.find(e=>e.id===ae)||R?.[0],V=(0,Q.useMemo)(()=>L?.type?L.type:B?.type?B.type:e.defaultViewType||`grid`,[L,B,e.defaultViewType]),H=e.navigation;(0,Q.useEffect)(()=>{let n=!0;return e.objectName&&t&&(async()=>{try{let r=await t.getObjectSchema(e.objectName);n&&h(r)}catch(e){console.error(`Failed to fetch object schema:`,e)}})(),()=>{n=!1}},[e.objectName,t]),(0,Q.useEffect)(()=>{let n=!0;return(async()=>{if(!l&&V!==`grid`&&!(!t||!e.objectName)){A(!0);try{let r=L?.filter||B?.filter||e.table?.defaultFilters||[],i=Object.entries(j).filter(([,e])=>e!==void 0&&e!==``&&e!==null).map(([e,t])=>[e,`=`,t]),o=[];o=r.length>0&&i.length>0?[`and`,...r,...i]:i.length===1?i[0]:i.length>1?[`and`,...i]:r;let s=P.length>0?P.map(e=>({field:e.field,order:e.direction})):L?.sort||B?.sort||e.table?.defaultSort||void 0,c=a(g.current?.fields),l=await t.find(e.objectName,{$filter:o.length>0?o:void 0,$orderby:s,$top:100,...c.length>0?{$expand:c}:{}}),u=[];Array.isArray(l)?u=l:l&&typeof l==`object`&&(Array.isArray(l.data)?u=l.data:Array.isArray(l.records)?u=l.records:Array.isArray(l.value)&&(u=l.value)),n&&O(u)}catch(e){console.error(`ObjectView data fetch error:`,e)}finally{n&&A(!1)}}})(),()=>{n=!1}},[e.objectName,t,V,j,P,w,L,B,l]);let U=e.layout||`drawer`,W=e.operations||e.table?.operations||{create:!0,read:!0,update:!0,delete:!0},se=(0,Q.useCallback)(()=>{U===`page`&&e.onNavigate?e.onNavigate(`new`,`edit`):(b(`create`),C(null),v(!0))},[U,e]),ce=(0,Q.useCallback)(t=>{if(c){c(t);return}if(U===`page`&&e.onNavigate){let n=t.id||t._id;e.onNavigate(n,`edit`)}else b(`edit`),C(t),v(!0)},[U,e,c]),le=(0,Q.useCallback)(t=>{if(U===`page`&&e.onNavigate){let n=t.id||t._id;e.onNavigate(n,`view`)}else b(`view`),C(t),v(!0)},[U,e]),G=(0,Q.useCallback)(t=>{if(s){s(t);return}if(H){if(H.mode===`none`||H.preventNavigation)return;if(H.mode===`new_window`||H.openNewTab){let n=t.id||t._id,r=`/${e.objectName}/${encodeURIComponent(String(n))}`;window.open(r,`_blank`);return}if(H.mode===`drawer`){b(`view`),C(t),v(!0);return}if(H.mode===`modal`){b(`view`),C(t),v(!0);return}if(H.mode===`page`){let n=t.id||t._id;e.onNavigate&&e.onNavigate(n,`view`);return}if(H.mode===`split`||H.mode===`popover`){b(`view`),C(t),v(!0);return}}W.read!==!1&&le(t)},[s,H,W.read,le,e]),K=(0,Q.useCallback)(e=>{T(e=>e+1)},[]),ue=(0,Q.useCallback)(e=>{T(e=>e+1)},[]),q=(0,Q.useCallback)(()=>{v(!1),C(null),T(e=>e+1)},[]),J=(0,Q.useCallback)(()=>{v(!1),C(null)},[]);(0,Q.useCallback)(()=>{T(e=>e+1)},[]);let fe=(0,Q.useMemo)(()=>!z||!R||R.length<=1?null:{type:`view-switcher`,variant:`tabs`,position:`top`,persistPreference:!0,storageKey:`view-pref-${e.objectName}`,defaultView:B?.type||`grid`,activeView:B?.type||`grid`,views:R.map(e=>({type:e.type,label:e.label,icon:{kanban:`kanban`,calendar:`calendar`,map:`map`,gallery:`layout-grid`,timeline:`activity`,gantt:`gantt-chart`,grid:`table`,list:`list`,detail:`file-text`,chart:`bar-chart-3`}[e.type]||`table`})),allowCreateView:e.allowCreateView,viewActions:e.viewActions},[z,R,B,e.objectName,e.allowCreateView,e.viewActions]),pe=(0,Q.useCallback)(e=>{if(!R)return;let t=R.find(t=>t.type===e);t&&o&&o(t.id)},[R,o]),he=(0,Q.useCallback)(e=>{I(e)},[]);(0,Q.useMemo)(()=>{if(e.showFilters===!1)return null;let t=e.filterableFields,n=m?.fields||{},r=(t?t.map(e=>[e,n[e]||{label:e}]):Object.entries(n).filter(([,e])=>!e.hidden).slice(0,8)).map(([e,t])=>{let n=t.type||`text`,r=`text`,i;return n===`number`||n===`currency`||n===`percent`?r=`number`:n===`boolean`||n===`toggle`?r=`boolean`:n===`date`||n===`datetime`?r=`date`:n===`select`||n===`status`||t.options?(r=`select`,i=(t.options||[]).map(e=>typeof e==`string`?{label:e,value:e}:{label:e.label,value:e.value})):(n===`lookup`||n===`master_detail`||n===`user`||n===`owner`)&&t.options&&t.options.length>0&&(r=`multi-select`,i=(t.options||[]).map(e=>typeof e==`string`?{label:e,value:e}:{label:e.label,value:e.value})),{field:e,label:t.label||e,type:r,placeholder:`Filter ${t.label||e}...`,...i?{options:i}:{}}});return r.length===0?null:{type:`filter-ui`,layout:`popover`,showClear:!0,showApply:!0,filters:r,values:j}},[e.showFilters,e.filterableFields,m,j]);let ge=e.showSort;(0,Q.useMemo)(()=>{if(ge===!1)return null;let e=m?.fields||{},t=Object.entries(e).filter(([,e])=>!e.hidden).slice(0,10).map(([e,t])=>({field:e,label:t.label||e}));return t.length===0?null:{type:`sort-ui`,variant:`dropdown`,multiple:!1,fields:t,sort:P}},[m,P,ge]);let ve=(0,Q.useCallback)(t=>{let n={objectName:e.objectName,fields:L?.columns||B?.columns||e.table?.fields,className:`h-full w-full`,showSearch:B?.showSearch??e.showSearch??!1,showSort:B?.showSort??e.showSort??!1,showFilters:B?.showFilters??e.showFilters??!1,striped:B?.striped??!1,bordered:B?.bordered??!1,color:B?.color},r=L?.options||B||{};switch(t){case`kanban`:{let e=r.kanban||{},t=e.groupByField||e.groupField||`status`,i=(Array.isArray(e.columns)&&e.columns.length>0?e.columns:n.fields)||[],{columns:a,groupByField:o,groupField:s,titleField:c,...l}=e;return{type:`object-kanban`,...n,groupBy:t,groupField:t,titleField:e.titleField||`name`,cardFields:i,...l}}case`calendar`:return{type:`object-calendar`,...n,startDateField:r.calendar?.startDateField||`start_date`,endDateField:r.calendar?.endDateField||`end_date`,titleField:r.calendar?.titleField||`name`,...r.calendar||{}};case`gallery`:return{type:`object-gallery`,...n,imageField:r.gallery?.imageField,titleField:r.gallery?.titleField||`name`,subtitleField:r.gallery?.subtitleField,...r.gallery||{}};case`timeline`:return{type:`object-timeline`,...n,dateField:r.timeline?.dateField||`created_at`,titleField:r.timeline?.titleField||`name`,...r.timeline||{}};case`gantt`:return{type:`object-gantt`,...n,startDateField:r.gantt?.startDateField||`start_date`,endDateField:r.gantt?.endDateField||`end_date`,progressField:r.gantt?.progressField||`progress`,dependenciesField:r.gantt?.dependenciesField||`dependencies`,...r.gantt||{}};case`map`:return{type:`object-map`,...n,locationField:r.map?.locationField||`location`,...r.map||{}};case`chart`:{let t=r.chart||{},n=Array.isArray(t.yAxisFields)&&t.yAxisFields[0]||t.valueField||`value`,i=t.xAxisField||t.categoryField||`name`;return{type:`object-chart`,objectName:e.objectName,chartType:t.chartType||`bar`,aggregate:{field:n,function:t.aggregation||`count`,groupBy:i},xAxisKey:i,series:[{dataKey:n,label:n}],className:`h-[400px] w-full`}}default:return null}},[e.objectName,e.table?.fields,L,B]),ye=(0,Q.useMemo)(()=>({type:`object-grid`,objectName:e.objectName,title:e.table?.title,description:e.table?.description,fields:L?.columns||B?.columns||e.table?.fields,columns:L?.columns||B?.columns||e.table?.columns,operations:{...W,create:!1},defaultFilters:L?.filter||B?.filter||e.table?.defaultFilters,defaultSort:L?.sort||B?.sort||e.table?.defaultSort,pageSize:e.table?.pageSize,selectable:e.table?.selectable,striped:B?.striped??e.table?.striped,bordered:B?.bordered??e.table?.bordered,className:e.table?.className}),[e,W,L,B]),be=()=>{let t=x?x.id||x._id:void 0;return{type:`object-form`,objectName:e.objectName,mode:y,recordId:t,title:e.form?.title,description:e.form?.description,fields:e.form?.fields,customFields:e.form?.customFields,groups:e.form?.groups,layout:e.form?.layout,columns:e.form?.columns,showSubmit:e.form?.showSubmit,submitText:e.form?.submitText,showCancel:e.form?.showCancel,cancelText:e.form?.cancelText,showReset:e.form?.showReset,initialValues:e.form?.initialValues,readOnly:e.form?.readOnly||y===`view`,className:e.form?.className,subforms:e.form?.subforms,onSuccess:q,onCancel:J}},Y=()=>{if(e.form?.title)return e.form.title;let t=m?.label||e.objectName;switch(y){case`create`:return`Create ${t}`;case`edit`:return`Edit ${t}`;case`view`:return`View ${t}`;default:return t}},xe=(0,Q.useMemo)(()=>{let e=H?.width;return e?typeof e==`number`?`max-w-[${e}px]`:`max-w-[${e}]`:``},[H]),Se=()=>(0,$.jsx)(_e,{open:_,onOpenChange:v,direction:`right`,children:(0,$.jsxs)(me,{className:N(`w-full sm:max-w-2xl`,xe),children:[(0,$.jsxs)(Ae,{children:[(0,$.jsx)(Le,{children:Y()}),e.form?.description&&(0,$.jsx)(oe,{children:e.form.description})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto px-4 pb-4`,children:(0,$.jsx)(He,{schema:be(),dataSource:t})})]})}),Ce=()=>(0,$.jsx)(S,{open:_,onOpenChange:v,children:(0,$.jsxs)(D,{className:N(`max-w-2xl max-h-[90vh] overflow-y-auto`,xe),children:[(0,$.jsxs)(ze,{children:[(0,$.jsx)(d,{children:Y()}),e.form?.description&&(0,$.jsx)(k,{children:e.form.description})]}),(0,$.jsx)(He,{schema:be(),dataSource:t})]})}),we=(0,Q.useMemo)(()=>Object.keys(j).some(e=>j[e]!==void 0&&j[e]!==``&&j[e]!==null)?Object.entries(j).filter(([,e])=>e!==void 0&&e!==``&&e!==null).map(([e,t])=>({field:e,operator:`equals`,value:t})):L?.filter||B?.filter||e.table?.defaultFilters,[j,L,B,e.table?.defaultFilters]),Te=(0,Q.useMemo)(()=>P.length>0?P:L?.sort||B?.sort||e.table?.defaultSort,[P,L,B,e.table?.defaultSort]),De=()=>{let n=`${e.objectName}-${ie||B?.id||`default`}-${V}-${w}`;if(l)return l({schema:{type:`list-view`,objectName:e.objectName,viewType:V,fields:L?.columns||B?.columns||e.table?.fields,filters:we,sort:Te,rowHeight:B?.rowHeight,densityMode:B?.densityMode,groupBy:B?.groupBy,groupBy2:B?.groupBy2,grouping:B?.grouping,options:L?.options||B,showSearch:B?.showSearch??e.showSearch,showFilters:B?.showFilters??e.showFilters,showSort:B?.showSort??e.showSort,showHideFields:B?.showHideFields??e.showHideFields,showGroup:B?.showGroup??e.showGroup,showColor:B?.showColor??e.showColor,showDensity:B?.showDensity??e.showDensity,compactToolbar:B?.compactToolbar??e.compactToolbar,allowExport:B?.allowExport??e.allowExport,striped:B?.striped??e.striped,bordered:B?.bordered??e.bordered,color:B?.color??e.color,inlineEdit:B?.inlineEdit??e.inlineEdit,wrapHeaders:B?.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:B?.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:B?.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:B?.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:B?.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:B?.fieldTextColor??e.fieldTextColor,prefixField:B?.prefixField??e.prefixField,showDescription:B?.showDescription??e.showDescription,navigation:B?.navigation??e.navigation,selection:B?.selection??e.selection,pagination:B?.pagination??e.pagination,searchableFields:B?.searchableFields??e.searchableFields,filterableFields:B?.filterableFields??e.filterableFields,resizable:B?.resizable??e.resizable,hiddenFields:B?.hiddenFields??e.hiddenFields,rowActions:B?.rowActions??e.rowActions,rowActionDefs:B?.rowActionDefs??e.rowActionDefs,bulkActions:B?.bulkActions??e.bulkActions,sharing:B?.sharing??e.sharing,addRecord:B?.addRecord??e.addRecord,conditionalFormatting:B?.conditionalFormatting??e.conditionalFormatting,quickFilters:B?.quickFilters??e.quickFilters,userFilters:B?.userFilters??e.userFilters,showRecordCount:B?.showRecordCount??e.showRecordCount,allowPrinting:B?.allowPrinting??e.allowPrinting,virtualScroll:B?.virtualScroll??e.virtualScroll,emptyState:B?.emptyState??e.emptyState,aria:B?.aria??e.aria,tabs:e.tabs,refreshTrigger:w},dataSource:t,onEdit:ce,onRowClick:G,className:`h-full`,refreshKey:w});if(V!==`grid`){let e=ve(V);if(e&&vt)return(0,$.jsx)(vt,{schema:e,dataSource:t,data:E,loading:ee},n);if(!vt)return(0,$.jsx)(`div`,{className:`flex items-center justify-center h-40 text-muted-foreground`,children:(0,$.jsxs)(`p`,{children:[`SchemaRenderer not available. Install @object-ui/react to render `,V,` views.`]})})}return(0,$.jsx)(nt,{schema:ye,dataSource:t,onRowClick:G,onEdit:W.update===!1?void 0:ce,onDelete:W.delete===!1?void 0:K,onBulkDelete:W.delete===!1?void 0:ue},n)},Oe=()=>{if(!re)return null;let e=Object.entries(F);return e.length<=1?null:(0,$.jsx)(de,{value:ie,onValueChange:he,className:`w-full`,children:(0,$.jsx)(Z,{className:`w-auto`,children:e.map(([e,t])=>(0,$.jsx)(Ee,{value:e,className:`text-sm`,children:t.label||e},e))})})},ke=()=>{let t=e.showCreate!==!1&&W.create!==!1,n=e.showViewSwitcher===!0,r=Oe();return!r&&!n&&!t&&!u?null:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[r,(n||t||u)&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:n&&fe&&(0,$.jsx)(_t,{schema:fe,onViewChange:pe,onCreateView:f,onViewAction:p,className:`overflow-x-auto`})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[u,t&&(0,$.jsxs)(X,{size:`sm`,onClick:se,children:[(0,$.jsx)(Re,{className:`h-4 w-4`}),`Create`]})]})]})]})},je=H?.mode===`modal`?`modal`:H?.mode===`drawer`?`drawer`:H?.mode===`split`?`split`:H?.mode===`popover`?`popover`:U,Me=e=>(0,$.jsx)(`div`,{className:`space-y-3`,children:(0,$.jsx)(He,{schema:be(),dataSource:t})}),Ne=(0,Q.useCallback)(e=>{e||J()},[J]);if(je===`split`){let t=m?.label||e.objectName;return(0,$.jsxs)(`div`,{className:N(`flex flex-col h-full min-w-0 overflow-hidden`,n),children:[(e.title||e.description)&&(0,$.jsxs)(`div`,{className:`mb-4 shrink-0`,children:[e.title&&(0,$.jsx)(`h2`,{className:`text-2xl font-bold tracking-tight`,children:e.title}),e.description&&(0,$.jsx)(`p`,{className:`text-muted-foreground mt-1`,children:e.description})]}),(0,$.jsx)(`div`,{className:`mb-4 shrink-0`,children:ke()}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:_&&x?(0,$.jsx)(M,{isOpen:_,selectedRecord:x,mode:`split`,close:J,setIsOpen:Ne,width:H?.width,isOverlay:!0,title:`${t} Detail`,mainContent:(0,$.jsx)(`div`,{className:`h-full overflow-auto`,children:De()}),children:Me}):De()})]})}return(0,$.jsxs)(`div`,{className:N(`flex flex-col h-full min-w-0 overflow-hidden`,n),children:[(e.title||e.description)&&(0,$.jsxs)(`div`,{className:`mb-4 shrink-0`,children:[e.title&&(0,$.jsx)(`h2`,{className:`text-2xl font-bold tracking-tight`,children:e.title}),e.description&&(0,$.jsx)(`p`,{className:`text-muted-foreground mt-1`,children:e.description})]}),(0,$.jsx)(`div`,{className:`mb-4 shrink-0`,children:ke()}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:De()}),je===`drawer`&&Se(),je===`modal`&&Ce(),je===`popover`&&_&&x&&(0,$.jsx)(M,{isOpen:_,selectedRecord:x,mode:`popover`,close:J,setIsOpen:Ne,width:H?.width,isOverlay:!0,title:Y(),children:Me})]})},bt=Ve(`flex`,{variants:{layout:{inline:`flex-col space-y-4`,popover:`items-center`,drawer:`items-center`}},defaultVariants:{layout:`inline`}}),xt=e=>e==null||e===``?!0:Array.isArray(e)?e.length===0:typeof e==`object`?Object.values(e).every(e=>e==null||e===``):!1,St=e=>Array.isArray(e)?{start:e[0]||``,end:e[1]||``}:e&&typeof e==`object`?{start:e.start||``,end:e.end||``}:{start:``,end:``},Ct=({schema:e,className:t,onChange:n})=>{let[r,i]=Q.useState(e.values||{}),[a,o]=Q.useState(!1);Q.useEffect(()=>{e.values&&i(e.values)},[e.values]);let s=Q.useCallback(t=>{n?.(t),e.onChange&&typeof window<`u`&&window.dispatchEvent(new CustomEvent(e.onChange,{detail:{values:t}}))},[n,e.onChange]),c=Q.useCallback((t,n)=>{let a={...r,[t]:n};i(a),e.showApply||s(a)},[s,e.showApply,r]),l=Q.useCallback(()=>{let t={};if(i(t),e.showApply){s(t);return}s(t)},[s,e.showApply]),d=Q.useCallback(()=>{s(r),o(!1)},[s,r]),f=Q.useMemo(()=>Object.values(r).filter(e=>!xt(e)).length,[r]),m=e=>{let t=e.label||e.field,n=e.placeholder||`Filter by ${t}`;switch(e.type){case`number`:return(0,$.jsx)(q,{type:`number`,value:r[e.field]??``,placeholder:n,onChange:t=>{let n=t.target.value,r=n===``?``:Number(n);c(e.field,r)}});case`select`:return(0,$.jsxs)(re,{value:r[e.field]===void 0?``:String(r[e.field]),onValueChange:t=>{let n=e.options?.find(e=>String(e.value)===t);c(e.field,n?n.value:t)},children:[(0,$.jsx)(V,{children:(0,$.jsx)(E,{placeholder:n})}),(0,$.jsx)(Be,{children:e.options?.map(e=>(0,$.jsx)(p,{value:String(e.value),children:e.label},String(e.value)))})]});case`multi-select`:{let t=r[e.field],n=Array.isArray(t)?t:t?[t]:[];return(0,$.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-0.5 border rounded-md p-2`,children:e.options?.map(t=>{let r=n.map(String).includes(String(t.value));return(0,$.jsxs)(`label`,{className:N(`flex items-center gap-2 text-sm py-1 px-1.5 rounded cursor-pointer`,r?`bg-primary/5 text-primary`:`hover:bg-muted`),children:[(0,$.jsx)(w,{checked:r,onCheckedChange:r=>{let i=r?[...n,t.value]:n.filter(e=>String(e)!==String(t.value));c(e.field,i)}}),(0,$.jsx)(`span`,{className:`truncate`,children:t.label})]},String(t.value))})})}case`date`:return(0,$.jsx)(q,{type:`date`,value:r[e.field]??``,onChange:t=>c(e.field,t.target.value)});case`date-range`:{let t=St(r[e.field]);return(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(q,{type:`date`,value:t.start??``,onChange:n=>{c(e.field,{...t,start:n.target.value})}}),(0,$.jsx)(q,{type:`date`,value:t.end??``,onChange:n=>{c(e.field,{...t,end:n.target.value})}})]})}case`boolean`:return(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(w,{checked:!!r[e.field],onCheckedChange:t=>c(e.field,!!t)}),(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Enabled`})]});default:return(0,$.jsx)(q,{value:r[e.field]??``,placeholder:n,onChange:t=>c(e.field,t.target.value)})}},h=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:e.filters.map(e=>(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(ve,{className:`text-xs text-muted-foreground`,children:e.label||e.field}),m(e)]},e.field))}),(e.showApply||e.showClear)&&(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t pt-3`,children:[e.showClear&&(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:l,children:`Clear`}),e.showApply&&(0,$.jsx)(X,{type:`button`,size:`sm`,onClick:d,children:`Apply`})]})]}),g=e.layout||`inline`;return g===`popover`?(0,$.jsx)(`div`,{className:N(bt({layout:g}),t),children:(0,$.jsxs)(U,{open:a,onOpenChange:o,children:[(0,$.jsx)(u,{asChild:!0,children:(0,$.jsxs)(X,{type:`button`,variant:f>0?`secondary`:`outline`,size:`sm`,className:`gap-2`,children:[(0,$.jsx)(G,{className:`h-4 w-4`}),`Filters`,f>0&&(0,$.jsx)(`span`,{className:`inline-flex h-5 min-w-[20px] items-center justify-center rounded-full bg-primary/10 px-1 text-xs font-medium text-primary`,children:f})]})}),(0,$.jsx)(P,{align:`start`,className:`w-[520px] p-4`,children:h})]})}):g===`drawer`?(0,$.jsxs)(`div`,{className:N(bt({layout:g}),t),children:[(0,$.jsxs)(X,{type:`button`,variant:f>0?`secondary`:`outline`,size:`sm`,className:`gap-2`,onClick:()=>o(!0),children:[(0,$.jsx)(G,{className:`h-4 w-4`}),`Filters`,f>0&&(0,$.jsx)(`span`,{className:`inline-flex h-5 min-w-[20px] items-center justify-center rounded-full bg-primary/10 px-1 text-xs font-medium text-primary`,children:f})]}),(0,$.jsx)(_e,{open:a,onOpenChange:o,children:(0,$.jsxs)(me,{children:[(0,$.jsxs)(Ae,{children:[(0,$.jsx)(Le,{children:`Filters`}),(0,$.jsx)(oe,{children:`Refine the data with advanced filters.`})]}),(0,$.jsx)(`div`,{className:`px-4 pb-6`,children:h})]})})]}):(0,$.jsxs)(`div`,{className:N(bt({layout:g}),t),children:[h,!e.showApply&&e.showClear&&(0,$.jsxs)(X,{type:`button`,variant:`ghost`,size:`sm`,className:`gap-2`,onClick:l,children:[(0,$.jsx)(Fe,{className:`h-3.5 w-3.5`}),`Clear filters`]})]})},wt=Ve(``,{variants:{variant:{buttons:`flex flex-wrap gap-2`,dropdown:`flex flex-wrap items-center gap-3`,builder:`space-y-3`}},defaultVariants:{variant:`dropdown`}}),Tt=e=>e?e.map(e=>({field:e.field,direction:e.direction})):[],Et=e=>e.map(e=>({id:`${e.field}-${e.direction}`,field:e.field,order:e.direction})),Dt=e=>e.filter(e=>e.field).map(e=>({field:e.field,direction:e.order})),Ot=({schema:e,className:t,onChange:n})=>{let[r,i]=Q.useState(()=>Tt(e.sort)),[a,o]=Q.useState(()=>Et(Tt(e.sort)));Q.useEffect(()=>{let t=Tt(e.sort);i(t),o(Et(t))},[e.sort]);let s=Q.useCallback(t=>{i(t),n?.(t),e.onChange&&typeof window<`u`&&window.dispatchEvent(new CustomEvent(e.onChange,{detail:{sort:t}}))},[n,e.onChange]),c=Q.useCallback(t=>{let n=r.find(e=>e.field===t),i=!!e.multiple;if(!n){s(i?[...r,{field:t,direction:`asc`}]:[{field:t,direction:`asc`}]);return}if(n.direction===`asc`){s(r.map(e=>e.field===t?{...e,direction:`desc`}:e));return}s(r.filter(e=>e.field!==t))},[s,e.multiple,r]);if((e.variant||`dropdown`)===`buttons`)return(0,$.jsx)(`div`,{className:N(wt({variant:`buttons`}),t),children:e.fields.map(e=>{let t=r.find(t=>t.field===e.field);return(0,$.jsxs)(X,{type:`button`,variant:t?`secondary`:`outline`,size:`sm`,onClick:()=>c(e.field),className:`gap-2`,children:[(0,$.jsx)(`span`,{children:e.label||e.field}),t&&(0,$.jsx)(B,{className:N(`h-3.5 w-3.5 motion-safe:transition-transform motion-safe:duration-200`,t.direction===`desc`&&`rotate-180`),"aria-label":t.direction===`asc`?`ascending`:`descending`})]},e.field)})});if(e.multiple)return(0,$.jsx)(`div`,{className:N(wt({variant:`builder`}),t),children:(0,$.jsx)(R,{fields:e.fields.map(e=>({value:e.field,label:e.label||e.field})),value:a,onChange:e=>{o(e),s(Dt(e))}})});let l=r[0];return(0,$.jsxs)(`div`,{className:N(wt({variant:`dropdown`}),t),children:[(0,$.jsxs)(re,{value:l?.field||``,onValueChange:e=>{if(!e){s([]);return}s([{field:e,direction:l?.direction||`asc`}])},children:[(0,$.jsx)(V,{className:`w-56`,children:(0,$.jsx)(E,{placeholder:`Select field`})}),(0,$.jsx)(Be,{children:e.fields.map(e=>(0,$.jsx)(p,{value:e.field,children:e.label||e.field},e.field))})]}),(0,$.jsxs)(re,{value:l?.direction||`asc`,onValueChange:e=>{l?.field&&s([{field:l.field,direction:e}])},children:[(0,$.jsx)(V,{className:`w-36`,children:(0,$.jsx)(E,{})}),(0,$.jsxs)(Be,{children:[(0,$.jsx)(p,{value:`asc`,children:`Ascending`}),(0,$.jsx)(p,{value:`desc`,children:`Descending`})]})]})]})};function kt(){if(typeof crypto<`u`&&typeof crypto.randomUUID==`function`)return crypto.randomUUID();if(typeof crypto<`u`&&typeof crypto.getRandomValues==`function`){let e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}function At(e,t,n,r){return`${e}/share/${t}/${n}?mode=readonly&token=${r}`}var jt=({objectName:e,viewId:t=`default`,baseUrl:n,onShare:r,className:i})=>{let[a,o]=Q.useState(null),[s,c]=Q.useState(!1),[l,d]=Q.useState(!1),[p,m]=Q.useState(``),[g,_]=Q.useState(``),y=n??(typeof window<`u`?window.location.origin:``),b=Q.useCallback(()=>{let n=At(y,e,t,kt());o(n),c(!1);let i=g?new Date(Date.now()+parseInt(g,10)*864e5).toISOString():void 0;r?.(n,{password:p||void 0,expiresAt:i})},[y,e,t,r,p,g]),x=Q.useCallback(async()=>{if(a)try{await navigator.clipboard.writeText(a),c(!0),setTimeout(()=>c(!1),2e3)}catch{let e=document.createElement(`textarea`);e.value=a,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e),c(!0),setTimeout(()=>c(!1),2e3)}},[a]);return(0,$.jsxs)(U,{open:l,onOpenChange:d,children:[(0,$.jsx)(u,{asChild:!0,children:(0,$.jsxs)(X,{variant:`outline`,size:`sm`,className:N(`gap-2`,i),children:[(0,$.jsx)(ge,{className:`h-4 w-4`}),`Share`]})}),(0,$.jsxs)(P,{className:`w-96 space-y-4`,align:`end`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium`,children:`Share View`}),(0,$.jsx)(te,{variant:`secondary`,className:`text-xs`,children:`Read-only`})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Generate a public link to share this view. Recipients can view data without logging in.`})]}),a?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(q,{value:a,readOnly:!0,className:`h-8 text-xs`,onClick:e=>e.target.select()}),(0,$.jsx)(X,{variant:`outline`,size:`sm`,onClick:x,className:`shrink-0 gap-1`,children:s?(0,$.jsx)(Se,{className:`h-4 w-4 text-green-500`}):(0,$.jsx)(f,{className:`h-4 w-4`})})]}),(p||g)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[p&&(0,$.jsxs)(te,{variant:`outline`,className:`text-xs gap-1`,children:[(0,$.jsx)(v,{className:`h-3 w-3`}),`Password protected`]}),g&&(0,$.jsxs)(te,{variant:`outline`,className:`text-xs gap-1`,children:[(0,$.jsx)(h,{className:`h-3 w-3`}),`Expires in `,g,` day`,g===`1`?``:`s`]})]})]}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs font-medium text-foreground`,children:[(0,$.jsx)(v,{className:`h-3.5 w-3.5`}),`Password protection (optional)`]}),(0,$.jsx)(q,{type:`password`,value:p,onChange:e=>m(e.target.value),placeholder:`Enter password...`,className:`h-8 text-xs`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs font-medium text-foreground`,children:[(0,$.jsx)(h,{className:`h-3.5 w-3.5`}),`Expires after (optional)`]}),(0,$.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`w-full h-8 text-xs rounded-md border border-input bg-background px-3`,children:[(0,$.jsx)(`option`,{value:``,children:`Never`}),(0,$.jsx)(`option`,{value:`1`,children:`1 day`}),(0,$.jsx)(`option`,{value:`7`,children:`7 days`}),(0,$.jsx)(`option`,{value:`30`,children:`30 days`}),(0,$.jsx)(`option`,{value:`90`,children:`90 days`})]})]}),(0,$.jsxs)(X,{onClick:b,className:`w-full gap-2`,size:`sm`,children:[(0,$.jsx)(ge,{className:`h-4 w-4`}),`Generate Link`]})]})]})]})};function Mt(){try{let{t:e}=s();return(t,n,r)=>{let i=e(t,r);return!i||i===t?n:i}}catch{return(e,t)=>t}}var Nt={private:0,team:1,organization:2,public:3},Pt=8,Ft=({id:e,disabled:t,children:n})=>{let{attributes:r,listeners:i,setNodeRef:a,transform:o,transition:s,isDragging:c}=Xe({id:e,disabled:t,attributes:{role:`tab`,roleDescription:`view tab`,tabIndex:0}});return(0,$.jsx)($.Fragment,{children:n({setNodeRef:a,style:{transform:Ue.Transform.toString(o),transition:s,zIndex:c?10:void 0,opacity:c?.5:void 0},listeners:i,attributes:r,isDragging:c})})},It=({views:e,activeViewId:t,onViewChange:n,viewTypeIcons:r={},config:i={},onAddView:a,onRenameView:o,onDuplicateView:s,onDeleteView:u,onSetDefaultView:d,onShareView:p,onSaveAsView:h,onPinView:S,onReorderViews:C,onChangeViewType:w,onConfigView:E,onManageViews:D,availableViewTypes:k,hasUnsavedChanges:A=!1,onResetChanges:M,className:te})=>{let{showAddButton:P=!0,inlineRename:ne=!0,contextMenu:re=!0,reorderable:R=!1,maxVisibleTabs:B=4,showIndicators:V=!0,showSaveAsView:H=!0,showPinnedSection:U=!0,showVisibilityGroups:oe=!1}=i,se=Mt(),[G,J]=(0,Q.useState)(null),[de,pe]=(0,Q.useState)(``),me=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{G&&me.current&&(me.current.focus(),me.current.select())},[G]);let he=(0,Q.useCallback)(t=>{if(!ne||!o)return;let n=e.find(e=>e.id===t);n&&(n.readonly||(J(t),pe(n.label)))},[ne,o,e]),_e=(0,Q.useCallback)(()=>{G&&de.trim()&&o&&o(G,de.trim()),J(null),pe(``)},[G,de,o]),ve=(0,Q.useCallback)(()=>{J(null),pe(``)},[]),Se=(0,Q.useMemo)(()=>e.length>0&&e.every(e=>!!e.readonly),[e]),Z=(0,Q.useMemo)(()=>{let t=[...e];return t.sort((e,t)=>{if(U){let n=+!!e.isPinned,r=+!!t.isPinned;if(n!==r)return r-n}if(oe){let n=Nt[e.visibility||`public`]??Nt.public,r=Nt[t.visibility||`public`]??Nt.public;if(n!==r)return n-r}return 0}),t},[e,U,oe]),{visibleViews:Ee,overflowViews:Ae}=(0,Q.useMemo)(()=>{let e=Z.slice(0,B),n=Z.slice(B),r=n.findIndex(e=>e.id===t);if(r===-1)return{visibleViews:e,overflowViews:n};let i=n[r],a=e.length>0?[...e.slice(0,-1),i]:[i],o=e.length>0?e[e.length-1]:null,s=n.filter((e,t)=>t!==r);return o&&s.unshift(o),{visibleViews:a,overflowViews:s}},[Z,B,t]),je=qe(Je(Ke,{activationConstraint:{distance:Pt}}),Je(tt)),Ne=(0,Q.useCallback)(e=>{let{active:t,over:n}=e;if(!n||t.id===n.id||!C)return;let r=Z.findIndex(e=>e.id===t.id),i=Z.findIndex(e=>e.id===n.id);r===-1||i===-1||C(Ye(Z,r,i).map(e=>e.id))},[Z,C]),Fe=O,Ie=(0,Q.useCallback)(e=>{if(!oe||e===0)return!1;let t=Ee[e-1],n=Ee[e],r=e=>e.visibility===`private`;return r(t)&&!r(n)},[oe,Ee]),Le=(e,i)=>{let a=e.id===t,h=r[e.type]||Fe,O=G===e.id,A=V&&(e.hasActiveFilters||e.hasActiveSort),j=Ie(i),M=!!e.readonly,te=(e=>oe?e.visibility===`private`?(0,$.jsx)(v,{"data-testid":`view-tab-visibility-${e.id}`,className:`h-3 w-3 text-muted-foreground shrink-0`}):e.visibility?(0,$.jsx)(Oe,{"data-testid":`view-tab-visibility-${e.id}`,className:`h-3 w-3 text-muted-foreground shrink-0`}):null:null)(e),P=t=>(0,$.jsxs)(`div`,{"data-testid":`view-tab-${e.id}`,role:`tab`,tabIndex:0,"aria-selected":a,onClick:()=>!O&&n(e.id),onDoubleClick:()=>he(e.id),onKeyDown:t=>{!O&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e.id))},...t?.listeners??{},...t?.attributes??{},className:N(`group/tab inline-flex items-center gap-1.5 px-3 py-2 text-sm font-medium border-b-2 transition-colors whitespace-nowrap relative outline-none focus-visible:ring-2 focus-visible:ring-ring`,t?.isDragging?`cursor-grabbing`:`cursor-pointer`,a?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground hover:border-border`),children:[R&&C&&(0,$.jsx)(`span`,{"data-testid":`view-tab-drag-handle-${e.id}`,"aria-hidden":`true`,className:N(`text-muted-foreground transition-opacity pointer-events-none`,`opacity-0 group-hover/tab:opacity-100`,t?.isDragging&&`opacity-100`),children:(0,$.jsx)(c,{className:`h-3 w-3`})}),U&&e.isPinned&&(0,$.jsx)(z,{"data-testid":`view-tab-pin-indicator-${e.id}`,className:`h-3 w-3 text-primary shrink-0`}),te,(0,$.jsx)(h,{className:`h-3.5 w-3.5`}),O?(0,$.jsx)(q,{ref:me,"data-testid":`view-tab-rename-input-${e.id}`,value:de,onChange:e=>pe(e.target.value),onBlur:_e,onKeyDown:e=>{e.key===`Enter`&&_e(),e.key===`Escape`&&ve()},className:`h-5 w-24 px-1 py-0 text-sm border-none focus-visible:ring-1`,onClick:e=>e.stopPropagation()}):(0,$.jsx)(`span`,{children:e.label}),M&&!Se&&(0,$.jsxs)(b,{children:[(0,$.jsx)(Y,{asChild:!0,children:(0,$.jsx)(v,{"data-testid":`view-tab-readonly-${e.id}`,"aria-label":se(`view.readonlyAriaLabel`,`Read-only view`),className:`h-3 w-3 text-muted-foreground shrink-0`})}),(0,$.jsx)(_,{side:`bottom`,className:`text-xs`,children:e.readonlyReason||se(`view.readonlyTooltip`,`System view — defined in code, read-only.`)})]}),A&&(0,$.jsxs)(b,{children:[(0,$.jsx)(Y,{asChild:!0,children:(0,$.jsxs)(`span`,{"data-testid":`view-tab-indicator-${e.id}`,className:`ml-1 inline-flex items-center gap-0.5 h-4 px-1 rounded-full bg-primary/10 text-primary shrink-0`,children:[e.hasActiveFilters&&(0,$.jsx)(De,{className:`h-2.5 w-2.5`}),e.hasActiveSort&&(0,$.jsx)(ae,{className:`h-2.5 w-2.5`})]})}),(0,$.jsx)(_,{side:`bottom`,className:`text-xs`,children:[e.hasActiveFilters&&`Active filters`,e.hasActiveSort&&`Active sort`].filter(Boolean).join(`, `)})]}),e.isDefault&&(0,$.jsx)(l,{className:`h-3 w-3 text-amber-500 fill-amber-500 shrink-0`}),a&&(E||o||s||u)&&(0,$.jsxs)(ce,{children:[(0,$.jsx)(xe,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"data-testid":`view-tab-actions-${e.id}`,className:`ml-0.5 h-4 w-4 flex items-center justify-center rounded hover:bg-accent shrink-0 opacity-70 hover:opacity-100 transition-opacity`,onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),"aria-label":se(`view.tabActionsFor`,`View actions for ${e.label}`,{name:e.label}),children:(0,$.jsx)(Te,{className:`h-3 w-3`})})}),(0,$.jsxs)(Ce,{align:`start`,className:`min-w-[180px]`,onClick:e=>e.stopPropagation(),children:[E&&!M&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-config-${e.id}`,onClick:()=>E(e.id),children:[(0,$.jsx)(W,{className:`h-4 w-4 mr-2`}),` Edit view config`]}),o&&!M&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-rename-${e.id}`,onClick:()=>he(e.id),children:[(0,$.jsx)(ee,{className:`h-4 w-4 mr-2`}),` Rename`]}),s&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-duplicate-${e.id}`,onClick:()=>s(e.id),children:[(0,$.jsx)(f,{className:`h-4 w-4 mr-2`}),` Duplicate view`]}),p&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-share-${e.id}`,onClick:()=>p(e.id),children:[(0,$.jsx)(ge,{className:`h-4 w-4 mr-2`}),` Share view`]}),d&&!M&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-default-${e.id}`,onClick:()=>d(e.id),children:[(0,$.jsx)(l,{className:`h-4 w-4 mr-2`}),` Set as default`]}),S&&!M&&(0,$.jsx)(K,{"data-testid":`view-tab-menu-pin-${e.id}`,onClick:()=>S(e.id,!e.isPinned),children:e.isPinned?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(T,{className:`h-4 w-4 mr-2`}),` Unpin view`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{className:`h-4 w-4 mr-2`}),` Pin view`]})}),w&&!M&&k&&k.length>0&&(0,$.jsxs)(ue,{children:[(0,$.jsxs)(we,{"data-testid":`view-tab-menu-change-type-${e.id}`,children:[(0,$.jsx)(x,{className:`h-4 w-4 mr-2`}),` Change view type`]}),(0,$.jsx)(fe,{children:k.map(t=>{let n=r[t.type]||Fe;return(0,$.jsxs)(K,{"data-testid":`view-tab-menu-type-${e.id}-${t.type}`,disabled:t.type===e.type,onClick:()=>w(e.id,t.type),children:[(0,$.jsx)(n,{className:`h-4 w-4 mr-2`}),(0,$.jsx)(`span`,{children:t.label})]},t.type)})})]}),u&&!M&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ke,{}),(0,$.jsxs)(K,{"data-testid":`view-tab-menu-delete-${e.id}`,onClick:()=>u(e.id),className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(F,{className:`h-4 w-4 mr-2`}),` Delete view`]})]}),D&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ke,{}),(0,$.jsxs)(K,{"data-testid":`view-tab-menu-manage-${e.id}`,onClick:D,children:[(0,$.jsx)(ye,{className:`h-4 w-4 mr-2`}),` Manage all views…`]})]})]})]})]}),ne=t=>!re||O?t:(0,$.jsxs)(le,{children:[(0,$.jsx)(g,{asChild:!0,children:t}),(0,$.jsxs)(Pe,{children:[o&&!M&&(0,$.jsxs)(I,{"data-testid":`context-menu-rename-${e.id}`,onClick:()=>he(e.id),children:[(0,$.jsx)(ee,{className:`h-4 w-4 mr-2`}),` Rename`]}),s&&(0,$.jsxs)(I,{"data-testid":`context-menu-duplicate-${e.id}`,onClick:()=>s(e.id),children:[(0,$.jsx)(f,{className:`h-4 w-4 mr-2`}),` Duplicate View`]}),p&&(0,$.jsxs)(I,{"data-testid":`context-menu-share-${e.id}`,onClick:()=>p(e.id),children:[(0,$.jsx)(ge,{className:`h-4 w-4 mr-2`}),` Share View`]}),d&&!M&&(0,$.jsxs)(I,{"data-testid":`context-menu-default-${e.id}`,onClick:()=>d(e.id),children:[(0,$.jsx)(l,{className:`h-4 w-4 mr-2`}),` Set as Default`]}),S&&!M&&(0,$.jsx)(I,{"data-testid":`context-menu-pin-${e.id}`,onClick:()=>S(e.id,!e.isPinned),children:e.isPinned?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(T,{className:`h-4 w-4 mr-2`}),` Unpin View`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{className:`h-4 w-4 mr-2`}),` Pin View`]})}),w&&!M&&k&&k.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(m,{}),(0,$.jsxs)(Me,{children:[(0,$.jsxs)(y,{"data-testid":`context-menu-change-type-${e.id}`,children:[(0,$.jsx)(x,{className:`h-4 w-4 mr-2`}),` Change View Type`]}),(0,$.jsx)(L,{"data-testid":`context-menu-type-submenu-${e.id}`,children:k.map(t=>{let n=r[t.type]||Fe;return(0,$.jsxs)(I,{"data-testid":`context-menu-type-${e.id}-${t.type}`,disabled:t.type===e.type,onClick:()=>w(e.id,t.type),children:[(0,$.jsx)(n,{className:`h-4 w-4 mr-2`}),(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`span`,{children:t.label}),t.description&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.description})]})]},t.type)})})]})]}),u&&!M&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(m,{}),(0,$.jsxs)(I,{"data-testid":`context-menu-delete-${e.id}`,onClick:()=>u(e.id),className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(F,{className:`h-4 w-4 mr-2`}),` Delete View`]})]}),D&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(m,{}),(0,$.jsxs)(I,{"data-testid":`context-menu-manage-${e.id}`,onClick:D,children:[(0,$.jsx)(ye,{className:`h-4 w-4 mr-2`}),` Manage all views…`]})]})]})]});return R&&C?(0,$.jsxs)(Q.Fragment,{children:[j&&(0,$.jsx)(`div`,{"data-testid":`view-tab-visibility-separator`,className:`w-px h-5 bg-border mx-1 self-center shrink-0`}),(0,$.jsx)(Ft,{id:e.id,children:({setNodeRef:e,style:t,listeners:n,attributes:r,isDragging:i})=>(0,$.jsx)(`div`,{ref:e,style:t,className:N(`flex`,i&&`z-10`),children:ne(P({listeners:n,attributes:r,isDragging:i}))})})]},e.id):(0,$.jsxs)(Q.Fragment,{children:[j&&(0,$.jsx)(`div`,{"data-testid":`view-tab-visibility-separator`,className:`w-px h-5 bg-border mx-1 self-center shrink-0`}),ne(P())]},e.id)},ze=(0,$.jsx)($.Fragment,{children:Ee.map((e,t)=>Le(e,t))});return(0,$.jsx)(j,{children:(0,$.jsxs)(`div`,{"data-testid":`view-tab-bar`,className:N(`flex items-center gap-0.5 -mb-px`,te),children:[R&&C?(0,$.jsx)(Ge,{sensors:je,collisionDetection:Ze,onDragEnd:Ne,children:(0,$.jsx)(et,{items:Ee.map(e=>e.id),strategy:Qe,children:(0,$.jsx)(`div`,{"data-testid":`view-tab-sortable-container`,className:`flex items-center gap-0.5`,children:ze})})}):ze,Ae.length>0&&(0,$.jsxs)(ce,{children:[(0,$.jsx)(xe,{asChild:!0,children:(0,$.jsxs)(`button`,{"data-testid":`view-tab-overflow`,className:`inline-flex items-center gap-1 px-2 py-2 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,$.jsx)(be,{className:`h-4 w-4`}),(0,$.jsxs)(`span`,{className:`text-xs`,children:[Ae.length,` more`]})]})}),(0,$.jsxs)(Ce,{align:`end`,children:[D&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(K,{"data-testid":`view-tab-overflow-manage`,onClick:D,className:`font-medium`,children:[(0,$.jsx)(ye,{className:`h-4 w-4 mr-2`}),` Manage all views…`]}),(0,$.jsx)(ke,{})]}),Ae.map(e=>{let t=r[e.type]||Fe;return(0,$.jsxs)(K,{"data-testid":`view-tab-overflow-${e.id}`,onClick:()=>n(e.id),children:[e.isPinned&&(0,$.jsx)(z,{className:`h-3 w-3 mr-1 text-primary shrink-0`}),(0,$.jsx)(t,{className:`h-4 w-4 mr-2`}),e.label,V&&(e.hasActiveFilters||e.hasActiveSort)&&(0,$.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-0.5 h-4 px-1 rounded-full bg-primary/10 text-primary`,children:[e.hasActiveFilters&&(0,$.jsx)(De,{className:`h-2.5 w-2.5`}),e.hasActiveSort&&(0,$.jsx)(ae,{className:`h-2.5 w-2.5`})]})]},e.id)})]})]}),P&&a&&(0,$.jsxs)(b,{children:[(0,$.jsx)(Y,{asChild:!0,children:(0,$.jsx)(`button`,{"data-testid":`view-tab-add`,onClick:a,className:`inline-flex items-center px-2 py-2 text-muted-foreground hover:text-foreground transition-colors`,children:(0,$.jsx)(Re,{className:`h-4 w-4`})})}),(0,$.jsx)(_,{children:`Add View`})]}),H&&A&&(0,$.jsxs)(`div`,{"data-testid":`view-tab-save-as`,className:`flex items-center gap-1 ml-2 text-xs text-amber-600 dark:text-amber-400`,children:[(0,$.jsx)(ie,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Unsaved changes`}),h&&(0,$.jsx)(X,{variant:`ghost`,size:`sm`,"data-testid":`view-tab-save-as-btn`,className:`h-6 px-2 text-xs`,onClick:h,children:`Save as View`}),M&&(0,$.jsx)(X,{variant:`ghost`,size:`sm`,"data-testid":`view-tab-reset-btn`,className:`h-6 px-2 text-xs`,onClick:M,children:`Reset`})]})]})})},Lt=O,Rt=({view:e,isActive:t,Icon:n,isRenaming:r,onStartRename:i,onCommitRename:a,onCancelRename:o,onRowClick:s,onDelete:u,onDuplicate:d,onSetDefault:p,onSetPinned:m,onConfigView:h})=>{let{attributes:g,listeners:y,setNodeRef:x,transform:S,transition:C,isDragging:w}=Xe({id:e.id}),E={transform:Ue.Transform.toString(S),transition:C,opacity:w?.5:1},D=(0,Q.useRef)(null),[O,k]=(0,Q.useState)(e.label),A=!!e.readonly;(0,Q.useEffect)(()=>{r&&(k(e.label),requestAnimationFrame(()=>{D.current?.focus(),D.current?.select()}))},[r,e.label]);let M=(0,Q.useCallback)(()=>{let t=O.trim();t&&t!==e.label?a(e.id,t):o()},[O,e.id,e.label,a,o]);return(0,$.jsxs)(`li`,{ref:x,style:E,"data-testid":`manage-views-row-${e.id}`,className:N(`group/row flex items-center gap-2 px-2 py-2 rounded-md border border-transparent`,`hover:bg-accent/50 transition-colors`,t&&`bg-accent/40 border-border`,w&&`shadow-md bg-background border-border z-10`),children:[(0,$.jsx)(`button`,{type:`button`,...g,...y,"aria-label":`Drag to reorder`,"data-testid":`manage-views-drag-${e.id}`,className:`shrink-0 h-6 w-5 flex items-center justify-center text-muted-foreground/40 hover:text-muted-foreground cursor-grab active:cursor-grabbing rounded hover:bg-accent`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(c,{className:`h-4 w-4`})}),(0,$.jsx)(n,{className:`shrink-0 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,onClick:()=>{r||s?.(e.id)},children:r?(0,$.jsx)(q,{ref:D,value:O,onChange:e=>k(e.target.value),onBlur:M,onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),M()):e.key===`Escape`&&(e.preventDefault(),o())},onClick:e=>e.stopPropagation(),className:`h-7 text-sm`,"data-testid":`manage-views-rename-input-${e.id}`}):(0,$.jsxs)(`button`,{type:`button`,className:`w-full text-left text-sm font-medium truncate cursor-pointer flex items-center gap-1.5`,onDoubleClick:t=>{t.stopPropagation(),A||i(e.id)},title:e.label,children:[(0,$.jsx)(`span`,{className:`truncate`,children:e.label}),A&&(0,$.jsx)(v,{"aria-label":`Read-only view`,"data-testid":`manage-views-readonly-${e.id}`,className:`h-3 w-3 text-muted-foreground shrink-0`}),e.isDefault&&(0,$.jsxs)(`span`,{className:`ml-1 inline-flex items-center text-[10px] uppercase tracking-wide text-muted-foreground`,title:`Default view`,children:[(0,$.jsx)(l,{className:`h-3 w-3 mr-0.5 fill-current`}),` default`]})]})}),m&&!r&&!A&&(0,$.jsx)(j,{delayDuration:300,children:(0,$.jsxs)(b,{children:[(0,$.jsx)(Y,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":e.isPinned?`Unpin view`:`Pin view`,"data-testid":`manage-views-pin-${e.id}`,onClick:t=>{t.stopPropagation(),m(e.id,!e.isPinned)},className:N(`shrink-0 h-7 w-7 inline-flex items-center justify-center rounded hover:bg-accent transition-colors`,e.isPinned?`text-amber-500`:`text-muted-foreground/40 opacity-0 group-hover/row:opacity-100`),children:e.isPinned?(0,$.jsx)(z,{className:`h-4 w-4 fill-current`}):(0,$.jsx)(z,{className:`h-4 w-4`})})}),(0,$.jsx)(_,{side:`top`,children:e.isPinned?`Unpin view`:`Pin view`})]})}),p&&!r&&!e.isDefault&&!A&&(0,$.jsx)(j,{delayDuration:300,children:(0,$.jsxs)(b,{children:[(0,$.jsx)(Y,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":`Set as default`,"data-testid":`manage-views-default-${e.id}`,onClick:t=>{t.stopPropagation(),p(e.id)},className:`shrink-0 h-7 w-7 inline-flex items-center justify-center rounded hover:bg-accent text-muted-foreground/40 hover:text-foreground opacity-0 group-hover/row:opacity-100 transition-colors`,children:(0,$.jsx)(l,{className:`h-4 w-4`})})}),(0,$.jsx)(_,{side:`top`,children:`Set as default`})]})}),!r&&(u||d||h||p)&&(0,$.jsxs)(ce,{children:[(0,$.jsx)(xe,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":`Actions for ${e.label}`,"data-testid":`manage-views-actions-${e.id}`,onClick:e=>e.stopPropagation(),className:`shrink-0 h-7 w-7 inline-flex items-center justify-center rounded hover:bg-accent text-muted-foreground opacity-60 group-hover/row:opacity-100 transition-opacity`,children:(0,$.jsx)(be,{className:`h-4 w-4`})})}),(0,$.jsxs)(Ce,{align:`end`,className:`min-w-[180px]`,children:[!A&&(0,$.jsxs)(K,{"data-testid":`manage-views-action-rename-${e.id}`,onClick:()=>i(e.id),children:[(0,$.jsx)(ee,{className:`h-4 w-4 mr-2`}),` Rename`]}),d&&(0,$.jsxs)(K,{"data-testid":`manage-views-action-duplicate-${e.id}`,onClick:()=>d(e.id),children:[(0,$.jsx)(f,{className:`h-4 w-4 mr-2`}),` Duplicate`]}),h&&!A&&(0,$.jsxs)(K,{"data-testid":`manage-views-action-config-${e.id}`,onClick:()=>h(e.id),children:[(0,$.jsx)(ee,{className:`h-4 w-4 mr-2`}),` Edit configuration…`]}),p&&!e.isDefault&&!A&&(0,$.jsxs)(K,{"data-testid":`manage-views-action-default-${e.id}`,onClick:()=>p(e.id),children:[(0,$.jsx)(l,{className:`h-4 w-4 mr-2`}),` Set as default`]}),m&&!A&&(0,$.jsx)(K,{"data-testid":`manage-views-action-pin-${e.id}`,onClick:()=>m(e.id,!e.isPinned),children:e.isPinned?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(T,{className:`h-4 w-4 mr-2`}),` Unpin`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{className:`h-4 w-4 mr-2`}),` Pin`]})}),u&&!A&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ke,{}),(0,$.jsxs)(K,{"data-testid":`manage-views-action-delete-${e.id}`,onClick:()=>u(e.id),className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(F,{className:`h-4 w-4 mr-2`}),` Delete`]})]})]})]}),r&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`Save name`,onMouseDown:e=>e.preventDefault(),onClick:M,className:`h-7 w-7 inline-flex items-center justify-center rounded hover:bg-accent text-emerald-600`,children:(0,$.jsx)(Se,{className:`h-4 w-4`})}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Cancel rename`,onMouseDown:e=>e.preventDefault(),onClick:o,className:`h-7 w-7 inline-flex items-center justify-center rounded hover:bg-accent text-muted-foreground`,children:(0,$.jsx)(Fe,{className:`h-4 w-4`})})]})]})},zt=({open:e,onOpenChange:t,views:n,activeViewId:r,viewTypeIcons:i={},onRename:a,onDelete:o,onDuplicate:s,onSetDefault:c,onSetPinned:l,onReorder:u,onAddView:f,onConfigView:p})=>{let[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(()=>n.map(e=>e.id));(0,Q.useEffect)(()=>{y(n.map(e=>e.id))},[n]),(0,Q.useEffect)(()=>{e||(_(null),h(``))},[e]);let b=(0,Q.useMemo)(()=>{let e=new Map(n.map(e=>[e.id,e]));return v.map(t=>e.get(t)).filter(Boolean)},[v,n]),x=(0,Q.useMemo)(()=>{if(!m.trim())return b;let e=m.toLowerCase();return b.filter(t=>t.label.toLowerCase().includes(e))},[b,m]),C=qe(Je(Ke,{activationConstraint:{distance:5}}),Je(tt,{coordinateGetter:We})),w=e=>{let{active:t,over:n}=e;if(!n||t.id===n.id)return;let r=v.indexOf(String(t.id)),i=v.indexOf(String(n.id));if(r<0||i<0)return;let a=Ye(v,r,i);y(a),u?.(a)},T=e=>{t(!1),requestAnimationFrame(()=>p?.(e))};return(0,$.jsx)(S,{open:e,onOpenChange:t,children:(0,$.jsxs)(D,{className:`sm:max-w-[560px] p-0 gap-0 overflow-hidden`,"data-testid":`manage-views-dialog`,children:[(0,$.jsxs)(ze,{className:`px-5 pt-5 pb-3`,children:[(0,$.jsx)(d,{className:`text-base`,children:`Manage views`}),(0,$.jsx)(k,{className:`text-xs`,children:`Reorder, rename, pin, or delete every view in this object.`})]}),(0,$.jsx)(`div`,{className:`px-5 pb-3`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Ie,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none`}),(0,$.jsx)(q,{value:m,onChange:e=>h(e.target.value),placeholder:`Search views`,className:`pl-8 h-9`,"data-testid":`manage-views-search`})]})}),(0,$.jsx)(`div`,{className:`px-3 pb-3 max-h-[55vh] overflow-y-auto`,"data-testid":`manage-views-list`,children:x.length===0?(0,$.jsx)(`div`,{className:`text-center text-sm text-muted-foreground py-10`,children:`No views match your search.`}):(0,$.jsx)(Ge,{sensors:C,collisionDetection:Ze,onDragEnd:w,children:(0,$.jsx)(et,{items:x.map(e=>e.id),strategy:$e,children:(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:x.map(e=>(0,$.jsx)(Rt,{view:e,Icon:i[e.type]||Lt,isActive:e.id===r,isRenaming:g===e.id,onStartRename:e=>_(e),onCancelRename:()=>_(null),onCommitRename:(e,t)=>{_(null),a?.(e,t)},onDelete:o,onDuplicate:s,onSetDefault:c,onSetPinned:l,onConfigView:p?T:void 0},e.id))})})})}),(0,$.jsxs)(ne,{className:`border-t bg-muted/30 px-5 py-3 flex sm:justify-between gap-2`,children:[f?(0,$.jsxs)(X,{variant:`ghost`,size:`sm`,onClick:()=>{t(!1),requestAnimationFrame(()=>f())},"data-testid":`manage-views-add`,className:`text-sm`,children:[(0,$.jsx)(Re,{className:`h-4 w-4 mr-1.5`}),` Add new view`]}):(0,$.jsx)(`span`,{}),(0,$.jsx)(X,{size:`sm`,onClick:()=>t(!1),"data-testid":`manage-views-done`,children:`Done`})]})]})})};function Bt(e){let t=(e||``).toLowerCase();return[`integer`,`int`,`float`,`double`,`number`,`currency`,`money`,`percent`,`rating`].includes(t)?`number`:[`date`,`datetime`,`datetime_tz`,`timestamp`,`time`].includes(t)?`date`:[`boolean`,`bool`,`checkbox`,`switch`].includes(t)?`boolean`:[`select`,`picklist`,`single_select`,`multi_select`,`enum`,`status`,`lookup`,`master_detail`,`user`,`owner`].includes(t)?`select`:`text`}function Vt(e){return e.fields?Object.entries(e.fields).filter(([e,t])=>!(e.startsWith(`_`)||t?.hidden)).map(([e,t])=>({value:e,label:t.label||e,type:Bt(t.type),options:t.options,rawType:t.type,rawName:e})):[]}var Ht=new Set([`image`,`image_url`,`photo`,`picture`,`avatar`,`file`,`attachment`,`attachments`,`media`,`url`,`link`]),Ut=[`image`,`photo`,`picture`,`avatar`,`thumbnail`,`thumb`,`logo`,`cover`,`banner`,`icon`,`attachment`];function Wt(e){if(!e)return!1;let t=(e.rawType||e.type||``).toLowerCase();if(Ht.has(t))return!0;let n=(e.rawName||e.name||e.key||e.value||``).toLowerCase();return n?Ut.some(e=>n.includes(e)):!1}var Gt=new Set([`geolocation`,`geo`,`geo_point`,`geopoint`,`location`,`latlng`,`lnglat`]);function Kt(e,t){if(!e)return!1;let n=(e.rawType||e.type||``).toLowerCase();if(Gt.has(n))return!0;let r=(e.rawName||e.name||e.key||e.value||``).toLowerCase();return r?t===`latitude`?/(^|[_-])lat([^a-z]|itude)?($|[_-])/.test(r)||r===`lat`:/(^|[_-])(lng|lon|long)([^a-z]|gitude)?($|[_-])/.test(r)||r===`lng`||r===`lon`:!1}function qt(e,t){if(e.length!==0){for(let n of t){let t=e.find(e=>e.value.toLowerCase().includes(n));if(t)return t.value}return e[0]?.value}}var Jt=[`status`,`stage`,`state`,`priority`,`category`,`type`],Yt=[`start_date`,`startdate`,`due_date`,`duedate`,`event_date`,`date`,`created_at`,`createdat`,`created`],Xt=[`end_date`,`enddate`,`finish_date`,`completion_date`,`closed_at`],Zt=i,Qt=({schema:e})=>(0,$.jsx)(yt,{schema:e,dataSource:(0,Q.useContext)(Zt)?.dataSource??null});o.register(`object-view`,Qt,{namespace:`plugin-view`,label:`Object View`,category:`view`,icon:`LayoutDashboard`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`layout`,type:`enum`,label:`Form Layout`,enum:[`drawer`,`modal`,`page`]},{name:`defaultViewType`,type:`enum`,label:`Default View Type`,enum:[`grid`,`kanban`,`gallery`,`calendar`,`timeline`,`gantt`,`map`]},{name:`defaultListView`,type:`string`,label:`Default Named View`},{name:`showSearch`,type:`boolean`,label:`Show Search`},{name:`showFilters`,type:`boolean`,label:`Show Filters`},{name:`showCreate`,type:`boolean`,label:`Show Create Button`},{name:`showRefresh`,type:`boolean`,label:`Show Refresh Button`},{name:`showViewSwitcher`,type:`boolean`,label:`Show View Switcher`},{name:`listViews`,type:`object`,label:`Named List Views`},{name:`navigation`,type:`object`,label:`Navigation Config`},{name:`searchableFields`,type:`array`,label:`Searchable Fields`},{name:`filterableFields`,type:`array`,label:`Filterable Fields`}],defaultProps:{layout:`drawer`,defaultViewType:`grid`,showSearch:!0,showFilters:!0,showCreate:!0,showRefresh:!0,showViewSwitcher:!0}}),o.register(`view`,Qt,{namespace:`plugin-view`,label:`View`,category:`view`}),o.register(`view-switcher`,_t,{namespace:`view`,label:`View Switcher`,category:`view`,icon:`LayoutGrid`,inputs:[{name:`views`,type:`array`,label:`Views`,required:!0},{name:`defaultView`,type:`string`,label:`Default View`},{name:`activeView`,type:`string`,label:`Active View`},{name:`variant`,type:`enum`,label:`Variant`,enum:[`tabs`,`buttons`,`dropdown`]},{name:`position`,type:`enum`,label:`Position`,enum:[`top`,`bottom`,`left`,`right`]},{name:`persistPreference`,type:`boolean`,label:`Persist Preference`},{name:`storageKey`,type:`string`,label:`Storage Key`},{name:`onViewChange`,type:`string`,label:`On View Change Event`}],defaultProps:{variant:`tabs`,position:`top`,defaultView:`grid`,views:[{type:`grid`,label:`Grid`,schema:{type:`text`,content:`Grid view`}},{type:`list`,label:`List`,schema:{type:`text`,content:`List view`}}]}}),o.register(`filter-ui`,Ct,{namespace:`view`,label:`Filter UI`,category:`view`,icon:`SlidersHorizontal`,inputs:[{name:`filters`,type:`array`,label:`Filters`,required:!0},{name:`values`,type:`object`,label:`Values`},{name:`onChange`,type:`string`,label:`On Change Event`},{name:`showClear`,type:`boolean`,label:`Show Clear Button`},{name:`showApply`,type:`boolean`,label:`Show Apply Button`},{name:`layout`,type:`enum`,label:`Layout`,enum:[`inline`,`popover`,`drawer`]}],defaultProps:{layout:`inline`,showApply:!1,showClear:!0,filters:[{field:`name`,label:`Name`,type:`text`,placeholder:`Search name`},{field:`status`,label:`Status`,type:`select`,options:[{label:`Open`,value:`open`},{label:`Closed`,value:`closed`}]},{field:`created_at`,label:`Created`,type:`date`}]}}),o.register(`sort-ui`,Ot,{namespace:`view`,label:`Sort UI`,category:`view`,icon:`ArrowUpDown`,inputs:[{name:`fields`,type:`array`,label:`Fields`,required:!0},{name:`sort`,type:`array`,label:`Sort`},{name:`onChange`,type:`string`,label:`On Change Event`},{name:`multiple`,type:`boolean`,label:`Allow Multiple`},{name:`variant`,type:`enum`,label:`Variant`,enum:[`dropdown`,`buttons`]}],defaultProps:{variant:`dropdown`,multiple:!0,fields:[{field:`name`,label:`Name`},{field:`created_at`,label:`Created At`}],sort:[{field:`name`,direction:`asc`}]}}),o.register(`shared-view-link`,jt,{namespace:`view`,label:`Shared View Link`,category:`view`,icon:`Share2`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`viewId`,type:`string`,label:`View ID`},{name:`baseUrl`,type:`string`,label:`Base URL`}],defaultProps:{objectName:`objects`,viewId:`default`}}),o.register(`view:simple`,({schema:e,className:t,children:n,dataSource:r,...i})=>(0,$.jsx)(`div`,{className:t,style:e.props?.columns?{display:`grid`,gridTemplateColumns:`repeat(${e.props.columns}, 1fr)`,gap:`1rem`}:void 0,...i,children:n}),{namespace:`plugin-view`,label:`Simple View`,category:`view`});export{Kt as a,zt as c,Vt as i,It as l,Jt as n,Wt as o,Yt as r,qt as s,Xt as t,yt as u};