<script setup lang="ts">

const {t} = useI18n()
const isOpen = useAuthModal()
const appConfig = useAppConfig()
const loginUrl = appConfig.myLayer.loginUrl

const emit = defineEmits<{
  (e: 'close'): void
}>()

const goAuth = () => {
  if (window) {
    let fullPath = encodeURIComponent(window.location.toString())
    if (fullPath.includes('basic-info')) {
      fullPath = fullPath.replace('%2Fcounterparty%2Fmain', '').replace('%2Fbasic-info', '')
    }
    window.location.href = `${loginUrl}?url=${fullPath}`
  }
}

const goRegister = () => {
  if (window) {
    let fullPath = encodeURIComponent(window.location.toString())
    if (fullPath.includes('basic-info')) {
      fullPath = fullPath.replace('%2Fcounterparty%2Fmain', '').replace('%2Fbasic-info', '')
    }
    window.location.href = `${loginUrl}register?url=${fullPath}`
  }
}
</script>

<template>
  <a-modal v-model="isOpen" :title="t('modals.auth.title')" >
    <div class="flex flex-col items-center gap-5 text-center text-sm">
      <a-ill-door ></a-ill-door>
      <div>{{ t('modals.auth.content') }}</div>
      <a-button @click="goAuth" block variant="success">{{ t('modals.buttons.logIn') }}</a-button>
      <div>{{ t('modals.auth.firstTime') }}</div>
    </div>
    <template #footer>
      <div class="flex gap-2">
        <a-button @click="$emit('close')" view="outline" block>{{ t('modals.buttons.close') }}</a-button>
        <a-button @click="goRegister" block>{{ t('modals.buttons.register') }}</a-button>
      </div>
    </template>
  </a-modal>
</template>

<style scoped></style>
