<template>
    <button class="new-note" @click="onClick">+ New Nota</button>
</template>

<script setup>
import useOpenNote from '@/composables/useOpenNote'
import useNotes from '@/composables/useNotes'

const props = defineProps({ category: String })
const emit = defineEmits(['noteOpened'])

const { createNote } = useNotes()
const { openNote } = useOpenNote()

const onClick = async () => {
    const note = await createNote(
        {
            category: props.category ?? null,
        },
        '',
    )
    openNote(note.id)
    emit('noteOpened')
}
</script>

<style lang="scss">
.new-note {
}
</style>
