<template>
  <div class="trading">
    <div class="content-left">
      <OverView :overviewValue="overviewValue" @clickOverviewChild="overviewChild" />
      <StatusRadio :statusValue="statusValue" @clickStatusChild="statusChild" />
    </div>
    <div class="content-right">
      <div class="content-right-content">
        <div class="pages-horizontal">
          <Card :nftData="nftList" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, toRaw } from "vue";
import OverView from "@/components/common/searchView/Overview.vue";
import StatusRadio from "@/components/common/searchView/statusRadio.vue";
import Card from "@/components/common/tradingCard.vue";
import { apiHistoryState, nftDetail } from "@/utils/marketplace"
import {walletStore} from "@/store/wallet";
import { parseTradeEvent } from "@/components/chain/utils"
const localWalletStore = walletStore()
const myAddress = ref(localWalletStore.address)
const nftList = ref([])
const overviewValue = ref()
const statusValue = ref('0')

const overviewChild = (val) => {
  overviewValue.value = val
}

const statusChild = (val) => {
  statusValue.value = val
  getHistoryList()
}

const getHistoryList = async () => {
  const data = {
    type: statusValue.value,
    page_size: '20',
    cursor: '',
  }
  if(myAddress.value) {
    let res = await apiHistoryState(myAddress.value,data)
    for (let sub of res.rows) {
      if (sub.event?.data) {
        const _data = parseTradeEvent(sub.event)
        sub.event.icon = _data.icon
        sub.event.usd = _data.usd
        sub.event.currencyName = _data.currencyName
        sub.event.amount = _data.amount
      }
    }
    nftList.value = res.rows
  }
}

onMounted(() => {
  getHistoryList()
})

</script>

<style lang="scss" scoped>
.trading {
  width: 100%;
  display: flex;
  justify-content: space-between;
  .content-left {
    width: 300px;
    padding: 0 35px;
  }
  .content-right {
    width: calc(100% - 300px);
    padding-right: 40px;
    // background: #fff;
    .content-right-header {
      width: calc(100% - 10px);
      height: 60px;
      display: flex;
      align-items: center;
      border-bottom: 2px solid #3a3b57;
      .bg-cor {
        width: 15px;
        height: 15px;
        background: #18ff00;
        margin-left: 10px;
        border-radius: 50%;
      }
      .results-total {
        display: flex;
        align-items: center;
        margin-left: 15px;
        font-size: 14px;
        color: #b3b5da;
      }
      .search-list {
        display: flex;
        align-items: center;
        color: #fff;
        li {
          margin-left: 10px;
          background: #2d2738;
          padding: 5px 10px;
          border-radius: 10px;
          font-size: 12px;
          cursor: pointer;
        }
        .clear-all {
          background: #5a4a6d;
        }
      }
    }
    .content-right-content {
      margin-top: 30px;
      .pages-horizontal {
        display: flex;
        // justify-content: space-between;
        flex-wrap: wrap;
        clear: both;
        li {
          width: calc(25% - 10px);
          // height: 360px;
          margin-right: 10px;
          margin-bottom: 10px;
          cursor: pointer;
          &:nth-child(4n) {
            margin-right: 0;
          }
        }
      }
      .pages-vertical {
        color: #fff;
      }
    }
  }
}
</style>