<template>
  <div>
    <GlobalForm
      endpoint="registration/checkin"
      :form-id="formId"
      :show-logs="false"
      @onRequestSuccess="requestCallback"
    >
      <template #fields>
        <BaseText>{{ $_tr('welcome') }}</BaseText>

        <InputEmail
          model-name="email"
          :form-id="formId"
          :label="$_tr('fields.email')"
          :rules="['required']"
        />

        <InputHidden
          model-name="langcode"
          :form-id="formId"
          :default-value="language"
        />
      </template>

      <template #submit>
        <submit-slot
          :form-id="formId"
          :submit-button-text="$_tr('common.actions.validate')"
        />
      </template>
    </GlobalForm>
  </div>
</template>

<script>
import { BaseText } from 'inside-collection/atoms'

import GlobalForm from '@inside-forms/displays/GlobalForm'
import InputEmail from '@inside-forms/displays/sub-components/fields/InputEmail'
import InputHidden from '@inside-forms/displays/sub-components/fields/InputHidden'
import GlobalFormSubmitSlot from '@inside-forms/displays/sub-components/globals/GlobalFormSubmitSlot'
import GetNavigatorLanguage from '../../../mixins/get-navigator-language'

/**
 * @module tryb-front
 * @type Component
 * @description Form page to ask the user email and redirect him to the next step
 *
 * @author LBrossault
 * @date 03/07/2019
 */
export default {
  name: 'check-in-register',
  $_i18nRootPath: 'customs.CHECK_IN_REGISTER',
  components: {
    BaseText,
    GlobalForm,
    InputEmail,
    InputHidden,
    'submit-slot': GlobalFormSubmitSlot
  },
  mixins: [GetNavigatorLanguage],
  data() {
    return {
      formId: 'email_register'
    }
  },
  methods: {
    requestCallback(data) {
      if (data.redirect) {
        this.$router.push(data.redirect)
      }
    }
  }
}
</script>
