<template>
  <div>
    <TitleBox />
    <div class="page-index__action-box">
      <div class="page-index__space" />
      <div class="page-index__login">
        <LoginBox />
      </div>
      <div class="page-index__separator">
        <span class="page-index__separator-text">{{ $t('or') }}</span>
      </div>
      <div class="page-index__create-team">
        <Button :border="false" @click="createTeam">{{ $t('create-team') }}</Button>
      </div>
      <div class="page-index__space" />
    </div>
    <div class="page-index__copyright-notice" @click="openInfoModal">
      v{{ config.version }}, © 2021-2022, Settel
    </div>
    <InfoModal v-if="showInfoModal" @close="closeInfoModal" />
    <CreateTeamDialog v-if="showCreateTeamDialog" @close="closeCreateTeamDialog" />
  </div>
</template>

<script setup lang="ts">
import { useRuntimeConfig, navigateTo } from '#app'
import { ref } from 'vue'
import useAuth from '@/composables/useAuth'
import useI18n from '@/composables/useI18n'

const { $t } = useI18n({
  'create-team': { en: 'Create Team ...', de: 'Team erstellen ...' },
  or: { en: 'or', de: 'oder' },
})

const config = useRuntimeConfig()

await useAuth().authenticateAndLoadUserInfo([''])

const showCreateTeamDialog = ref(false)
const showInfoModal = ref(false)
const createTeam = () => { showCreateTeamDialog.value = true }
const closeCreateTeamDialog = () => { showCreateTeamDialog.value = false }
const openInfoModal = () => { showInfoModal.value = true }
const closeInfoModal = () => { showInfoModal.value = false }
</script>

<style lang="scss">
@import '~/assets/css/components';

body {
  background-color: $background-primary-color;
  color: $text-primary-color;

  margin: 0;
}

.page-index {
  &__action-box {
    display: flex;
    width: 100%;
    height: 120px;

    @media (max-width: $phone-max-width) {
      flex-direction: column;
      margin: 32px 0 0 0;
    }
  }

  &__login,
  &__create-team {
    width: 320px;
    align-self: center;

    @media (max-width: $phone-max-width) {
      width: auto;
    }
  }

  &__separator {
    width: 1px;
    margin: 0 48px;
    border-left: $box-primary-border;

    @media (max-width: $phone-max-width) {
      position: relative;
      width: 300px;
      height: 1px;
      margin: 48px 0;
      border-left: none;
      border-bottom: $box-primary-border;
      align-self: center;
    }

    &-text {
      display: none;

      @media (max-width: $phone-max-width) {
        display: block;
        position: absolute;
        top: -10px;
        left: 120px;
        width: 60px;
        background-color: $background-primary-color;
        font-size: 18px;
        color: $text-primary-color;
        text-align: center;
      }
    }
  }

  &__space {
    flex-grow: 1;
  }

  &__copyright-notice {
    position: absolute;
    right: 1em;
    bottom: 0;
    color: #606060;
    cursor: pointer;

    &:hover {
      color: #c0c0c0;
    }
  }
}
</style>