<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-security v-if="step === 'questions'" @stepEvent="setStep" @tokenEvent="loadToken" :info="info"/>
      <step-new v-if="step === 'new'" @stepEvent="setStep" @lastEvent="setStepLast" :tokenId="tokenId"/>
      <step-success v-if="step === 'last'" :stepLast="stepLast"/>
      <step-appeal v-if="step === 'appeal'" @stepEvent="setStep" @lastEvent="setStepLast"/>
    </template>
    <template v-else>
      <accountCenter-header/>
      <change-stepSelect v-if="step === 'select'" @stepEvent="setStep" @setDataEvent="setInfo"/>
      <change-stepMobile v-if="step === 'mobile'" @stepEvent="setStep" @tokenEvent="loadToken" :info="info"/>
      <change-stepEmail v-if="step === 'email'" @stepEvent="setStep" :info="info"/>
      <change-stepSecurity v-if="step === 'questions'" @stepEvent="setStep" @tokenEvent="loadToken" :info="info"/>
      <change-stepNew v-if="step === 'new'" @stepEvent="setStep" @lastEvent="setStepLast" :tokenId="tokenId"/>
      <change-stepSuccess v-if="step === 'last'"/>
    </template>
  </div>
</template>
<script>
  import AccountCenterHeader from '~components/default/AccountCenterHeader.vue'
  import { ChangeStepSelect, ChangeStepMobile, ChangeStepEmail, ChangeStepSecurity, ChangeStepNew, ChangeStepSuccess } from '~components/change'
  import {StepSelect, StepMobile, StepEmail, StepSecurity, StepNew, StepSuccess, StepAppeal} from '~components/mobile/changeManager'
  export default {
    layout (content) {
      return content.store.state.option.isMobile ? 'mobile' : 'default'
    },
    transition: {
      name: 'fade',
      mode: 'out-in'
    },
    components: {
      AccountCenterHeader,
      ChangeStepSelect,
      ChangeStepMobile,
      ChangeStepEmail,
      ChangeStepSecurity,
      ChangeStepNew,
      ChangeStepSuccess,
      StepSelect,
      StepMobile,
      StepEmail,
      StepSecurity,
      StepNew,
      StepSuccess,
      StepAppeal
    },
    data () {
      return {
        step: 'select',
        info: '',
        tokenId: '',
        stepLast: 'new'
      }
    },
    computed: {
      isMobile () {
        return this.$store.state.option.isMobile
      }
    },
    mounted () {
      if (this.$route.query.token) {
        this.step = 'new'
      } else {
        if (this.$store.state.option.isLogin.data.content.isLogin) {
          this.step = 'select'
        } else {
          this.$router.push('/')
        }
      }
    },
    methods: {
      setStep (type) {
        this.step = type
      },
      setInfo (info) {
        this.info = info
      },
      loadToken (token) {
        this.tokenId = token
      },
      setStepLast (type) {
        this.stepLast = type
      }
    }
  }
</script>
