import { IS_BROWSER } from 'fresh/runtime'
import { useEffect } from 'preact/hooks'

let getSnow: () => { clear: () => void } | undefined = () => undefined

if (IS_BROWSER) {
	const { LetItGo } = await import('jsr:@eastsun5566/let-it-go')
	getSnow = () =>
		new LetItGo({
			radiusRange: [1, 2],
			number: globalThis.innerWidth / 4,
		})
}

export default function Snow() {
	useEffect(() => {
		const snow = getSnow()
		return () => snow?.clear()
	}, [])

	return null
}
