<!--
Header de l'application
Contient entre autres le nom de l'organisation, l'accès à l'aide et aux préférences de l'utilisateur
-->

<template>
  <v-app-bar
      order="0"
      density="compact"
      class="bg-ot-green text-ot-white"
  >
    <template #prepend>
      <v-app-bar-nav-icon
          v-if="hasMainMenu"
          :icon="isMainMenuOpened ? 'mdi:mdi-menu-open' : 'mdi:mdi-menu'"
          class="text-ot-white"
          @click="toggleMainMenu"
      />
    </template>

    <v-toolbar-title v-if="mdAndUp" v-text="title"/>

    <LayoutHeaderUniversalCreationCreateButton v-if="showUniversalButton" />

    <LayoutHeaderHomeBtn />

    <LayoutHeaderMenu name="WebsiteList" />

    <LayoutHeaderMenu name="MyAccesses" />

    <LayoutHeaderMenu name="MyFamily" />

    <LayoutHeaderNotification />

    <LayoutHeaderMenu name="Configuration" />

    <LayoutHeaderMenu name="Account" />

    <a
        href="https://support.opentalent.fr/"
        class="text-body pa-3 ml-2 bg-ot-dark-grey text-ot-white text-decoration-none"
        target="_blank"
    >
      <!-- TODO: mettre le lien vers le support dans les .env ou dans la conf -->
      <span class="d-none d-sm-none d-md-flex">{{ $t('help_access') }}</span>
      <v-icon icon="fas fa-question-circle" class="d-sm-flex d-md-none" color="white" />
    </a>
  </v-app-bar>
</template>

<script setup lang="ts">

import {computed, ComputedRef} from "@vue/reactivity";
import {useMenu} from "~/composables/layout/useMenu";
import {useAbility} from "@casl/vue";
import { useDisplay } from 'vuetify'
import {useOrganizationProfileStore} from "~/stores/organizationProfile";

const organizationProfile = useOrganizationProfileStore()

const title: ComputedRef<string> = computed(() => organizationProfile.name ?? 'Opentalent')

const { hasMenu, isMenuOpened, toggleMenu } = useMenu()

const { mdAndUp } = useDisplay()

const hasMainMenu = computed(() => hasMenu('Main'))
const isMainMenuOpened = computed(() => isMenuOpened('Main'))
const toggleMainMenu = () => toggleMenu('Main')

const { can } = useAbility()

const showUniversalButton =
    can('manage', 'users')
  || can('manage', 'courses')
  || can('manage', 'examens')
  || can('manage', 'educationalprojects')
  || can('manage', 'events')
  || can('manage', 'emails')
  || can('manage', 'mails')
  || can('manage', 'texto')
  || can('display', 'message_send_page')
  || can('manage', 'equipments') ;

</script>

<style scoped>
  .help {
    padding: 14px 14px 13px;
    font-size: 14px;
    text-decoration: none;
  }
</style>
