import { useEffect, useState } from 'react'

import { IWindowSize } from '@/types'

export function useWindowSize() {
	const [windowSize, setWindowSize] = useState<IWindowSize>({
		width: undefined,
		height: undefined
	})

	useEffect(() => {
		function handleResize() {
			setWindowSize({
				width: window.innerWidth,
				height: window.innerHeight
			})
		}

		handleResize()

		window.addEventListener('resize', handleResize)

		return () => window.removeEventListener('resize', handleResize)
	}, [])

	return windowSize
}
