<template>
  <div>
    <template v-if="isMobile">
      <step-select v-if="step === 'select'" @stepEvent="setStep" @setDataEvent="setInfo"/>
      <step-mobile v-if="step === 'mobile'" @stepEvent="setStep" @tokenEvent="loadToken" :info="info"/>
      <step-email v-if="step === 'email'" @stepEvent="setStep" :info="info"/>
      <step-new v-if="step === 'new'" @stepEvent="setStep" :tokenId="tokenId"/>
      <step-success v-if="step === 'success'"/>
    </template>
    <template v-else>
      <accountCenter-header/>
      <encrypted-select v-if="step === 'select'" @stepEvent="setStep" @setDataEvent="setInfo"/>
      <encrypted-mobile v-if="step === 'mobile'" @stepEvent="setStep" @tokenEvent="loadToken" :info="info"/>
      <encrypted-email v-if="step === 'email'" @stepEvent="setStep" :info="info"/>
      <encrypted-new v-if="step === 'new'" @stepEvent="setStep" :tokenId="tokenId"/>
      <encrypted-success v-if="step === 'success'"/>
    </template>
  </div>
</template>
<script>
  import AccountCenterHeader from '~components/default/AccountCenterHeader.vue'
  import {EncryptedSelect, EncryptedMobile, EncryptedEmail, EncryptedNew, EncryptedSuccess} from '~components/encrypted-setting'
  import {StepSelect, StepMobile, StepEmail, StepNew, StepSuccess} from '~components/mobile/encryptedSetting'
  export default {
    layout (content) {
      return content.store.state.option.isMobile ? 'mobile' : 'default'
    },
    transition: {
      name: 'fade',
      mode: 'out-in'
    },
    data () {
      return {
        step: 'select',
        info: '',
        tokenId: ''
      }
    },
    components: {
      AccountCenterHeader,
      EncryptedSelect,
      EncryptedMobile,
      EncryptedEmail,
      EncryptedNew,
      EncryptedSuccess,
      StepSelect,
      StepMobile,
      StepEmail,
      StepNew,
      StepSuccess
    },
    mounted () {
      if (this.$route.query.token) {
        this.step = 'new'
      } else {
        if (this.$store.state.option.isLogin.data.content.isLogin) {
          this.step = 'select'
        } else {
          this.$route.push('/')
        }
      }
    },
    computed: {
      isMobile () {
        return this.$store.state.option.isMobile
      }
    },
    methods: {
      setStep (step) {
        this.step = step
      },
      setInfo (info) {
        this.info = info
      },
      loadToken (token) {
        this.tokenId = token
      }
    }
  }
</script>
