<template>
    <transition name="menu">
        <div v-if="menuOpen" class="menu" ref="container">
            <Nav />

            <div class="menu-wrap layout-block">
                <new-note class="menu-item" @noteOpened="closeMenu" />
                <router-link class="menu-item" to="/category">
                    + New Capitulum
                </router-link>
                <theme-switcher class="menu-item" />
                <router-link class="menu-item" to="/instructions">
                    Instructio
                </router-link>
                <button class="menu-item">Import</button>
                <button class="menu-item">Export</button>
                <router-link class="menu-item" to="/preferences">
                    Preferences
                </router-link>
            </div>
        </div>
    </transition>
</template>

<script setup>
import NewNote from '@/components/NewNote.vue'
import ThemeSwitcher from '@/components/ThemeSwitcher.vue'
import { onClickOutside } from '@vueuse/core'
import { ref, watch } from 'vue'
import Nav from './Nav.vue'
import useMenu from '@/composables/useMenu'
import { useRoute } from 'vue-router'

const container = ref()

const { menuOpen, closeMenu } = useMenu()

// Close on click outside
onClickOutside(container, () => {
    closeMenu()
})

// Close on route change
const route = useRoute()
watch(
    () => route.path,
    () => {
        closeMenu()
    },
)

const openNewCategory = () => {}
</script>

<style lang="scss">
.menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--theme-bg);
    border-bottom: 1px solid var(--grey-100);

    .menu-wrap {
        display: flex;
        flex-direction: column;
        padding-top: 3px;
        padding-bottom: 10px;

        .menu-item {
            padding: 16px 0;
            text-align: center;

            &:not(:last-child) {
                border-bottom: 1px dashed currentColor;
            }
            &:hover {
                color: var(--theme-accent);
            }
        }
    }

    &.menu-enter-active,
    &.menu-leave-active {
        transition: transform 300ms var(--ease-out-expo);
    }
    &.menu-enter-from,
    &.menu-leave-to {
        transform: translateY(-100%);
    }
}
</style>
