<template>
  <q-btn flat dense :icon="icon" :to="{ name: link }" v-if="hasPermissions"/>
</template>

<script lang="ts">
import {computed, defineComponent} from '@vue/composition-api';
import {Store} from "vuex";
import {StateInterface} from "src/store";
export default defineComponent({
  name: 'ShortCutLink',
  props: {
    link: {
      required: true,
      type: String
    },
    icon: {
      required: true,
      type: String
    },
    permissions: {
      default: undefined
    }
  },
  setup(props, {root}) {

    const hasPermissions = computed(() => {
      let permissions = props.permissions
      if (permissions) {
        return (<string[]>permissions).every(permission => {
          return (<{'user/permissions': string[]}>(<Store<StateInterface>>root.$store).getters)['user/permissions'].includes(permission)
        })
      }
      return true
    })
    return {hasPermissions}
  }
});
</script>
