import{C as m,A as q,L as B,B as L,P as W,b as A,d as F,D as T,e as P,f as Y,T as j,p as z,h as H,i as V,j as J,k as N,M as G,l as K,m as O,n as Q}from"./charts-3gEHPHRq.js";import{v as C,d as u,$ as U}from"./app-QjDgb7aF.js";import{u as X}from"./use-chart-tooltip-CwWaLiz4.js";import{b as Z,w as tt,c as et,E as at,j as v,p as M,u as st,g as rt,q as nt,z as _,a as ot,n as it}from"./vue-Cm77DuTi.js";const lt=(y,a)=>{const o=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(y),g=parseInt(o[1],16),p=parseInt(o[2],16),f=parseInt(o[3],16);return`rgba(${g}, ${p}, ${f}, ${a})`};function dt(){m.register(q,B,L,W,A,F,T,P,Y,j,z,H,V,J,N,G,K,O,Q),m.defaults.color=getComputedStyle(document.documentElement).getPropertyValue("--fg"),m.defaults.borderColor=C.state.darkMode?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.1)",m.defaults.animation=!1}const ct={key:1},gt=Z({__name:"MkHeatmap",props:{src:{}},setup(y){dt();const a=y,o=_(null),g=_(null),p=new Date;let f=null,w=ot(!0);const{handler:E}=X({position:"middle"}),S=(d,i,l)=>d.length===i.length&&i.length===l.length?d.map((r,h)=>r+i[h]+l[h]):null;async function k(){f&&f.destroy();const d=o.value.offsetWidth>700,i=o.value.offsetWidth<400,l=d?50:i?10:25,r=7*l,h=t=>{const e=p.getFullYear(),n=p.getMonth(),c=p.getDate();return new Date(e,n,c-t)},$=t=>t.map((e,n)=>{const c=h(n),x=`${c.getFullYear()}-${(c.getMonth()+1).toString().padStart(2,"0")}-${c.getDate().toString().padStart(2,"0")}`;return{x,y:c.getDay(),d:x,v:e}});let s;if(a.src==="active-users")s=(await u("charts/active-users",{limit:r,span:"day"})).readWrite;else if(a.src==="notes")s=(await u("charts/notes",{limit:r,span:"day"})).local.inc;else if(a.src==="ap-requests-inbox-received")s=(await u("charts/ap-request",{limit:r,span:"day"})).inboxReceived;else if(a.src==="ap-requests-deliver-succeeded")s=(await u("charts/ap-request",{limit:r,span:"day"})).deliverSucceeded;else if(a.src==="ap-requests-deliver-failed")s=(await u("charts/ap-request",{limit:r,span:"day"})).deliverFailed;else if(a.src==="my-notes"){const t=await u("charts/user/notes",{limit:r,span:"day",userId:U.id});s=S(t.diffs.normal,t.diffs.reply,t.diffs.renote)}w.value=!1,await it();const D=C.state.darkMode?"#ebbcba":"#d7827e",I=s.slice().sort((t,e)=>e-t).slice(0,3).reduce((t,e)=>t+e,0)/3,R=Math.max(0,Math.min(...s)-1),b=4;f=new m(g.value,{type:"matrix",data:{datasets:[{label:"Read & Write",data:$(s),pointRadius:0,borderWidth:0,borderJoinStyle:"round",borderRadius:3,backgroundColor(t){const e=t.dataset.data[t.dataIndex].v;let n=(e-R)/I;return e!==0&&(n=Math.max(n,.05)),lt(D,n)},fill:!0,width(t){const e=t.chart.chartArea??{};return(e.right-e.left)/l-b},height(t){const e=t.chart.chartArea??{};return(e.bottom-e.top)/7-b}}]},options:{aspectRatio:d?6:i?1.8:3.2,layout:{padding:{left:8,right:0,top:0,bottom:0}},scales:{x:{type:"time",offset:!0,position:"bottom",time:{unit:"week",round:"week",isoWeekday:0,displayFormats:{day:"M/d",month:"Y/M",week:"M/d"}},grid:{display:!1},ticks:{display:!0,maxRotation:0,autoSkipPadding:8}},y:{offset:!0,reverse:!0,position:"right",grid:{display:!1},ticks:{maxRotation:0,autoSkip:!0,padding:1,font:{size:9},callback:(t,e,n)=>["","Mon","","Wed","","Fri",""][t]}}},plugins:{legend:{display:!1},tooltip:{enabled:!1,callbacks:{title(t){return t[0].dataset.data[t[0].dataIndex].d},label(t){return["Active: "+t.dataset.data[t.dataIndex].v]}},animation:{duration:0},external:E}}}})}return tt(()=>a.src,()=>{w.value=!0,k()}),et(async()=>{k()}),(d,i)=>{const l=at("MkLoading");return v(),M("div",{ref_key:"rootEl",ref:o},[st(w)?(v(),rt(l,{key:0})):(v(),M("div",ct,[nt("canvas",{ref_key:"chartEl",ref:g},null,512)]))],512)}}});export{gt as _,lt as a,dt as i};
//# sourceMappingURL=MkHeatmap.vue_vue_type_script_setup_true_lang-DYR2-u-l.js.map
