import { inject, onBeforeUnmount } from 'vue'

export default (callback = () => {}, instanceId) => {
    const instanceKey = `lenis${instanceId ? `-${instanceId}` : ''}`
    const lenis = inject(instanceKey)

    if (lenis.value) {
        lenis.value.on('scroll', callback)
    }

    onBeforeUnmount(() => lenis.value?.off('scroll', callback))

    return lenis
}
