import{b9 as p,Z as $,t as w,i as y,P as v}from"./index-BbBXKozi.js";const x=async({teamId:o})=>{const{status:l,data:e}=await p.get(`${$}/teams/v1/${o}/color.json`,{validateStatus:s=>s===403||s===200});return l===403?null:e.color},T=({teamId:o})=>w({queryKey:["teamColor",o],queryFn:o?()=>x({teamId:o}):void 0,staleTime:6e5,retry:!1,enabled:!!o}),A=async o=>new Promise(l=>{const e=new Image;e.setAttribute("crossOrigin","anonymous"),e.onload=function(){const s=document.createElement("canvas");s.width=e.width,s.height=e.height;const i=s.getContext("2d");if(!i)return;i.drawImage(e,0,0);const n=i.getImageData(0,0,e.width,e.height).data,c={};let u=0,d=0,b=0,g=0;for(let t=0;t<n.length;t+=4){const r=n[t],a=n[t+1],h=n[t+2],C=n[t+3],f=`${r},${a},${h}`;C!==0&&(u+=r,d+=a,b+=h,g++,c[f]?c[f]++:c[f]=1)}let m=Object.entries(c).sort((t,r)=>r[1]-t[1]);if(m=m.filter(([t])=>{const[r,a,h]=t.split(",").map(Number);return!(r<50&&a<50&&h<50)&&!(r>205&&a>205&&h>205)}),(m.length>0?m[0][1]:0)/g>=.02){const[t,r,a]=m[0][0].split(",").map(Number);l(`rgb(${t},${r},${a})`)}else{const t=Math.round(u/g),r=Math.round(d/g),a=Math.round(b/g);l(`rgb(${t},${r},${a})`)}},e.src=o.src}),{useState:E,useEffect:F}=await y("react"),S=(o,l)=>{const e=l?.opacity??1,[s,i]=E(null),{data:n,isError:c}=T({teamId:o});return F(()=>{if(o){if(n){i(n);return}if(c||n===null){const u=new Image;u.onload=()=>{A(u).then(d=>{const b=d.replace("rgb","rgba").replace(")",`,${e})`);i(b)})},u.src=v("teams",o,{format:"auto",width:"50"})}}},[o,n,c,e]),{teamColor:s}};export{S as u}; //# sourceMappingURL=index-wZR8asJ0.js.map