<!--
Menu déroulant générique pour l'affichage des menus du
header principal (configuration, paramètres du compte...)
-->

<template>
  <v-menu offset-y left>
    <template v-slot:activator="{ on: { click }, attrs }">
      <v-tooltip bottom>
        <template v-slot:activator="{ on: on_tooltips , attrs: attrs_tooltips }">
          <v-btn

            icon
            v-bind="[attrs, attrs_tooltips]"
            color=""
            v-on="on_tooltips"
            @click="click"
          >
            <v-avatar
              v-if="avatar"
              size="30"
            >
              <UiImage :id="avatarId" :imageByDefault="avatarByDefault" :width="30"></UiImage>
            </v-avatar>
            <v-icon  v-else class="ot_white--text" small>
              {{ menu.icon }}
            </v-icon>
          </v-btn>
        </template>
        <span>{{ $t(menu.title) }}</span>
      </v-tooltip>
    </template>
    <v-card scrollable>
      <v-card-title class="ot_super_light_grey text-body-2 font-weight-bold">
        {{$t(menu.title)}}
      </v-card-title>
      <v-card-text style="max-height: 300px; overflow-y: scroll" class="ma-0 pa-0">
        <v-list dense :subheader="true">
          <template v-for="(item, index) in menu.children">
            <v-list-item

              :id="item.title"
              :key="item.title"
              :href="item.isExternalLink ? item.to : undefined"
              :to="!item.isExternalLink ? item.to : undefined"
              router
              exact
            >
              <v-list-item-title v-text="$t(item.title)"/>
            </v-list-item>
          </template>
        </v-list>
      </v-card-text>
      <v-card-actions class="ma-0 pa-0">
        <template v-for="(item, index) in menu.actions">
          <v-list-item
            class="text-body-2"
            :id="item.title"
            :key="item.title"
            :href="item.isExternalLink ? item.to : undefined"
            :to="!item.isExternalLink ? item.to : undefined"
            router
          >
            <v-list-item-title v-text="$t(item.title)"/>
          </v-list-item>
        </template>
      </v-card-actions>
    </v-card>


  </v-menu>
</template>

<script lang="ts">
import {defineComponent, useStore} from '@nuxtjs/composition-api'
import {accessState} from "~/types/interfaces";
import {Store} from "vuex";

export default defineComponent({
  props: {
    menu: {
      type: Object,
      required: true
    },
    avatar: {
      type: Boolean,
      required: false
    }
  },
  setup () {
    const store:Store<any> = useStore()
    const accessStore: accessState = store.state.profile.access
    return {
      avatarId: accessStore.avatarId,
      avatarByDefault: accessStore.gender == 'MISTER' ? 'men-1.png' : 'women-1.png'
    }
  }
})
</script>
<style scoped>
  #logout{
    background: var(--v-ot_green-base, white);
    color: white;
  }
</style>
