import NextLink from 'next/link'
import { useRouter } from 'next/router'
import { useEffect } from 'react'

const Link = ({ children, ...props }) => {
  const router = useRouter()

  useEffect(() => {
    router.events.on('routeChangeStart', () => window.scrollTo({ top: 0, behavior: 'smooth' }))
  }, [router])

  return (
    <NextLink
      {...props}
      // onClick={() => window.scrollTo({ top: 0, behavior: 'smooth' })}
      scroll={false}
      className={`block font-medium text-red_r-11 ${props?.className || ''}`}
    >
      {children}
    </NextLink>
  )
}

Link.defaultProps = NextLink.defaultProps

export default Link
