<!--
Barre d'alerte quand au statut (l'avancement) de l'inscription en ligne de l'utilisateur

-->

<template>
  <UiSystemBar
      v-if="!pending && message"
      :text="$t(message)"
      icon="fas fa-id-card"
      class="theme-secondary"
  />
</template>

<script setup lang="ts">
import {useEntityFetch} from "~/composables/data/useEntityFetch";
import {useAccessProfileStore} from "~/stores/accessProfile";
import RegistrationStatus from "~/models/OnlineRegistration/RegistrationStatus";
import type {ComputedRef} from "@vue/reactivity";

const { fetch } = useEntityFetch()

const accessProfile = useAccessProfileStore()

const { data: registrationStatus, pending } = fetch(RegistrationStatus, accessProfile.id ?? 0)

const messagesByStatus = {
  'NEGOTIABLE': "your_application_is_awaiting_processing",
  'PENDING': "you_have_been_placed_on_the_waiting_list",
  'ACCEPTED': "your_registration_file_has_been_validated",
  'DENIED': "your_application_has_been_refused",
}

const message: ComputedRef<string> = computed(() => {
  if (!registrationStatus.value) {
    return ''
  }
  const status = (registrationStatus.value as RegistrationStatus).status
  return status ? messagesByStatus[status] : ''
})
</script>

<style scoped lang="scss">

</style>
