"use client"; import { useEffect, useState } from "react"; const COLORS = [ { name: "Wit", value: "#ffffff", text: "#1e293b" }, { name: "Zwart", value: "#0f172a", text: "#f8fafc" }, { name: "Donker", value: "#1e293b", text: "#f8fafc" }, { name: "Grijs", value: "#f1f5f9", text: "#1e293b" }, { name: "Zilvergrijs", value: "#94a3b8", text: "#1e293b" }, { name: "Leisteen", value: "#475569", text: "#f8fafc" }, { name: "Bruin", value: "#92400e", text: "#f8fafc" }, { name: "Koper", value: "#b45309", text: "#f8fafc" }, { name: "Amber", value: "#f59e0b", text: "#1e293b" }, { name: "Goud", value: "#eab308", text: "#1e293b" }, { name: "Oranje", value: "#ea580c", text: "#ffffff" }, { name: "Rood", value: "#ef4444", text: "#ffffff" }, { name: "Bordeaux", value: "#991b1b", text: "#f8fafc" }, { name: "Roze", value: "#ec4899", text: "#ffffff" }, { name: "Fuchsia", value: "#d946ef", text: "#ffffff" }, { name: "Paars", value: "#8b5cf6", text: "#ffffff" }, { name: "Violet", value: "#6d28d9", text: "#f8fafc" }, { name: "Indigo", value: "#6366f1", text: "#ffffff" }, { name: "Blauw", value: "#3b82f6", text: "#ffffff" }, { name: "Koningsblauw", value: "#1d4ed8", text: "#ffffff" }, { name: "Cyaan", value: "#06b6d4", text: "#ffffff" }, { name: "Mint", value: "#14b8a6", text: "#ffffff" }, { name: "Groen", value: "#22c55e", text: "#1e293b" }, { name: "Olijf", value: "#84cc16", text: "#1e293b" }, { name: "Limoen", value: "#65a30d", text: "#ffffff" }, ]; export function NavbarColorPicker() { const [open, setOpen] = useState(false); const [active, setActive] = useState(() => { if (typeof window === "undefined") return 0; const saved = localStorage.getItem("navbarColor"); if (!saved) return 0; return Math.max( 0, COLORS.findIndex((c) => c.value === saved), ); }); const [mounted, setMounted] = useState(false); function apply(index: number) { // eslint-disable-next-line security/detect-object-injection -- index validated by findIndex + Math.max, guard below const c = COLORS[index]; if (!c) return; document.documentElement.style.setProperty("--color-navbar", c.value); document.documentElement.style.setProperty("--color-navbar-text", c.text); document.documentElement.style.setProperty( "--color-navbar-text-readable", c.text, ); try { localStorage.setItem("navbarColor", c.value); localStorage.setItem("navbarTextColor", c.text); } catch {} setActive(index); setOpen(false); } useEffect(() => { const saved = localStorage.getItem("navbarColor"); const savedText = localStorage.getItem("navbarTextColor"); if (saved) { document.documentElement.style.setProperty("--color-navbar", saved); } if (savedText) { document.documentElement.style.setProperty( "--color-navbar-text", savedText, ); document.documentElement.style.setProperty( "--color-navbar-text-readable", savedText, ); } setMounted(true); }, []); return (