<template>
  <q-drawer
    :model-value="drawer"
    show-if-above
    :width="200"
    :breakpoint="1024"
    @update:model-value="$emit('drawer-toggle')">
    <q-scroll-area class="fit">
      <q-list
        padding
        class="menu-list">
        <template
          v-for="link in enabledLinks"
          :key="link.name">
          <!-- TODO: Template this to be DRY -->
          <q-item
            clickable
            v-ripple
            :to="link.to">
            <q-item-section avatar>
              <q-icon :name="link.icon" />
            </q-item-section>

            <q-item-section>
              <span :class="link.color ? `text-${link.color}` : ''">
                {{ link.name }}
              </span>
            </q-item-section>
          </q-item>
          <q-list v-if="link.sublinks">
            <div
              v-for="sublink in link.sublinks"
              :key="sublink.name">
              <q-item
                clickable
                v-ripple
                :to="sublink.to"
                class="q-ml-md">
                <q-item-section avatar>
                  <q-icon :name="sublink.icon" />
                </q-item-section>

                <q-item-section>
                  <span :class="sublink.color ? `text-${sublink.color}` : ''">
                    {{ sublink.name }}
                  </span>
                </q-item-section>
              </q-item>
            </div>
          </q-list>
        </template>
        <q-item
          clickable
          v-ripple
          @click="logout()">
          <q-item-section avatar><q-icon name="logout" /></q-item-section>
          <q-item-section>Logout</q-item-section>
        </q-item>
      </q-list>
    </q-scroll-area>
  </q-drawer>
</template>

<script lang="ts" setup>
import { defineComponent } from 'vue';
import { enabledLinks } from 'src/router/navlinks.js';
import { logout } from 'boot/appwrite';

defineProps(['drawer']);
defineEmits(['drawer-toggle']);

defineComponent({
  name: 'LeftDrawer',
});
</script>

<style lang="sass" scoped>
.menu-list .q-item
  border-radius: 0 32px 32px 0
</style>
