"use client";
import React, { useEffect, useState } from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";

function Navigation() {
  const pathname = usePathname();
  const [activeLink, setActiveLink] = useState("");

  useEffect(() => {
    if (pathname) {
      setActiveLink(pathname);
    }
  }, [pathname]);

  const menuItems = [
    { name: "Übersicht", path: "/dashboard" },
    { name: "Kabelüberwachung", path: "/kabelueberwachung" },
    //{ name: "Zutrittskontrolle", path: "/access" },
    //{ name: "Ein- und Ausgänge", path: "/einausgaenge" },
    //{ name: "Analoge Eingänge", path: "/analogeEingaenge" },
    { name: "Meldungen", path: "/meldungen" },
  ];

  return (
    <aside>
      <nav className="w-64 flex-shrink-0 mt-24 overflow-hidden">
        {menuItems.map((item) => (
          <Link href={item.path} key={item.name}>
            <div
              className={`block px-4 py-2 mb-4 font-bold whitespace-nowrap transition duration-300 ${
                activeLink === item.path
                  ? "bg-sky-500 text-white rounded-r-full"
                  : "text-black hover:bg-gray-200 rounded-r-full"
              }`}
            >
              {item.name}
            </div>
          </Link>
        ))}
      </nav>
    </aside>
  );
}

export default Navigation;
