import React, { useState, useEffect } from "react"
import "../assets/css/navbar.css"
import logo from "../assets/images/logo.svg"
import logoBlue from "../assets/images/logo-blue.svg"
import { FaAlignRight } from "react-icons/fa"
import pageLinks from "../constants/links"
import { Link } from "gatsby"
const Navbar = () => {
const [navbar, setNavbar] = useState(false)
const [navbarLogo, setNavbarLogo] = useState(logo)
const changeBackground = () => {
console.log(window.scrollY)
if (window.scrollY >= 66) {
setNavbar(true)
} else {
setNavbar(false)
}
}
useEffect(() => {
changeBackground()
window.addEventListener("scroll", changeBackground)
})
const changeLogo = () => {
if (window.scrollY >= 60) {
setNavbarLogo(logoBlue)
} else {
setNavbarLogo(logo)
}
}
useEffect(() => {
changeLogo()
window.addEventListener("scroll", changeLogo)
})
return (
<nav className={navbar ? "navbar active" : "navbar"}>
<div className="nav-center">
<div className="nav-header">
<Link to="/">
<img src={navbarLogo} alt="logo" />
</Link>
<button type="button" className="toggle-btn">
<FaAlignRight />
</button>
</div>
<div className="nav-links">
{pageLinks.map(links => {
return (
<Link key={links.id} to={links.url}>
{links.text}
</Link>
)
})}
</div>
</div>
</nav>
)
}
export default Navbar