<template>
  <div class="container">
    <svg-icon name="login" class="login-icon-bg" />
    <div class="login-box">
      <span class="login-title-main">{{ $t("login.Wallet") }}</span>
      <span class="login-title-hint">{{ $t("login.Support") }}ACC、BTC、ETH、TRX、BS</span>
    </div>


    <div class="operation-body">
      <van-button class="create-btn" type="primary" round @click="changeCreate">{{ $t("login.CreateWallet") }}</van-button>
      <van-button class="operation-button" type="default" round @click="changeImport">{{ $t("login.ImportWallet")}}</van-button>
    </div>

    <div class="bottom-body">
      <van-checkbox v-model="checked" icon-size="16" style="margin-right: 6px;" checked-color="#4765dd"></van-checkbox>
      <span> {{ $t("login.LoginTxt") }} Local Block</span>
      <a class="a-link" @click="toAgreement">{{ $t("login.PrivacyPolicy") }}</a>
      <span>{{ $t("login.And") }}</span>
      <a class="a-link" @click="toAgreement">{{ $t("login.UserAgreement") }}</a>
    </div>
  </div>


  <van-popup
    v-model:show="showBottom"
    round
    position="bottom"
    :style="{ height: '30.4%' }"
  >
    <div class="popup-content">
      <span class="popup-title">{{  $t("login.UserAgreement") }}</span>
      <span  class="popup-txt">{{  $t("login.UserAgreementTxt") }}</span>


      <van-button type="primary" round class="popup-btn" color="#4F4F4F"  @click="evAgree">{{ $t("login.IHaveReadAndAgree") }}</van-button>
      <span class="popup-cancel" @click="showBottom = false">{{ $t("login.Cancel") }}</span>
    </div>
  </van-popup>
</template>
<script setup>
import { useSystemStore } from "@/stores/modules/systemStore"
import { useRoute } from 'vue-router'
const router = useRouter();
const route = useRoute();
const systemStore = useSystemStore();
const obj = route.query

const checked = ref(false)
const showBottom = ref(false);
const isCreate = ref(true); //true:创建钱包  false：导入钱包
const isFirst = Object.keys(obj).length === 0 ? true : false; //true:首次  false:不是首次
// 创建
const changeCreate = () => {
  isCreate.value = true;
  if(checked.value){
    goTo();
  }else{
    showBottom.value = true;
  }
}
// 导入
const changeImport = () => {
  isCreate.value = false;
  if(checked.value){
    goTo();
  }else{
    showBottom.value = true;
  }
}
// 弹框跳转
const evAgree = ()=>{
  goTo();
}
const goTo = () => { 
  systemStore.ISCREATE = isCreate.value; 
  systemStore.$persist()
  // 如果是第一次登录，需要选择网络
  if(isFirst){
    router.push({
      path: '/selectNetwork'
    })
  }else{
    // 以后登录直接去创建或者导入，不需要选择网络
    if(isCreate.value){
      router.push({
        path: '/createWallet'
      })
    }else{
      // 导入方式
      router.push({
        path: '/importMethod'
      })
    }
  }
}
// 跳转协议
const toAgreement = () =>{
  router.push({
    path: '/agreement'
  })
}

</script>

<style scoped lang="less">
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  .login-icon-bg {
    width: 285px;
    height: 305px;
    margin-top: 110px;
  }
  .login-box {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .login-title-main { 
    font-weight: 500;
    font-size: 25px;
    margin: 0 0 9px 0;
  }
  .login-title-hint {
    font-weight: 400;
    font-size: 15px;
    color: @font-color2;
  }

  .operation-body{
    width: 312px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    margin-top: 90px;
    .operation-button{
      margin-top: 23px;
      border-radius: 70px;
      border: 1px solid #8D8D8D;
      box-sizing: border-box;
      color: #000000;
      height: 50px !important;
      font-family: PingFang SC, PingFang SC;
      font-weight: 600;
      font-size: 19px;
      color: #000000;
      padding: 14px 0;
    }
    .create-btn{
      background: @theme-color1 !important;
      border:none !important;
      border-radius: 70px;
      height: 50px !important;
      box-sizing: border-box;
      font-family: PingFang SC, PingFang SC;
      font-weight: 600;
      font-size: 19px;
      color: #FFFFFF;
      padding: 14px 0;
    }
  }
  .bottom-body{
    display: flex;
    align-items: center;
    font-size: 12px;
    margin-top: 30px;
  }
  .a-link{
    margin: 0 5px;
  }

}
.popup-content{
  display: flex;
  flex-direction:column;
  align-items: center;
  height: 100%;
  width: 100%;
  .popup-title{
    font-size: 17px;
    font-weight: 500px;
    margin-top: 32px;
  }
  .popup-txt{
    font-size: 12px;
    margin: 17px 23px 0 23px;
    color: @font-color2;
    letter-spacing: 1px;
  }
  .popup-btn{
    margin-top: 30px;
    width: 312px;
    height: 54px; 
    border-radius: 70px 70px 70px 70px;
    :deep(.van-button__text){
      font-size: 19px;
    }
  }
  .popup-cancel{
    margin-top: 19px;
    font-size: 19px;
    color: @font-color2;
    &:hover {
      cursor: pointer;
      color: @hover-color;
    }
  }
}
</style>
