import { useSearch } from "@/lib/context/isOpenState"; import { getCurrentSeason } from "@/utils/getTimes"; import { ArrowLeftIcon, ArrowUpCircleIcon } from "@heroicons/react/20/solid"; import { UserIcon } from "@heroicons/react/24/solid"; import { signIn, signOut, useSession } from "next-auth/react"; import Image from "next/image"; import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import { AniListInfoTypes } from "types/info/AnilistInfoTypes"; const getScrollPosition = (el: Window | Element = window) => { if (el instanceof Window) { return { x: el.pageXOffset, y: el.pageYOffset }; } else { return { x: el.scrollLeft, y: el.scrollTop }; } }; type NavbarProps = { info?: AniListInfoTypes | null; scrollP?: number; toTop?: boolean; withNav?: boolean; paddingY?: string; home?: boolean; back?: boolean; manga?: boolean; shrink?: boolean; bgHover?: boolean; }; export function Navbar({ info = null, scrollP = 200, toTop = false, withNav = false, paddingY = "py-3", home = false, back = false, manga = false, shrink = false, bgHover = false, }: NavbarProps) { const { data: session }: { data: any } = useSession(); const router = useRouter(); const [scrollPosition, setScrollPosition] = useState< { x: number; y: number } | undefined >(); const { setIsOpen } = useSearch(); const year = new Date().getFullYear(); const season = getCurrentSeason(); useEffect(() => { const handleScroll = () => { setScrollPosition(getScrollPosition()); }; // Add a scroll event listener when the component mounts window.addEventListener("scroll", handleScroll); // Clean up the event listener when the component unmounts return () => { window.removeEventListener("scroll", handleScroll); }; }, []); return ( <> {toTop && ( )} ); }