<template>
  <q-item v-if="isGranted" clickable tag="a" target="self" :to="{ name: link }">
    <q-item-section v-if="icon" avatar>
      <q-icon :name="icon" />
    </q-item-section>

    <q-item-section>
      <q-item-label>{{ title }}</q-item-label>
      <!--<q-item-label caption>
        {{ caption }}
      </q-item-label>-->
    </q-item-section>
  </q-item>
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue';
import { hasPermissions } from 'src/utils/permission';

export default defineComponent({
  name: 'EssentialLink',
  props: {
    title: {
      type: String,
      required: true,
    },
    caption: {
      type: String,
      default: '',
    },
    link: {
      type: String,
      default: 'dashboard',
    },
    icon: {
      type: String,
      default: '',
    },
    permissions: {
      default: () => Array<string>(),
      type: Array as () => Array<string>,
    },
  },

  setup(props) {
    const isGranted = computed(() => hasPermissions(props.permissions));
    return { isGranted };
  },
});
</script>
