<template>
  <div class="field-list_SecurityCheck">
    <div class="header-box">{{ $t('securityCheck.securityCheck') }}</div>
    <div class="field-list-status" v-show="ChainObj.honeypot.request">
      <div class="field-header">
        <div class="label">
          {{ $t('securityCheck.honeypot') }}：
          <a :href="honeypotLink" target="_blank">
            <Share></Share>
          </a>
        </div>
      </div>
      <div class="field-row">
        <div class="label">{{ $t('securityCheck.checkResult') }}：</div>
        <div
          class="value"
          v-show="
            honeypotData.list.IsHoneypot !== '' &&
            honeypotData.list.IsHoneypot !== undefined
          "
        >
          {{
            honeypotData.list.IsHoneypot
              ? $t('securityCheck.yes')
              : $t('securityCheck.no')
          }}
        </div>
      </div>
      <div class="field-row">
        <div class="label">{{ $t('securityCheck.gasUsedForBuying') }}：</div>
        <div class="value">{{ honeypotData.list.BuyGas ?? '-' }}</div>
      </div>
      <div class="field-row">
        <div class="label">{{ $t('securityCheck.gasUsedForSelling') }}：</div>
        <div class="value">{{ honeypotData.list.SellGas ?? '-' }}</div>
      </div>
      <div class="field-row">
        <div class="label">{{ $t('securityCheck.buyTax') }}：</div>
        <div class="value">{{ honeypotData.list.BuyTax ?? '-' }}</div>
      </div>
      <div class="field-row">
        <div class="label">{{ $t('securityCheck.sellTax') }}：</div>
        <div class="value">{{ honeypotData.list.SellTax ?? '-' }}</div>
      </div>
    </div>
    <div class="field-list-status">
      <div class="field-header">
        <div class="label">
          {{ $t('securityCheck.gopluslabs') }}：
          <a :href="gopluslabsLink" target="_blank">
            <Share></Share>
          </a>
        </div>
      </div>
      <div class="field-row">
        <div class="label">{{ $t('securityCheck.tradingSwitched') }}：</div>
        <div
          class="value"
          v-show="
            Fixedgoplus.list.cannot_buy == '1' ||
            Fixedgoplus.list.cannot_buy == '0'
          "
        >
          {{
            Fixedgoplus.list.cannot_buy == '0'
              ? $t('securityCheck.open')
              : $t('securityCheck.close')
          }}
        </div>
        <div class="value" v-show="Fixedgoplus.list.cannot_buy === '-'">
          {{ Fixedgoplus.list.cannot_buy }}
        </div>
      </div>
      <div class="field-row">
        <div class="label">{{ $t('securityCheck.checkResult') }}：</div>
        <div
          class="value"
          v-show="
            Fixedgoplus.list.is_honeypot == '1' ||
            Fixedgoplus.list.is_honeypot == '0'
          "
        >
          {{
            Fixedgoplus.list.is_honeypot == '1'
              ? $t('securityCheck.yes')
              : $t('securityCheck.no')
          }}
        </div>
        <div class="value" v-show="Fixedgoplus.list.is_honeypot === '-'">
          {{ Fixedgoplus.list.is_honeypot }}
        </div>
      </div>
      <div class="field-row" v-for="item in Sortgoplus.list" :key="item.key">
        <div class="label">{{ $t(`securityCheck.${item.key}`) }}：</div>
        <div v-if="item.type === 'isit' && item.value !== '-'">
          <div class="value" v-show="item.value == '1' || item.value == '0'">
            {{
              item.value == '1'
                ? $t('securityCheck.yes')
                : $t('securityCheck.no')
            }}
          </div>
        </div>
        <div v-else-if="item.type === 'number' && item.value !== '-'">
          <div class="value">
            {{ item.value }}
          </div>
        </div>
        <div class="value" v-else-if="item.value == '-'">
          {{ item.value }}
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import Share from '/public/images/svg/rightDetail/share.svg';
import request from '@/utils/otherRequest';
import { filterChainObj, goplusList } from '@/constants/UnifiedManagementChain';
const props = defineProps({
  token: String,
  currentPath: String,
});
// 当前链
const chain = useChain();
// 链接
const honeypotLink = 'https://honeypot.is/';
const gopluslabsLink = 'https://gopluslabs.io/';

// 固定不动的goplus
const Fixedgoplus = reactive({
  list: {} as any,
});

// goplus排序后的数据
const Sortgoplus = reactive({
  list: goplusList,
});

//honeypot数据
const honeypotData = reactive({
  list: {} as any,
});

// 当前链的所有数据
const ChainObj = ref(
  filterChainObj('value', props.currentPath ? props.currentPath : chain.value)
);
watch(
  () => props.token,
  (v) => {
    if (v) {
      // 查出当前链的数据
      ChainObj.value = filterChainObj('value', chain.value);
      getList(v, ChainObj.value);
    }
  }
);
const getList = (token: string, Obj: any) => {
  honeypotData.list = {};
  // 请求前清空数据
  Sortgoplus.list.forEach((item: any) => {
    item.value = '-';
  });
  // 清空固定的数据
  Object.keys(Fixedgoplus.list).forEach((item: any) => {
    Fixedgoplus.list[item] = '-';
  });

  if (Obj.honeypot.request) {
    request.get(`${Obj.honeypot.url}${token}`).then((res) => {
      if (res) {
        honeypotData.list = res;
      }
    });
  }
  if (Obj.gopluslabs.request) {
    request.get(`${Obj.gopluslabs.url}${token}`).then((res) => {
      if (res.code == 1 && Object.keys(res['result']).length) {
        let list = res['result'][token.toLowerCase()];
        // 获取到数据后插入数组
        Object.keys(list).forEach((item: any) => {
          // 固定的数据
          if (item === 'cannot_buy' || item === 'is_honeypot') {
            Fixedgoplus.list[item] = list[item];
          }
          goplusList.forEach((it: any) => {
            if (item == it.key) {
              it.value = list[item];
            }
          });
        });
        let newList: any = [];
        // 排序
        goplusList.forEach((item: any, index: number) => {
          if (item.value == '0' || item.value == '') {
            newList.push(item);
          } else {
            newList.unshift(item);
          }
        });
        Sortgoplus.list = newList;
      }
    });
  }
};
</script>
<style lang="less">
@import '@/style/flex.less';
@import '@/style/variables.less';
.field-list_SecurityCheck {
  margin-top: 8px;
  border: 1px solid var(--td-Search-info-border-bottom-2);
  background-color: var(--td-bg-color-container);
  border-radius: @border-radius;
  .header-box {
    padding: 4px 12px;
    .dja();
    font-size: var(--font-size-base);
    font-weight: bold;
    height: 40px;
    border-bottom: 1px solid var(--td-search-brand-color-1);
    color: var(--td-search-btn-back-1);
  }
  .field-list-status {
    .field-header {
      padding: 4px 12px;
      font-size: var(--font-size-l);
      color: var(--td--main-btn-color-1);
      margin-top: 5px;
      .label {
        width: 78%;
        .dj(space-between);
      }
    }
    .field-row {
      padding: 4px 12px;
      font-size: 12px;
      .dj(space-between);
      width: 80%;
      &:hover {
        background-color: var(--td-bg-color-secondarycontainer-hover);
      }
      .label {
        color: var(--td-text-color-secondary);
        font-family: fiveFont;
      }
      .value {
        color: var(--td-text-color-primary);
        font-family: fiveFont;
      }
    }
  }
}
</style>
