<template>
  <div>
    <div class="top-header" style="">
      <div class="viewLogo">
        <a href="/">
          <img
            class="logo"
            alt="logo"
            src="@/assets/main/p1/icon_logo_t.png" />
        </a>
      </div>
      <div class="header-menu">
        <a class="menu-item" href="/official">
          <div class="item" :class="{'active': currentTab==='official'}">
            Official Shop
            <div class="active-bottom" v-if="currentTab==='presell'"></div>
          </div
          >
        </a>
        <a class="menu-item" href="/market">
          <div class="item " :class="{'active': currentTab==='market'}">
            Marketplace
            <div class="active-bottom" v-if="currentTab==='market'"></div>
          </div
          >
        </a>
      </div>

      <div class="rightContainer">
        <div class="contact">
          <span class="span">Contact Us</span>
        </div>
        <button v-if="!walletCollected" @click="collectToWallet" class="general-btn connectButton">
          <span>Connect Wallet</span>
        </button>
        <img
          draggable="false"
          v-if="walletCollected"
          class="avatar"
          ref="avatar"
          src="https://assets.thetanarena.com/cosmetic/avatar/3.png"
          alt="avatar"
          @click="infoPanelShow=!infoPanelShow"
        >
      </div>
    </div>
    <top-user-info
      v-show="infoPanelShow && walletCollected"
      v-on:close-self="onClose"
    ></top-user-info>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import TopUserInfo from '@/components/market/TopUserInfo.vue'
import { BlockChain } from '@/utils/blockchain'
import { AppModule } from '@/store/modules/app'

declare module 'vue/types/vue' {
  interface Vue {
    currentTab?: string
  }
}

@Component({
  name: 'Navbar',
  components: { TopUserInfo },
  props: ['currentTab']
})
export default class extends Vue {
  infoPanelShow = false
  bc = new BlockChain();

  get walletCollected() {
    return AppModule.walletConnected
  }

  async collectToWallet() {
    return this.bc.connect()
  }

  async disconnectWallet() {
    return this.bc.disconnect()
  }

  onClose() {
    this.infoPanelShow = false
  }
}
</script>

<style lang="scss" scoped>
.top-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  background: rgba(20, 16, 59, 0.8);
  box-shadow: 0 1em 1.5em rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(5em);
  z-index: 8;
  height: 5.25em;
  --tooltip-text-color: white;
  --tooltip-margin: 1.875em;
  --tooltip-arrow-size: 0.75em;
}

.top-header .header-menu {
  display: flex;
  height: 100%;
  position: relative;
  z-index: 1;
  flex: auto;
}

.top-header .header-menu .menu-item {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.top-header .header-menu .menu-item .item {
  font-weight: bold;
  font-size: 1.125em;
  color: #fff;
  height: 100%;
  align-items: center;
  justify-content: center;
  display: flex;
  width: 13.438em;
  box-sizing: border-box;
}

.top-header .header-menu .menu-item .active {
  background: linear-gradient(
      90deg,
      #362b6d 73.48%,
      rgba(54, 43, 109, 0) 161.57%
  );
  margin-left: -2em;
  clip-path: polygon(15% 0, 100% 0, 85% 100%, 0 100%);
}

.active-bottom {
  border-bottom: 0.3125em #563cb8 solid;
  width: 120%;
  position: absolute;
  bottom: 0;
}

.top-header .viewLogo {
  display: flex;
  justify-content: center;
  width: 20vw;
}

.logo {
  height: 3rem;
}

.rightContainer {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  padding-right: 2.5em;
  z-index: 1;
}

.rightContainer .contact {
  margin-right: 1.875em;
}

.rightContainer .contact .span {
  cursor: pointer;
  font-size: 1.125em;
  color: #a796e1;
}

.connectButton {
  border-radius: 0.25em;
  background: radial-gradient(
      123.41% 70.85% at 47.63% 49.99%,
      #558ada 0%,
      #1b68db 100%
  ) !important;
  cursor: pointer;
  height: 2.75em !important;
  padding: 0 1.688em;
  font-size: 1.125em !important;
}

.connectButton span {
  text-decoration: none;

  font-weight: bold;
  font-size: 1.125em;
  line-height: 1.33;
  color: white;
}

.avatar {
  width: 3.125em;
  height: 3.125em;
  border-radius: 1.563em;
  cursor: pointer;
}

@media (max-width: 767px) {

}
</style>
