<template>
  <div>
    <q-tabs v-model="tab" v-if="$q.screen.gt.sm">
      <q-tab
        v-for="(tabindex, index) in tabs"
        :key="'tab' + index"
        :name="tabindex.name"
        :label="tabindex.label"
      />
    </q-tabs>
    <div class="fit row justify-end" v-else>
      <q-btn flat round icon="mdi-menu" @click="showDrawer = !showDrawer" />
    </div>
    <q-drawer side="right" v-model="showDrawer" @click="showDrawer = !showDrawer" behavior="mobile">
      <q-list v-model="tab">
        <q-item
          v-for="(tabindex, index) in tabs"
          :key="'tab' + index"
          :active="tab == tabindex.name"
          clickable
          @click="tab = tabindex.name"
        >
          <q-item-label>{{ tabindex.label }}</q-item-label>
        </q-item>
      </q-list>
    </q-drawer>
    <q-page padding class="fit row justify-center content-start items-start q-gutter-sm">
      <q-tab-panels
        v-model="tab"
        style="background-color: transparent;"
        class="q-ma-none q-pa-none fit row justify-center content-start items-start"
        animated
      >
        <q-tab-panel name="agendaView">
          <AgendaView />
        </q-tab-panel>
        <q-tab-panel name="eventtypes">
          <Eventtypes />
        </q-tab-panel>
        <q-tab-panel name="jobtypes">
          <JobTypes v-if="canEditRoles" />
        </q-tab-panel>
      </q-tab-panels>
    </q-page>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, ref } from '@vue/composition-api';
import Eventtypes from '../components/management/Eventtypes.vue';
import JobTypes from '../components/management/JobTypes.vue';
import CreateEvent from '../components/management/CreateEvent.vue';
import AgendaView from '../components/overview/AgendaView.vue';
import { Store } from 'vuex';
import { StateInterface } from 'src/store';
import { hasPermission } from 'src/utils/permission';
import { PERMISSIONS } from '../permissions';
import { Screen } from 'quasar';

export default defineComponent({
  name: 'EventOverview',
  components: { AgendaView, Eventtypes, JobTypes },
  setup(_, { root }) {
    const store = <Store<StateInterface>>root.$store;

    const canEditRoles = computed(() => hasPermission(PERMISSIONS.ROLES_EDIT, store));

    interface Tab {
      name: string;
      label: string;
    }

    const tabs: Tab[] = [
      { name: 'agendaView', label: 'Kalendar' }
      // { name: 'eventtypes', label: 'Veranstaltungsarten' },
      // { name: 'jobtypes', label: 'Dienstarten' }
    ];

    const drawer = ref<boolean>(false);

    const showDrawer = computed({
      get: () => {
        return !Screen.gt.sm && drawer.value;
      },
      set: (val: boolean) => {
        drawer.value = val;
      }
    });

    const tab = ref<string>('agendaView');

    return {
      canEditRoles,
      showDrawer,
      tab,
      tabs
    };
  }
});
</script>
