<template>
  <div class="trading">
    <div class="content-left">
      <OverView :overviewValue="marketplaceList.overview" @clickOverviewChild="overviewChild" />
      <Status :statusValue="marketplaceList.status" @clickStatusChild="statusChild" />
    </div>
    <div class="content-right">
      <!-- <div class="content-right-header">
        <div class="bg-cor"></div>
        <div class="results-total">{{ nftList.length }} Results</div>
        <div class="search-list">{{ marketplaceList.overview }}
          <li v-if="marketplaceList.overview">
            <span>Overview:</span>
            <span>{{ marketplaceList.overview }}</span>
            <span v-if="marketplaceList.overview" @click="clearOverviewAll">×</span>
          </li>
          <li
            v-if="marketplaceList.status.length != undefined && marketplaceList.status.length > 0"
          >
            <span
              v-if="marketplaceList.status.length != undefined && marketplaceList.status.length > 0"
            >Hero:</span>
            <span v-for="(item,index) in marketplaceList.status" :key="item">
              <span>{{ item }}</span>
              <span v-if="marketplaceList.status.length != index+1">/</span>
            </span>
            <span
              v-if="marketplaceList.status != undefined && marketplaceList.status.length > 0"
              @click="clearStatusAll"
            >×</span>
          </li>
          <li v-if="filterList !== undefined && filterList.length > 0" class="clear-all" @click="clearAll">Clear All</li>
        </div>
      </div> -->
      <div class="content-right-content">
        <div class="pages-horizontal">
          <!-- <li v-for="(item, index) in nftList" :key="index"> -->
            <!-- <Card v-if="nftList != undefined || nftList.length > 0" :nftData="nftList"  /> -->
          <!-- </li> -->
          <Card :nftData="nftList" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import OverView from "@/components/common/searchView/Overview.vue";
import Status from "@/components/common/searchView/status.vue";
import Card from "@/components/common/tradingCard.vue";
import { apiHistoryState, nftDetail } from "@/utils/marketplace"
import { useTradingStore } from "@/store/trading"
import {walletStore} from "@/store/wallet";
const localWalletStore = walletStore()
const marketplaceList = useTradingStore()
const myAddress = ref(localWalletStore.address)

const nftList = ref([])
const filterList = ref()

const clearOverviewAll = () => {
  marketplaceList.overview = ''
}
const overviewChild = (val) => {
  marketplaceList.overview = val
}

const clearStatusAll = () => {
  marketplaceList.status = ''
}
const statusChild = (val) => {
  marketplaceList.status = val
}

const clearAll = () => {
  marketplaceList.overview = ''
  marketplaceList.status = ''
}

// 获取nft信息
const getNftData = async () => {
  if(myAddress.value) {
    let nftDetailData = {}
    const { errcode, errmsg, data } = await nftDetail('0x0cf08c8661f87cbf823128d37ba75814cbcdf08b','6240603010010208')
    if(errcode == 0) {
      nftDetailData = data
    } else {
      alert(errmsg)
    }
    // return nftDetailData
    console.log('nftDetailData',nftDetailData)
  }
}

const getHistoryList = async () => {
  console.log(myAddress.value)
  const data = {
    type: '0',
    page_size: '20',
    cursor: '',
  }
  if(myAddress.value) {
    let res = await apiHistoryState(myAddress.value,data)
    nftList.value = res.rows
    console.log(res)
  }
}

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

</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>