function e(e){return e.toISOString().split(`T`)[0]}function t(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function n(e){let t=new Date(e);return t.setHours(0,0,0,0),t}function r(e){let t=e.getDay(),n=t===0?-6:1-t,r=new Date(e);return r.setDate(e.getDate()+n),r.setHours(0,0,0,0),r}function i(e,t){return Math.round((t.getTime()-e.getTime())/(86400*1e3))}function a(e,t){let n=new Date,r=n.toISOString().slice(0,13),i=24;if(e.length>0){let t=e[0].hour,n=e[e.length-1].hour;(new Date(n+`:00:00`).getTime()-new Date(t+`:00:00`).getTime())/(3600*1e3)+1>24&&(i=48)}let a=new Map;for(let t of e)a.set(t.hour,t);let o=[];for(let e=i-1;e>=0;e--){let i=new Date(n.getTime()-e*3600*1e3),s=i.toISOString().slice(0,13),c=a.get(s),l=c?.value??0,u=!!c,d=i.getHours(),f=i.toISOString().split(`T`)[0]===n.toISOString().split(`T`)[0]?`${String(d).padStart(2,`0`)}:00`:`${i.toLocaleDateString(void 0,{month:`short`,day:`numeric`})} ${String(d).padStart(2,`0`)}:00`;o.push({key:s,label:f,value:l,hasData:u,highlight:s===r,tooltip:c?.tooltip??`${s}: ${t(0)}`})}return o}function o(r,a){let o=n(new Date),c=e(o);if(r.length===0)return s(t(o,-6),o,new Map,c,a);let l=new Map;for(let e of r)l.set(e.date,e);let u=r.map(e=>new Date(e.date+`T00:00:00`)).sort((e,t)=>e.getTime()-t.getTime()),d=u[0],f=u[u.length-1],p=i(d,f)+1,m;m=p<=7?7:p<=30?30:90;let h=o;return s(t(h,-(m-1)),h,l,c,a)}function s(t,n,r,i,a){let o=[],s=new Date(t);for(;s<=n;){let t=e(s),n=r.get(t),c=n?.value??0,l=!!n,u=new Date(s).toLocaleDateString(void 0,{month:`short`,day:`numeric`});o.push({key:t,label:u,value:c,hasData:l,highlight:t===i,tooltip:n?.tooltip??`${t}: ${a(0)}`}),s.setDate(s.getDate()+1)}return o}function c(a,o){let s=n(new Date);e(s);let c=r(s);if(a.length===0)return l(t(c,-49),c,new Map,c,o);let u=new Map;for(let e of a)u.set(e.weekStart,e);let d=a.map(e=>new Date(e.weekStart+`T00:00:00`)).sort((e,t)=>e.getTime()-t.getTime()),f=d[0],p=d[d.length-1],m=Math.round(i(f,p)/7)+1,h;h=m<=4?8:m<=12?16:26;let g=r(new Date(f.getTime()+(p.getTime()-f.getTime())/2)),_=t(g,-7*Math.floor(h/2)),v=t(g,7*(Math.ceil(h/2)-1));return v>c&&(v=c,_=t(v,-7*(h-1))),l(_,v,u,c,o)}function l(t,n,r,i,a){let o=[],s=new Date(t),c=e(i);for(;s<=n;){let t=e(s),n=r.get(t),i=n?.value??0,l=!!n,u=new Date(s).toLocaleDateString(void 0,{month:`short`,day:`numeric`});o.push({key:t,label:u,value:i,hasData:l,highlight:t===c,tooltip:n?.tooltip??`Week of ${t}: ${a(0)}`}),s.setDate(s.getDate()+7)}return o}function u(e,t){let n=new Date,r=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}`;if(e.length===0)return f(d(n,-5),n,new Map,r,t);let i=new Map;for(let t of e)i.set(t.month,t);let a=e.map(e=>{let[t,n]=e.month.split(`-`);return new Date(parseInt(t),parseInt(n)-1,1)}).sort((e,t)=>e.getTime()-t.getTime()),o=a[0],s=a[a.length-1],c=(s.getFullYear()-o.getFullYear())*12+(s.getMonth()-o.getMonth())+1,l;l=c<=3?6:c<=6?12:18;let u=Math.floor((s.getMonth()+s.getFullYear()*12+o.getMonth()+o.getFullYear()*12)/2),p=Math.floor(u/12),m=u%12,h=new Date(p,m,1),g=d(h,-Math.floor(l/2)),_=d(h,Math.ceil(l/2)-1),v=new Date(n.getFullYear(),n.getMonth(),1);return _>v&&(_=v,g=d(_,-(l-1))),f(g,_,i,r,t)}function d(e,t){let n=new Date(e);return n.setMonth(n.getMonth()+t),n.setDate(1),n}function f(e,t,n,r,i){let a=[],o=new Date(e);o.setDate(1);let s=t.getFullYear()*12+t.getMonth();for(;o.getFullYear()*12+o.getMonth()<=s;){let e=`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,`0`)}`,t=n.get(e),s=t?.value??0,c=!!t,l=o.toLocaleDateString(void 0,{month:`short`,year:`2-digit`});a.push({key:e,label:l,value:s,hasData:c,highlight:e===r,tooltip:t?.tooltip??`${e}: ${i(0)}`}),o.setMonth(o.getMonth()+1)}return a}function p(e,t,n){return t===`daily`?o(e.map(e=>({date:e.sortKey,value:e.value,tooltip:e.tooltip})),n):t===`weekly`?c(e.map(e=>({weekStart:e.sortKey.replace(/^W/,``),value:e.value,tooltip:e.tooltip})),n):u(e.map(e=>({month:e.sortKey,value:e.value,tooltip:e.tooltip})),n)}export{c as a,u as i,o as n,a as r,p as t};