export function useScrollEnd() {
  let callback = null

  const handleScroll = () => {
    const scrollPosition = window.innerHeight + window.scrollY
    const pageHeight = document.documentElement.offsetHeight

    if (scrollPosition >= pageHeight && typeof callback === 'function') {
      callback()
    }
  }

  const onScrollEnd = (cb) => {
    callback = cb
  }

  onMounted(() => {
    window.addEventListener('scroll', handleScroll)
  })

  onUnmounted(() => {
    window.removeEventListener('scroll', handleScroll)
  })

  return { onScrollEnd }
}