import"react";import{Modal as qe,ModalBody as Je,ModalCloseButton as He,ModalContent as Qe,ModalHeader as Ye,ModalOverlay as Ke}from"@chakra-ui/react";import{createContext as se,useContext as le,useRef as et}from"react";import{jsx as ot}from"react/jsx-runtime";var ce=se(void 0);var L=()=>le(ce);import{Flex as ee}from"@chakra-ui/layout";import{Box as Be,Skeleton as g,Table as Ee,TableContainer as De,Tbody as $e,Td as x,Text as te,Th as Fe,Thead as Oe,Tr as I}from"@chakra-ui/react";import Ne from"@emotion/styled";import{useCallback as oe,useEffect as Ve,useState as S}from"react";import{Flex as V,Text as Ce}from"@chakra-ui/react";import W from"@emotion/styled";import{useEffect as ye,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 B=(e,t)=>{if(navigator.clipboard&&navigator.permissions)navigator.clipboard.writeText(e).then(t);else if(document.queryCommandSupported("copy")){let o=document.createElement("textarea");o.value=e,document.body.appendChild(o),o.select(),document.execCommand("copy"),document.body.removeChild(o),t?.()}};import E,{jsNumberForAddress as de}from"react-jazzicon";import{default as pe}from"react-shadow/emotion";import{jsx as fe}from"react/jsx-runtime";var ue=({address:e})=>{let t=Object.keys(pe).length?E.default:E;return fe(t,{diameter:"24",seed:de(e),svgStyles:{display:"block",verticalAlign:"middle"},paperStyles:{border:"1px solid #ffffff"}})},D=ue;import"react";import{jsx as $,jsxs as he}from"react/jsx-runtime";var me=e=>he("svg",{width:"32",height:"32",viewBox:"0 0 32 32",fill:"none",...e,children:[$("path",{d:"M21.5 13L14.1625 20L10.5 16.5",stroke:e.iconcolor??"#49536E",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),$("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"})]}),F=me;import"react";import{jsx as O,jsxs as xe}from"react/jsx-runtime";var ge=e=>xe("svg",{width:"32",height:"32",viewBox:"0 0 32 32",fill:"none",...e,children:[O("path",{d:"M27 23V5H9",stroke:e.iconcolor??"#49536E",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),O("path",{d:"M23 9H5V27H23V9Z",stroke:e.iconcolor??"#49536E",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),N=ge;import{jsx as v,jsxs as U}from"react/jsx-runtime";var be=W(N)`
  cursor: pointer;
`,we=W(F)`
  cursor: pointer;
`,ve=({address:e,domain:t})=>{let[o,a]=_(!1),[r,i]=_(e),C=()=>{a(!0),B(e),setTimeout(()=>{a(!1)},1e3)};return ye(()=>{i(t||z(e,6))},[t,e]),U(V,{alignItems:"center",children:[v(D,{address:e}),U(V,{alignItems:"center",children:[v(Ce,{mx:"1",children:r}),o?v(we,{width:24,height:24,iconcolor:o&&"green"}):v(be,{width:24,height:24,onClick:C})]})]})},q=ve;import{useContext as Pe}from"react";import{createContext as Se,useCallback as jt,useEffect as Gt,useState as Xt}from"react";import Vt from"axios";import{createContext as ke,useMemo as At}from"react";import{jsx as Bt}from"react/jsx-runtime";var Lt=ke(void 0),J="production";var P=J==="development"?"https://qa-api-v2.bandit.network/sdk":"https://api-v2.bandit.network/sdk";import{jsx as qt,jsxs as Jt}from"react/jsx-runtime";import{jsx as ro}from"react/jsx-runtime";var H=Se(void 0);var Q=()=>Pe(H);import Re from"axios";var Y=async(e,t,o,a)=>{try{return(await Re.get(`${P}/spaces/leaderboard?space_ids=${e}&offset=${t}&limit=${o}`,{headers:{"X-API-KEY":a}})).data}catch(r){throw r}};import"react";import{useMemo as Ie}from"react";var h="...",k=(e,t)=>{let o=t-e+1;return Array.from({length:o},(a,r)=>r+e)},K=({totalCount:e,pageSize:t,siblingCount:o=1,currentPage:a})=>Ie(()=>{let i=Math.ceil(e/t);if(o+5>=i)return k(1,i);let c=Math.max(a-o,1),u=Math.min(a+o,i),f=c>2,d=u<i-2,p=1,s=i;if(!f&&d){let l=3+2*o;return[...k(1,l),h,i]}if(f&&!d){let l=3+2*o,w=k(i-l+1,i);return[p,h,...w]}if(f&&d){let l=k(c,u);return[p,h,...l,h,s]}},[e,t,o,a]);import Z from"@emotion/styled";var j=Z.ul`
  display: flex;
  align-items: center;
  justify-content: center;
  list-style-type: none;
`,R=Z.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 Te,ChevronRightIcon as Me}from"@chakra-ui/icons";import{Box as G,Flex as Ae}from"@chakra-ui/react";import{jsx as m,jsxs as ze}from"react/jsx-runtime";var Le=e=>{let{onPageChange:t,totalCount:o,siblingCount:a=1,currentPage:r,pageSize:i,className:C}=e,c=K({currentPage:r,totalCount:o,siblingCount:a,pageSize:i});if(r===0||c.length<2)return null;let u=()=>{t(r+1)},f=()=>{t(r-1)},d=c[c.length-1];return ze(Ae,{align:"center",children:[m(G,{children:m(Te,{boxSize:6,onClick:r===1?()=>{}:f,opacity:r===1?.1:1,cursor:r===1?"not-allowed":"pointer"})}),m(j,{children:c.map((p,s)=>p===h?m(R,{className:"dots",children:"\u2026"},s):m(R,{className:p===r?"selected":"",onClick:p===r?()=>{}:()=>t(p),children:p},s))}),m(G,{children:m(Me,{boxSize:6,onClick:r===d?()=>{}:u,opacity:r===d?.1:1,cursor:r===d?"not-allowed":"pointer"})})]})},X=Le;import{jsx as n,jsxs as y}from"react/jsx-runtime";var T=Ne(Fe)`
  padding-left: 0;
  text-transform: unset;
  /* color: ${({theme:e})=>e.colors.text}; */
  font-size: 14px;
`,M=10,_e=({selectedSpaceId:e})=>{let[t,o]=S(1),[a,r]=S(!1),[i,C]=S(0),[c,u]=S({}),{accessKey:f}=Q(),d=oe(async()=>{try{r(!0);let{data:s,totalResults:l}=await Y(e,(t-1)*M,M,f);u(w=>({...w,[t]:s.map(A=>({collectionId:A?.User?.username,...A}))})),C(l)}catch{}finally{r(!1)}},[e,t,u]);Ve(()=>{e&&d()},[e,d]);let p=oe(s=>{r(!0),o(s)},[]);return y(ee,{flexDir:"column",w:"full",children:[n(De,{pt:"20px",children:y(Ee,{size:"sm",children:[n(Oe,{width:"100",children:y(I,{pb:"2",children:[n(T,{color:"mutedForeground",borderColor:"input",children:"Ranking"}),n(T,{color:"mutedForeground",borderColor:"input",textAlign:"left",px:"0",children:"User"}),n(T,{color:"mutedForeground",borderColor:"input",textAlign:"right",px:"0",children:"Quest completed"})]})}),n($e,{children:c?.[t]?c?.[t]?.map((s,l)=>y(I,{children:[n(x,{"data-title":"Raking",borderColor:"input",px:"0",w:"24",children:a?n(g,{borderRadius:"4",w:"6",h:"6",startColor:"muted",endColor:"input"}):n(Be,{children:n(te,{children:s?.rank})})}),n(x,{"data-title":"User",borderColor:"input",px:"0",children:a?n(g,{borderRadius:"4",w:"32",h:"6",startColor:"muted",endColor:"input"}):n(q,{domain:s?.user?.domainName,address:s?.user?.username})}),n(x,{"data-title":"Quest completed",borderColor:"input",px:"0",children:a?n(g,{borderRadius:"4",ml:"auto",w:"8",h:"6",startColor:"muted",endColor:"input"}):n(te,{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(I,{children:[n(x,{"data-title":"Raking",borderColor:"input",px:"0",w:"24",children:n(g,{borderRadius:"4",w:"6",h:"6",startColor:"muted",endColor:"input"})}),n(x,{"data-title":"User",borderColor:"input",px:"0",children:n(g,{borderRadius:"4",w:"32",h:"6",startColor:"muted",endColor:"input"})}),n(x,{"data-title":"Quest completed",borderColor:"input",px:"0",children:n(g,{borderRadius:"4",ml:"auto",w:"8",h:"6",startColor:"muted",endColor:"input"})})]},l))})]})}),n(ee,{justify:"center",marginY:3,children:n(X,{currentPage:t,totalCount:i,pageSize:M,onPageChange:p})})]})},re=_e;import{useDispatch as Ze,useSelector as je}from"react-redux";import{createSlice as Ue}from"@reduxjs/toolkit";var We={selectedCollectionId:null,showMint:!1,collectionViewOpen:!1,selectedSpaceId:!1},ne=Ue({name:"collection",initialState:We,reducers:{updateSelectedCollectionId(e,{payload:{id:t}}){e.selectedCollectionId=t},updateShowMint(e,{payload:{showMint:t}}){e.showMint=t},updateCollectionViewOpen(e,{payload:{collectionViewOpen:t}}){e.collectionViewOpen=t},updateSelectedSpaceId(e,{payload:{id:t}}){e.selectedSpaceId=t}}}),{updateSelectedCollectionId:Fo,updateShowMint:Oo,updateCollectionViewOpen:No,updateSelectedSpaceId:ae}=ne.actions,Vo=ne.reducer;import{jsx as b,jsxs as ie}from"react/jsx-runtime";var Ko=({isOpen:e=!0})=>{let{rootRef:t}=L(),o=je(i=>i.collection.selectedSpaceId),a=Ze(),r=()=>{a(ae({id:null}))};return o?ie(qe,{blockScrollOnMount:!1,portalProps:{containerRef:t},isOpen:!!o,onClose:r,isCentered:!0,size:"4xl",children:[b(Ke,{}),ie(Qe,{children:[b(Ye,{children:" Leaderboard"}),b(He,{}),b(Je,{children:b(re,{selectedSpaceId:o})})]})]}):null};export{Ko as Leaderboard};
