import{Flex as G}from"@chakra-ui/layout";import{Box as Pe,Skeleton as g,Table as Te,TableContainer as Re,Tbody as Se,Td as x,Text as X,Th as Ie,Thead as Ae,Tr as R}from"@chakra-ui/react";import ze from"@emotion/styled";import{useCallback as ee,useEffect as Le,useState as k}from"react";import{Flex as N,Text as ce}from"@chakra-ui/react";import W from"@emotion/styled";import{useEffect as de,useState as _}from"react";var z=(e,t)=>e?e.length>t?e.substr(0,t-1)+"..."+e.substr(e.length-(t-1),e.length-1):e:"";var L=(e,t)=>{if(navigator.clipboard&&navigator.permissions)navigator.clipboard.writeText(e).then(t);else if(document.queryCommandSupported("copy")){let n=document.createElement("textarea");n.value=e,document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),t?.()}};import E,{jsNumberForAddress as te}from"react-jazzicon";import{default as oe}from"react-shadow/emotion";import{jsx as ne}from"react/jsx-runtime";var re=({address:e})=>{let t=Object.keys(oe).length?E.default:E;return ne(t,{diameter:"24",seed:te(e),svgStyles:{display:"block",verticalAlign:"middle"},paperStyles:{border:"1px solid #ffffff"}})},B=re;import"react";import{jsx as M,jsxs as ae}from"react/jsx-runtime";var ie=e=>ae("svg",{width:"32",height:"32",viewBox:"0 0 32 32",fill:"none",...e,children:[M("path",{d:"M21.5 13L14.1625 20L10.5 16.5",stroke:e.iconcolor??"#49536E",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),M("path",{d:"M16 28C22.6274 28 28 22.6274 28 16C28 9.37258 22.6274 4 16 4C9.37258 4 4 9.37258 4 16C4 22.6274 9.37258 28 16 28Z",stroke:e.iconcolor??"#49536E",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),D=ie;import"react";import{jsx as $,jsxs as le}from"react/jsx-runtime";var se=e=>le("svg",{width:"32",height:"32",viewBox:"0 0 32 32",fill:"none",...e,children:[$("path",{d:"M27 23V5H9",stroke:e.iconcolor??"#49536E",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),$("path",{d:"M23 9H5V27H23V9Z",stroke:e.iconcolor??"#49536E",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),F=se;import{jsx as w,jsxs as U}from"react/jsx-runtime";var pe=W(F)`
  cursor: pointer;
`,ue=W(D)`
  cursor: pointer;
`,fe=({address:e,domain:t})=>{let[n,i]=_(!1),[o,a]=_(e),C=()=>{i(!0),L(e),setTimeout(()=>{i(!1)},1e3)};return de(()=>{a(t||z(e,6))},[t,e]),U(N,{alignItems:"center",children:[w(B,{address:e}),U(N,{alignItems:"center",children:[w(ce,{mx:"1",children:o}),n?w(ue,{width:24,height:24,iconcolor:n&&"green"}):w(pe,{width:24,height:24,onClick:C})]})]})},V=fe;import{useContext as ge}from"react";import{createContext as he,useCallback as Rt,useEffect as St,useState as It}from"react";import ht from"axios";import{createContext as me,useMemo as it}from"react";import{jsx as lt}from"react/jsx-runtime";var at=me(void 0),q="production";var P=q==="development"?"https://qa-api-v2.bandit.network/sdk":"https://api-v2.bandit.network/sdk";import{jsx as yt,jsxs as bt}from"react/jsx-runtime";import{jsx as Et}from"react/jsx-runtime";var O=he(void 0);var J=()=>ge(O);import xe from"axios";var j=async(e,t,n,i)=>{try{return(await xe.get(`${P}/spaces/leaderboard?space_ids=${e}&offset=${t}&limit=${n}`,{headers:{"X-API-KEY":i}})).data}catch(o){throw o}};import"react";import{useMemo as Ce}from"react";var h="...",v=(e,t)=>{let n=t-e+1;return Array.from({length:n},(i,o)=>o+e)},Q=({totalCount:e,pageSize:t,siblingCount:n=1,currentPage:i})=>Ce(()=>{let a=Math.ceil(e/t);if(n+5>=a)return v(1,a);let c=Math.max(i-n,1),u=Math.min(i+n,a),f=c>2,d=u<a-2,p=1,s=a;if(!f&&d){let l=3+2*n;return[...v(1,l),h,a]}if(f&&!d){let l=3+2*n,b=v(a-l+1,a);return[p,h,...b]}if(f&&d){let l=v(c,u);return[p,h,...l,h,s]}},[e,t,n,i]);import Y from"@emotion/styled";var H=Y.ul`
  display: flex;
  align-items: center;
  justify-content: center;
  list-style-type: none;
`,T=Y.li`
  padding: 0 12px;
  height: 32px;
  min-width: 32px;
  text-align: center;
  margin: auto 4px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;

  ${({disabled:e})=>e&&`
    pointer-events: none;

    &:hover {
      background-color: transparent;
      cursor: default;
    }
  `}

  &.dots:hover {
    background-color: transparent;
    cursor: default;
  }
  &:hover {
    background-color: var(--bad-colors-muted);
    cursor: pointer;
  }

  &.selected {
    background-color: var(--bad-colors-muted);
  }

  &.disabled {
  }
`;import{ChevronLeftIcon as ye,ChevronRightIcon as be}from"@chakra-ui/icons";import{Box as K,Flex as we}from"@chakra-ui/react";import{jsx as m,jsxs as ke}from"react/jsx-runtime";var ve=e=>{let{onPageChange:t,totalCount:n,siblingCount:i=1,currentPage:o,pageSize:a,className:C}=e,c=Q({currentPage:o,totalCount:n,siblingCount:i,pageSize:a});if(o===0||c.length<2)return null;let u=()=>{t(o+1)},f=()=>{t(o-1)},d=c[c.length-1];return ke(we,{align:"center",children:[m(K,{children:m(ye,{boxSize:6,onClick:o===1?()=>{}:f,opacity:o===1?.1:1,cursor:o===1?"not-allowed":"pointer"})}),m(H,{children:c.map((p,s)=>p===h?m(T,{className:"dots",children:"\u2026"},s):m(T,{className:p===o?"selected":"",onClick:p===o?()=>{}:()=>t(p),children:p},s))}),m(K,{children:m(be,{boxSize:6,onClick:o===d?()=>{}:u,opacity:o===d?.1:1,cursor:o===d?"not-allowed":"pointer"})})]})},Z=ve;import{jsx as r,jsxs as y}from"react/jsx-runtime";var S=ze(Ie)`
  padding-left: 0;
  text-transform: unset;
  /* color: ${({theme:e})=>e.colors.text}; */
  font-size: 14px;
`,I=10,Ee=({selectedSpaceId:e})=>{let[t,n]=k(1),[i,o]=k(!1),[a,C]=k(0),[c,u]=k({}),{accessKey:f}=J(),d=ee(async()=>{try{o(!0);let{data:s,totalResults:l}=await j(e,(t-1)*I,I,f);u(b=>({...b,[t]:s.map(A=>({collectionId:A?.User?.username,...A}))})),C(l)}catch{}finally{o(!1)}},[e,t,u]);Le(()=>{e&&d()},[e,d]);let p=ee(s=>{o(!0),n(s)},[]);return y(G,{flexDir:"column",w:"full",children:[r(Re,{pt:"20px",children:y(Te,{size:"sm",children:[r(Ae,{width:"100",children:y(R,{pb:"2",children:[r(S,{color:"mutedForeground",borderColor:"input",children:"Ranking"}),r(S,{color:"mutedForeground",borderColor:"input",textAlign:"left",px:"0",children:"User"}),r(S,{color:"mutedForeground",borderColor:"input",textAlign:"right",px:"0",children:"Quest completed"})]})}),r(Se,{children:c?.[t]?c?.[t]?.map((s,l)=>y(R,{children:[r(x,{"data-title":"Raking",borderColor:"input",px:"0",w:"24",children:i?r(g,{borderRadius:"4",w:"6",h:"6",startColor:"muted",endColor:"input"}):r(Pe,{children:r(X,{children:s?.rank})})}),r(x,{"data-title":"User",borderColor:"input",px:"0",children:i?r(g,{borderRadius:"4",w:"32",h:"6",startColor:"muted",endColor:"input"}):r(V,{domain:s?.user?.domainName,address:s?.user?.username})}),r(x,{"data-title":"Quest completed",borderColor:"input",px:"0",children:i?r(g,{borderRadius:"4",ml:"auto",w:"8",h:"6",startColor:"muted",endColor:"input"}):r(X,{textAlign:"right",fontWeight:600,fontSize:14,children:s?.stats?.questCompleted})})]},l)):[1,2,3,4,5,6,7,8,9,10].map((s,l)=>y(R,{children:[r(x,{"data-title":"Raking",borderColor:"input",px:"0",w:"24",children:r(g,{borderRadius:"4",w:"6",h:"6",startColor:"muted",endColor:"input"})}),r(x,{"data-title":"User",borderColor:"input",px:"0",children:r(g,{borderRadius:"4",w:"32",h:"6",startColor:"muted",endColor:"input"})}),r(x,{"data-title":"Quest completed",borderColor:"input",px:"0",children:r(g,{borderRadius:"4",ml:"auto",w:"8",h:"6",startColor:"muted",endColor:"input"})})]},l))})]})}),r(G,{justify:"center",marginY:3,children:r(Z,{currentPage:t,totalCount:a,pageSize:I,onPageChange:p})})]})},lo=Ee;export{lo as default};
