<template>
    <main class="directory layout-block">
        <category-row
            v-for="(category, i) in categories"
            :index="i"
            :category="category"
            :key="category"
        />

        <h2 class="label">Summarium</h2>

        <div class="notes">
            <note-row v-for="note in notes" :note="note" :key="note.id" />
        </div>
    </main>
</template>

<script setup>
import useNotes from '@/composables/useNotes'
import usePlugins from '@/composables/usePlugins'
import useConfig from '@/composables/useConfig'
import { onMounted, ref, watch } from 'vue'
import CategoryRow from '@/components/CategoryRow.vue'
import NoteRow from '@/components/NoteRow.vue'

const { categories, loadCategories, loadCategoryNotes, notesChangeCount } =
    useNotes()

const { config } = useConfig()

const notes = ref()

async function refreshNotes() {
    await loadCategories()
    notes.value = await loadCategoryNotes()
}

onMounted(async () => {
    await refreshNotes()
})

watch(notesChangeCount, async () => {
    await refreshNotes()
})
</script>

<style lang="scss">
main.directory {
    padding-top: 18px;
    padding-bottom: 30px;

    .label {
        text-transform: uppercase;
        margin: 17px 0 24px;
        @include p;
    }
    .notes {
        display: flex;
        flex-direction: column;
        gap: 14px;
    }
}
</style>
