const l=e=>{if(e==null||e==="")return 0;const t=Number(e);return isNaN(t)?0:t},g=(e,t)=>{if(t===0&&e===0)return"stable";if(t===0)return"up";const n=(e-t)/t*100;return n>5?"up":n<-5?"down":"stable"},f=(e,t)=>t===0?e>0?100:0:(e-t)/t*100,d=(e,t)=>{const n=Math.ceil((t.getTime()-e.getTime())/864e5),c=new Date(e);c.setDate(c.getDate()-1);const r=new Date(c);return r.setDate(r.getDate()-n),{currentPeriod:{from:e,to:t},previousPeriod:{from:r,to:c}}},m=(e,t)=>{if(e.length===0)return;const n=Object.keys(e[0]),c=[n.join(","),...e.map(i=>n.map(a=>{const u=i[a],s=String(u??"");return s.includes(",")||s.includes('"')||s.includes(`
`)?`"${s.replace(/"/g,'""')}"`:s}).join(","))].join(`
`),r=new Blob(["\uFEFF"+c],{type:"text/csv;charset=utf-8;"}),o=document.createElement("a");o.href=URL.createObjectURL(r),o.download=`${t}-${new Date().toISOString().split("T")[0]}.csv`,o.click()},b=(e,t)=>{const n=e-t,c=f(e,t),r=g(e,t);return{currentTotal:e,previousTotal:t,change:n,changePercent:c,trend:r}};export{l as a,f as b,g as c,b as d,m as g,d as s};
