import { searchInputPlaceholder } from "@/constant";
import { getRpc } from "ycc-api/src/service/Rpc";
import { getBlockDetail } from "ycc-api/src/service/blockDetail/index";
import Vue from "vue";
const Rpc = getRpc("/yccApi");
export default Vue.extend({
  data() {
    return {
      searchInputPlaceholder,
      searchValue: "",
      tabList: [
        { name: "交易记录", value: "1" },
        { name: "共识节点", value: "2" },
      ],
      focusedTab: "1",
      optionList: [
        { name: "交易记录", value: "1" },
        { name: "共识节点", value: "2" },
      ],
      selectedOption: "1",
      overview: {
        txCount: 0,
        blockTime: 0,
        hash: "",
        stateHash: "",
        txHash: "",
        lastBlockHeight: 0,
        nextBlockHeight: 0,
      },
      loadingOverview: false,
      loadingTable: false,
      Trades: [],
      txHashes: [],
      pages: {
        currentPage: 1,
        pageSize: 10,
        total: 0,
      },
    };
  },
  methods: {
    selectOption(v: string) {
      this.selectedOption = v;
    },
    clickSearch(v: string) {
      console.log(v, " show search value");
    },
    setSearchValue(v: string) {
      this.searchValue = v;
    },
    setFocusedTab(v: string) {
      this.focusedTab = v;
    },
    async init() {
      this.loadingOverview = true;
      this.loadingTable = true;
      const { overview, txs } =
        (await getBlockDetail("ycc", "/yccApi", {
          height: Number(this.$route.query.height),
        })) || {};
      if (overview) {
        this.overview = overview;
        this.pages.total = overview.txCount;
        this.Trades = txs;
      }
      this.loadingOverview = false;
      this.loadingTable = false;
    },
    // 交易组模块
    groupCellName(val: any) {
      switch (val.row.tradeG) {
        case 0:
          break;
        case 1:
          return "tx-middle";
        case 2:
          return "tx-start";
        case 3:
          return "tx-end";
        default:
          break;
      }
    },
    pageChange(page: number) {
      this.pages.currentPage = page;
    },
    sizeChange(size: number) {
      this.pages.pageSize = size;
    },
  },
  async mounted() {
    this.init();
  },
  watch: {
    "$route.query.height"(newV, oldV) {
      this.pages = {
        currentPage: 1,
        pageSize: 10,
        total: 0,
      };
      this.init();
    },
  },
});
