import{L as e,_ as t,a as n,b as r,c as i,f as a,i as o,nt as s,rt as c,s as l,t as u,v as d,x as f}from"./runtime-core.esm-bundler.BCIfMFaf.js";import{l as p}from"./colord.BTI3XySM.js";import{d as m,f as h}from"./index.ChkmaRqp.js";var g=[`viewBox`],_=[`transform`],v=[`x`,`y`],y=[`transform`],b={class:`heatmap-day-label`,x:0,y:20},x={class:`heatmap-day-label`,x:0,y:44},S={class:`heatmap-day-label`,x:0,y:69},C=[`transform`],w=[`transform`],T=[`transform`,`aria-label`,`data-tooltip`,`onClick`],E={class:`heatmap-footer`},D={class:`heatmap-legend`},O=[`x`],k=10,A=2,j=7,M=a({__name:`ActivityHeatmap`,props:{values:{},locale:{}},setup(a){let M=a,N=[`var(--color-secondary-alpha-60)`,`var(--color-primary-light-4)`,`var(--color-primary-light-2)`,`var(--color-primary)`,`var(--color-primary-dark-2)`,`var(--color-primary-dark-4)`],P=Math.ceil(k*2.5),F=new Date;function I(e){return`${e.getFullYear()}${String(e.getMonth()).padStart(2,`0`)}${String(e.getDate()).padStart(2,`0`)}`}function L(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}let R=o(()=>{let e=L(F,-365),t=e.getDay(),n=j-1-F.getDay(),r=(366+t+n)/j,i=M.values.length?Math.max(...M.values.map(e=>e.count)):0,a=i>0?Math.ceil(i/5*4):1,o=new Map;for(let{date:e,count:t}of M.values){let n=t>=a?4:Math.max(1,Math.ceil(t/a*3));o.set(I(e),{count:t,colorIndex:n})}let{on:s}=M.locale.heatMapLocale,{noDataText:c,tooltipUnit:l}=M.locale,u=p(),d=L(e,-t),f=new Date(d.getFullYear(),d.getMonth(),d.getDate()),m=[];for(let e=0;e<r;e++){let e=[];for(let t=0;t<j;t++){let t=o.get(I(f)),n=f.toLocaleDateString(u,{year:`numeric`,month:`short`,day:`numeric`}),r=t?`${t.count} ${l}`:c;e.push({date:new Date(f),colorIndex:t?t.colorIndex:0,ariaLabel:`${r} ${s} ${n}`,tooltip:`<b>${r}</b> ${s} ${n}`}),f.setDate(f.getDate()+1)}m.push(e)}let h=[];for(let e=1;e<m.length;e++){let t=m[e-1][0].date,n=m[e][0].date;t.getMonth()!==n.getMonth()&&h.push({monthIdx:n.getMonth(),weekIdx:e})}return{calendar:m,monthLabels:h,width:P+12*r+A,height:99}}),z=`12 0 ${k*(N.length+2)} ${k}`,B=new Map,V=null;d(()=>{V=m([],{overrides:[],moveTransition:`transform 0.1s ease-out`,allowHTML:!0,theme:`tooltip`,role:`tooltip`,placement:`top`})}),t(()=>{V?.destroy();for(let e of B.values())e.destroy();B.clear()});function H(e){let t=e.target;!V||B.has(t)||!t.classList.contains(`heatmap-day`)||(B.set(t,h(t,{content:t.getAttribute(`data-tooltip`)})),V.setInstances([...B.values()]))}function U(e){let t=new URLSearchParams(document.location.search),n=t.get(`date`),r=new Date(e.getTime()-e.getTimezoneOffset()*6e4).toISOString().substring(0,10);n&&n===r?t.delete(`date`):t.set(`date`,r),t.delete(`page`);let i=t.toString();window.location.search=i.length?`?${i}`:``}return(t,o)=>(r(),i(`div`,null,[(r(),i(`svg`,{class:`heatmap-svg`,viewBox:`0 0 ${R.value.width} ${R.value.height}`},[n(`g`,{class:`heatmap-month-labels`,transform:`translate(${e(P)}, 0)`},[(r(!0),i(u,null,f(R.value.monthLabels,e=>(r(),i(`text`,{key:e.weekIdx,class:`heatmap-month-label`,x:12*e.weekIdx,y:12-A},c(a.locale.heatMapLocale.months[e.monthIdx]),9,v))),128))],8,_),n(`g`,{class:`heatmap-day-labels`,transform:`translate(0, 15)`},[n(`text`,b,c(a.locale.heatMapLocale.days[1]),1),n(`text`,x,c(a.locale.heatMapLocale.days[3]),1),n(`text`,S,c(a.locale.heatMapLocale.days[5]),1)],8,y),n(`g`,{class:`heatmap-grid`,transform:`translate(${e(P)}, 15)`,onMouseover:H},[(r(!0),i(u,null,f(R.value.calendar,(t,n)=>(r(),i(`g`,{key:n,class:`heatmap-week`,transform:`translate(${n*12}, 0)`},[(r(!0),i(u,null,f(t,(t,n)=>(r(),i(u,{key:n},[t.date<e(F)?(r(),i(`rect`,{key:0,class:`heatmap-day`,transform:`translate(0, ${n*12})`,width:k,height:k,style:s({fill:N[t.colorIndex]}),"aria-label":t.ariaLabel,"data-tooltip":t.tooltip,onClick:e=>U(t.date)},null,12,T)):l(``,!0)],64))),128))],8,w))),128))],40,C)],8,g)),n(`div`,E,[n(`div`,null,c(a.locale.textTotalContributions),1),n(`div`,D,[n(`div`,null,c(a.locale.heatMapLocale.less),1),(r(),i(`svg`,{class:`heatmap-legend-svg`,viewBox:z,height:k},[(r(),i(u,null,f(N,(e,t)=>n(`rect`,{key:t,width:k,height:k,x:(t+1)*12,style:s({fill:e})},null,12,O)),64))])),n(`div`,null,c(a.locale.heatMapLocale.more),1)])])]))}});export{M as default};
//# sourceMappingURL=ActivityHeatmap.CL2pe9k5.js.map