@objectstack/console 8.0.1 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AiPendingActionsPage-GMbp_gU6.js → AiPendingActionsPage-B9iWZUDQ.js} +1 -1
- package/dist/assets/{ApiConsolePage-fx31NUJu.js → ApiConsolePage-ZBL7GLt2.js} +1 -1
- package/dist/assets/AppManagementPage-A8AufLcC.js +1 -0
- package/dist/assets/{ApprovalsInboxPage-Nx8dWGIh.js → ApprovalsInboxPage-Be6DrS7X.js} +1 -1
- package/dist/assets/{AuditLogPage-BbJVvOwP.js → AuditLogPage-DWQl9my4.js} +1 -1
- package/dist/assets/{ComponentNavView-BDbQBPDu.js → ComponentNavView-CqfUzDMU.js} +1 -1
- package/dist/assets/ConsoleFloatingChatbot-ByiTKdo6.js +1 -0
- package/dist/assets/DeveloperHubPage-D7pt27Ji.js +1 -0
- package/dist/assets/FlowRunsPage-R-JzHY35.js +1 -0
- package/dist/assets/{IntegrationsPage-ByxF20mz.js → IntegrationsPage-CHg7ApBe.js} +2 -2
- package/dist/assets/{MonacoImpl-D8XcOOYC.js → MonacoImpl-BsJjT9SV.js} +1 -1
- package/dist/assets/{ProfilePage-Cg44IVsv.js → ProfilePage-D7kxyCKj.js} +1 -1
- package/dist/assets/PublicFormsPage-B1VZJXuJ.js +1 -0
- package/dist/assets/{RecentItemsProvider-PPHUem2M.js → RecentItemsProvider-DiJIrHwK.js} +1 -1
- package/dist/assets/{SettingsHub-BSUyG7Hf.js → SettingsHub-DerOpof3.js} +1 -1
- package/dist/assets/SettingsView-BNq6smI8.js +1 -0
- package/dist/assets/SystemHubPage-UTl8x-Bf.js +1 -0
- package/dist/assets/data-adapter-DlR5JXpU.js +1 -0
- package/dist/assets/{dist-BG5mNWi0.js → dist-DYcwLEm6.js} +1 -1
- package/dist/assets/{framework-CzhT5JRV.js → framework-DoGxClbR.js} +6 -6
- package/dist/assets/{highlighted-body-OFNGDK62-BhGyBfwq.js → highlighted-body-OFNGDK62-Bu5WidAv.js} +1 -1
- package/dist/assets/index-Bt0jFx__.js +32 -0
- package/dist/assets/index-CJppnf0b.css +2 -0
- package/dist/assets/infrastructure-CxityHZF.js +3 -0
- package/dist/assets/mergeServerFields-DL5isEen.js +7 -0
- package/dist/assets/mermaid-GHXKKRXX-BAcku4Xs.js +1 -0
- package/dist/assets/plugin-calendar-CUnlH4Wo.js +1 -0
- package/dist/assets/plugin-charts-BjUzf65B.js +7 -0
- package/dist/assets/plugin-chatbot-DUla2_T9.js +120 -0
- package/dist/assets/plugin-dashboard-DbPGiGy-.js +5 -0
- package/dist/assets/plugin-form-CcC4fdyJ.js +1 -0
- package/dist/assets/plugin-gantt-BRef4N3J.js +1 -0
- package/dist/assets/plugin-grid-BiWgglXK.js +6 -0
- package/dist/assets/plugin-kanban-C1UyFHza.js +1 -0
- package/dist/assets/plugin-map-Bt30Mxn6.js +1 -0
- package/dist/assets/plugin-markdown-tayYSGF3.js +7 -0
- package/dist/assets/plugin-report-qca5M0OZ.js +59 -0
- package/dist/assets/{plugin-timeline-Cj7Vdr5S.js → plugin-timeline-DZoFKL82.js} +1 -1
- package/dist/assets/plugin-view-Ei4BPIYk.js +1 -0
- package/dist/assets/plugins-views-qoGCOQ47.js +4 -0
- package/dist/assets/runtime-config-ir5bt3TX.js +1 -0
- package/dist/assets/{src-DkkPzDZy.js → src-DOKKicsm.js} +1 -1
- package/dist/assets/{types-CUTB6-yK.js → types-TLjbGkho.js} +1 -1
- package/dist/assets/ui-components-DeXgqLMc.js +42 -0
- package/dist/assets/{ui-layout-BiOdr9x-.js → ui-layout-CvIgXgRF.js} +1 -1
- package/dist/assets/vendor-charts-DAigH0Ti.js +39 -0
- package/dist/assets/{vendor-dndkit-Ds4hJT77.js → vendor-dndkit-DMFEUxSy.js} +1 -1
- package/dist/assets/{vendor-i18n-D22Ua8-0.js → vendor-i18n-CdF5ccW5.js} +1 -1
- package/dist/assets/{vendor-icons-core-XrvLM9sL.js → vendor-icons-core-C_yMA5lO.js} +1 -1
- package/dist/assets/{vendor-markdown-CW3B88C8.js → vendor-markdown-C9mPywRm.js} +2 -2
- package/dist/assets/vendor-objectstack-B2q1QmZh.js +102 -0
- package/dist/assets/vendor-radix-CSVEhP0L.js +56 -0
- package/dist/assets/vendor-react-DR370ovB.js +11 -0
- package/dist/assets/vendor-sentry-Cv_7Tgs6.js +501 -0
- package/dist/assets/{vendor-ui-utils-CjuGfYLJ.js → vendor-ui-utils-rQOI1gAo.js} +1 -1
- package/dist/index.html +6 -6
- package/package.json +1 -1
- package/dist/assets/AppManagementPage-D8RAo63V.js +0 -1
- package/dist/assets/ConsoleFloatingChatbot-ez78SjMT.js +0 -1
- package/dist/assets/DeveloperHubPage-DcJoR8P3.js +0 -1
- package/dist/assets/FlowRunsPage-lx4QRpzF.js +0 -1
- package/dist/assets/PublicFormsPage-Cy_6D1eO.js +0 -1
- package/dist/assets/SettingsView-DPBCFHk1.js +0 -1
- package/dist/assets/SystemHubPage-CJGBoDcK.js +0 -1
- package/dist/assets/data-adapter-_AZenlJe.js +0 -1
- package/dist/assets/index-BN0WVFAv.js +0 -32
- package/dist/assets/index-TbUZx7_1.css +0 -2
- package/dist/assets/infrastructure-ai8_U_pI.js +0 -3
- package/dist/assets/mergeServerFields-B5HoGDzy.js +0 -7
- package/dist/assets/mermaid-GHXKKRXX-DjL587yX.js +0 -1
- package/dist/assets/plugin-calendar-CJzupXd5.js +0 -1
- package/dist/assets/plugin-charts-BEUWAwv7.js +0 -7
- package/dist/assets/plugin-chatbot-Bu4iH5QF.js +0 -120
- package/dist/assets/plugin-dashboard-Cp10Wl4m.js +0 -3
- package/dist/assets/plugin-form-C0Ec8keG.js +0 -1
- package/dist/assets/plugin-gantt-BCNazePX.js +0 -1
- package/dist/assets/plugin-grid-b1qcltrl.js +0 -6
- package/dist/assets/plugin-kanban-DH3H0Wva.js +0 -1
- package/dist/assets/plugin-map-Bq_z3o3E.js +0 -1
- package/dist/assets/plugin-markdown-MGi27oiL.js +0 -7
- package/dist/assets/plugin-report-DSe9lGEO.js +0 -59
- package/dist/assets/plugin-view-DcCK17lP.js +0 -1
- package/dist/assets/plugins-views-BCJT2gzM.js +0 -4
- package/dist/assets/ui-components-BHdgV-R1.js +0 -42
- package/dist/assets/vendor-charts-4buVt82U.js +0 -39
- package/dist/assets/vendor-objectstack-DRFh8zSo.js +0 -96
- package/dist/assets/vendor-radix-Bzf7fki-.js +0 -56
- package/dist/assets/vendor-react-BMpe6Iqg.js +0 -13
- package/dist/assets/vendor-sentry-BreXt3n4.js +0 -501
|
@@ -1,59 +0,0 @@
|
|
|
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{B as i,H as a,mt as o,nt as s,rt as c}from"./framework-CzhT5JRV.js";import{n as l}from"./vendor-i18n-D22Ua8-0.js";import{Ai as u,At as d,Bn as f,Fi as p,Fn as m,Fr as h,Gn as g,Go as _,H as v,Ia as y,In as b,Jn as x,Kn as S,Ln as C,Qn as w,Qs as T,Ri as E,Rn as D,Rr as O,Rs as k,Sa as A,T as j,Vn as M,Ws as N,Xn as P,Yn as F,Ys as I,bs as ee,cs as te,en as L,et as ne,hi as re,in as R,jo as ie,l as ae,m as oe,mr as z,nt as se,oo as ce,qn as B,rt as V,tt as H,us as le,vi as ue,xi as de,zn as fe}from"./ui-components-BHdgV-R1.js";import{r as pe}from"./plugin-grid-b1qcltrl.js";var U=e(r(),1),W=n(),me=({schema:e})=>{let{title:t,description:n,data:r,columns:i}=e;e.chart?.type;let a=!!e.chart;return(0,W.jsxs)(S,{className:`h-full flex flex-col ${e.className||``}`,children:[(0,W.jsxs)(F,{children:[t&&(0,W.jsx)(P,{children:t}),n&&(0,W.jsx)(x,{children:n})]}),(0,W.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,W.jsx)(`div`,{className:`min-h-[300px] border rounded-lg p-4 bg-background/50`,children:(0,W.jsx)(n,{schema:{...e.chart,data:e.chart.data||r}})}):(0,W.jsxs)(`div`,{className:`min-h-[100px] border rounded-md p-4 bg-muted/20 text-muted-foreground flex items-center justify-center`,children:[`Unknown component type: `,t||`chart`]})})(),r&&r.length>0&&(0,W.jsx)(`div`,{className:`border rounded-lg`,children:(()=>{let e=o.get(`grid`)||o.get(`table`);return e?(0,W.jsx)(e,{schema:{type:`grid`,rowData:r,columnDefs:i,domLayout:`autoHeight`}}):(0,W.jsx)(`div`,{className:`overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,W.jsx)(`thead`,{className:`text-xs uppercase bg-muted`,children:(0,W.jsx)(`tr`,{children:i?.map(e=>(0,W.jsx)(`th`,{className:`px-6 py-3`,children:e.headerName||e.label||e.field},e.field))})}),(0,W.jsx)(`tbody`,{children:r.map((e,t)=>(0,W.jsx)(`tr`,{className:`bg-background border-b`,children:i?.map(t=>(0,W.jsx)(`td`,{className:`px-6 py-4`,children:e[t.field]},t.field))},t))})]})})})()})]})]})};function G(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function he(e,t){if(e==null)return null;let n=e instanceof Date?e:new Date(String(e));if(Number.isNaN(n.getTime()))return null;let r=n.getUTCFullYear(),i=n.getUTCMonth(),a=n.getUTCDate();switch(t){case`year`:return String(r);case`quarter`:return`${r}-Q${Math.floor(i/3)+1}`;case`month`:return`${r}-${String(i+1).padStart(2,`0`)}`;case`week`:{let e=new Date(Date.UTC(r,i,a)),t=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-t);let n=new Date(Date.UTC(e.getUTCFullYear(),0,1)),o=Math.ceil(((e.getTime()-n.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${String(o).padStart(2,`0`)}`}case`day`:return`${r}-${String(i+1).padStart(2,`0`)}-${String(a).padStart(2,`0`)}`;default:return String(e)}}function K(e,t){let n=e[t.field];return t.dateGranularity?he(n,t.dateGranularity)??`(empty)`:n==null||n===``?`(empty)`:String(n)}function q(e,t){let n={};for(let r of t){if(!r.aggregate){let t=e.find(e=>e[r.field]!=null);n[G(r)]=t?t[r.field]:null;continue}let t=e.map(e=>e[r.field]);switch(r.aggregate){case`count`:n[G(r)]=t.length;break;case`unique`:{let e=new Set;for(let n of t)n!=null&&e.add(n);n[G(r)]=e.size;break}case`sum`:{let e=0;for(let n of t)e+=Number(n)||0;n[G(r)]=e;break}case`avg`:{let e=0,i=0;for(let n of t){if(n==null||n===``)continue;let t=Number(n);Number.isNaN(t)||(e+=t,i+=1)}n[G(r)]=i===0?null:e/i;break}case`min`:{let e=null;for(let n of t){if(n==null)continue;let t=Number(n);Number.isNaN(t)||(e===null||t<e)&&(e=t)}n[G(r)]=e;break}case`max`:{let e=null;for(let n of t){if(n==null)continue;let t=Number(n);Number.isNaN(t)||(e===null||t>e)&&(e=t)}n[G(r)]=e;break}default:n[G(r)]=null}}return n}function ge(e,t,n,r={},i=[]){if(t.length===0)return[];let[a,...o]=t,s=new Map;for(let t of e){let e=K(t,a),n=s.get(e);n||(n=[],s.set(e,n)),n.push(t)}let c=[];for(let[e,t]of s){let s={...r,[a.field]:e},l=[...i,e],u=q(t,n),d=o.length>0?ge(t,o,n,s,l):void 0;c.push({groupKey:s,groupPath:l,values:u,count:t.length,children:d})}let l=a.sort===`desc`?-1:1;return c.sort((e,t)=>{let n=String(e.groupPath[e.groupPath.length-1]),r=String(t.groupPath[t.groupPath.length-1]);return n.localeCompare(r)*l}),typeof a.limit==`number`&&a.limit>0?c.slice(0,a.limit):c}function _e(e,t,n,r){let i=ve(e,n),a=ve(e,r),o={},s={},c={};for(let c of i){o[c.id]={};let i=ye(e,c.key,n);s[c.id]=q(i,t);for(let e of a){let n=ye(i,e.key,r);n.length!==0&&(o[c.id][e.id]=q(n,t))}}for(let n of a){let i=ye(e,n.key,r);c[n.id]=q(i,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:q(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function ve(e,t){if(t.length===0)return[{key:{},path:[],id:``}];let n=new Map;for(let r of e){let e=[],i={};for(let n of t){let t=K(r,n);e.push(t),i[n.field]=t}let a=e.join(``);n.has(a)||n.set(a,{key:i,path:e,id:a})}let r=Array.from(n.values());r.sort((e,n)=>{for(let r=0;r<t.length;r++){let i=t[r].sort===`desc`?-1:1,a=e.path[r].localeCompare(n.path[r])*i;if(a!==0)return a}return 0});let i=t[0].limit;if(typeof i==`number`&&i>0){let e=new Set;for(let t of r)e.size>=i&&!e.has(t.path[0])||e.add(t.path[0]);return r.filter(t=>e.has(t.path[0]))}return r}function ye(e,t,n){let r=Object.entries(t);if(r.length===0)return e;let i=new Map;for(let e of n)i.set(e.field,e);return e.filter(e=>{for(let[t,n]of r){let r=i.get(t);if((r?K(e,r):e[t]==null?`(null)`:String(e[t]))!==String(n))return!1}return!0})}function J(e,t){let n={};for(let r of t){if(!r.aggregate)continue;let t=G(r),i=0,a=0,o=null,s=null;for(let n of e){let e=n[t];typeof e==`number`&&(i+=e,a+=1,(o==null||e<o)&&(o=e),(s==null||e>s)&&(s=e))}r.aggregate===`min`?n[t]=o:r.aggregate===`max`?n[t]=s:r.aggregate===`avg`?n[t]=a===0?null:i/a:n[t]=i}return n}function be(e,t,n,r){let i=xe(e,n),a=xe(e,r),o={},s={},c={};for(let n of i){o[n.id]={};let r=e.filter(e=>Se(e,n.key));s[n.id]=J(r,t);for(let e of a){let i=r.filter(t=>Se(t,e.key));if(i.length===0)continue;let a={};for(let e of t){if(!e.aggregate)continue;let t=G(e);a[t]=i[0][t]}o[n.id][e.id]=a}}for(let n of a){let r=e.filter(e=>Se(e,n.key));c[n.id]=J(r,t)}return{rowHeaders:i,colHeaders:a,cells:o,rowTotals:s,colTotals:c,grandTotal:J(e,t),columns:t,downGroupings:n,acrossGroupings:r}}function xe(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 Se(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 Y(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 Ce(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 we(e,t,n){let r=[...e.groupingsDown??[],...e.groupingsAcross??[]],i=(e.columns??[]).filter(e=>!!e.aggregate);if(r.length===0&&i.length===0)return null;let a=r.map(e=>e.dateGranularity?{field:e.field,dateGranularity:e.dateGranularity}:e.field),o=i.map(e=>({function:e.aggregate===`unique`?`count_distinct`:e.aggregate,field:e.field,alias:G(e)})),s=Y(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 Te(e,t,n){for(let[r,i]of Object.entries(t)){let t=n.find(e=>e.field===r);if((t?K(e,t):String(e[r]??`(empty)`))!==String(i))return!1}return!0}var X=[];function Ee(e,t={}){let{dataSource:n,runtimeFilter:r,maxRows:i=5e3,enabled:a=!0,rows:o,preferServerAggregation:s=!0}=t,[c,l]=(0,U.useState)(o??X),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(()=>o?!1:!!(e&&a&&n)),[m,h]=(0,U.useState)(null),g=(0,U.useRef)(0),_=(0,U.useCallback)(async()=>{if(!e||!a)return;if(o){l(o),d(!1);return}if(!n){l(X);return}let t=++g.current;p(!0),h(null);try{let a=s?we(e,r,i):null;if(a&&typeof n.aggregate==`function`)try{let r=De(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(X),d(!1);return}let o=Y(e.filter,r),c=Ce(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=De(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(X),d(!1)}finally{t===g.current&&p(!1)}},[e,a,o,n,r,i,s]);(0,U.useEffect)(()=>{_()},[_]);let{rows:v,totals:y,pivot:b}=(0,U.useMemo)(()=>{if(!e)return{rows:[],totals:{},pivot:null};let t=e.groupingsDown??[],n=e.groupingsAcross??[],r=e.columns??[],i=n.length>0;if(u){let e=[...t,...n],a=c.map(t=>{let n={},r=[];for(let i of e){let e=t[i.field];n[i.field]=e,r.push(e==null?`(null)`:String(e))}let i={...t};for(let t of e)delete i[t.field];return{groupKey:n,groupPath:r,values:i,count:1}}),o=J(c,r),s=i?be(c,r,t,n):null;return{rows:i&&s?s.rowHeaders.map(e=>({groupKey:e.key,groupPath:e.path,values:s.rowTotals[e.id]??{},count:1})):a,totals:o,pivot:s}}let a=i?t:[...t,...n];return{rows:a.length>0?ge(c,a,r):c.map(e=>({groupKey:{},groupPath:[],values:r.length>0?q([e],r):{...e},count:1})),totals:q(c,r),pivot:i?_e(c,r,t,n):null}},[e,c,u]);return{rows:v,rawRows:c,totals:y,pivot:b,serverAggregated:u,loading:f,error:m,refetch:_,drillDown:(0,U.useCallback)(t=>{if(!e)return[];let n=[...e.groupingsDown??[],...e.groupingsAcross??[]];return c.filter(e=>Te(e,t,n))},[e,c])}}function De(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 X}function Oe(e){return e.aggregate?`${e.field}__${e.aggregate}`:e.field}function ke(e){let t=[],n=e=>{e.children&&e.children.length>0?e.children.forEach(n):t.push(e)};return e.forEach(n),t}function Ae({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=Oe(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=ke(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 je(e,t,n={}){let r=Y(Y(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 Me(e){return!!e&&e.type===`drill`}function Ne(e){return async t=>{if(!Me(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 Pe(e,t){return e.registerHandler(`drill`,Ne(t)),()=>e.unregisterHandler(`drill`)}function Fe(e){return e?e===`unique`?`count_distinct`:e:null}function Ie(e){if(!(!e||e.length===0))return{fields:e.map(e=>({field:e.field,order:e.sort??`asc`,collapsed:!1}))}}function Le(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 Re={padding:`12px 16px`,border:`1px dashed rgb(203 213 225)`,borderRadius:8,color:`rgb(100 116 139)`,fontSize:14},ze=({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}=T(),[h,g]=U.useState(null);U.useEffect(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`||!e.objectName)return;let r=!1;return n.getObjectSchema(e.objectName).then(e=>{r||g(e??null)}).catch(()=>{}),()=>{r=!0}},[t,e.objectName]);let _=U.useCallback(t=>{if(t.label)return String(t.label);let n=h?.fields?.[t.field]?.label??t.field,r=p(e.objectName,t.field,n);return t.aggregate?`${r} · ${f(`report.aggregate.${t.aggregate}`,t.aggregate)}`:r},[h,e.objectName,p,f]),v=U.useCallback((t,n)=>{if(n==null)return;let r=h?.fields?.[t];if(!r||!(r.type===`select`||r.type===`status`)||!Array.isArray(r.options)||r.options.length===0)return;let i=m(e.objectName,t,r.options),a=String(n);for(let e of i)if(e&&e.value!==void 0&&e.value!==null&&String(e.value)===a)return e.label==null?a:String(e.label)},[h,e.objectName,m]),{rawRows:y,rows:b,totals:x,serverAggregated:S,loading:C,error:w,drillDown:E}=Ee(e,{dataSource:t,rows:n,runtimeFilter:r});if(d===`matrix`||d===`joined`)return(0,W.jsxs)(`div`,{className:u,style:Re,children:[`Report type `,(0,W.jsx)(`code`,{children:d}),` is not yet supported by SpecReportGrid. It will be rendered by a dedicated component in M2 (matrix) / M3 (joined).`]});let D=U.useMemo(()=>{if(S){let t=(e.groupingsDown??[]).map(e=>({field:e.field,label:e.field.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})),n=(e.columns??[]).filter(e=>e.aggregate).map(e=>({field:G(e),label:`${(typeof e.label==`string`?e.label:null)??e.field} (${e.aggregate})`,...e.format?{format:e.format}:{}}));return{type:`object-grid`,objectName:e.objectName,columns:[...t,...n]}}let t=d===`summary`?Ie(e.groupingsDown):void 0,n=(e.columns??[]).map(e=>{let t=Fe(e.aggregate);return t?{field:e.field,type:t}:null}).filter(e=>e!==null);return{type:`object-grid`,objectName:e.objectName,columns:Le(e),grouping:t,aggregations:n.length>0?n:void 0}},[e,d,S]),O=y,k=U.useCallback(t=>{let n=e.groupingsDown??[],i={};for(let e of n)i[e.field]=t[e.field];if(o){let t=je(e,i,{runtimeFilter:r,view:s,openIn:c});o.execute(t)}a&&a(i,E(i))},[o,E,c,s,a,e,r]),A=!!a||!!o,j=(e.columns??[]).filter(e=>e.aggregate),M=j.length>0&&x&&Object.keys(x).length>0,N=U.useMemo(()=>d!==`summary`||!e.chart||!e.chart.type?null:Ae({report:e,rows:b,labels:{resolveColumnLabel:_,resolveCountLabel:t=>{let n=h?.fields?.[t]?.label??t;return`${p(e.objectName,t,n)} · ${f(`report.aggregate.count`,`Count`)}`},resolveAxisValue:v}}).schema,[e,b,d,_,v,h,p,f]);return(0,W.jsxs)(`div`,{className:u,"data-testid":`spec-report-grid`,"aria-busy":C||void 0,children:[w?(0,W.jsx)(`div`,{role:`alert`,style:{...Re,color:`rgb(190 18 60)`},children:w.message}):null,M?(0,W.jsxs)(`div`,{"data-testid":`spec-report-totals`,className:`mb-3 flex flex-wrap items-baseline gap-x-6 gap-y-1 rounded-md border bg-muted/40 px-3 py-2 text-sm`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:f(`report.totals`,`Totals`)}),j.map(e=>{let t=G(e),n=x[t],r=_(e),i=typeof n==`number`?n.toLocaleString(void 0,{maximumFractionDigits:2}):String(n??`—`);return(0,W.jsxs)(`span`,{"data-testid":`spec-report-total-${t}`,className:`inline-flex items-baseline gap-1.5`,children:[(0,W.jsxs)(`span`,{className:`text-muted-foreground`,children:[r,`:`]}),(0,W.jsx)(`span`,{className:`font-mono font-medium tabular-nums`,children:i})]},t)})]}):null,N?(0,W.jsx)(`div`,{className:`mb-4`,"data-testid":`spec-report-chart`,children:(0,W.jsx)(i,{schema:N})}):null,(0,W.jsx)(pe,{schema:D,data:O,dataSource:t,onRowClick:A?k:void 0})]})};ze.displayName=`SpecReportGrid`;var Be=`—`;function Ve(e){return e==null?Be:typeof e==`number`?e.toLocaleString():String(e)}function He(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 Ue({header:e,groupings:t,metaByField:n,fallback:r,emptyLabel:i}){return e.path.length===0?(0,W.jsx)(W.Fragment,{children:r}):(0,W.jsx)(W.Fragment,{children:e.path.map((e,r)=>{let a=t[r]?.field;return He(e,a?n.get(a):void 0,i)}).join(` / `)})}var We=({report:e,dataSource:t,rows:n,runtimeFilter:r,onCellClick:i,actionRunner:a,drillView:o,drillOpenIn:s,className:c,emptyCellText:u=Be})=>{let{pivot:d,loading:f,error:p}=Ee(e,{dataSource:t,rows:n,runtimeFilter:r}),m=e.columns??[],h=m.length>1,{fieldLabel:g,translateOptions:_}=T(),{t:v}=l(),y=v(`report.emptyLabel`,`(Empty)`),b=v(`report.allLabel`,`(All)`),[x,S]=U.useState(null);U.useEffect(()=>{let n=t;if(!n||typeof n.getObjectSchema!=`function`||!e.objectName)return;let r=!1;return n.getObjectSchema(e.objectName).then(e=>{r||S(e??null)}).catch(()=>{}),()=>{r=!0}},[t,e.objectName]);let C=e.groupingsDown??[],w=e.groupingsAcross??[],E=U.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,_]),D=U.useMemo(()=>{let t=new Map,n=x?.fields??{};for(let r of m){let i=G(r);if(r.label){t.set(i,String(r.label));continue}let a=n[r.field]?.label??r.field,o=g(e.objectName,r.field,a);if(r.aggregate){let e=v(`report.aggregate.${r.aggregate}`,r.aggregate);t.set(i,`${o} · ${e}`)}else t.set(i,o)}return t},[m,x,e.objectName,g,v]),O=U.useCallback((t,n,c)=>{let l={...t.key,...n.key};if(a){let t=je(e,l,{runtimeFilter:r,view:o,openIn:s});a.execute(t)}i&&i({rowKey:t.key,colKey:n.key,combinedKey:l,values:c})},[a,s,o,i,e,r]);if(p)return(0,W.jsx)(`div`,{className:I(`rounded-md border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive`,c),role:`alert`,"data-testid":`matrix-error`,children:v(`report.failedToLoad`,`Failed to load matrix: {{message}}`,{message:p.message})});if(!d)return(0,W.jsx)(`div`,{className:I(`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=>E.get(e.field)?.fieldLabel??e.field).join(` / `)||v(`report.rowsLabel`,`Row`),j=w.map(e=>E.get(e.field)?.fieldLabel??e.field).join(` / `)||v(`report.columnsLabel`,`Column`),M=m.length>0?G(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,W.jsx)(`div`,{className:I(`overflow-auto rounded-lg border border-border bg-card shadow-sm`,c),"data-testid":`matrix-renderer`,"aria-busy":f||void 0,children:(0,W.jsxs)(`table`,{role:`table`,className:`w-full border-separate border-spacing-0 text-sm`,children:[(0,W.jsx)(`thead`,{children:(0,W.jsxs)(`tr`,{children:[(0,W.jsxs)(`th`,{scope:`col`,className:I(`sticky left-0 top-0 z-30 border-b border-r border-border bg-muted/60`,`px-3 py-2 text-left text-xs font-semibold uppercase tracking-wide text-muted-foreground`),"aria-label":`${A} \u2192 ${j}`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground/70`,children:A}),(0,W.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`\\`}),(0,W.jsx)(`span`,{className:`text-foreground/80`,children:j})]}),d.colHeaders.map(e=>(0,W.jsx)(`th`,{scope:`col`,className:`sticky top-0 z-20 whitespace-nowrap border-b border-border bg-muted/60 px-3 py-2 text-right text-xs font-semibold text-foreground`,children:(0,W.jsx)(Ue,{header:e,groupings:w,metaByField:E,fallback:b,emptyLabel:y})},`col-${e.id}`)),(0,W.jsx)(`th`,{scope:`col`,className:`sticky top-0 z-20 whitespace-nowrap border-b border-l border-border bg-muted px-3 py-2 text-right text-xs font-semibold uppercase tracking-wide text-foreground`,children:v(`report.rowTotal`,`Row Total`)})]})}),(0,W.jsx)(`tbody`,{children:d.rowHeaders.map((e,t)=>(0,W.jsxs)(`tr`,{className:`group`,children:[(0,W.jsx)(`th`,{scope:`row`,className:I(`sticky left-0 z-10 whitespace-nowrap border-b border-r border-border bg-card px-3 py-2 text-left text-sm font-medium text-foreground`,`group-hover:bg-muted/50`,t===0&&`border-t-0`),children:(0,W.jsx)(Ue,{header:e,groupings:C,metaByField:E,fallback:b,emptyLabel:y})}),d.colHeaders.map(t=>{let n=d.cells[e.id]?.[t.id],r=!n,i=P(n);return(0,W.jsx)(`td`,{className:I(`border-b border-border px-3 py-2 text-right tabular-nums transition-colors`,r?`text-muted-foreground/40`:`text-foreground`,k&&!r&&`cursor-pointer hover:outline hover:outline-2 hover:-outline-offset-2 hover:outline-primary/50`,`group-hover:bg-muted/30`),style:i>0?{backgroundColor:`rgba(59, 130, 246, ${.06+i*.28})`}:void 0,onClick:k&&!r?()=>O(e,t,n):void 0,"data-row":e.id,"data-col":t.id,children:r?u:Z(m,n,h,D)},`cell-${e.id}-${t.id}`)}),(0,W.jsx)(`td`,{className:I(`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:Z(m,d.rowTotals[e.id]??{},h,D)})]},`row-${e.id}`))}),(0,W.jsx)(`tfoot`,{children:(0,W.jsxs)(`tr`,{children:[(0,W.jsx)(`th`,{scope:`row`,className:`sticky left-0 z-10 whitespace-nowrap border-t-2 border-r border-border bg-muted px-3 py-2 text-left text-xs font-semibold uppercase tracking-wide text-foreground`,children:v(`report.columnTotal`,`Column Total`)}),d.colHeaders.map(e=>(0,W.jsx)(`td`,{className:`border-t-2 border-border bg-muted/40 px-3 py-2 text-right text-sm font-semibold tabular-nums text-foreground`,children:Z(m,d.colTotals[e.id]??{},h,D)},`coltotal-${e.id}`)),(0,W.jsx)(`td`,{className:`border-l border-t-2 border-border bg-primary/10 px-3 py-2 text-right text-sm font-bold tabular-nums text-foreground`,children:Z(m,d.grandTotal,h,D)})]})})]})})};function Z(e,t,n,r){return e.length?n?(0,W.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:e.map(e=>{let n=G(e);return(0,W.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r?.get(n)??e.label??n}),(0,W.jsx)(`span`,{className:`tabular-nums`,children:Ve(t[n])})]},n)})}):Ve(t[G(e[0])]):Be}function Ge(e,t){return e?typeof e==`string`?e:typeof e==`object`&&typeof e.default==`string`?e.default:t:t}function Ke(e,t){if(!t||Object.keys(t).length===0)return e;let n=Y(t,e.filter);return{...e,filter:n}}var qe=({report:e,dataSource:t,runtimeFilter:n,actionRunner:r,drillView:i,drillOpenIn:a,className:o,renderBlock:c})=>{if(!s(e))return(0,W.jsxs)(`div`,{className:o,"data-testid":`joined-report-invalid`,style:{color:`var(--color-destructive, #b91c1c)`,fontSize:13,padding:12},children:[`JoinedReportRenderer requires a report with `,(0,W.jsx)(`code`,{children:`type: 'joined'`}),` and a `,(0,W.jsx)(`code`,{children:`blocks`}),` array.`]});let l=e.blocks??[],u=e.filter,d=e.objectName;return(0,W.jsx)(`div`,{className:o,"data-testid":`joined-report`,"data-report-name":e.name,style:{display:`flex`,flexDirection:`column`,gap:24},children:l.map((e,o)=>{let s=e.objectName??d??``,l=Ke({...e,objectName:s,type:e.type??`tabular`,columns:e.columns??[]},u),f=Ge(e.label,e.name),p=e.description?Ge(e.description,``):``,m=e.name??`block-${o}`,h=(0,W.jsxs)(`section`,{"data-testid":`joined-report-block`,"data-block-id":m,style:{display:`flex`,flexDirection:`column`,gap:8,border:`1px solid var(--color-border, #e4e4e7)`,borderRadius:8,padding:16,background:`var(--color-card, #ffffff)`},children:[(0,W.jsxs)(`header`,{style:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,W.jsx)(`h3`,{style:{margin:0,fontSize:16,fontWeight:600},children:f}),p?(0,W.jsx)(`p`,{style:{margin:0,fontSize:13,color:`var(--color-muted-foreground, #71717a)`},children:p}):null]}),(0,W.jsx)(Ye,{schema:l,dataSource:t,runtimeFilter:n,actionRunner:r,drillView:i,drillOpenIn:a})]},m);return c?c(e,o,h):h})})},Je={border:`1px dashed var(--color-border, #d4d4d8)`,borderRadius:8,padding:16,color:`var(--color-muted-foreground, #71717a)`,background:`var(--color-muted, #f4f4f5)`,fontSize:13},Ye=e=>{let{dataSource:t,rows:n,runtimeFilter:r,actionRunner:i,drillView:o,drillOpenIn:l,className:u}=e,d=U.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),c(p)){let e=p.type??`tabular`;return e===`matrix`?(0,W.jsx)(We,{report:p,dataSource:f,rows:n,runtimeFilter:r,actionRunner:i,drillView:o,drillOpenIn:l,className:u}):e===`joined`?s(p)?(0,W.jsx)(qe,{report:p,dataSource:f,runtimeFilter:r,actionRunner:i,drillView:o,drillOpenIn:l,className:u}):(0,W.jsxs)(`div`,{className:u,style:Je,"data-testid":`report-joined-placeholder`,children:[`Joined report (`,(0,W.jsx)(`code`,{children:p.name}),`) is missing a `,(0,W.jsx)(`code`,{children:`blocks`}),` array.`]}):(0,W.jsx)(ze,{report:p,dataSource:f,rows:n,runtimeFilter:r,actionRunner:i,drillView:o,drillOpenIn:l,className:u})}return(0,W.jsx)(me,{schema:p})};function Xe(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=nt(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
|
|
2
|
-
`))?`"${n.replace(/"/g,`""`)}"`:n??``}));at([...n?.includeHeaders===!1?[]:[i.join(`,`)],...a.map(e=>e.join(`,`))].join(`
|
|
3
|
-
`),n?.filename||`${e.title||`report`}.csv`,`text/csv`)}function Ze(e,t,n){let r={title:e.title,description:e.description,generatedAt:new Date().toISOString(),data:t};at(JSON.stringify(r,null,2),n?.filename||`${e.title||`report`}.json`,`application/json`)}function Qe(e,t,n){let r=e.fields||[],i=it(n?.orientation),a=rt(n?.pageSize);at(`<!DOCTYPE html>
|
|
4
|
-
<html>
|
|
5
|
-
<head>
|
|
6
|
-
<meta charset="utf-8">
|
|
7
|
-
<title>${Q(e.title||`Report`)}</title>
|
|
8
|
-
<style>
|
|
9
|
-
@page { size: ${a} ${i}; margin: 20mm; }
|
|
10
|
-
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
|
|
11
|
-
h1 { font-size: 24px; margin-bottom: 8px; }
|
|
12
|
-
.description { color: #666; margin-bottom: 24px; }
|
|
13
|
-
.meta { color: #999; font-size: 12px; margin-bottom: 16px; }
|
|
14
|
-
table { width: 100%; border-collapse: collapse; margin-top: 16px; }
|
|
15
|
-
th { background: #f5f5f5; text-align: left; padding: 8px 12px; border: 1px solid #ddd; font-weight: 600; }
|
|
16
|
-
td { padding: 8px 12px; border: 1px solid #ddd; }
|
|
17
|
-
tr:nth-child(even) { background: #fafafa; }
|
|
18
|
-
</style>
|
|
19
|
-
</head>
|
|
20
|
-
<body>
|
|
21
|
-
<h1>${Q(e.title||`Report`)}</h1>
|
|
22
|
-
${e.description?`<p class="description">${Q(e.description)}</p>`:``}
|
|
23
|
-
<p class="meta">Generated: ${new Date().toLocaleString()}</p>
|
|
24
|
-
<table>
|
|
25
|
-
<thead><tr>${r.map(e=>`<th>${Q(e.label||e.name)}</th>`).join(``)}</tr></thead>
|
|
26
|
-
<tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${Q(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
|
|
27
|
-
</table>
|
|
28
|
-
</body>
|
|
29
|
-
</html>`,n?.filename||`${e.title||`report`}.html`,`text/html`)}function $e(e,t,n){let r=e.fields||[],i=it(n?.orientation),a=rt(n?.pageSize),o=window.open(``,`_blank`);if(!o){Qe(e,t,{...n,format:`html`,filename:n?.filename?.replace(/\.pdf$/,`.html`)||`${e.title||`report`}.html`});return}o.document.write(`<!DOCTYPE html>
|
|
30
|
-
<html>
|
|
31
|
-
<head>
|
|
32
|
-
<meta charset="utf-8">
|
|
33
|
-
<title>${Q(e.title||`Report`)}</title>
|
|
34
|
-
<style>
|
|
35
|
-
@page { size: ${a} ${i}; margin: 20mm; }
|
|
36
|
-
@media print { .no-print { display: none; } }
|
|
37
|
-
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #333; }
|
|
38
|
-
h1 { font-size: 24px; margin-bottom: 8px; }
|
|
39
|
-
.description { color: #666; margin-bottom: 24px; }
|
|
40
|
-
.meta { color: #999; font-size: 12px; margin-bottom: 16px; }
|
|
41
|
-
table { width: 100%; border-collapse: collapse; margin-top: 16px; }
|
|
42
|
-
th { background: #f5f5f5; text-align: left; padding: 8px 12px; border: 1px solid #ddd; font-weight: 600; }
|
|
43
|
-
td { padding: 8px 12px; border: 1px solid #ddd; }
|
|
44
|
-
tr:nth-child(even) { background: #fafafa; }
|
|
45
|
-
</style>
|
|
46
|
-
</head>
|
|
47
|
-
<body>
|
|
48
|
-
<h1>${Q(e.title||`Report`)}</h1>
|
|
49
|
-
${e.description?`<p class="description">${Q(e.description)}</p>`:``}
|
|
50
|
-
<p class="meta">Generated: ${new Date().toLocaleString()}</p>
|
|
51
|
-
<table>
|
|
52
|
-
<thead><tr>${r.map(e=>`<th>${Q(e.label||e.name)}</th>`).join(``)}</tr></thead>
|
|
53
|
-
<tbody>${t.map(e=>`<tr>${r.map(t=>`<td>${Q(String(e[t.name]??``))}</td>`).join(``)}</tr>`).join(``)}</tbody>
|
|
54
|
-
</table>
|
|
55
|
-
</body>
|
|
56
|
-
</html>`),o.document.close(),o.onload=()=>{o.print()}}function et(e,t,n){let r=e.fields||[],i=r.map(e=>e.label||e.name),a=t.map(e=>r.map(t=>{let n=e[t.name];return n=nt(n),typeof n==`string`&&(n.includes(`,`)||n.includes(`"`)||n.includes(`
|
|
57
|
-
`)||n.includes(` `))?`"${n.replace(/"/g,`""`)}"`:n??``}));at(``+[...n?.includeHeaders===!1?[]:[i.join(` `)],...a.map(e=>e.join(` `))].join(`
|
|
58
|
-
`),n?.filename||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function tt(e,t,n,r){switch(e){case`csv`:Xe(t,n,r);break;case`json`:Ze(t,n,r);break;case`html`:Qe(t,n,r);break;case`pdf`:$e(t,n,r);break;case`excel`:et(t,n,r);break;default:console.warn(`Unsupported export format: ${e}`)}}function Q(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function nt(e){if(typeof e==`string`&&e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`\t${e}`}return e}function rt(e){return[`A4`,`A3`,`Letter`,`Legal`].includes(e||``)?e:`A4`}function it(e){return e===`landscape`?`landscape`:`portrait`}function at(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function ot(e,t){if(e==null||e===``)return``;let n=t?.type,r=t?.format;if(n===`date`||r===`date`||st(e))return ct(e);if(n===`number`||typeof e==`number`){let t=typeof e==`number`?e:Number(e);return isNaN(t)?String(e):r===`currency`||r===`currency_cny`?`¥${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`currency_usd`?`$${t.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:0})}`:r===`percent`?`${t.toLocaleString(`en-US`,{minimumFractionDigits:1,maximumFractionDigits:1})}%`:t.toLocaleString(`en-US`)}return String(e)}function st(e){return typeof e==`string`?/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(e):!1}function ct(e){try{let t=new Date(e);return isNaN(t.getTime())?String(e):`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}catch{return String(e)}}function lt(e,t){if(!t||t.length===0||!e||e.length===0)return null;let n=t[0],r=n.field,i=new Map;for(let t of e){let e=String(t[r]??`(empty)`);i.has(e)||i.set(e,[]),i.get(e).push(t)}let a=[];for(let[e,t]of i)a.push({key:e,label:`${n.label||r}: ${e}`,rows:t});let o=n.sort===`desc`?-1:1;return a.sort((e,t)=>e.key.localeCompare(t.key)*o),a}var ut=({schema:e,onRefresh:t})=>{let{report:n,data:r,showToolbar:a=!0,allowExport:s=!0,allowPrint:c=!0,loading:l=!1}=e,f=e=>{if(!n){console.warn(`ReportViewer: Cannot export, no report defined`);return}tt(e,n,r||[],n.exportConfigs?.[e])},m=()=>{window.print()},h=()=>{t?.()},g=(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``}},_=(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}}},v=(e,t)=>{if(e==null||e===``)return``;if(t.renderAs===`badge`&&(!t.type||t.type===`string`||t.type===`text`))return(0,W.jsx)(w,{className:t.colorMap?.[String(e)]||``,children:String(e)});if(t.aggregation)return ot(e,t);if(t.type){let n={...t};return t.colorMap&&!n.options&&(n.options=Object.entries(t.colorMap).map(([e,t])=>({value:e,label:e,color:t}))),(0,W.jsx)(ae(oe(n)),{value:e,field:n})}return ot(e,t)};return n?(0,W.jsxs)(`div`,{className:`space-y-4`,children:[a&&(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2 p-4 bg-card rounded-lg border`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold`,children:n.title}),n.description&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.description})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n.refreshInterval&&(0,W.jsxs)(z,{variant:`outline`,size:`sm`,onClick:h,children:[(0,W.jsx)(u,{className:`h-4 w-4 mr-2`}),`Refresh`]}),c&&(0,W.jsxs)(z,{variant:`outline`,size:`sm`,onClick:m,children:[(0,W.jsx)(p,{className:`h-4 w-4 mr-2`}),`Print`]}),s&&n.showExportButtons&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,W.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>f(`pdf`),children:[(0,W.jsx)(ie,{className:`h-4 w-4 mr-2`}),`PDF`]}),(0,W.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>f(`excel`),children:[(0,W.jsx)(ie,{className:`h-4 w-4 mr-2`}),`Excel`]}),(0,W.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>f(`csv`),children:[(0,W.jsx)(ie,{className:`h-4 w-4 mr-2`}),`CSV`]})]})]})]}),(0,W.jsxs)(S,{children:[(0,W.jsxs)(F,{children:[!a&&n.title&&(0,W.jsx)(P,{children:n.title}),!a&&n.description&&(0,W.jsx)(x,{children:n.description})]}),(0,W.jsxs)(B,{className:`space-y-6`,children:[l&&(0,W.jsxs)(`div`,{className:`space-y-6`,children:[(0,W.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[1,2,3].map(e=>(0,W.jsx)(S,{children:(0,W.jsxs)(B,{className:`p-4 space-y-2`,children:[(0,W.jsx)(d,{className:`h-4 w-20`}),(0,W.jsx)(d,{className:`h-8 w-28`})]})},e))}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(d,{className:`h-10 w-full`}),[1,2,3,4,5].map(e=>(0,W.jsx)(d,{className:`h-8 w-full`},e))]})]}),!l&&n.sections?.map((e,t)=>e.visible===!1?null:(0,W.jsxs)(`div`,{className:`space-y-2`,children:[e.title&&e.type!==`header`&&(0,W.jsx)(`h3`,{className:`text-lg font-semibold border-b pb-2`,children:e.title}),e.type===`header`&&e.title&&(0,W.jsx)(`div`,{className:`text-2xl font-bold py-4`,children:e.title}),e.type===`summary`&&(0,W.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:n.fields?.filter(e=>e.showInSummary).map((e,t)=>(0,W.jsx)(S,{children:(0,W.jsxs)(B,{className:`p-4`,children:[(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e.label||e.name}),(0,W.jsx)(`div`,{className:`text-2xl font-bold`,children:ot(g(e.name,e.aggregation),e)})]})},t))}),e.type===`chart`&&e.chart&&(0,W.jsx)(`div`,{className:`min-h-[300px]`,children:(()=>{let t=e.chart.type,n=!!e.chart.chartType;!t&&n&&(t=`chart`),t&&o.get(t)||(t=`chart`);let 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,W.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,W.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,W.jsx)(`thead`,{className:`bg-muted`,children:(0,W.jsx)(`tr`,{children:e.columns?.map((e,t)=>(0,W.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,W.jsx)(`tbody`,{children:(()=>{let t=lt(r||[],n.groupBy||[]);return t?t.map(t=>(0,W.jsxs)(U.Fragment,{children:[(0,W.jsx)(`tr`,{className:`bg-muted/60`,children:(0,W.jsxs)(`td`,{colSpan:e.columns?.length||1,className:`px-4 py-2 font-semibold text-sm`,children:[t.label,` (`,t.rows.length,`)`]})}),t.rows.map((t,n)=>(0,W.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,W.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:_(e.name,t[e.name]),children:v(t[e.name],e)},n))},n))]},t.key)):r?.map((t,n)=>(0,W.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:e.columns?.map((e,n)=>(0,W.jsx)(`td`,{className:`px-4 py-2 ${e.type===`number`?`text-right tabular-nums`:``}`,style:_(e.name,t[e.name]),children:v(t[e.name],e)},n))},n))})()})]})}),e.type===`text`&&e.text&&(0,W.jsx)(`div`,{className:`prose max-w-none`,children:(0,W.jsx)(`p`,{children:e.text})}),e.type===`page-break`&&(0,W.jsx)(`div`,{className:`border-t-2 border-dashed my-8 print:page-break-after-always`}),e.content&&(0,W.jsx)(i,{schema:e.content})]},t)),!n.sections&&r&&r.length>0&&(0,W.jsx)(`div`,{className:`border rounded-lg overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full text-sm min-w-[600px]`,children:[(0,W.jsx)(`thead`,{className:`bg-muted`,children:(0,W.jsx)(`tr`,{children:n.fields?.map((e,t)=>(0,W.jsx)(`th`,{className:`px-4 py-2 font-medium ${e.type===`number`?`text-right`:`text-left`}`,children:e.label||e.name},t))})}),(0,W.jsx)(`tbody`,{children:r.map((e,t)=>(0,W.jsx)(`tr`,{className:`border-t hover:bg-muted/50 even:bg-muted/20`,children:n.fields?.map((t,n)=>(0,W.jsx)(`td`,{className:`px-4 py-2 ${t.type===`number`?`text-right tabular-nums`:``}`,style:_(t.name,e[t.name]),children:v(e[t.name],t)},n))},t))})]})})]})]})]}):(0,W.jsx)(S,{children:(0,W.jsx)(B,{className:`p-8 text-center text-muted-foreground`,children:`No report to display`})})},dt=({schedule:e,onChange:t})=>{let[n,r]=(0,U.useState)(e||{enabled:!1,frequency:`weekly`,time:`09:00`,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,recipients:[],formats:[`pdf`]}),i=e=>{let i={...n,...e};r(i),t?.(i)};return(0,W.jsxs)(S,{children:[(0,W.jsx)(F,{children:(0,W.jsxs)(P,{className:`flex items-center gap-2`,children:[(0,W.jsx)(ee,{className:`h-5 w-5`}),`Schedule Configuration`]})}),(0,W.jsxs)(B,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`checkbox`,id:`schedule-enabled`,checked:n.enabled||!1,onChange:e=>i({enabled:e.target.checked}),className:`rounded`}),(0,W.jsx)(R,{htmlFor:`schedule-enabled`,children:`Enable Scheduled Report`})]}),n.enabled&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(R,{children:`Frequency`}),(0,W.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:n.frequency||`weekly`,onChange:e=>i({frequency:e.target.value}),children:[{value:`once`,label:`Once`},{value:`daily`,label:`Daily`},{value:`weekly`,label:`Weekly`},{value:`monthly`,label:`Monthly`},{value:`quarterly`,label:`Quarterly`},{value:`yearly`,label:`Yearly`}].map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),n.frequency===`weekly`&&(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(R,{children:`Day of Week`}),(0,W.jsx)(`select`,{className:`w-full border rounded-md p-2 bg-background`,value:n.dayOfWeek??1,onChange:e=>i({dayOfWeek:Number(e.target.value)}),children:[{value:0,label:`Sunday`},{value:1,label:`Monday`},{value:2,label:`Tuesday`},{value:3,label:`Wednesday`},{value:4,label:`Thursday`},{value:5,label:`Friday`},{value:6,label:`Saturday`}].map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),n.frequency===`monthly`&&(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(R,{children:`Day of Month`}),(0,W.jsx)(L,{type:`number`,min:1,max:31,value:n.dayOfMonth??1,onChange:e=>i({dayOfMonth:Number(e.target.value)})})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(R,{className:`flex items-center gap-2`,children:[(0,W.jsx)(_,{className:`h-4 w-4`}),`Time`]}),(0,W.jsx)(L,{type:`time`,value:n.time||`09:00`,onChange:e=>i({time:e.target.value})})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(R,{children:`Timezone`}),(0,W.jsx)(L,{value:n.timezone||``,onChange:e=>i({timezone:e.target.value}),placeholder:`e.g. America/New_York`})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(R,{children:`Export Formats`}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:[{value:`pdf`,label:`PDF`},{value:`excel`,label:`Excel`},{value:`csv`,label:`CSV`},{value:`html`,label:`HTML`}].map(e=>(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 px-3 py-1.5 border rounded-md cursor-pointer hover:bg-muted/50`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:n.formats?.includes(e.value)||!1,onChange:t=>{let r=n.formats||[];i({formats:t.target.checked?[...r,e.value]:r.filter(t=>t!==e.value)})},className:`rounded`}),(0,W.jsx)(`span`,{className:`text-sm`,children:e.label})]},e.value))})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(R,{className:`flex items-center gap-2`,children:[(0,W.jsx)(A,{className:`h-4 w-4`}),`Email Recipients`]}),(0,W.jsx)(L,{placeholder:`email1@example.com, email2@example.com`,value:n.recipients?.join(`, `)||``,onChange:e=>i({recipients:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(R,{children:`Email Subject`}),(0,W.jsx)(L,{value:n.subject||``,onChange:e=>i({subject:e.target.value}),placeholder:`Scheduled Report: {report_title}`})]})]})]})]})},ft=({schema:e})=>{let{report:t,dataSources:n=[],availableFields:r=[],showPreview:i=!0,onSave:a,onCancel:o}=e,[s,c]=(0,U.useState)(t||{type:`report`,title:`New Report`,fields:[],filters:[],groupBy:[],sections:[],showExportButtons:!0,showPrintButton:!0}),[l,u]=(0,U.useState)(s.fields||[]),[d,f]=(0,U.useState)(s.filters||[]),[p,m]=(0,U.useState)(s.groupBy||[]),[h,g]=(0,U.useState)(s.sections||[]),_=()=>{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})}}},v=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})},w=e=>{let t=d.filter((t,n)=>n!==e);f(t),c({...s,filters:t})},T=(e,t)=>{let n=[...d];n[e]=t,f(n),c({...s,filters:n})},D=()=>{let e={field:r[0]?.name||``,sort:`asc`},t=[...p,e];m(t),c({...s,groupBy:t})},k=e=>{let t=p.filter((t,n)=>n!==e);m(t),c({...s,groupBy:t})},A=(e,t)=>{let n=[...p];n[e]=t,m(n),c({...s,groupBy:n})},j=e=>{let t={type:e,title:`New ${e} Section`},n=[...h,t];g(n),c({...s,sections:n})},M=e=>{let t=h.filter((t,n)=>n!==e);g(t),c({...s,sections:t})},N=(e,t)=>{let n=[...h];n[e]=t,g(n),c({...s,sections:n})};return(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(S,{children:[(0,W.jsxs)(F,{children:[(0,W.jsx)(P,{children:`Report Builder`}),(0,W.jsx)(x,{children:`Configure your report settings, fields, filters, and sections`})]}),(0,W.jsxs)(B,{children:[(0,W.jsxs)(ne,{defaultValue:`basic`,className:`w-full`,children:[(0,W.jsxs)(se,{className:`grid w-full grid-cols-6`,children:[(0,W.jsxs)(V,{value:`basic`,children:[(0,W.jsx)(re,{className:`h-4 w-4 mr-2`}),`Basic`]}),(0,W.jsxs)(V,{value:`fields`,children:[(0,W.jsx)(y,{className:`h-4 w-4 mr-2`}),`Fields`]}),(0,W.jsxs)(V,{value:`filters`,children:[(0,W.jsx)(ce,{className:`h-4 w-4 mr-2`}),`Filters`]}),(0,W.jsxs)(V,{value:`grouping`,children:[(0,W.jsx)(y,{className:`h-4 w-4 mr-2`}),`Group By`]}),(0,W.jsxs)(V,{value:`sections`,children:[(0,W.jsx)(y,{className:`h-4 w-4 mr-2`}),`Sections`]}),(0,W.jsxs)(V,{value:`schedule`,children:[(0,W.jsx)(ee,{className:`h-4 w-4 mr-2`}),`Schedule`]})]}),(0,W.jsx)(H,{value:`basic`,className:`space-y-4 mt-4`,children:(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(R,{htmlFor:`report-title`,children:`Report Title`}),(0,W.jsx)(L,{id:`report-title`,value:s.title||``,onChange:e=>c({...s,title:e.target.value}),placeholder:`Enter report title`})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(R,{htmlFor:`report-description`,children:`Description`}),(0,W.jsx)(L,{id:`report-description`,value:s.description||``,onChange:e=>c({...s,description:e.target.value}),placeholder:`Enter report description`})]}),n.length>0&&(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(R,{children:`Data Source`}),(0,W.jsxs)(`select`,{className:`w-full border rounded-md p-2`,children:[(0,W.jsx)(`option`,{value:``,children:`Select a data source`}),n.map((e,t)=>(0,W.jsxs)(`option`,{value:t,children:[`Data Source `,t+1]},t))]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(R,{children:`Export Options`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,W.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:s.showExportButtons||!1,onChange:e=>c({...s,showExportButtons:e.target.checked})}),(0,W.jsx)(`span`,{className:`text-sm`,children:`Show Export Buttons`})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:s.showPrintButton||!1,onChange:e=>c({...s,showPrintButton:e.target.checked})}),(0,W.jsx)(`span`,{className:`text-sm`,children:`Show Print Button`})]})]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(R,{htmlFor:`export-format`,children:`Default Export Format`}),(0,W.jsxs)(`select`,{id:`export-format`,className:`w-full border rounded-md p-2`,value:s.defaultExportFormat||`pdf`,onChange:e=>c({...s,defaultExportFormat:e.target.value}),children:[(0,W.jsx)(`option`,{value:`pdf`,children:`PDF`}),(0,W.jsx)(`option`,{value:`excel`,children:`Excel`}),(0,W.jsx)(`option`,{value:`csv`,children:`CSV`}),(0,W.jsx)(`option`,{value:`json`,children:`JSON`}),(0,W.jsx)(`option`,{value:`html`,children:`HTML`})]})]})]})}),(0,W.jsxs)(H,{value:`fields`,className:`space-y-4 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(R,{children:`Report Fields`}),(0,W.jsxs)(z,{size:`sm`,variant:`outline`,onClick:_,disabled:l.length>=r.length,children:[(0,W.jsx)(E,{className:`h-4 w-4 mr-2`}),`Add Field`]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[l.map((e,t)=>(0,W.jsx)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:(0,W.jsxs)(`div`,{className:`flex-1 grid grid-cols-4 gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(R,{className:`text-xs`,children:`Field Name`}),(0,W.jsx)(`div`,{className:`text-sm font-medium`,children:e.name})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(R,{className:`text-xs`,children:`Label`}),(0,W.jsx)(L,{className:`h-8 text-sm`,value:e.label||e.name,onChange:n=>b(t,{...e,label:n.target.value})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(R,{className:`text-xs`,children:`Aggregation`}),(0,W.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.aggregation||``,onChange:n=>b(t,{...e,aggregation:n.target.value}),children:[(0,W.jsx)(`option`,{value:``,children:`None`}),(0,W.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,W.jsx)(`option`,{value:`count`,children:`Count`}),(0,W.jsx)(`option`,{value:`avg`,children:`Average`}),(0,W.jsx)(`option`,{value:`min`,children:`Min`}),(0,W.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,W.jsx)(`div`,{className:`flex items-end justify-end`,children:(0,W.jsx)(z,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>v(t),children:(0,W.jsx)(O,{className:`h-4 w-4`})})})]})},t)),l.length===0&&(0,W.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No fields selected. Click "Add Field" to begin.`})]})]}),(0,W.jsxs)(H,{value:`filters`,className:`space-y-4 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(R,{children:`Report Filters`}),(0,W.jsxs)(z,{size:`sm`,variant:`outline`,onClick:C,children:[(0,W.jsx)(E,{className:`h-4 w-4 mr-2`}),`Add Filter`]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[d.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,W.jsxs)(`div`,{className:`flex-1 grid grid-cols-3 gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(R,{className:`text-xs`,children:`Field`}),(0,W.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>T(t,{...e,field:n.target.value}),children:r.map((e,t)=>(0,W.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(R,{className:`text-xs`,children:`Operator`}),(0,W.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.operator,onChange:n=>T(t,{...e,operator:n.target.value}),children:[(0,W.jsx)(`option`,{value:`equals`,children:`Equals`}),(0,W.jsx)(`option`,{value:`contains`,children:`Contains`}),(0,W.jsx)(`option`,{value:`gt`,children:`Greater Than`}),(0,W.jsx)(`option`,{value:`lt`,children:`Less Than`}),(0,W.jsx)(`option`,{value:`between`,children:`Between`})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(R,{className:`text-xs`,children:`Value`}),(0,W.jsx)(L,{className:`h-8 text-sm`,value:String(e.value),onChange:n=>T(t,{...e,value:n.target.value})})]})]}),(0,W.jsx)(z,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>w(t),children:(0,W.jsx)(O,{className:`h-4 w-4`})})]},t)),d.length===0&&(0,W.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No filters defined.`})]})]}),(0,W.jsxs)(H,{value:`grouping`,className:`space-y-4 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(R,{children:`Grouping Rules`}),(0,W.jsxs)(z,{size:`sm`,variant:`outline`,onClick:D,children:[(0,W.jsx)(E,{className:`h-4 w-4 mr-2`}),`Add Group`]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[p.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border rounded-lg`,children:[(0,W.jsxs)(`div`,{className:`flex-1 grid grid-cols-2 gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(R,{className:`text-xs`,children:`Field`}),(0,W.jsx)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.field,onChange:n=>A(t,{...e,field:n.target.value}),children:r.map((e,t)=>(0,W.jsx)(`option`,{value:e.name,children:e.label||e.name},t))})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(R,{className:`text-xs`,children:`Sort Order`}),(0,W.jsxs)(`select`,{className:`w-full border rounded-md h-8 text-sm px-2`,value:e.sort||`asc`,onChange:n=>A(t,{...e,sort:n.target.value}),children:[(0,W.jsx)(`option`,{value:`asc`,children:`Ascending`}),(0,W.jsx)(`option`,{value:`desc`,children:`Descending`})]})]})]}),(0,W.jsx)(z,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50 self-end`,onClick:()=>k(t),children:(0,W.jsx)(O,{className:`h-4 w-4`})})]},t)),p.length===0&&(0,W.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No grouping rules applied.`})]})]}),(0,W.jsxs)(H,{value:`sections`,className:`space-y-4 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(R,{children:`Report Sections`}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>j(`header`),children:[(0,W.jsx)(E,{className:`h-4 w-4 mr-2`}),`Header`]}),(0,W.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>j(`chart`),children:[(0,W.jsx)(E,{className:`h-4 w-4 mr-2`}),`Chart`]}),(0,W.jsxs)(z,{size:`sm`,variant:`outline`,onClick:()=>j(`table`),children:[(0,W.jsx)(E,{className:`h-4 w-4 mr-2`}),`Table`]})]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[h.map((e,t)=>(0,W.jsxs)(`div`,{className:`p-3 border rounded-lg space-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{className:`font-medium flex items-center gap-2`,children:[(0,W.jsx)(`div`,{className:`text-xs bg-muted px-2 py-0.5 rounded uppercase`,children:e.type}),e.title]}),(0,W.jsx)(z,{size:`sm`,variant:`ghost`,className:`text-red-500 hover:text-red-700 hover:bg-red-50`,onClick:()=>M(t),children:(0,W.jsx)(O,{className:`h-4 w-4`})})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(R,{className:`text-xs`,children:`Title`}),(0,W.jsx)(L,{className:`h-8 text-sm`,value:e.title||``,onChange:n=>N(t,{...e,title:n.target.value})})]}),e.type===`text`&&(0,W.jsxs)(`div`,{className:`col-span-2`,children:[(0,W.jsx)(R,{className:`text-xs`,children:`Content`}),(0,W.jsx)(L,{className:`h-8 text-sm`,value:e.text||``,onChange:n=>N(t,{...e,text:n.target.value})})]}),e.type===`chart`&&(0,W.jsxs)(`div`,{className:`col-span-2 grid grid-cols-2 gap-2 mt-2 p-2 bg-muted/20 rounded`,children:[(0,W.jsx)(`div`,{className:`col-span-2`,children:(0,W.jsx)(R,{className:`text-xs font-semibold`,children:`Chart Configuration`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(R,{className:`text-xs`,children:`Chart Type`}),(0,W.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.chartType||`bar`,onChange:n=>N(t,{...e,chart:{...e.chart,type:`chart`,chartType:n.target.value}}),children:[(0,W.jsx)(`option`,{value:`bar`,children:`Bar`}),(0,W.jsx)(`option`,{value:`line`,children:`Line`}),(0,W.jsx)(`option`,{value:`area`,children:`Area`}),(0,W.jsx)(`option`,{value:`pie`,children:`Pie`})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(R,{className:`text-xs`,children:`X-Axis Field`}),(0,W.jsxs)(`select`,{className:`flex h-8 w-full rounded-md border border-input bg-background px-3 py-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,value:e.chart?.xAxisField||``,onChange:n=>N(t,{...e,chart:{...e.chart,type:`chart`,xAxisField:n.target.value}}),children:[(0,W.jsx)(`option`,{value:``,children:`Select Field...`}),r.map(e=>(0,W.jsx)(`option`,{value:e.name,children:e.label||e.name},e.name)),r.length===0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`option`,{value:`name`,children:`Name`}),(0,W.jsx)(`option`,{value:`month`,children:`Month`})]})]})]}),(0,W.jsxs)(`div`,{className:`col-span-2`,children:[(0,W.jsx)(R,{className:`text-xs`,children:`Y-Axis Fields (comma separated)`}),(0,W.jsx)(L,{className:`h-8 text-sm`,placeholder:`e.g. value, count`,value:e.chart?.yAxisFields?.join(`, `)||``,onChange:n=>N(t,{...e,chart:{...e.chart,type:`chart`,yAxisFields:n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}})})]})]})]})]},t)),h.length===0&&(0,W.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No customized sections. The default report layout will be used.`})]})]}),(0,W.jsx)(H,{value:`schedule`,className:`space-y-4 mt-4`,children:(0,W.jsx)(dt,{schedule:s.schedule,onChange:e=>c({...s,schedule:e})})})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-6 pt-4 border-t`,children:[(0,W.jsx)(z,{variant:`outline`,onClick:()=>{o&&console.log(`Report cancelled:`,o)},children:`Cancel`}),(0,W.jsxs)(z,{onClick:()=>{console.log(`Saving report:`,s),a&&alert(`Report saved! (Handler: `+a+`)`)},children:[(0,W.jsx)(de,{className:`h-4 w-4 mr-2`}),`Save Report`]})]})]})]}),i&&(0,W.jsxs)(S,{className:`mt-8 border-2 border-blue-100`,children:[(0,W.jsx)(F,{className:`bg-blue-50/50`,children:(0,W.jsx)(P,{className:`text-blue-900 text-sm uppercase tracking-wide`,children:`Live Preview`})}),(0,W.jsx)(B,{className:`pt-6`,children:(0,W.jsx)(ut,{schema:{type:`report-viewer`,report:{...s,fields:l,filters:d,groupBy:p,sections:h},data:[{id:1,name:`Sample Item A`,value:100,status:`New`},{id:2,name:`Sample Item B`,value:250,status:`Active`},{id:3,name:`Sample Item C`,value:75,status:`Closed`}]}})})]})]})},pt=[`tabular`,`summary`,`matrix`];function mt(e){let t=e.length+1,n=new Set(e.map(e=>e.name).filter(Boolean)),r=`block_${t}`;for(;n.has(r);)t+=1,r=`block_${t}`;return{name:r,type:`tabular`,columns:[]}}function ht(e){return typeof e.label==`string`?e.label:e.label&&typeof e.label==`object`?e.label.default??``:``}function gt(e){return typeof e.description==`string`?e.description:e.description&&typeof e.description==`object`?e.description.default??``:``}function _t({block:e,index:t,total:n,availableFields:r,t:i,duplicateName:a,onChange:o,onRemove:s,onMove:c}){let[l,u]=U.useState(t===0),d=e.type??`tabular`,f=d===`summary`,p=d===`matrix`,m=f||p,g=!e.name||!e.name.trim(),_=g||a,v=t=>o({...e,...t});return(0,W.jsxs)(`div`,{className:`border rounded-md bg-card text-card-foreground`,"data-testid":`joined-block-${t}`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1 p-1.5 border-b bg-muted/30`,children:[(0,W.jsx)(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,W.jsx)(le,{className:`h-3.5 w-3.5`}):(0,W.jsx)(te,{className:`h-3.5 w-3.5`})}),(0,W.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background flex-1 min-w-0 ${_?`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,W.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:pt.map(e=>(0,W.jsx)(`option`,{value:e,children:i(`report.editor.type${e.charAt(0).toUpperCase()}${e.slice(1)}`)},e))}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-0.5 shrink-0`,children:[(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===0,onClick:()=>c(-1),"aria-label":`Move block up`,children:(0,W.jsx)(k,{className:`h-2.5 w-2.5`})}),(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:t===n-1,onClick:()=>c(1),"aria-label":`Move block down`,children:(0,W.jsx)(N,{className:`h-2.5 w-2.5`})})]}),(0,W.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,W.jsx)(O,{className:`h-3 w-3`})})]}),_&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 text-[10px] text-destructive bg-destructive/5 border-b`,children:[(0,W.jsx)(h,{className:`h-3 w-3`}),i(g?`report.editor.validationBlockNameRequired`:`report.editor.validationBlockNameDuplicate`)]}),l&&(0,W.jsxs)(`div`,{className:`p-2 space-y-2 text-xs`,children:[(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.blockLabel`)}),(0,W.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background`,value:ht(e),onChange:e=>v({label:e.target.value||void 0}),placeholder:i(`report.editor.blockLabelPlaceholder`),"data-testid":`joined-block-label-${t}`})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.objectName`)}),(0,W.jsx)(`input`,{type:`text`,className:`h-6 text-xs border rounded px-1.5 bg-background`,value:e.objectName??``,onChange:e=>v({objectName:e.target.value||void 0}),placeholder:i(`report.editor.objectNamePlaceholder`),"data-testid":`joined-block-object-${t}`})]})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.blockDescription`)}),(0,W.jsx)(`textarea`,{className:`text-xs border rounded px-1.5 py-1 bg-background resize-y min-h-[2rem]`,rows:2,value:gt(e),onChange:e=>v({description:e.target.value||void 0}),placeholder:i(`report.editor.blockDescriptionPlaceholder`),"data-testid":`joined-block-description-${t}`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.columns`)}),(0,W.jsx)(It,{availableFields:r,value:e.columns,onChange:e=>v({columns:e}),t:i})]}),(f||p)&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.rows`)}),(0,W.jsx)(Lt,{availableFields:r,value:e.groupingsDown,onChange:e=>v({groupingsDown:e}),t:i})]}),p&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.columnsAxis`)}),(0,W.jsx)(Lt,{availableFields:r,value:e.groupingsAcross,onChange:e=>v({groupingsAcross:e}),t:i})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.filters`)}),(0,W.jsx)(kt,{availableFields:r,value:e.filter,onChange:e=>v({filter:e}),t:i})]}),m&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-0.5`,children:i(`report.editor.chart`)}),(0,W.jsx)(Rt,{availableFields:r,columns:Ft(e.columns),value:e.chart,onChange:e=>v({chart:e}),t:i})]})]})]})}function vt(e){return Array.isArray(e)?e.map(e=>{let t=e??{};return{name:t.name??``,type:t.type??`tabular`,columns:Array.isArray(t.columns)?t.columns:[],...t}}):[]}function yt({value:e,onChange:t,availableFields:n,getFieldsForObject:r,containerObjectName:i,t:a}){let o=vt(e),s=e=>r?r(e.objectName??i)??n:n,c={};for(let e of o)e.name&&(c[e.name]=(c[e.name]??0)+1);let l=(e,n)=>{t(o.map((t,r)=>r===e?n:t))},u=e=>{t(o.filter((t,n)=>n!==e))},d=(e,n)=>{let r=e+n;if(r<0||r>=o.length)return;let i=[...o];[i[e],i[r]]=[i[r],i[e]],t(i)};return(0,W.jsxs)(`div`,{className:`space-y-2`,"data-testid":`joined-blocks-editor`,children:[o.length===0&&(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic px-1`,children:a(`report.editor.validationJoinedNeedsBlocks`)}),o.map((e,t)=>(0,W.jsx)(_t,{block:e,index:t,total:o.length,availableFields:s(e),t:a,duplicateName:!!e.name&&(c[e.name]??0)>1,onChange:e=>l(t,e),onRemove:()=>u(t),onMove:e=>d(t,e)},t)),(0,W.jsxs)(z,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 text-xs w-full`,onClick:()=>{t([...o,mt(o)])},"data-testid":`joined-block-add`,children:[(0,W.jsx)(E,{className:`h-3 w-3 mr-1`}),a(`report.editor.addBlock`)]})]})}function bt(e,t){let n=[];if(!Array.isArray(e)||e.length===0)return n.push(t(`report.editor.validationJoinedNeedsBlocks`)),n;let r=new Map,i=!1,a=!1,o=!1;for(let t of e){let e=t??{};if(!e.name||!String(e.name).trim())i=!0;else{let t=(r.get(e.name)??0)+1;r.set(e.name,t),t===2&&(a=!0)}(!Array.isArray(e.columns)||e.columns.length===0)&&(o=!0)}return i&&n.push(t(`report.editor.validationBlockNameRequired`)),a&&n.push(t(`report.editor.validationBlockNameDuplicate`)),o&&n.push(t(`report.editor.validationBlockNeedsColumns`)),n}var xt={$eq:`equals`,$ne:`notEquals`,$gt:`greaterThan`,$gte:`greaterOrEqual`,$lt:`lessThan`,$lte:`lessOrEqual`,$in:`in`,$nin:`notIn`,$contains:`contains`,$notContains:`notContains`,$exists:`isNotEmpty`},St={equals:`$eq`,notEquals:`$ne`,greaterThan:`$gt`,greaterOrEqual:`$gte`,lessThan:`$lt`,lessOrEqual:`$lte`,in:`$in`,notIn:`$nin`,contains:`$contains`,notContains:`$notContains`},Ct=()=>({id:`root`,logic:`and`,conditions:[]});function wt(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function $(){return Math.random().toString(36).slice(2,10)}function Tt(e,t){if(typeof t!=`object`||!t||Array.isArray(t))return[{id:$(),field:e,operator:Array.isArray(t)?`in`:`equals`,value:t}];let n=[];for(let[r,i]of Object.entries(t)){if(r===`$exists`){n.push({id:$(),field:e,operator:i===!1?`isEmpty`:`isNotEmpty`,value:``});continue}if(r===`$null`){n.push({id:$(),field:e,operator:i===!1?`isNotEmpty`:`isEmpty`,value:``});continue}let t=xt[r];if(!t||wt(i)&&`$field`in i)return null;n.push({id:$(),field:e,operator:t,value:i})}return n.length>0?n:null}function Et(e){if(e==null)return{group:Ct(),complex:!1};if(!wt(e))return{group:Ct(),complex:!0};let t=Object.keys(e);if(t.length===1&&(t[0]===`$and`||t[0]===`$or`)){let n=t[0]===`$or`?`or`:`and`,r=e[t[0]];if(!Array.isArray(r))return{group:Ct(),complex:!0};let i=[],a=!1;for(let e of r){if(!wt(e)){a=!0;continue}if(Object.keys(e).some(e=>e===`$and`||e===`$or`||e===`$not`)){a=!0;continue}for(let[t,n]of Object.entries(e)){let e=Tt(t,n);e?i.push(...e):a=!0}}return{group:{id:`root`,logic:n,conditions:i},complex:a}}if(t.includes(`$not`)||t.includes(`$and`)||t.includes(`$or`))return{group:Ct(),complex:!0};let n=[],r=!1;for(let[t,i]of Object.entries(e)){let e=Tt(t,i);e?n.push(...e):r=!0}return{group:{id:`root`,logic:`and`,conditions:n},complex:r}}function Dt(e){if(!e||!Array.isArray(e.conditions)||e.conditions.length===0)return;let t=e.conditions.filter(e=>e.field).map(e=>Ot(e));if(t.length!==0)return t.length===1?t[0]:{[e.logic===`or`?`$or`:`$and`]:t}}function Ot(e){let{field:t,operator:n,value:r}=e;if(n===`isEmpty`)return{[t]:{$exists:!1}};if(n===`isNotEmpty`)return{[t]:{$exists:!0}};if(n===`equals`)return{[t]:r};let i=St[n];return i?{[t]:{[i]:r}}:{[t]:r}}function kt({availableFields:e,value:t,onChange:n,t:r}){let i=U.useMemo(()=>JSON.stringify(t??null),[t]),a=U.useMemo(()=>Et(t),[i]),[o,s]=U.useState(a.group),c=U.useRef(i);U.useEffect(()=>{c.current!==i&&(s(a.group),c.current=i)},[i,a.group]);let l=e=>{s(e);let t=Dt(e);c.current=JSON.stringify(t??null),n(t)};if(a.complex)return(0,W.jsxs)(`div`,{className:`flex items-start gap-2 p-2 rounded border border-amber-300 bg-amber-50 text-amber-900 text-[11px]`,children:[(0,W.jsx)(h,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:r(`report.editor.filtersComplex`)})]});let u=()=>{l({...o,conditions:[...o.conditions,{id:$(),field:e[0]?.value??``,operator:`equals`,value:``}]})},d=e=>{l({...o,conditions:o.conditions.filter(t=>t.id!==e)})},f=(e,t)=>{l({...o,conditions:o.conditions.map(n=>n.id===e?{...n,...t}:n)})},p=[{value:`equals`,label:`=`},{value:`notEquals`,label:`≠`},{value:`greaterThan`,label:`>`},{value:`greaterOrEqual`,label:`≥`},{value:`lessThan`,label:`<`},{value:`lessOrEqual`,label:`≤`},{value:`contains`,label:r(`report.editor.opContains`,`contains`)},{value:`in`,label:`in`},{value:`notIn`,label:`not in`},{value:`isEmpty`,label:r(`report.editor.opIsEmpty`,`is empty`)},{value:`isNotEmpty`,label:r(`report.editor.opIsNotEmpty`,`is not empty`)}];return(0,W.jsxs)(`div`,{className:`space-y-1.5 py-1`,"data-testid":`spec-filter-adapter`,children:[o.conditions.length>1&&(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,W.jsx)(`span`,{children:r(`report.editor.combineLogic`,`Combine with`)}),(0,W.jsxs)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background`,value:o.logic,onChange:e=>l({...o,logic:e.target.value}),"data-testid":`filter-logic-select`,children:[(0,W.jsx)(`option`,{value:`and`,children:`AND`}),(0,W.jsx)(`option`,{value:`or`,children:`OR`})]})]}),o.conditions.map(t=>(0,W.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] p-1 border rounded bg-muted/20`,children:[(0,W.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background flex-1 min-w-0`,value:t.field,onChange:e=>f(t.id,{field:e.target.value}),"data-testid":`filter-field-${t.id}`,children:e.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,W.jsx)(`select`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-20 shrink-0`,value:t.operator,onChange:e=>f(t.id,{operator:e.target.value}),"data-testid":`filter-op-${t.id}`,children:p.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))}),t.operator!==`isEmpty`&&t.operator!==`isNotEmpty`&&(0,W.jsx)(`input`,{className:`h-5 text-[10px] border rounded px-1 bg-background w-24 shrink-0`,value:Array.isArray(t.value)?t.value.join(`,`):(t.value??``).toString(),placeholder:`value`,onChange:e=>{let n=e.target.value,r=t.operator===`in`||t.operator===`notIn`?n.split(`,`).map(e=>e.trim()).filter(Boolean):n;f(t.id,{value:r})},"data-testid":`filter-value-${t.id}`}),(0,W.jsx)(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,W.jsx)(O,{className:`h-3 w-3`})})]},t.id)),(0,W.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,W.jsx)(E,{className:`h-3 w-3 mr-1`}),r(`report.editor.addCondition`,`Add condition`)]})]})}var At=new Set([`date`,`datetime`,`time`]),jt=new Set([`number`,`currency`,`percent`,`rating`,`integer`]);function Mt({availableFields:e,selectedValues:t,onAdd:n,t:r,triggerLabel:i,title:a,description:o,testIdPrefix:s=`field-picker`,singleSelect:c=!1,commitOnSelect:l=!1,disabled:u=!1,triggerClassName:d,trigger:p}){let[h,_]=U.useState(!1),[v,y]=U.useState(``),[x,S]=U.useState(new Set),w=U.useMemo(()=>new Set(t),[t]);U.useEffect(()=>{h&&(y(``),S(new Set))},[h]);let T=v.trim().toLowerCase(),O=e.filter(e=>!w.has(e.value)),k=T?O.filter(e=>e.label.toLowerCase().includes(T)||e.value.toLowerCase().includes(T)):O,A=e=>{if(c&&l){n([e]),_(!1);return}S(t=>{let n=new Set(c?[]:t);return t.has(e)?n.delete(e):n.add(e),n})},j=()=>{if(x.size===0){_(!1);return}n(O.map(e=>e.value).filter(e=>x.has(e))),_(!1)},N=()=>{_(!1)},P=e.length===0,F=!P&&O.length===0,I=i??r(`report.editor.addColumns`,`Add fields`),ee=a??r(`report.editor.fieldPickerTitle`,`Select fields`),te=o??r(`report.editor.fieldPickerDescription`,`Pick one or more fields to add. Use the search box to narrow the list.`);return(0,W.jsxs)(m,{open:h,onOpenChange:_,children:[(0,W.jsx)(M,{asChild:!0,children:p??(0,W.jsxs)(z,{type:`button`,variant:`outline`,size:`sm`,className:d??`h-8 gap-1.5`,disabled:u||P||F,"data-testid":`${s}-trigger`,children:[(0,W.jsx)(E,{className:`h-3.5 w-3.5`}),(0,W.jsx)(`span`,{children:I})]})}),(0,W.jsxs)(b,{className:`sm:max-w-md max-w-[92vw] gap-3`,"data-testid":`${s}-dialog`,children:[(0,W.jsxs)(fe,{children:[(0,W.jsx)(f,{children:ee}),(0,W.jsx)(C,{children:te})]}),(0,W.jsxs)(`div`,{className:`relative`,children:[(0,W.jsx)(ue,{className:`pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,W.jsx)(`input`,{type:`text`,className:`h-9 w-full text-sm border rounded pl-7 pr-2 bg-background`,placeholder:r(`report.editor.searchFields`,`Search fields…`),value:v,onChange:e=>y(e.target.value),"data-testid":`${s}-search`,autoFocus:!0})]}),(0,W.jsxs)(`div`,{className:`text-[11px] text-muted-foreground flex items-center justify-between`,children:[(0,W.jsxs)(`span`,{children:[k.length,`/`,O.length,x.size>0?` · ${r(`report.editor.fieldPickerSelected`,`{n} selected`).replace(`{n}`,String(x.size))}`:``]}),x.size>0&&(0,W.jsx)(`button`,{type:`button`,className:`text-[11px] underline-offset-2 hover:underline text-muted-foreground`,onClick:()=>S(new Set),"data-testid":`${s}-clear`,children:r(`report.editor.fieldPickerClear`,`Clear selection`)})]}),(0,W.jsx)(`div`,{className:`max-h-72 overflow-auto border rounded bg-background/40 p-1 space-y-0.5`,"data-testid":`${s}-list`,children:P?(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noFields`,`No fields available — pick a data source first.`)}):F?(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noFieldsAvailable`,`All fields already added.`)}):k.length===0?(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground px-2 py-3 text-center`,children:r(`report.editor.noMatchingFields`,`No fields match your search.`)}):k.map(e=>{let t=x.has(e.value);return(0,W.jsxs)(`label`,{className:`flex items-center gap-2 px-2 py-1.5 rounded hover:bg-muted/50 text-sm cursor-pointer`,"data-testid":`${s}-row-${e.value}`,children:[(0,W.jsx)(g,{checked:t,onCheckedChange:()=>A(e.value),"data-testid":`${s}-toggle-${e.value}`}),(0,W.jsx)(`span`,{className:`flex-1 truncate`,title:e.label,children:e.label}),e.type&&(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:e.type})]},e.value)})}),!(c&&l)&&(0,W.jsxs)(D,{className:`gap-2 sm:gap-2`,children:[(0,W.jsx)(z,{type:`button`,variant:`ghost`,size:`sm`,onClick:N,"data-testid":`${s}-cancel`,children:r(`common.cancel`,`Cancel`)}),(0,W.jsx)(z,{type:`button`,size:`sm`,onClick:j,disabled:x.size===0,"data-testid":`${s}-confirm`,children:x.size>0?r(`report.editor.fieldPickerAddN`,`Add {n}`).replace(`{n}`,String(x.size)):r(`report.editor.fieldPickerAdd`,`Add`)})]})]})]})}function Nt(e){return[{value:``,label:e(`report.editor.noneOption`)},{value:`sum`,label:e(`report.aggregate.sum`)},{value:`count`,label:e(`report.aggregate.count`)},{value:`unique`,label:e(`report.aggregate.countDistinct`)},{value:`avg`,label:e(`report.aggregate.avg`)},{value:`min`,label:e(`report.aggregate.min`)},{value:`max`,label:e(`report.aggregate.max`)}]}function Pt(e){return[{value:``,label:e(`report.editor.formatAuto`,`Auto`)},{value:`currency`,label:e(`report.editor.formatCurrency`,`Currency`)},{value:`percent`,label:e(`report.editor.formatPercent`,`Percent`)},{value:`integer`,label:e(`report.editor.formatInteger`,`Integer`)},{value:`date`,label:e(`report.editor.formatDate`,`Date`)},{value:`datetime`,label:e(`report.editor.formatDatetime`,`Date & time`)}]}function Ft(e){return Array.isArray(e)?e.map(e=>typeof e==`string`?{field:e,label:e,type:`string`}:{field:e.field||e.name||e.value,label:e.label,type:e.type||`string`,aggregate:e.aggregate??e.aggregation,format:e.format}):[]}function It({availableFields:e,value:t,onChange:n,t:r}){let i=Ft(t),a=new Set(i.map(e=>e.field)),o=Nt(r),s=Pt(r),c=t=>{if(t.length===0)return;let r=t.filter(e=>!a.has(e)).map(t=>{let n=e.find(e=>e.value===t);return{field:t,label:n?.label,type:n?.type||`string`}});r.length!==0&&n([...i,...r])},l=e=>{n(i.filter(t=>t.field!==e))},u=(e,t)=>{n(i.map(n=>n.field===e?{...n,...t}:n))},d=(e,t)=>{let r=[...i],a=e+t;a<0||a>=r.length||([r[e],r[a]]=[r[a],r[e]],n(r))};return e.length===0?(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground py-2`,"data-testid":`columns-editor-empty`,children:r(`report.editor.noFields`,`No fields available — pick a data source first.`)}):(0,W.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`columns-editor`,children:[i.length>0&&(0,W.jsx)(`div`,{className:`space-y-1.5`,"data-testid":`columns-selected`,children:i.map((t,n)=>{let a=e.find(e=>e.value===t.field);return(0,W.jsxs)(`div`,{className:`grid grid-cols-[auto_1fr_auto] gap-1.5 p-1.5 border rounded bg-muted/30 text-xs`,"data-testid":`column-row-${t.field}`,children:[(0,W.jsxs)(`div`,{className:`row-span-2 flex flex-col items-center justify-center gap-0.5`,children:[(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===0,onClick:()=>d(n,-1),"aria-label":`Move up`,"data-testid":`column-up-${t.field}`,children:(0,W.jsx)(k,{className:`h-3 w-3`})}),(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===i.length-1,onClick:()=>d(n,1),"aria-label":`Move down`,"data-testid":`column-down-${t.field}`,children:(0,W.jsx)(N,{className:`h-3 w-3`})})]}),(0,W.jsx)(`input`,{className:`h-7 text-xs border rounded px-2 bg-background min-w-0 w-full`,value:t.label??``,placeholder:a?.label??t.field,onChange:e=>u(t.field,{label:e.target.value||void 0}),"data-testid":`column-label-${t.field}`,title:a?.label??t.field}),(0,W.jsx)(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,W.jsx)(O,{className:`h-3.5 w-3.5`})}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wide`,children:r(`report.editor.aggregateColumn`,`Aggregate`)}),(0,W.jsx)(`select`,{className:`h-7 text-xs border rounded px-1 bg-background w-full min-w-0`,value:t.aggregate??``,onChange:e=>u(t.field,{aggregate:e.target.value===``?void 0:e.target.value}),"data-testid":`column-agg-${t.field}`,children:o.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wide`,children:r(`report.editor.formatColumn`,`Format`)}),(0,W.jsx)(`select`,{className:`h-7 text-xs border rounded px-1 bg-background w-full min-w-0`,value:t.format??``,onChange:e=>u(t.field,{format:e.target.value===``?void 0:e.target.value}),"data-testid":`column-fmt-${t.field}`,children:s.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]})]},t.field)})}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i.length>0?r(`report.editor.columnsCount`,`{n} column(s) selected`).replace(`{n}`,String(i.length)):r(`report.editor.columnsEmpty`,`No columns selected yet.`)}),(0,W.jsx)(Mt,{availableFields:e,selectedValues:i.map(e=>e.field),onAdd:c,t:r,testIdPrefix:`columns-picker`,triggerLabel:r(`report.editor.addColumns`,`Add fields`)})]})]})}function Lt({availableFields:e,value:t,onChange:n,t:r,testIdPrefix:i=`grouping`}){let a=Array.isArray(t)?t.map(e=>({field:e.field??``,sortOrder:e.sortOrder??e.sort??`asc`,dateGranularity:e.dateGranularity})):[],o=[{value:``,label:r(`report.editor.dateGranularityNone`)},{value:`day`,label:r(`report.editor.day`)},{value:`week`,label:r(`report.editor.week`)},{value:`month`,label:r(`report.editor.month`)},{value:`quarter`,label:r(`report.editor.quarter`)},{value:`year`,label:r(`report.editor.year`)}],s=a.map(e=>e.field).filter(Boolean),c=e=>{n(a.filter((t,n)=>n!==e))},l=(e,t)=>{n(a.map((n,r)=>r===e?{...n,...t}:n))},u=(e,t)=>{let r=[...a],i=e+t;i<0||i>=r.length||([r[e],r[i]]=[r[i],r[e]],n(r))},d=e=>{if(e.length===0)return;let t=e.map(e=>({field:e,sortOrder:`asc`}));n([...a,...t])},f=(t,n)=>{let r=n[0];if(!r)return;let i=e.find(e=>e.value===r);l(t,{field:r,dateGranularity:i&&At.has(i.type??``)?a[t]?.dateGranularity:void 0})};return(0,W.jsxs)(`div`,{className:`space-y-1.5 py-1`,"data-testid":`${i}s-builder`,children:[a.map((t,n)=>{let d=e.find(e=>e.value===t.field),p=d&&At.has(d.type??``),m=d?.label??t.field??r(`report.editor.fieldPickerEmpty`,`(pick field)`);return(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 p-1.5 border rounded bg-muted/20 text-xs`,"data-testid":`${i}-row-${n}`,children:[(0,W.jsxs)(`div`,{className:`flex flex-col gap-0.5 shrink-0`,children:[(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===0,onClick:()=>u(n,-1),"aria-label":`Move up`,"data-testid":`${i}-up-${n}`,children:(0,W.jsx)(k,{className:`h-3 w-3`})}),(0,W.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,disabled:n===a.length-1,onClick:()=>u(n,1),"aria-label":`Move down`,"data-testid":`${i}-down-${n}`,children:(0,W.jsx)(N,{className:`h-3 w-3`})})]}),(0,W.jsx)(Mt,{availableFields:e,selectedValues:s.filter(e=>e!==t.field),onAdd:e=>f(n,e),t:r,singleSelect:!0,commitOnSelect:!0,testIdPrefix:`${i}-field-picker-${n}`,title:r(`report.editor.fieldPickerChangeTitle`,`Change field`),trigger:(0,W.jsxs)(`button`,{type:`button`,className:`h-7 flex-1 min-w-0 text-left text-xs border rounded px-2 bg-background hover:bg-muted/40 inline-flex items-center justify-between gap-1.5`,"data-testid":`${i}-field-${n}`,title:m,children:[(0,W.jsx)(`span`,{className:`truncate`,children:m}),(0,W.jsx)(le,{className:`h-3 w-3 text-muted-foreground shrink-0`})]})}),(0,W.jsxs)(`select`,{className:`h-7 text-xs border rounded px-1.5 bg-background w-20 shrink-0`,value:t.sortOrder??`asc`,onChange:e=>l(n,{sortOrder:e.target.value}),"data-testid":`${i}-sort-${n}`,children:[(0,W.jsx)(`option`,{value:`asc`,children:r(`report.editor.sortAsc`)}),(0,W.jsx)(`option`,{value:`desc`,children:r(`report.editor.sortDesc`)})]}),p&&(0,W.jsx)(`select`,{className:`h-7 text-xs border rounded px-1.5 bg-background w-24 shrink-0`,value:t.dateGranularity??``,onChange:e=>l(n,{dateGranularity:e.target.value||void 0}),"data-testid":`${i}-granularity-${n}`,children:o.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,W.jsx)(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,W.jsx)(O,{className:`h-3.5 w-3.5`})})]},n)}),(0,W.jsx)(Mt,{availableFields:e,selectedValues:s,onAdd:d,t:r,singleSelect:!0,commitOnSelect:!0,testIdPrefix:`${i}-add-picker`,triggerLabel:r(`report.editor.addGrouping`),title:r(`report.editor.fieldPickerAddGroupingTitle`,`Add grouping`),triggerClassName:`h-8 w-full justify-center gap-1.5`})]})}function Rt({availableFields:e,columns:t,value:n,onChange:r,t:i}){let a=n||{},o=a.type??a.chartType??``,s=a.xAxis??a.xAxisField??``,c=a.yAxis??a.yAxisFields?.[0]??``,l=e=>{let t={...a,...e};if(`type`in e&&delete t.chartType,`xAxis`in e&&delete t.xAxisField,`yAxis`in e&&delete t.yAxisFields,!e.type&&e.type===``)return r(void 0);r(t)},u=()=>r(void 0),d=[{value:``,label:i(`report.editor.chartNone`)},{value:`bar`,label:i(`report.editor.chartBar`)},{value:`line`,label:i(`report.editor.chartLine`)},{value:`area`,label:i(`report.editor.chartArea`)},{value:`pie`,label:i(`report.editor.chartPie`)},{value:`donut`,label:i(`report.editor.chartDonut`)},{value:`funnel`,label:i(`report.editor.chartFunnel`)}],f=t.filter(e=>e.aggregate).map(e=>e.field),p=e.filter(e=>jt.has(e.type??``)).map(e=>e.value),m=new Set([...f,...p]),h=e.filter(e=>m.has(e.value));return(0,W.jsxs)(`div`,{className:`space-y-2 py-1`,"data-testid":`chart-config`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartType`)}),(0,W.jsx)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:o,onChange:e=>{let t=e.target.value;t?l({type:t}):u()},"data-testid":`chart-type-select`,children:d.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),o&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartTitle`)}),(0,W.jsx)(`input`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:a.title??``,placeholder:i(`report.editor.chartTitlePlaceholder`),onChange:e=>l({title:e.target.value||void 0}),"data-testid":`chart-title`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartXAxis`)}),(0,W.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:s,onChange:e=>l({xAxis:e.target.value||void 0}),"data-testid":`chart-x-field`,children:[(0,W.jsx)(`option`,{value:``,children:`—`}),e.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground`,children:i(`report.editor.chartYAxis`)}),(0,W.jsxs)(`select`,{className:`w-full h-7 text-xs border rounded px-2 bg-background`,value:c,onChange:e=>l({yAxis:e.target.value||void 0}),"data-testid":`chart-y-field`,children:[(0,W.jsx)(`option`,{value:``,children:`—`}),(h.length>0?h:e).map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,W.jsx)(g,{checked:a.showLegend!==!1,onCheckedChange:e=>l({showLegend:e===!0}),"data-testid":`chart-show-legend`}),(0,W.jsx)(`span`,{children:i(`report.editor.chartShowLegend`)})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,W.jsx)(g,{checked:!!a.showDataLabels,onCheckedChange:e=>l({showDataLabels:e===!0}),"data-testid":`chart-show-data-labels`}),(0,W.jsx)(`span`,{children:i(`report.editor.chartShowDataLabels`)})]})]})]})}function zt(e,t,n){let r=e=>e.type===`summary`,i=e=>e.type===`matrix`,a=e=>e.type===`summary`||e.type===`matrix`,o=[{key:`basic`,title:t(`report.editor.basic`),fields:[{key:`label`,label:t(`report.editor.title`),type:`input`,placeholder:t(`report.editor.titlePlaceholder`)},{key:`description`,label:t(`report.editor.description`),type:`textarea`,placeholder:t(`report.editor.descriptionPlaceholder`)},{key:`type`,label:t(`report.editor.type`),type:`select`,defaultValue:`tabular`,options:[{value:`tabular`,label:t(`report.editor.typeTabular`)},{value:`summary`,label:t(`report.editor.typeSummary`)},{value:`matrix`,label:t(`report.editor.typeMatrix`)},{value:`joined`,label:t(`report.editor.typeJoined`)}],helpText:t(`report.editor.typeHelp`)}]},{key:`data`,title:t(`report.editor.data`),collapsible:!0,fields:[{key:`objectName`,label:t(`report.editor.objectName`),type:`input`,placeholder:t(`report.editor.objectNamePlaceholder`),helpText:t(`report.editor.objectNameHelp`)},{key:`limit`,label:t(`report.editor.limit`),type:`input`,placeholder:t(`report.editor.limitPlaceholder`)}]},{key:`rows`,title:t(`report.editor.rows`),collapsible:!0,hint:t(`report.editor.rowsHint`),visibleWhen:e=>r(e)||i(e),fields:[{key:`groupingsDown`,label:t(`report.editor.grouping`),type:`custom`,render:(n,r)=>(0,W.jsx)(Lt,{availableFields:e,value:n,onChange:r,t,testIdPrefix:`rows-grouping`})}]},{key:`columnsAxis`,title:t(`report.editor.columnsAxis`),collapsible:!0,hint:t(`report.editor.columnsAxisHint`),visibleWhen:e=>i(e),fields:[{key:`groupingsAcross`,label:t(`report.editor.grouping`),type:`custom`,render:(n,r)=>(0,W.jsx)(Lt,{availableFields:e,value:n,onChange:r,t,testIdPrefix:`cols-grouping`})}]},{key:`tabular-columns`,title:t(`report.editor.columns`),collapsible:!0,hint:t(`report.editor.columnsHint`),visibleWhen:e=>e.type!==`joined`&&!r(e)&&!i(e),fields:[{key:`columns`,label:t(`report.editor.columns`),type:`custom`,render:(n,r)=>(0,W.jsx)(It,{availableFields:e,value:n,onChange:r,t})}]},{key:`values`,title:t(`report.editor.values`),collapsible:!0,hint:t(`report.editor.valuesHint`),visibleWhen:e=>r(e)||i(e),fields:[{key:`columns`,label:t(`report.editor.values`),type:`custom`,render:(n,r)=>(0,W.jsx)(It,{availableFields:e,value:n,onChange:r,t})}]},{key:`filters`,title:t(`report.editor.filters`),collapsible:!0,hint:t(`report.editor.filtersHint`),visibleWhen:e=>e.type!==`joined`,fields:[{key:`filter`,label:t(`report.editor.filters`),type:`custom`,render:(n,r)=>(0,W.jsx)(kt,{availableFields:e,value:n,onChange:r,t})}]},{key:`blocks`,title:t(`report.editor.blocks`),collapsible:!0,hint:t(`report.editor.blocksHint`),visibleWhen:e=>e.type===`joined`,fields:[{key:`blocks`,label:t(`report.editor.blocks`),type:`custom`,render:(r,i,a)=>(0,W.jsx)(yt,{value:r,onChange:i,availableFields:e,getFieldsForObject:n,containerObjectName:a?.objectName,t})}]},{key:`chart`,title:t(`report.editor.chart`),collapsible:!0,defaultCollapsed:!0,hint:t(`report.editor.chartHint`),visibleWhen:e=>a(e),fields:[{key:`chart`,label:t(`report.editor.chart`),type:`custom`,render:(n,r,i)=>(0,W.jsx)(Rt,{availableFields:e,columns:Ft(i.columns),value:n,onChange:r,t})}]}];return{breadcrumb:[t(`report.editor.breadcrumb`,`Configuration`)],sections:o}}function Bt(e,t){let n=[],r=e.type??`tabular`,i=Array.isArray(e.groupingsDown)?e.groupingsDown.length:0,a=Array.isArray(e.groupingsAcross)?e.groupingsAcross.length:0,o=Array.isArray(e.columns)?e.columns.length:0;if(e.objectName||n.push({level:o>0?`error`:`warning`,message:t(`report.editor.validationNeedsObject`)}),r===`matrix`&&(i===0||a===0)&&n.push({level:`error`,message:t(`report.editor.validationMatrixNeedsRowsCols`)}),r===`summary`&&i===0&&n.push({level:`error`,message:t(`report.editor.validationSummaryNeedsRows`)}),r===`joined`)for(let r of bt(e.blocks,t))n.push({level:`error`,message:r});return n}function Vt({problems:e}){return e.length===0?null:(0,W.jsx)(`div`,{className:`space-y-1 p-2 border-b`,"data-testid":`report-validation-banner`,children:e.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] rounded px-2 py-1 `+(e.level===`error`?`bg-red-50 border border-red-200 text-red-900`:`bg-amber-50 border border-amber-200 text-amber-900`),children:[(0,W.jsx)(h,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:e.message})]},t))})}function Ht({open:e,onClose:t,config:n,onSave:r,onFieldChange:i,availableFields:a,getFieldsForObject:o}){let{t:s}=l(),c=U.useCallback((e,t,n)=>t===void 0?s(e,n):s(e,{defaultValue:t,...n||{}}),[s]),u=a??[],d=U.useMemo(()=>zt(u,c,o),[u,c,o]),{draft:f,isDirty:p,updateField:m,discard:h}=j(U.useMemo(()=>n??{},[n])),g=U.useCallback((e,t)=>{m(e,t),i?.(e,t,{...f,[e]:t})},[m,i,f]),_=U.useCallback(()=>{r(f),t()},[f,r,t]),y=U.useMemo(()=>Bt(f,c),[f,c]);return e?(0,W.jsx)(v,{open:e,onClose:t,schema:d,draft:f,isDirty:p,onFieldChange:g,onSave:_,onDiscard:h,headerExtra:(0,W.jsx)(Vt,{problems:y}),style:{"--config-panel-width":`440px`}}):null}async function Ut(e,t){let{dataSource:n,resource:r,queryParams:i,format:a,exportConfig:o}=t,s=a||e.defaultExportFormat||`pdf`;try{let t=(await n.find(r,i)).data||[];return tt(s,e,t,{format:s,...e.exportConfigs?.[s],...o}),{success:!0,recordCount:t.length,format:s}}catch(e){return{success:!1,recordCount:0,format:s,error:e.message}}}function Wt(e,t,n={}){let{columns:r,filename:i,includeAggregationRow:a=!1}=n,o=r||(e.fields||[]).map(Kt),s=o.map(e=>e.header),c=t.map((e,t)=>o.map(n=>{if(n.formula)return n.formula.replace(/\{ROW\}/g,String(t+2));let r=e[n.name];return qt(r,n.numberFormat)}));if(a&&t.length>0){let n=o.map((n,r)=>{let i=(e.fields||[]).find(e=>e.name===n.name);if(i?.aggregation){let e=Yt(r),n=t.length+1;switch(i.aggregation){case`sum`:return`=SUM(${e}2:${e}${n})`;case`avg`:return`=AVERAGE(${e}2:${e}${n})`;case`count`:return`=COUNTA(${e}2:${e}${n})`;case`min`:return`=MIN(${e}2:${e}${n})`;case`max`:return`=MAX(${e}2:${e}${n})`;default:return``}}return``});c.push(n)}Zt(``+[s.join(` `),...c.map(e=>e.join(` `))].join(`
|
|
59
|
-
`),i||`${e.title||`report`}.tsv`,`text/tab-separated-values`)}function Gt(e,t,n,r){return async()=>{let i=e.schedule;if(!i?.enabled)return[];let a=i.formats||[e.defaultExportFormat||`pdf`],o=[];for(let r of a){let i=await Ut(e,{dataSource:t,resource:n,format:r});o.push(i)}return r(e,i),o}}function Kt(e){return{name:e.name,header:e.label||e.name}}function qt(e,t){return e==null?``:typeof e==`number`&&t?e.toLocaleString(`en-US`,Jt(t)):Xt(String(e))}function Jt(e){if(e.includes(`%`))return{style:`percent`,minimumFractionDigits:0};let t=(e.match(/0/g)||[]).length;return{minimumFractionDigits:Math.max(0,t-1),maximumFractionDigits:Math.max(0,t-1)}}function Yt(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function Xt(e){if(e.length>0){let t=e.charAt(0);if(t===`=`||t===`+`||t===`-`||t===`@`||t===`|`)return`'${e}`}return e}function Zt(e,t,n){let r=new Blob([e],{type:`${n};charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}var Qt=t({JoinedBlocksEditor:()=>yt,JoinedReportRenderer:()=>qe,LegacyReportRenderer:()=>me,MatrixRenderer:()=>We,ReportBuilder:()=>ft,ReportConfigPanel:()=>Ht,ReportRenderer:()=>Ye,ReportViewer:()=>ut,ScheduleConfig:()=>dt,SpecReportGrid:()=>ze,aggregateRows:()=>q,bucketDate:()=>he,buildAggregateQuery:()=>we,buildDrillAction:()=>je,collectFields:()=>Ce,columnKey:()=>G,createDrillHandler:()=>Ne,createScheduleTrigger:()=>Gt,exportAsCSV:()=>Xe,exportAsExcel:()=>et,exportAsHTML:()=>Qe,exportAsJSON:()=>Ze,exportAsPDF:()=>$e,exportExcelWithFormulas:()=>Wt,exportReport:()=>tt,exportWithLiveData:()=>Ut,formatValue:()=>ot,groupAndAggregate:()=>ge,groupingValue:()=>K,isDrillAction:()=>Me,mergeFilters:()=>Y,pivotRows:()=>_e,registerDrillHandler:()=>Pe,useReportData:()=>Ee,validateJoinedBlocks:()=>bt});o.register(`report`,Ye,{namespace:`report`,label:`Report`,category:`Report`,inputs:[{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`chart`,type:`code`,label:`Chart Configuration`}]}),o.register(`spec-report`,Ye,{namespace:`report`,label:`Spec Report`,category:`Report`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`},{name:`type`,type:`string`,label:`Report Type`}]}),o.register(`report-viewer`,ut,{namespace:`report`,label:`Report Viewer`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Report Definition`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`}]}),o.register(`report-builder`,ft,{namespace:`report`,label:`Report Builder`,category:`Report`,inputs:[{name:`report`,type:`code`,label:`Initial Report`}]});export{Qt as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-BMpe6Iqg.js";import{B as r,H as i,lt as a,mt as o,r as s}from"./framework-CzhT5JRV.js";import{$a as c,$r as l,$t as u,Bn as d,Bs as f,Bt as p,Cn as m,Da as h,Dn as g,Dt as _,En as v,Et as y,Fn as b,Gi as x,Gn as S,Hi as C,Ht as w,In as T,Jr as E,Js as D,Ln as O,Oa as ee,Oo as te,Ot as k,P as ne,Pa as A,Qa as re,Qn as j,Qt as ie,Ri as ae,Rn as M,Rr as N,Rs as P,Rt as F,Sn as I,Ta as L,Tn as oe,U as se,Vi as R,Vt as z,Wa as B,Ys as V,Zt as H,_n as ce,_o as U,ai as W,an as le,ba as ue,bn as de,bs as G,ci as fe,cn as K,dn as pe,ds as q,en as J,eo as me,et as he,fn as ge,gi as _e,gn as ve,gr as ye,hi as be,hn as Y,in as X,kt as xe,mi as Se,mn as Ce,mr as Z,nt as we,on as Te,oo as Ee,pn as De,rt as Oe,un as ke,us as Ae,vi as je,vn as Me,wn as Ne,xi as Pe,xn as Fe,xr as Ie,yn as Le,zn as Re,zo as ze,zt as Be}from"./ui-components-BHdgV-R1.js";import{i as Ve}from"./vendor-ui-utils-CjuGfYLJ.js";import{t as He}from"./plugin-form-C0Ec8keG.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-Ds4hJT77.js";import{r as nt}from"./plugin-grid-b1qcltrl.js";var Q=e(n(),1),$=t(),rt={list:`List`,detail:`Detail`,grid:`Grid`,kanban:`Kanban`,calendar:`Calendar`,timeline:`Timeline`,map:`Map`,gallery:`Gallery`,gantt:`Gantt`},it={list:h,detail:U,grid:c,kanban:A,calendar:G,timeline:D,map:ue,gallery:B,gantt:W},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 ye[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:Se,settings:be,duplicate:ze,delete:N},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)(Z,{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)(Z,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>i?.(),title:o,children:(0,$.jsx)(ae,{className:`h-3.5 w-3.5`})}):null,C=(0,$.jsxs)(`div`,{className:V(ot({orientation:b}),`flex items-center gap-1`),children:[_===`dropdown`&&(0,$.jsxs)(F,{value:h,onValueChange:e=>f(e),children:[(0,$.jsx)(z,{className:V(`w-full`,y?`h-10`:`h-9`),children:(0,$.jsx)(w,{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:V(st({orientation:b})),children:e.views.map((e,t)=>{let n=e.type===m,r=pt(e);return(0,$.jsxs)(Z,{type:`button`,size:`sm`,variant:n?`secondary`:`ghost`,className:V(`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)(he,{value:h,onValueChange:e=>f(e),children:(0,$.jsx)(we,{className:V(ct({orientation:b})),children:e.views.map((e,t)=>{let n=pt(e);return(0,$.jsxs)(Oe,{value:e.type,className:V(`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]}),T=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:V(at({position:v}),t),children:[(0,$.jsx)(`div`,{className:V(`shrink-0`,y?`flex flex-col`:`flex`),children:C}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:T})]})},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,x]=(0,Q.useState)(`create`),[S,C]=(0,Q.useState)(null),[w,E]=(0,Q.useState)(0);(0,Q.useEffect)(()=>{if(!(!t?.onMutation||!e.objectName)&&!l)return t.onMutation(t=>{t.resource===e.objectName&&E(e=>e+1)})},[t,e.objectName,l]);let[D,ee]=(0,Q.useState)([]),[te,k]=(0,Q.useState)(!1),[A,re]=(0,Q.useState)({}),[j,ie]=(0,Q.useState)([]),M=e.listViews,N=M!=null&&Object.keys(M).length>0,[P,F]=(0,Q.useState)(()=>e.defaultListView&&M?.[e.defaultListView]?e.defaultListView:M&&Object.keys(M)[0]||``),I=(0,Q.useMemo)(()=>!N||!P?null:M[P]||null,[N,P,M]),L=(0,Q.useMemo)(()=>r&&r.length>0?r:null,[r]),oe=L!=null&&L.length>0,se=i||L?.[0]?.id,R=L?.find(e=>e.id===se)||L?.[0],z=(0,Q.useMemo)(()=>I?.type?I.type:R?.type?R.type:e.defaultViewType||`grid`,[I,R,e.defaultViewType]),B=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&&z!==`grid`&&!(!t||!e.objectName)){k(!0);try{let r=I?.filter||R?.filter||e.table?.defaultFilters||[],i=Object.entries(A).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=j.length>0?j.map(e=>({field:e.field,order:e.direction})):I?.sort||R?.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&&ee(u)}catch(e){console.error(`ObjectView data fetch error:`,e)}finally{n&&k(!1)}}})(),()=>{n=!1}},[e.objectName,t,z,A,j,w,I,R,l]);let H=e.layout||`drawer`,U=e.operations||e.table?.operations||{create:!0,read:!0,update:!0,delete:!0},W=(0,Q.useCallback)(()=>{H===`page`&&e.onNavigate?e.onNavigate(`new`,`edit`):(x(`create`),C(null),v(!0))},[H,e]),le=(0,Q.useCallback)(t=>{if(c){c(t);return}if(H===`page`&&e.onNavigate){let n=t.id||t._id;e.onNavigate(n,`edit`)}else x(`edit`),C(t),v(!0)},[H,e,c]),ue=(0,Q.useCallback)(t=>{if(H===`page`&&e.onNavigate){let n=t.id||t._id;e.onNavigate(n,`view`)}else x(`view`),C(t),v(!0)},[H,e]),de=(0,Q.useCallback)(t=>{if(s){s(t);return}if(B){if(B.mode===`none`||B.preventNavigation)return;if(B.mode===`new_window`||B.openNewTab){let n=t.id||t._id,r=`/${e.objectName}/${encodeURIComponent(String(n))}`;window.open(r,`_blank`);return}if(B.mode===`drawer`){x(`view`),C(t),v(!0);return}if(B.mode===`modal`){x(`view`),C(t),v(!0);return}if(B.mode===`page`){let n=t.id||t._id;e.onNavigate&&e.onNavigate(n,`view`);return}if(B.mode===`split`||B.mode===`popover`){x(`view`),C(t),v(!0);return}}U.read!==!1&&ue(t)},[s,B,U.read,ue,e]),G=(0,Q.useCallback)(e=>{E(e=>e+1)},[]),fe=(0,Q.useCallback)(e=>{E(e=>e+1)},[]),K=(0,Q.useCallback)(()=>{v(!1),C(null),E(e=>e+1)},[]),pe=(0,Q.useCallback)(()=>{v(!1),C(null)},[]);(0,Q.useCallback)(()=>{E(e=>e+1)},[]);let q=(0,Q.useMemo)(()=>!oe||!L||L.length<=1?null:{type:`view-switcher`,variant:`tabs`,position:`top`,persistPreference:!0,storageKey:`view-pref-${e.objectName}`,defaultView:R?.type||`grid`,activeView:R?.type||`grid`,views:L.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},[oe,L,R,e.objectName,e.allowCreateView,e.viewActions]),J=(0,Q.useCallback)(e=>{if(!L)return;let t=L.find(t=>t.type===e);t&&o&&o(t.id)},[L,o]),me=(0,Q.useCallback)(e=>{F(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:A}},[e.showFilters,e.filterableFields,m,A]);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:j}},[m,j,ge]);let _e=(0,Q.useCallback)(t=>{let n={objectName:e.objectName,fields:I?.columns||R?.columns||e.table?.fields,className:`h-full w-full`,showSearch:R?.showSearch??e.showSearch??!1,showSort:R?.showSort??e.showSort??!1,showFilters:R?.showFilters??e.showFilters??!1,striped:R?.striped??!1,bordered:R?.bordered??!1,color:R?.color},r=I?.options||R||{};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,I,R]),ye=(0,Q.useMemo)(()=>({type:`object-grid`,objectName:e.objectName,title:e.table?.title,description:e.table?.description,fields:I?.columns||R?.columns||e.table?.fields,columns:I?.columns||R?.columns||e.table?.columns,operations:{...U,create:!1},defaultFilters:I?.filter||R?.filter||e.table?.defaultFilters,defaultSort:I?.sort||R?.sort||e.table?.defaultSort,pageSize:e.table?.pageSize,selectable:e.table?.selectable,striped:R?.striped??e.table?.striped,bordered:R?.bordered??e.table?.bordered,className:e.table?.className}),[e,U,I,R]),be=()=>{let t=S?S.id||S._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:K,onCancel:pe}},X=()=>{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=B?.width;return e?typeof e==`number`?`max-w-[${e}px]`:`max-w-[${e}]`:``},[B]),Se=()=>(0,$.jsx)(Y,{open:_,onOpenChange:v,direction:`right`,children:(0,$.jsxs)(ve,{className:V(`w-full sm:max-w-2xl`,xe),children:[(0,$.jsxs)(Me,{children:[(0,$.jsx)(Le,{children:X()}),e.form?.description&&(0,$.jsx)(ce,{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)(b,{open:_,onOpenChange:v,children:(0,$.jsxs)(T,{className:V(`max-w-2xl max-h-[90vh] overflow-y-auto`,xe),children:[(0,$.jsxs)(Re,{children:[(0,$.jsx)(d,{children:X()}),e.form?.description&&(0,$.jsx)(O,{children:e.form.description})]}),(0,$.jsx)(He,{schema:be(),dataSource:t})]})}),Te=(0,Q.useMemo)(()=>Object.keys(A).some(e=>A[e]!==void 0&&A[e]!==``&&A[e]!==null)?Object.entries(A).filter(([,e])=>e!==void 0&&e!==``&&e!==null).map(([e,t])=>({field:e,operator:`equals`,value:t})):I?.filter||R?.filter||e.table?.defaultFilters,[A,I,R,e.table?.defaultFilters]),Ee=(0,Q.useMemo)(()=>j.length>0?j:I?.sort||R?.sort||e.table?.defaultSort,[j,I,R,e.table?.defaultSort]),De=()=>{let n=`${e.objectName}-${P||R?.id||`default`}-${z}-${w}`;if(l)return l({schema:{type:`list-view`,objectName:e.objectName,viewType:z,fields:I?.columns||R?.columns||e.table?.fields,filters:Te,sort:Ee,rowHeight:R?.rowHeight,densityMode:R?.densityMode,groupBy:R?.groupBy,groupBy2:R?.groupBy2,grouping:R?.grouping,options:I?.options||R,showSearch:R?.showSearch??e.showSearch,showFilters:R?.showFilters??e.showFilters,showSort:R?.showSort??e.showSort,showHideFields:R?.showHideFields??e.showHideFields,showGroup:R?.showGroup??e.showGroup,showColor:R?.showColor??e.showColor,showDensity:R?.showDensity??e.showDensity,compactToolbar:R?.compactToolbar??e.compactToolbar,allowExport:R?.allowExport??e.allowExport,striped:R?.striped??e.striped,bordered:R?.bordered??e.bordered,color:R?.color??e.color,inlineEdit:R?.inlineEdit??e.inlineEdit,wrapHeaders:R?.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:R?.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:R?.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:R?.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:R?.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:R?.fieldTextColor??e.fieldTextColor,prefixField:R?.prefixField??e.prefixField,showDescription:R?.showDescription??e.showDescription,navigation:R?.navigation??e.navigation,selection:R?.selection??e.selection,pagination:R?.pagination??e.pagination,searchableFields:R?.searchableFields??e.searchableFields,filterableFields:R?.filterableFields??e.filterableFields,resizable:R?.resizable??e.resizable,hiddenFields:R?.hiddenFields??e.hiddenFields,rowActions:R?.rowActions??e.rowActions,rowActionDefs:R?.rowActionDefs??e.rowActionDefs,bulkActions:R?.bulkActions??e.bulkActions,sharing:R?.sharing??e.sharing,addRecord:R?.addRecord??e.addRecord,conditionalFormatting:R?.conditionalFormatting??e.conditionalFormatting,quickFilters:R?.quickFilters??e.quickFilters,userFilters:R?.userFilters??e.userFilters,showRecordCount:R?.showRecordCount??e.showRecordCount,allowPrinting:R?.allowPrinting??e.allowPrinting,virtualScroll:R?.virtualScroll??e.virtualScroll,emptyState:R?.emptyState??e.emptyState,aria:R?.aria??e.aria,tabs:e.tabs,refreshTrigger:w},dataSource:t,onEdit:le,onRowClick:de,className:`h-full`,refreshKey:w});if(z!==`grid`){let e=_e(z);if(e&&vt)return(0,$.jsx)(vt,{schema:e,dataSource:t,data:D,loading:te},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 `,z,` views.`]})})}return(0,$.jsx)(nt,{schema:ye,dataSource:t,onRowClick:de,onEdit:U.update===!1?void 0:le,onDelete:U.delete===!1?void 0:G,onBulkDelete:U.delete===!1?void 0:fe},n)},ke=()=>{if(!N)return null;let e=Object.entries(M);return e.length<=1?null:(0,$.jsx)(he,{value:P,onValueChange:me,className:`w-full`,children:(0,$.jsx)(we,{className:`w-auto`,children:e.map(([e,t])=>(0,$.jsx)(Oe,{value:e,className:`text-sm`,children:t.label||e},e))})})},Ae=()=>{let t=e.showCreate!==!1&&U.create!==!1,n=e.showViewSwitcher===!0,r=ke();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&&q&&(0,$.jsx)(_t,{schema:q,onViewChange:J,onCreateView:f,onViewAction:p,className:`overflow-x-auto`})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[u,t&&(0,$.jsxs)(Z,{size:`sm`,onClick:W,children:[(0,$.jsx)(ae,{className:`h-4 w-4`}),`Create`]})]})]})]})},je=B?.mode===`modal`?`modal`:B?.mode===`drawer`?`drawer`:B?.mode===`split`?`split`:B?.mode===`popover`?`popover`:H,Ne=e=>(0,$.jsx)(`div`,{className:`space-y-3`,children:(0,$.jsx)(He,{schema:be(),dataSource:t})}),Pe=(0,Q.useCallback)(e=>{e||pe()},[pe]);if(je===`split`){let t=m?.label||e.objectName;return(0,$.jsxs)(`div`,{className:V(`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:Ae()}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:_&&S?(0,$.jsx)(ne,{isOpen:_,selectedRecord:S,mode:`split`,close:pe,setIsOpen:Pe,width:B?.width,isOverlay:!0,title:`${t} Detail`,mainContent:(0,$.jsx)(`div`,{className:`h-full overflow-auto`,children:De()}),children:Ne}):De()})]})}return(0,$.jsxs)(`div`,{className:V(`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:Ae()}),(0,$.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:De()}),je===`drawer`&&Se(),je===`modal`&&Ce(),je===`popover`&&_&&S&&(0,$.jsx)(ne,{isOpen:_,selectedRecord:S,mode:`popover`,close:pe,setIsOpen:Pe,width:B?.width,isOverlay:!0,title:X(),children:Ne})]})},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)(J,{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)(F,{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)(z,{children:(0,$.jsx)(w,{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:V(`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)(S,{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)(J,{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)(J,{type:`date`,value:t.start??``,onChange:n=>{c(e.field,{...t,start:n.target.value})}}),(0,$.jsx)(J,{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)(S,{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)(J,{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)(X,{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)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:l,children:`Clear`}),e.showApply&&(0,$.jsx)(Z,{type:`button`,size:`sm`,onClick:d,children:`Apply`})]})]}),g=e.layout||`inline`;return g===`popover`?(0,$.jsx)(`div`,{className:V(bt({layout:g}),t),children:(0,$.jsxs)(H,{open:a,onOpenChange:o,children:[(0,$.jsx)(u,{asChild:!0,children:(0,$.jsxs)(Z,{type:`button`,variant:f>0?`secondary`:`outline`,size:`sm`,className:`gap-2`,children:[(0,$.jsx)(fe,{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)(ie,{align:`start`,className:`w-[520px] p-4`,children:h})]})}):g===`drawer`?(0,$.jsxs)(`div`,{className:V(bt({layout:g}),t),children:[(0,$.jsxs)(Z,{type:`button`,variant:f>0?`secondary`:`outline`,size:`sm`,className:`gap-2`,onClick:()=>o(!0),children:[(0,$.jsx)(fe,{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)(Y,{open:a,onOpenChange:o,children:(0,$.jsxs)(ve,{children:[(0,$.jsxs)(Me,{children:[(0,$.jsx)(Le,{children:`Filters`}),(0,$.jsx)(ce,{children:`Refine the data with advanced filters.`})]}),(0,$.jsx)(`div`,{className:`px-4 pb-6`,children:h})]})})]}):(0,$.jsxs)(`div`,{className:V(bt({layout:g}),t),children:[h,!e.showApply&&e.showClear&&(0,$.jsxs)(Z,{type:`button`,variant:`ghost`,size:`sm`,className:`gap-2`,onClick:l,children:[(0,$.jsx)(Ie,{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:V(wt({variant:`buttons`}),t),children:e.fields.map(e=>{let t=r.find(t=>t.field===e.field);return(0,$.jsxs)(Z,{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)(P,{className:V(`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:V(wt({variant:`builder`}),t),children:(0,$.jsx)(se,{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:V(wt({variant:`dropdown`}),t),children:[(0,$.jsxs)(F,{value:l?.field||``,onValueChange:e=>{if(!e){s([]);return}s([{field:e,direction:l?.direction||`asc`}])},children:[(0,$.jsx)(z,{className:`w-56`,children:(0,$.jsx)(w,{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)(F,{value:l?.direction||`asc`,onValueChange:e=>{l?.field&&s([{field:l.field,direction:e}])},children:[(0,$.jsx)(z,{className:`w-36`,children:(0,$.jsx)(w,{})}),(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),[f,p]=Q.useState(``),[m,h]=Q.useState(``),g=n??(typeof window<`u`?window.location.origin:``),_=Q.useCallback(()=>{let n=At(g,e,t,kt());o(n),c(!1);let i=m?new Date(Date.now()+parseInt(m,10)*864e5).toISOString():void 0;r?.(n,{password:f||void 0,expiresAt:i})},[g,e,t,r,f,m]),v=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)(H,{open:l,onOpenChange:d,children:[(0,$.jsx)(u,{asChild:!0,children:(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,className:V(`gap-2`,i),children:[(0,$.jsx)(Se,{className:`h-4 w-4`}),`Share`]})}),(0,$.jsxs)(ie,{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)(j,{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)(J,{value:a,readOnly:!0,className:`h-8 text-xs`,onClick:e=>e.target.select()}),(0,$.jsx)(Z,{variant:`outline`,size:`sm`,onClick:v,className:`shrink-0 gap-1`,children:s?(0,$.jsx)(q,{className:`h-4 w-4 text-green-500`}):(0,$.jsx)(ze,{className:`h-4 w-4`})})]}),(f||m)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[f&&(0,$.jsxs)(j,{variant:`outline`,className:`text-xs gap-1`,children:[(0,$.jsx)(L,{className:`h-3 w-3`}),`Password protected`]}),m&&(0,$.jsxs)(j,{variant:`outline`,className:`text-xs gap-1`,children:[(0,$.jsx)(G,{className:`h-3 w-3`}),`Expires in `,m,` day`,m===`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)(L,{className:`h-3.5 w-3.5`}),`Password protection (optional)`]}),(0,$.jsx)(J,{type:`password`,value:f,onChange:e=>p(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)(G,{className:`h-3.5 w-3.5`}),`Expires after (optional)`]}),(0,$.jsxs)(`select`,{value:m,onChange:e=>h(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)(Z,{onClick:_,className:`w-full gap-2`,size:`sm`,children:[(0,$.jsx)(Se,{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:c,onSetDefaultView:u,onShareView:d,onSaveAsView:p,onPinView:h,onReorderViews:b,onChangeViewType:S,onConfigView:w,onManageViews:T,availableViewTypes:D,hasUnsavedChanges:O=!1,onResetChanges:ne,className:j})=>{let{showAddButton:ie=!0,inlineRename:M=!0,contextMenu:P=!0,reorderable:F=!1,maxVisibleTabs:se=4,showIndicators:z=!0,showSaveAsView:B=!0,showPinnedSection:H=!0,showVisibilityGroups:ce=!1}=i,U=Mt(),[W,ue]=(0,Q.useState)(null),[G,fe]=(0,Q.useState)(``),q=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{W&&q.current&&(q.current.focus(),q.current.select())},[W]);let he=(0,Q.useCallback)(t=>{if(!M||!o)return;let n=e.find(e=>e.id===t);n&&(n.readonly||(ue(t),fe(n.label)))},[M,o,e]),ve=(0,Q.useCallback)(()=>{W&&G.trim()&&o&&o(W,G.trim()),ue(null),fe(``)},[W,G,o]),ye=(0,Q.useCallback)(()=>{ue(null),fe(``)},[]),be=(0,Q.useMemo)(()=>e.length>0&&e.every(e=>!!e.readonly),[e]),Y=(0,Q.useMemo)(()=>{let t=[...e];return t.sort((e,t)=>{if(H){let n=+!!e.isPinned,r=+!!t.isPinned;if(n!==r)return r-n}if(ce){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,H,ce]),{visibleViews:X,overflowViews:we}=(0,Q.useMemo)(()=>{let e=Y.slice(0,se),n=Y.slice(se),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}},[Y,se,t]),Oe=qe(Je(Ke,{activationConstraint:{distance:Pt}}),Je(tt)),je=(0,Q.useCallback)(e=>{let{active:t,over:n}=e;if(!n||t.id===n.id||!b)return;let r=Y.findIndex(e=>e.id===t.id),i=Y.findIndex(e=>e.id===n.id);r===-1||i===-1||b(Ye(Y,r,i).map(e=>e.id))},[Y,b]),Me=E,Ie=(0,Q.useCallback)(e=>{if(!ce||e===0)return!1;let t=X[e-1],n=X[e],r=e=>e.visibility===`private`;return r(t)&&!r(n)},[ce,X]),Le=(e,i)=>{let a=e.id===t,p=r[e.type]||Me,E=W===e.id,O=z&&(e.hasActiveFilters||e.hasActiveSort),te=Ie(i),k=!!e.readonly,ne=(e=>ce?e.visibility===`private`?(0,$.jsx)(L,{"data-testid":`view-tab-visibility-${e.id}`,className:`h-3 w-3 text-muted-foreground shrink-0`}):e.visibility?(0,$.jsx)(me,{"data-testid":`view-tab-visibility-${e.id}`,className:`h-3 w-3 text-muted-foreground shrink-0`}):null:null)(e),j=t=>(0,$.jsxs)(`div`,{"data-testid":`view-tab-${e.id}`,role:`tab`,tabIndex:0,"aria-selected":a,onClick:()=>!E&&n(e.id),onDoubleClick:()=>he(e.id),onKeyDown:t=>{!E&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e.id))},...t?.listeners??{},...t?.attributes??{},className:V(`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:[F&&b&&(0,$.jsx)(`span`,{"data-testid":`view-tab-drag-handle-${e.id}`,"aria-hidden":`true`,className:V(`text-muted-foreground transition-opacity pointer-events-none`,`opacity-0 group-hover/tab:opacity-100`,t?.isDragging&&`opacity-100`),children:(0,$.jsx)(re,{className:`h-3 w-3`})}),H&&e.isPinned&&(0,$.jsx)(R,{"data-testid":`view-tab-pin-indicator-${e.id}`,className:`h-3 w-3 text-primary shrink-0`}),ne,(0,$.jsx)(p,{className:`h-3.5 w-3.5`}),E?(0,$.jsx)(J,{ref:q,"data-testid":`view-tab-rename-input-${e.id}`,value:G,onChange:e=>fe(e.target.value),onBlur:ve,onKeyDown:e=>{e.key===`Enter`&&ve(),e.key===`Escape`&&ye()},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}),k&&!be&&(0,$.jsxs)(y,{children:[(0,$.jsx)(xe,{asChild:!0,children:(0,$.jsx)(L,{"data-testid":`view-tab-readonly-${e.id}`,"aria-label":U(`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||U(`view.readonlyTooltip`,`System view — defined in code, read-only.`)})]}),O&&(0,$.jsxs)(y,{children:[(0,$.jsx)(xe,{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)(Ee,{className:`h-2.5 w-2.5`}),e.hasActiveSort&&(0,$.jsx)(f,{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&&(w||o||s||c)&&(0,$.jsxs)(le,{children:[(0,$.jsx)(Ce,{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":U(`view.tabActionsFor`,`View actions for ${e.label}`,{name:e.label}),children:(0,$.jsx)(Ae,{className:`h-3 w-3`})})}),(0,$.jsxs)(Te,{align:`start`,className:`min-w-[180px]`,onClick:e=>e.stopPropagation(),children:[w&&!k&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-config-${e.id}`,onClick:()=>w(e.id),children:[(0,$.jsx)(_e,{className:`h-4 w-4 mr-2`}),` Edit view config`]}),o&&!k&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-rename-${e.id}`,onClick:()=>he(e.id),children:[(0,$.jsx)(x,{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)(ze,{className:`h-4 w-4 mr-2`}),` Duplicate view`]}),d&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-share-${e.id}`,onClick:()=>d(e.id),children:[(0,$.jsx)(Se,{className:`h-4 w-4 mr-2`}),` Share view`]}),u&&!k&&(0,$.jsxs)(K,{"data-testid":`view-tab-menu-default-${e.id}`,onClick:()=>u(e.id),children:[(0,$.jsx)(l,{className:`h-4 w-4 mr-2`}),` Set as default`]}),h&&!k&&(0,$.jsx)(K,{"data-testid":`view-tab-menu-pin-${e.id}`,onClick:()=>h(e.id,!e.isPinned),children:e.isPinned?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(C,{className:`h-4 w-4 mr-2`}),` Unpin view`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{className:`h-4 w-4 mr-2`}),` Pin view`]})}),S&&!k&&D&&D.length>0&&(0,$.jsxs)(pe,{children:[(0,$.jsxs)(De,{"data-testid":`view-tab-menu-change-type-${e.id}`,children:[(0,$.jsx)(A,{className:`h-4 w-4 mr-2`}),` Change view type`]}),(0,$.jsx)(ge,{children:D.map(t=>{let n=r[t.type]||Me;return(0,$.jsxs)(K,{"data-testid":`view-tab-menu-type-${e.id}-${t.type}`,disabled:t.type===e.type,onClick:()=>S(e.id,t.type),children:[(0,$.jsx)(n,{className:`h-4 w-4 mr-2`}),(0,$.jsx)(`span`,{children:t.label})]},t.type)})})]}),c&&!k&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ke,{}),(0,$.jsxs)(K,{"data-testid":`view-tab-menu-delete-${e.id}`,onClick:()=>c(e.id),className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(N,{className:`h-4 w-4 mr-2`}),` Delete view`]})]}),T&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ke,{}),(0,$.jsxs)(K,{"data-testid":`view-tab-menu-manage-${e.id}`,onClick:T,children:[(0,$.jsx)(ee,{className:`h-4 w-4 mr-2`}),` Manage all views…`]})]})]})]})]}),ie=t=>!P||E?t:(0,$.jsxs)(de,{children:[(0,$.jsx)(g,{asChild:!0,children:t}),(0,$.jsxs)(Fe,{children:[o&&!k&&(0,$.jsxs)(I,{"data-testid":`context-menu-rename-${e.id}`,onClick:()=>he(e.id),children:[(0,$.jsx)(x,{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)(ze,{className:`h-4 w-4 mr-2`}),` Duplicate View`]}),d&&(0,$.jsxs)(I,{"data-testid":`context-menu-share-${e.id}`,onClick:()=>d(e.id),children:[(0,$.jsx)(Se,{className:`h-4 w-4 mr-2`}),` Share View`]}),u&&!k&&(0,$.jsxs)(I,{"data-testid":`context-menu-default-${e.id}`,onClick:()=>u(e.id),children:[(0,$.jsx)(l,{className:`h-4 w-4 mr-2`}),` Set as Default`]}),h&&!k&&(0,$.jsx)(I,{"data-testid":`context-menu-pin-${e.id}`,onClick:()=>h(e.id,!e.isPinned),children:e.isPinned?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(C,{className:`h-4 w-4 mr-2`}),` Unpin View`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{className:`h-4 w-4 mr-2`}),` Pin View`]})}),S&&!k&&D&&D.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(m,{}),(0,$.jsxs)(Ne,{children:[(0,$.jsxs)(v,{"data-testid":`context-menu-change-type-${e.id}`,children:[(0,$.jsx)(A,{className:`h-4 w-4 mr-2`}),` Change View Type`]}),(0,$.jsx)(oe,{"data-testid":`context-menu-type-submenu-${e.id}`,children:D.map(t=>{let n=r[t.type]||Me;return(0,$.jsxs)(I,{"data-testid":`context-menu-type-${e.id}-${t.type}`,disabled:t.type===e.type,onClick:()=>S(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)})})]})]}),c&&!k&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(m,{}),(0,$.jsxs)(I,{"data-testid":`context-menu-delete-${e.id}`,onClick:()=>c(e.id),className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(N,{className:`h-4 w-4 mr-2`}),` Delete View`]})]}),T&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(m,{}),(0,$.jsxs)(I,{"data-testid":`context-menu-manage-${e.id}`,onClick:T,children:[(0,$.jsx)(ee,{className:`h-4 w-4 mr-2`}),` Manage all views…`]})]})]})]});return F&&b?(0,$.jsxs)(Q.Fragment,{children:[te&&(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:V(`flex`,i&&`z-10`),children:ie(j({listeners:n,attributes:r,isDragging:i}))})})]},e.id):(0,$.jsxs)(Q.Fragment,{children:[te&&(0,$.jsx)(`div`,{"data-testid":`view-tab-visibility-separator`,className:`w-px h-5 bg-border mx-1 self-center shrink-0`}),ie(j())]},e.id)},Re=(0,$.jsx)($.Fragment,{children:X.map((e,t)=>Le(e,t))});return(0,$.jsx)(k,{children:(0,$.jsxs)(`div`,{"data-testid":`view-tab-bar`,className:V(`flex items-center gap-0.5 -mb-px`,j),children:[F&&b?(0,$.jsx)(Ge,{sensors:Oe,collisionDetection:Ze,onDragEnd:je,children:(0,$.jsx)(et,{items:X.map(e=>e.id),strategy:Qe,children:(0,$.jsx)(`div`,{"data-testid":`view-tab-sortable-container`,className:`flex items-center gap-0.5`,children:Re})})}):Re,we.length>0&&(0,$.jsxs)(le,{children:[(0,$.jsx)(Ce,{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)(te,{className:`h-4 w-4`}),(0,$.jsxs)(`span`,{className:`text-xs`,children:[we.length,` more`]})]})}),(0,$.jsxs)(Te,{align:`end`,children:[T&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(K,{"data-testid":`view-tab-overflow-manage`,onClick:T,className:`font-medium`,children:[(0,$.jsx)(ee,{className:`h-4 w-4 mr-2`}),` Manage all views…`]}),(0,$.jsx)(ke,{})]}),we.map(e=>{let t=r[e.type]||Me;return(0,$.jsxs)(K,{"data-testid":`view-tab-overflow-${e.id}`,onClick:()=>n(e.id),children:[e.isPinned&&(0,$.jsx)(R,{className:`h-3 w-3 mr-1 text-primary shrink-0`}),(0,$.jsx)(t,{className:`h-4 w-4 mr-2`}),e.label,z&&(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)(Ee,{className:`h-2.5 w-2.5`}),e.hasActiveSort&&(0,$.jsx)(f,{className:`h-2.5 w-2.5`})]})]},e.id)})]})]}),ie&&a&&(0,$.jsxs)(y,{children:[(0,$.jsx)(xe,{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)(ae,{className:`h-4 w-4`})})}),(0,$.jsx)(_,{children:`Add View`})]}),B&&O&&(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)(Pe,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Unsaved changes`}),p&&(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,"data-testid":`view-tab-save-as-btn`,className:`h-6 px-2 text-xs`,onClick:p,children:`Save as View`}),ne&&(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,"data-testid":`view-tab-reset-btn`,className:`h-6 px-2 text-xs`,onClick:ne,children:`Reset`})]})]})})},Lt=E,Rt=({view:e,isActive:t,Icon:n,isRenaming:r,onStartRename:i,onCommitRename:a,onCancelRename:o,onRowClick:s,onDelete:c,onDuplicate:u,onSetDefault:d,onSetPinned:f,onConfigView:p})=>{let{attributes:m,listeners:h,setNodeRef:g,transform:v,transition:b,isDragging:S}=Xe({id:e.id}),w={transform:Ue.Transform.toString(v),transition:b,opacity:S?.5:1},T=(0,Q.useRef)(null),[E,D]=(0,Q.useState)(e.label),O=!!e.readonly;(0,Q.useEffect)(()=>{r&&(D(e.label),requestAnimationFrame(()=>{T.current?.focus(),T.current?.select()}))},[r,e.label]);let ee=(0,Q.useCallback)(()=>{let t=E.trim();t&&t!==e.label?a(e.id,t):o()},[E,e.id,e.label,a,o]);return(0,$.jsxs)(`li`,{ref:g,style:w,"data-testid":`manage-views-row-${e.id}`,className:V(`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`,S&&`shadow-md bg-background border-border z-10`),children:[(0,$.jsx)(`button`,{type:`button`,...m,...h,"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)(re,{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)(J,{ref:T,value:E,onChange:e=>D(e.target.value),onBlur:ee,onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),ee()):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(),O||i(e.id)},title:e.label,children:[(0,$.jsx)(`span`,{className:`truncate`,children:e.label}),O&&(0,$.jsx)(L,{"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`]})]})}),f&&!r&&!O&&(0,$.jsx)(k,{delayDuration:300,children:(0,$.jsxs)(y,{children:[(0,$.jsx)(xe,{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(),f(e.id,!e.isPinned)},className:V(`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)(R,{className:`h-4 w-4 fill-current`}):(0,$.jsx)(R,{className:`h-4 w-4`})})}),(0,$.jsx)(_,{side:`top`,children:e.isPinned?`Unpin view`:`Pin view`})]})}),d&&!r&&!e.isDefault&&!O&&(0,$.jsx)(k,{delayDuration:300,children:(0,$.jsxs)(y,{children:[(0,$.jsx)(xe,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":`Set as default`,"data-testid":`manage-views-default-${e.id}`,onClick:t=>{t.stopPropagation(),d(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&&(c||u||p||d)&&(0,$.jsxs)(le,{children:[(0,$.jsx)(Ce,{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)(te,{className:`h-4 w-4`})})}),(0,$.jsxs)(Te,{align:`end`,className:`min-w-[180px]`,children:[!O&&(0,$.jsxs)(K,{"data-testid":`manage-views-action-rename-${e.id}`,onClick:()=>i(e.id),children:[(0,$.jsx)(x,{className:`h-4 w-4 mr-2`}),` Rename`]}),u&&(0,$.jsxs)(K,{"data-testid":`manage-views-action-duplicate-${e.id}`,onClick:()=>u(e.id),children:[(0,$.jsx)(ze,{className:`h-4 w-4 mr-2`}),` Duplicate`]}),p&&!O&&(0,$.jsxs)(K,{"data-testid":`manage-views-action-config-${e.id}`,onClick:()=>p(e.id),children:[(0,$.jsx)(x,{className:`h-4 w-4 mr-2`}),` Edit configuration…`]}),d&&!e.isDefault&&!O&&(0,$.jsxs)(K,{"data-testid":`manage-views-action-default-${e.id}`,onClick:()=>d(e.id),children:[(0,$.jsx)(l,{className:`h-4 w-4 mr-2`}),` Set as default`]}),f&&!O&&(0,$.jsx)(K,{"data-testid":`manage-views-action-pin-${e.id}`,onClick:()=>f(e.id,!e.isPinned),children:e.isPinned?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(C,{className:`h-4 w-4 mr-2`}),` Unpin`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{className:`h-4 w-4 mr-2`}),` Pin`]})}),c&&!O&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ke,{}),(0,$.jsxs)(K,{"data-testid":`manage-views-action-delete-${e.id}`,onClick:()=>c(e.id),className:`text-destructive focus:text-destructive`,children:[(0,$.jsx)(N,{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:ee,className:`h-7 w-7 inline-flex items-center justify-center rounded hover:bg-accent text-emerald-600`,children:(0,$.jsx)(q,{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)(Ie,{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 x=(0,Q.useMemo)(()=>{let e=new Map(n.map(e=>[e.id,e]));return v.map(t=>e.get(t)).filter(Boolean)},[v,n]),S=(0,Q.useMemo)(()=>{if(!m.trim())return x;let e=m.toLowerCase();return x.filter(t=>t.label.toLowerCase().includes(e))},[x,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)},E=e=>{t(!1),requestAnimationFrame(()=>p?.(e))};return(0,$.jsx)(b,{open:e,onOpenChange:t,children:(0,$.jsxs)(T,{className:`sm:max-w-[560px] p-0 gap-0 overflow-hidden`,"data-testid":`manage-views-dialog`,children:[(0,$.jsxs)(Re,{className:`px-5 pt-5 pb-3`,children:[(0,$.jsx)(d,{className:`text-base`,children:`Manage views`}),(0,$.jsx)(O,{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)(je,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none`}),(0,$.jsx)(J,{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:S.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:S.map(e=>e.id),strategy:$e,children:(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:S.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?E:void 0},e.id))})})})}),(0,$.jsxs)(M,{className:`border-t bg-muted/30 px-5 py-3 flex sm:justify-between gap-2`,children:[f?(0,$.jsxs)(Z,{variant:`ghost`,size:`sm`,onClick:()=>{t(!1),requestAnimationFrame(()=>f())},"data-testid":`manage-views-add`,className:`text-sm`,children:[(0,$.jsx)(ae,{className:`h-4 w-4 mr-1.5`}),` Add new view`]}):(0,$.jsx)(`span`,{}),(0,$.jsx)(Z,{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};
|