<template>
  <div>
    <template v-if="isMobile">
      <validationPhone-stepSelect v-if="step === 'select'" @stepEvent="setStep" @setDataEvent="setInfo"/>
      <validationPhone-stepMobile v-if="step === 'mobile'" @stepEvent="setStep" @tokenEvent="loadToken" :info="info"/>
      <validationPhone-stepEmail v-if="step === 'email'" @stepEvent="setStep" :info="info"/>
      <validationPhone-stepSecurity v-if="step === 'questions'" @stepEvent="setStep" @tokenEvent="loadToken"/>
      <validationPhone-stepNew v-if="step === 'new'" @stepEvent="setStep" @lastEvent="setStepLast" :stepLast="stepLast" :tokenId="tokenId"/>
      <validationPhone-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/>
      <phone-stepSelect v-if="step === 'select'" @stepEvent="setStep" @setDataEvent="setInfo"/>
      <phone-stepMobile v-if="step === 'mobile'" @stepEvent="setStep" @tokenEvent="loadToken" :info="info"/>
      <phone-stepEmail v-if="step === 'email'" @stepEvent="setStep" :info="info"/>
      <phone-stepSecurity v-if="step === 'questions'" @stepEvent="setStep" @tokenEvent="loadToken" :info="info"/>
      <phone-stepNew v-if="step === 'new'" @stepEvent="setStep" @lastEvent="setStepLast" :tokenId="tokenId"/>
      <phone-stepSuccess v-if="step === 'last'" @stepEvent="setStep"/>
    </template>
  </div>
</template>
<script>
  import AccountCenterHeader from '~components/default/AccountCenterHeader.vue'
  import { PhoneStepSelect, PhoneStepMobile, PhoneStepEmail, PhoneStepSecurity, PhoneStepNew, PhoneStepSuccess } from '~components/validation'
  import {ValidationPhoneStepSelect, ValidationPhoneStepMobile, ValidationPhoneStepEmail, ValidationPhoneStepSecurity, ValidationPhoneStepNew, ValidationPhoneStepSuccess, StepAppeal} from '~components/mobile/validation'
  export default {
    layout (context) {
      return context.store.state.option.isMobile ? 'mobile' : 'default'
    },
    // middleware: 'authenticated',
    transition: {
      name: 'fade',
      mode: 'out-in'
    },
    data () {
      return {
        step: 'select',
        info: '',
        tokenId: '',
        stepLast: 'new'
      }
    },
    components: {
      AccountCenterHeader,
      PhoneStepSelect,
      PhoneStepMobile,
      PhoneStepEmail,
      PhoneStepSecurity,
      PhoneStepNew,
      PhoneStepSuccess,
      ValidationPhoneStepSelect,
      ValidationPhoneStepMobile,
      ValidationPhoneStepEmail,
      ValidationPhoneStepSecurity,
      ValidationPhoneStepNew,
      ValidationPhoneStepSuccess,
      StepAppeal
    },
    computed: {
      isMobile () {
        return this.$store.state.option.isMobile
      },
      logged () {
        return this.$store.state.option.isLogin.data.content
      }
    },
    mounted () {
      if (this.$route.query.token) {
        this.step = 'new'
      } else {
        if (this.logged && this.logged.isLogin) {
          this.step = 'select'
        } else {
          this.$router.push('/')
        }
      }
    },
    methods: {
      setStep (type) {
        this.step = type
      },
      setInfo (style) {
        this.info = style
      },
      loadToken (token) {
        this.tokenId = token
      },
      setStepLast (type) {
        this.stepLast = type
      }
    }
  }
</script>
