<!--
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" :translate-label="false" />

    <LayoutHeaderMenu name="MyAccesses" />

    <LayoutHeaderMenu name="MyFamily" :translate-label="false" />

    <LayoutHeaderNotification />

    <LayoutHeaderMenu name="Configuration" />

    <LayoutHeaderMenu name="Account" />

    <a
        :href="runtimeConfig.supportUrl"
        class="text-body pa-3 ml-2 bg-ot-dark-grey text-ot-white text-decoration-none"
        target="_blank"
    >
      <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 runtimeConfig = useRuntimeConfig()
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 ability = useAbility()
const showUniversalButton =
    ability.can('manage', 'users')
    || ability.can('manage', 'courses')
    || ability.can('manage', 'examens')
    || ability.can('manage', 'educationalprojects')
    || ability.can('manage', 'events')
    || ability.can('manage', 'emails')
    || ability.can('manage', 'mails')
    || ability.can('manage', 'texto')
    || ability.can('display', 'message_send_page')
    || ability.can('manage', 'equipments')

</script>

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