import{j as s,d as S,c as J,aV as z,y as _,dN as P,r as x}from"./index-CK33qGU_.js";import{S as L,r as Q,a as T,s as j}from"./transform-C0Urpblx.js";import{o as U,l as X,b as O}from"./linear-DWGfDWoG.js";import{m as q}from"./max-DBeXZoyG.js";const Y=t=>({bg:t,width:"10px",height:"10px",borderRadius:"50%"}),Z=({values:t,groupKey:i,keys:c,amount:l,colors:f,type:m,...y})=>s.jsxs(S,{...y,mt:"10px",flexDirection:"column",children:[s.jsx(S,{flexDirection:"row",children:c.map((r,n)=>s.jsxs(S,{mr:"12px",children:[s.jsx(J,{mr:"5px",mt:"3px",sx:Y(f[n])}),s.jsx(z,{children:t?t[r]:""}),s.jsx(_,{ml:"5px",children:t?t[r]!==1?r:r.slice(0,-1):r})]},`legend-${r}`))}),s.jsxs(S,{mt:"20px",justifyContent:"space-between",children:[s.jsx(z,{children:m==="executions"?"Number of execution":"Commits over time"}),m==="executions"?s.jsx(_,{mr:"5px",children:t?t[i]:`last 30 day${l===1?"":"s"}`}):s.jsx(_,{mr:"5px",children:t?t[i]:`${l} last commit${l===1?"":"s"}`})]},`legend-${i}`)]});function w(t){return typeof t=="string"?new L([document.querySelectorAll(t)],[document.documentElement]):new L([T(t)],Q)}const k=t=>+t,K=({values:t,groupKey:i,keys:c,colors:l,backgroundColor:f,onSelect:m,type:y})=>{const r=P(),n=x.useRef(null),d={top:10,right:20,bottom:10,left:30},C={commits:"commits",executions:"executions"},[$,D]=x.useState(0);x.useEffect(()=>{const h=t.length>30?5:10;y===C.executions?D(h):D(30)},[t,y,C.executions]);const[E,M]=x.useMemo(()=>{const h=l.map(N=>{const g=N.split(".")[1];return r.colors.labels[g]});return[U().range(h),f]},[l,r.colors,f]),W=4,H=0,o=x.useMemo(()=>q(t,h=>q(c,A=>h[A])),[t,c]),B=x.useMemo(()=>{switch(!0){case(o>1e3&&o<1e6):return`${(o/1e3).toFixed(1)}K`;case(o>=1e6&&o<1e9):return`${(o/1e6).toFixed(1)}M`;case o>=1e9:return`${(o/1e9).toFixed(1)}B`;default:return o}},[o]),I=x.useCallback((h,A)=>{const g=A.parentElement.offsetWidth,b=g/W,F=X().domain([H,o]).nice().rangeRound([b-d.bottom,d.top]),R=O().domain(h.map(e=>e[i])).rangeRound([d.left,g-d.right]).paddingInner(.5),V=O().domain(c).rangeRound([0,R.bandwidth()]).padding(.05),p=j(A).append("svg").attr("width",g).attr("height",b).style("background-color",M).on("mouseleave",e=>{m(null),w("rect").transition().duration(200).ease(k).style("opacity",1)});return p.append("rect").attr("width",g).attr("class","background").attr("height",b).attr("fill","#F5F5F5"),p.append("g").selectAll("g").data(h).join("g").attr("class","commit").attr("id",(e,a)=>a).attr("transform",e=>`translate(${(R((e[i]||0).toString())||0)+$},0)`).selectAll("rect").data(e=>c.map(a=>({key:a,value:e[a]}))).join("rect").attr("x",e=>V(e.key)).attr("y",e=>F(e.value)).attr("width",V.bandwidth()).attr("height",e=>F(0)-F(e.value||0)).attr("fill",e=>E(e.key)),p.selectAll("g").on("mouseover",e=>{const a=e==null?void 0:e.target,u=a==null?void 0:a.parentElement;u&&(m(parseInt(u.id,10)),w("rect").style("opacity",.3),j(u).selectChildren().style("opacity",1),j(u).selectChildren().style("fill","black"),w(".axis").style("opacity",1),w(".background").style("opacity",1))}),p.selectAll("g").on("mouseout",e=>{const a=e==null?void 0:e.target,u=a==null?void 0:a.parentElement;u&&(m(parseInt(u.id,10)),j(u).selectChildren().style("fill",r.colors.primary),w(".axis").style("opacity",1),w(".background").style("opacity",1))}),p.append("rect").attr("class","axis").attr("x",20).attr("y",b-10).attr("width",g).attr("height",1).style("fill",r.colors.grayShade2),p.append("rect").attr("x",44).attr("y",10).attr("class","axis").attr("width",1).attr("height",b-20).style("fill",r.colors.grayShade2),p.append("text").attr("x",34).attr("class","axis").attr("y",b-13).style("fill",r.colors.gray).attr("font-size","12px").attr("font-family","Inter").text(0),p.append("text").attr("x",42).attr("class","axis").attr("y",23).attr("text-anchor","end").style("fill",r.colors.gray).attr("font-size","12px").attr("font-family","Inter").text(B),p.node()},[B,i,c,d.bottom,d.left,d.right,d.top,o,r,m,M,E,$]);return x.useLayoutEffect(()=>{n!=null&&n.current&&(j(n==null?void 0:n.current).selectChildren().size()!==0&&j(n==null?void 0:n.current).selectChildren().remove(),I(t,n.current))},[t,i,c,f,I]),s.jsx("div",{ref:n})},G=["labels.green","labels.red","labels.orange"],v="grayShade3",tt={commits:"commits",executions:"executions"},ot=({values:t,groupKey:i,keys:c,type:l,...f})=>{const[m,y]=x.useState(null),r=x.useMemo(()=>{if(l===tt.executions){if(t.length>=30)return t;const d=new Array(30-t.length).fill(null).map((C,$)=>({date:$.toString(),"executions by day":null,deleted:null,modified:null}));return t.concat(d)}if(t.length>=10)return t;const n=new Array(10-t.length).fill(null).map((d,C)=>({date:C.toString(),added:null,deleted:null,modified:null}));return t.concat(n)},[t,l]);return s.jsxs(S,{...f,flexDirection:"column",width:"100%",children:[s.jsx(K,{values:r,keys:c,groupKey:i,backgroundColor:v,colors:G,onSelect:y,type:l}),s.jsx(Z,{keys:c,groupKey:i,amount:t.length,colors:G,values:m!==null?t[m]:null,type:l})]})};export{ot as C};
