import{j as s,q as S,F as H,bl as N,c as _,eA as J,r as x}from"./index-C6OVXshM.js";import{S as L,a as P,r as Q,s as j}from"./transform-C2GfmqNu.js";import{o as U,l as X,b as O}from"./linear-C3cNlZpH.js";import{m as V}from"./max-DBeXZoyG.js";const Y=t=>({bg:t,width:"10px",height:"10px",borderRadius:"50%"}),Z=({values:t,groupKey:l,keys:i,amount:c,colors:f,type:m,...y})=>s.jsxs(S,{...y,mt:"10px",flexDirection:"column",children:[s.jsx(S,{flexDirection:"row",children:i.map((r,n)=>s.jsxs(S,{mr:"12px",children:[s.jsx(H,{mr:"5px",mt:"3px",sx:Y(f[n])}),s.jsx(N,{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(N,{children:m==="executions"?"Number of execution":"Commits over time"}),m==="executions"?s.jsx(_,{mr:"5px",children:t?t[l]:`last 30 day${c===1?"":"s"}`}):s.jsx(_,{mr:"5px",children:t?t[l]:`${c} last commit${c===1?"":"s"}`})]},`legend-${l}`)]});function w(t){return typeof t=="string"?new L([document.querySelectorAll(t)],[document.documentElement]):new L([P(t)],Q)}const k=t=>+t,K=({values:t,groupKey:l,keys:i,colors:c,backgroundColor:f,onSelect:m,type:y})=>{const r=J(),n=x.useRef(null),d={top:10,right:20,bottom:10,left:30},C={executions:"executions"},[$,M]=x.useState(0);x.useEffect(()=>{const h=t.length>30?5:10;y===C.executions?M(h):M(30)},[t,y,C.executions]);const[D,I]=x.useMemo(()=>{const h=c.map(R=>{const g=R.split(".")[1];return r.colors.labels[g]});return[U().range(h),f]},[c,r.colors,f]),T=4,W=0,o=x.useMemo(()=>V(t,h=>V(i,A=>h[A])),[t,i]),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]),E=x.useCallback((h,A)=>{const g=A.parentElement.offsetWidth,b=g/T,F=X().domain([W,o]).nice().rangeRound([b-d.bottom,d.top]),q=O().domain(h.map(e=>e[l])).rangeRound([d.left,g-d.right]).paddingInner(.5),z=O().domain(i).rangeRound([0,q.bandwidth()]).padding(.05),p=j(A).append("svg").attr("width",g).attr("height",b).style("background-color",I).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(${(q((e[l]||0).toString())||0)+$},0)`).selectAll("rect").data(e=>i.map(a=>({key:a,value:e[a]}))).join("rect").attr("x",e=>z(e.key)).attr("y",e=>F(e.value)).attr("width",z.bandwidth()).attr("height",e=>F(0)-F(e.value||0)).attr("fill",e=>D(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,l,i,d.bottom,d.left,d.right,d.top,o,r,m,I,D,$]);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(),E(t,n.current))},[t,l,i,f,E]),s.jsx("div",{ref:n})},G=["labels.green","labels.red","labels.orange"],v="grayShade3",tt={executions:"executions"},ot=({values:t,groupKey:l,keys:i,type:c,...f})=>{const[m,y]=x.useState(null),r=x.useMemo(()=>{if(c===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,c]);return s.jsxs(S,{...f,flexDirection:"column",width:"100%",children:[s.jsx(K,{values:r,keys:i,groupKey:l,backgroundColor:v,colors:G,onSelect:y,type:c}),s.jsx(Z,{keys:i,groupKey:l,amount:t.length,colors:G,values:m!==null?t[m]:null,type:c})]})};export{ot as C};
