<template>
  <div class="mx-auto md:w-bodySet blockChain min-w-1200 relative">
    <ChainCard :msgList="msgList" class="chainCard"></ChainCard>
    <ChainTitle />
    <chain-search
      style="width: 600px;"
      placeholder="请输入地址/交易哈希/区块高度/代币"
      :value="value"
      :setValue="setValue"
      :clickSearch="clickSearch"
    />
    <div class="rect-block"></div>
    <ChainOverview />
    <div class="flex justify-between mt-14">
      <latest-block :latestBlocks="latestBlocks"></latest-block>
      <latest-tx :latestTxs="latestTxs"></latest-tx>
    </div>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'
import ChainCard from '@/components/pc/BlockChainBrowser/ChainOverview/ChainCard.vue'
import ChainTitle from '@/components/pc/BlockChainBrowser/ChainTitle.vue'
import ChainSearch from '@/components/pc/BlockChainBrowser/ChainSearch.vue'
import ChainOverview from '@/components/pc/BlockChainBrowser/ChainOverview/index.vue'
import LatestBlock from '@/components/pc/BlockChainBrowser/LatestBlock/index.vue'
import LatestTx from '@/components/pc/BlockChainBrowser/LatestTx/index.vue'
import { getLatestBlock } from 'ycc-api/dist/cmjs/service/home/index'
import { iBlockMsg } from 'ycc-api/dist/cmjs/service/home/types'

export default Vue.extend({
  components: {
    ChainCard,
    ChainTitle,
    ChainSearch,
    ChainOverview,
    LatestBlock,
    LatestTx,
  },
  data() {
    return {
      msgList: [
        {
          icon: require('@/assets/images/blockChainBrowser/home/latestBlock.png'),
          title: '最新区块',
          number: 102938,
        },
        {
          icon: require('@/assets/images/blockChainBrowser/home/nodeNumber.png'),
          title: '节点数量',
          number: 102938,
        },
        {
          icon: require('@/assets/images/blockChainBrowser/home/circulateNumber.png'),
          title: '流通量',
          number: 102938,
        },
        {
          icon: require('@/assets/images/blockChainBrowser/home/pledgeQuantity.png'),
          title: '质押数量',
          number: 102938,
        },
      ],
      value: '',
      latestBlocks: [] as iBlockMsg[],
      latestTxs: [
        {
          hash: 'lkajskfdkasdf',
          from: 'laksjdflas',
          to: 'lakdjflkasdf',
          time_block: 1643167975993,
          amount: 30000000,
        },
        {
          hash: 'lkajskfdkasdf',
          from: 'laksjdflas',
          to: 'lakdjflkasdf',
          time_block: 1643167975993,
          amount: 30000000,
        },
        {
          hash: 'lkajskfdkasdf',
          from: 'laksjdflas',
          to: 'lakdjflkasdf',
          time_block: 1643167975993,
          amount: 30000000,
        },
      ],
    }
  },
  mounted() {
    this.latestBlocks = (' '
      .repeat(6)
      .split(' ')
      .map((i) => ({})) as unknown) as iBlockMsg[]
    getLatestBlock('ycc', '/yccApi').then((ret) => {
      this.latestBlocks = ret || []
    })
  },
  methods: {
    setValue(v: string) {
      this.value = v
    },
    clickSearch(value: string) {
      console.log(value, 'show value')
    },
  },
})
</script>

<style scoped>
.blockChain {
  margin-top: 70px;
}
.chainCard {
  position: relative;
  z-index: 1;
}
.rect-block {
  /* position: absolute;
  z-index: 60;
  top: -64px;
  left: 197px;
  width: 600px;
  height: 840px;
  background: #2545cb; */
}
</style>
