import { useRouter } from 'vue-router'

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

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

        // Electron environment check
        const isElectron =
            typeof window !== 'undefined' &&
            window.api &&
            typeof window.api.openNoteWindow === 'function'

        if (newWindow && isElectron) {
            window.api.openNoteWindow(noteId)
            return
        }

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

    return {
        openNote,
    }
}
