import Link from 'next/link' import { InlineLogo, useColorShift } from '../logo' import { useEffect, useState } from 'react'; import { UseColorShiftReturnType } from '../logo/useColorShift'; import { RxActivityLog } from "react-icons/rx"; interface HoverState { about: boolean projects: boolean contact: boolean } const SHIFT_INTERVAL = 3000; export default function Navbar({ pageIsScrolled = false }) { const navbarColorShift = useColorShift(SHIFT_INTERVAL); const { shift } = navbarColorShift; const [colors, setColors] = useState>({ firstColor: 'bg-inherit', secondColor: 'bg-inherit', thirdColor: 'bg-inherit', }); const [hoverState, setHoverState] = useState({ about: false, projects: false, contact: false, }) const [mobileMenuOpen, setMobileMenuOpen] = useState(false); function mouseOver(source: keyof HoverState) { const { colorKeys, actualColorReferences, activeIndex } = identifyActiveButton(); setColors({ ...colors, [colorKeys[activeIndex]]: actualColorReferences[activeIndex] }); setHoverState({ ...hoverState, [source]: true }) } function mouseOut(source: keyof HoverState) { setHoverState({ ...hoverState, [source]: false }) setColors({ firstColor: 'bg-inherit', secondColor: 'bg-inherit', thirdColor: 'bg-inherit' }); } function identifyActiveButton() { const buttonKeys: (keyof HoverState)[] = ['about', 'projects', 'contact']; const { firstColor, secondColor, thirdColor } = navbarColorShift; const colorKeys = ['firstColor', 'secondColor', 'thirdColor']; const actualColorReferences = [firstColor, secondColor, thirdColor]; const activeButton = buttonKeys.find(key => hoverState[key]); const activeIndex = buttonKeys.indexOf(activeButton as keyof HoverState); return { colorKeys, actualColorReferences, activeIndex }; } useEffect(() => { const interval = setInterval(shift, SHIFT_INTERVAL); return () => clearInterval(interval); }, []) useEffect(() => { const interval = setInterval(() => { const { colorKeys, actualColorReferences, activeIndex } = identifyActiveButton(); for (const key in hoverState) { if (hoverState[key as keyof HoverState]) { setColors({ ...colors, [colorKeys[activeIndex]]: actualColorReferences[activeIndex] }); } } }, 1000); return () => clearInterval(interval); }, [shift]) return ( <>
setMobileMenuOpen(false)} className={`flex flex-col z-50 rounded-bl-lg justify-end md:hidden fixed top-24 w-[35vw] text-right place-self-end bg-[#131313] ${mobileMenuOpen ? 'translate-x-[65vw]' : 'translate-x-[100vw]'} transition-all duration-500`}> {/*
*/} setMobileMenuOpen(false)} passHref href="/" className="w-auto px-2">

Home

setMobileMenuOpen(false)} passHref href="/about" className="w-auto px-2">

About

setMobileMenuOpen(false)} passHref href="/projects" className="w-auto px-2">

Projects

setMobileMenuOpen(false)} passHref href="/contact" className="w-auto px-2">

Contact

) }