<script setup>
import { useDisplay, useTheme } from "vuetify/lib/framework.mjs";
import { ref } from "vue";
import { navigateTo, useRoute } from "#app";

const route = useRoute();

const { mobile } = useDisplay();
const navOpen = ref(!mobile.value);
const navSelected = ref([route.path]);

const theme = useTheme();
function switchTheme() {
  theme.global.name.value = theme.global.current.value.dark ? 'light' : 'dark';
}
</script>

<template>
  <VAppBar v-if="mobile" order="5">
    <VAppBarNavIcon @click.end="navOpen = !navOpen" />
    <VToolbarTitle>Database Project</VToolbarTitle>
  </VAppBar>
  <VNavigationDrawer v-model="navOpen" :temporary="mobile">
    <VList v-model:selected="navSelected" density="compact" nav>
      <VListItem prepend-icon="mdi-login" title="Login" value="/login" @click="navigateTo('/login')" />
      <VListItem prepend-icon="mdi-account" title="Clients" value="/clients" @click="navigateTo('/clients')" />
      <VListItem prepend-icon="mdi-receipt-text" title="Orders" value="/orders" @click="navigateTo('/orders')" />
      <VDivider />
    </VList>
    <template #append>
      <VList density="compact" nav>
        <VDivider />
        <VListItem prepend-icon="mdi-theme-light-dark" title="Switch theme" class="mx-auto" @click="switchTheme()" />
      </VList>
    </template>
  </VNavigationDrawer>
</template>
