import Link from "next/link"; import { useEffect, useState } from "react"; import { useRouter } from "next/router"; import { parseCookies, setCookie } from "nookies"; import Image from "next/image"; function Footer() { const [year] = useState(new Date().getFullYear()); const [season] = useState(getCurrentSeason()); const [lang, setLang] = useState("en"); const [checked, setChecked] = useState(false); const [cookie, setCookies] = useState(null); const router = useRouter(); useEffect(() => { let lang = null; if (!cookie) { const cookie = parseCookies(); lang = cookie.lang || null; setCookies(cookie); } if (lang === "en" || lang === null) { setLang("en"); setChecked(false); } else if (lang === "id") { setLang("id"); setChecked(true); } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); function switchLang() { setChecked(!checked); if (checked) { console.log("switching to en"); setCookie(null, "lang", "en", { maxAge: 365 * 24 * 60 * 60, path: "/", }); router.push("/en"); } else { router.push("/id"); } } return ( ); } export default Footer; function getCurrentSeason() { const now = new Date(); const month = now.getMonth() + 1; // getMonth() returns 0-based index switch (month) { case 12: case 1: case 2: return "WINTER"; case 3: case 4: case 5: return "SPRING"; case 6: case 7: case 8: return "SUMMER"; case 9: case 10: case 11: return "FALL"; default: return "UNKNOWN SEASON"; } }