"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../chunks/date-formatter-B4EBSe9C.js");function H(r,e,n,t){const o=r instanceof Date?r.toISOString():String(r),u=(t==null?void 0:t.browserTimezone)||n,s=(t==null?void 0:t.isSqlCard)??!1;if(e!=null&&e.useRelativeTime)return l.formatRelativeTime(o,(e==null?void 0:e.sourceTimezone)||"auto");const i=e!=null&&e.useCustomFormat&&(e!=null&&e.customFormat)?e.customFormat:(e==null?void 0:e.format)||"MM/dd/yyyy";return l.formatDate(o,i,e!=null&&e.timezone&&(e==null?void 0:e.timezone)!=="auto"?e.timezone:s?u:n,(e==null?void 0:e.sourceTimezone)||"auto")}function h(r,e,n){if(r==null)return"";if(!n.useFormattedValues||!e)return String(r);switch(e.type){case"number":return typeof r=="number"?l.formatNumberWithColumnSettings(r,e.numberFormat,n.locale):String(r);case"date":return H(r,e.dateFormat,n.timezone,{browserTimezone:n.browserTimezone,isSqlCard:n.isSqlCard});case"progress":return typeof r=="number"?`${r}%`:String(r);case"badge":case"link":case"text":case"none":default:return String(r)}}function T(r,e){return e.visibleColumns.map(n=>{const t=r[n],o=e.columnSettings[n];return h(t,o,{useFormattedValues:e.useFormattedValues,timezone:e.timezone,locale:e.locale})})}function m(r,e=","){if(r==null)return"";const n=String(r);return n.includes(e)||n.includes('"')||n.includes(`
`)||n.includes("\r")?`"${n.replace(/"/g,'""')}"`:n}function f(r,e=","){return r.map(n=>m(n,e)).join(e)}function d(r,e={}){const{delimiter:n=",",lineEnding:t=`
`}=e;return r.map(o=>f(o,n)).join(t)}function N(r,e={}){if(r.length===0)return"";const{delimiter:n=",",lineEnding:t=`
`,includeHeaders:o=!0,columns:u}=e,s=u||Object.keys(r[0]),i=[];o&&i.push(s);for(const c of r){const p=s.map(b=>{const a=c[b];return a==null?"":String(a)});i.push(p)}return d(i,{delimiter:n,lineEnding:t})}function y(r,e){const n=[];e.includeHeaders&&n.push(f(e.visibleColumns,e.delimiter));for(const t of r){const o=T(t,e);n.push(o.map(u=>m(u,e.delimiter)).join(e.delimiter))}return n}function v(r,e,n=`
`){return y(r,e).join(n)}function j(r,e,n){return r==null?"":n.useFormattedValues?typeof r=="number"&&(e==null?void 0:e.type)==="number"?l.formatNumberWithColumnSettings(r,e.numberFormat,n.locale):typeof r=="number"?r.toLocaleString(n.locale):String(r):String(r)}function V(r,e,n){var o,u;const t=[];if(r.isSubtotal&&!r.isGrandTotal){const s=e.groupByColumns.findIndex(i=>i.alias===r.subtotalLevel);e.groupByColumns.forEach((i,c)=>{var p,b,a,S;if(c===s){const A=(b=(p=e.rowAggregates)==null?void 0:p.find(E=>E.groupLevel===r.subtotalLevel))==null?void 0:b.label,L=(S=(a=r.subtotalContext)==null?void 0:a.groupByValues)==null?void 0:S[i.alias];t.push(A??`Subtotal (${L??"Total"})`)}else c<s?t.push(String(r[i.alias]??"")):t.push("")})}else if(r.isGrandTotal){const s=(u=(o=e.rowAggregates)==null?void 0:o.find(i=>i.groupLevel==="ALL"))==null?void 0:u.label;t.push(s||"Grand Total"),e.groupByColumns.slice(1).forEach(()=>t.push(""))}else e.groupByColumns.forEach(s=>{t.push(String(r[s.alias]??""))});return e.pivotSchema.filter(s=>s.isMetricColumn).forEach(s=>{const i=r[s.alias],c=n.columnSettings[s.alias];t.push(j(i,c,n))}),t}function C(r){const e=r.groupByColumns.map(t=>t.label||t.name),n=r.pivotSchema.filter(t=>t.isMetricColumn).map(t=>t.displayLabel||t.metricLabel||t.metricName||t.alias);return[...e,...n]}function D(r,e,n){const t=[];if(n.includeHeaders){const o=C(e);t.push(f(o,n.delimiter))}for(const o of r){const u=V(o,e,n);t.push(u.map(s=>m(s,n.delimiter)).join(n.delimiter))}return t}function w(r,e,n){for(const t of r){if(t.level<n){e[t.level].push(t.name);for(let o=1;o<t.colspan;o++)e[t.level].push("")}t.children?w(t.children,e,n):t.columnKey&&e[n].push(t.name)}}function z(r){const e=r.pivotByColumns.length,n=r.groupByColumns.length,t=Array.from({length:e+1},()=>[]);for(let o=0;o<e;o++)t[o].push(...Array(n).fill(""));if(t[e].push(...r.groupByColumns.map(o=>o.label||o.name)),w(r.columnHeadersTree,t,e),r.showRowTotals){for(let o=0;o<e;o++)t[o].push("");t[e].push("Total")}return t}function P(r,e,n){if(r==null)return"";if(!n.useFormattedValues)return String(r);const t=n.columnSettings[e];return typeof r=="number"&&(t==null?void 0:t.type)==="number"?l.formatNumberWithColumnSettings(r,t.numberFormat,n.locale):typeof r=="number"?r.toLocaleString(n.locale):String(r)}function R(r,e,n){const t=[];r.fieldValues.forEach((u,s)=>{r.isSubtotal&&s===0?t.push(`${u} Total`):r.isSubtotal?t.push(""):t.push(String(u??""))});let o=0;return e.columnHeaders.forEach(u=>{var c;const s=(c=r.cells[u])==null?void 0:c.value,i=P(s,u,n);t.push(i),e.showRowTotals&&typeof s=="number"&&(o+=s)}),e.showRowTotals&&t.push(o.toLocaleString(n.locale)),t}function B(r,e,n){const t=[];if(n.includeHeaders){const o=z(e);for(const u of o)t.push(f(u,n.delimiter))}for(const o of r){const u=R(o,e,n);t.push(u.map(s=>m(s,n.delimiter)).join(n.delimiter))}return t}exports.formatCurrency=l.formatCurrency;exports.formatDate=l.formatDate;exports.formatDuration=l.formatDuration;exports.formatNumber=l.formatNumber;exports.formatNumberCustom=l.formatNumberCustom;exports.formatNumberWithColumnSettings=l.formatNumberWithColumnSettings;exports.formatPercent=l.formatPercent;exports.formatRelativeTime=l.formatRelativeTime;exports.formatScientific=l.formatScientific;exports.getTimezoneAbbreviation=l.getTimezoneAbbreviation;exports.getTimezoneName=l.getTimezoneName;exports.parseWithSourceTimezone=l.parseWithSourceTimezone;exports.resolveTimezone=l.resolveTimezone;exports.arrayToCSV=d;exports.arrayToCSVRow=f;exports.escapeCSVValue=m;exports.formatAggregateRow=V;exports.formatAggregateTableForCSV=D;exports.formatCellValue=h;exports.formatPivotDataRow=R;exports.formatPivotTableForCSV=B;exports.formatRowForExport=T;exports.formatTableForCSV=y;exports.generateAggregateHeaders=C;exports.generatePivotHeaders=z;exports.generateTableCSV=v;exports.objectsToCSV=N;
