import { useRouter } from 'vue-router'
import { useEnvironment, ENVIRONMENTS } from './useEnvironment'

export default () => {
    const router = useRouter()

    function openNote(noteId, options = {}) {
        const { newWindow = true } = options

        const environment = useEnvironment()

        if (newWindow && environment === ENVIRONMENTS.ELECTRON) {
            window.api.openNoteWindow(noteId)
            return
        }

        // Fallback to SPA navigation
        router.push(`/note/${noteId}`)
    }

    return {
        openNote,
    }
}
