<template>
  <div>
    <template v-if="isMobile">
      <step-first v-if="step === 'first'" @stepEvent="setStep"/>
      <step-select v-if="step === 'select'" @stepEvent="setStep" @setDataEvent="setInfo"/>
      <step-before v-if="step === 'before'" @stepEvent="setStep" @tokenEvent="loadToken"/>
      <step-email v-if="step === 'email'" @stepEvent="setStep" :info="info"/>
      <step-mobile v-if="step === 'mobile'" @stepEvent="setStep" @tokenEvent="loadToken" :info="info"/>
      <!--<step-appeal v-if="step === 'appeal'" @stepEvent="setStep" @lastEvent="setStepLast"/>-->
      <step-security v-if="step === 'security'" @stepEvent="setStep" @tokenEvent="loadToken" :tokenId="tokenId"/>
      <step-new v-if="step === 'new'" @stepEvent="setStep" @lastEvent="setStepLast" :stepLast="stepLast" :tokenId="tokenId"/>
      <step-Last v-if="step === 'last'" @stepEvent="setStep" :stepLast="stepLast"/>
    </template>
    <template v-else>
      <accountCenter-header/>
      <password-stepFirst v-if="step === 'first'" @stepEvent="setStep"/>
      <password-stepSelect v-if="step === 'select'" @stepEvent="setStep" @setDataEvent="setInfo"/>
      <password-stepBefore v-if="step === 'before'" @stepEvent="setStep" @tokenEvent="loadToken"/>
      <password-stepMobile v-if="step === 'mobile'" @stepEvent="setStep" @tokenEvent="loadToken" :info="info"/>
      <password-stepEmail v-if="step === 'email'" @stepEvent="setStep" :info="info"/>
      <password-stepSecurity v-if="step === 'security'" @stepEvent="setStep" @tokenEvent="loadToken" :tokenId="tokenId"/>
      <password-StepNew v-if="step === 'new'" @stepEvent="setStep" @lastEvent="setStepLast" :stepLast="stepLast" :tokenId="tokenId"/>
      <password-stepSuccess v-if="step === 'last'" @stepEvent="setStep" :stepLast="stepLast"/>
    </template>
  </div>
</template>
<script>
  import AccountCenterHeader from '~components/default/AccountCenterHeader.vue'
  import { PasswordStepFirst, PasswordStepSelect, PasswordStepBefore, PasswordStepMobile, PasswordStepEmail, PasswordStepSecurity, PasswordStepNew, PasswordStepSuccess } from '~components/reset'
  import {StepFirst, StepSelect, StepBefore, StepEmail, StepMobile, StepAppeal, StepNew, StepSecurity, StepLast} from '~components/mobile/reset'
  export default {
    layout (context) {
      return context.store.state.option.isMobile ? 'mobile' : 'default'
    },
    transition: {
      name: 'fade',
      mode: 'out-in'
    },
    data () {
      return {
        step: 'first',
        stepLast: 'new',
        info: '',
        tokenId: ''
      }
    },
    components: {
      AccountCenterHeader,
      PasswordStepFirst,
      PasswordStepSelect,
      PasswordStepBefore,
      PasswordStepMobile,
      PasswordStepEmail,
      PasswordStepSecurity,
      PasswordStepNew,
      PasswordStepSuccess,
      StepFirst,
      StepSelect,
      StepNew,
      StepLast,
      StepSecurity,
      StepBefore,
      StepMobile,
      StepEmail,
      StepAppeal
    },
    mounted () {
      if (this.$route.query.token) {
        this.step = 'security'
      } else {
        if (this.logged && this.logged.isLogin) {
          this.step = 'select'
        } else {
          this.step = 'first'
        }
      }
    },
    computed: {
      logged () {
        return this.$store.state.option.isLogin.data.content
      },
      isMobile () {
        return this.$store.state.option.isMobile
      }
    },
    methods: {
      setStepLast (type) {
        this.stepLast = type
      },
      loadToken (type) {
        this.tokenId = type
      },
      setInfo (type) {
        this.info = type
      },
      setStep (type) {
        this.step = type
      }
    }
  }
</script>
