<template>
  <div>
    <template v-if="isMobile">
      <validationEmail-stepSelect v-if="step === 'select'" @stepEvent="setStep" @setDataEvent="setInfo"/>
      <validationEmail-stepMobile v-if="step === 'mobile'" @stepEvent="setStep" @tokenEvent="loadToken" :info="info"/>
      <validationEmail-stepEmail v-if="step === 'email'" @stepEvent="setStep" :info="info"/>
      <validationEmail-stepSecurity v-if="step === 'questions'" @stepEvent="setStep" @tokenEvent="loadToken"/>
      <validationEmail-stepNew v-if="step === 'new'" @stepEvent="setStep" @lastEvent="setStepLast" :tokenId="tokenId"/>
      <validationEmail-stepSuccess v-if="step === 'last'" @stepEvent="setStep" :stepLast="stepLast"/>
      <step-appeal v-if="step === 'appeal'" @stepEvent="setStep" @lastEvent="setStepLast"/>
    </template>
    <template v-else>
      <accountCenter-header/>
      <email-validation/>
    </template>
  </div>
</template>
<script>
  import AccountCenterHeader from '~components/default/AccountCenterHeader.vue'
  import EmailValidation from '~components/validation/EmailValidation.vue'
  import {ValidationEmailStepSelect, ValidationEmailStepMobile, ValidationEmailStepEmail, ValidationEmailStepSecurity, ValidationEmailStepNew, ValidationEmailStepSuccess, StepAppeal} from '~components/mobile/validation'
  export default {
    layout (content) {
      // console.log(content, 'content')
      return content.store.state.option.isMobile ? 'mobile' : 'default'
    },
    middleware: 'authenticated',
    transition: {
      name: 'fade',
      mode: 'out-in'
    },
    data () {
      return {
        step: 'select',
        info: '',
        tokenId: '',
        stepLast: 'new'
      }
    },
    components: {
      AccountCenterHeader,
      EmailValidation,
      ValidationEmailStepSelect,
      ValidationEmailStepMobile,
      ValidationEmailStepEmail,
      ValidationEmailStepSecurity,
      ValidationEmailStepNew,
      ValidationEmailStepSuccess,
      StepAppeal
    },
    mounted () {
      console.log('111')
      if (this.logged.isLogin) {
        if (this.$route.query.token) {
          this.step = 'last'
        } else {
          this.step = 'select'
        }
      } else {
        if (this.$route.query.token) {
          this.step = 'last'
        } else {
          this.$router.push('/')
        }
      }
    },
    computed: {
      logged () {
        // console.log(this.$store.state.option.isLogin.data.content.isLogin)
        return this.$store.state.option.isLogin.data.content
      },
      isMobile () {
        return this.$store.state.option.isMobile
      }
    },
    methods: {
      setStep (step) {
        this.step = step
      },
      setInfo (info) {
        this.info = info
      },
      loadToken (token) {
        this.tokenId = token
      }
    }
  }
</script>
