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

interface NavigationProps {
  className?: string;
}

const Navigation: React.FC<NavigationProps> = ({ className }) => {
  const pathname = usePathname();
  const [activeLink, setActiveLink] = useState("");

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

  const formatPath = (path: string) => {
    return process.env.NODE_ENV === "production" ? `${path}.html` : path;
  };

  const menuItems = [
    { name: "Übersicht", path: "/dashboard" },
    { name: "Kabelüberwachung", path: "/kabelueberwachung" },
    { name: "Ein- und Ausgänge", path: "/einausgaenge" },
    { name: "Analoge Eingänge", path: "/analogeEingaenge" },
    { name: "Meldungen", path: "/messages" },
    { name: "Einstellungen", path: "/settings" },
    // Weitere Menüpunkte hier
  ];

  return (
    <aside>
      <nav className="w-48 h-full flex-shrink-0 mt-16">
        {menuItems.map((item) => (
          <Link href={formatPath(item.path)} key={item.name}>
            <div
              className={`block px-4 py-2 mb-4 font-bold whitespace-nowrap transition duration-300 text-[1rem] sm:text-[1rem] md:text-[1rem] lg:text-[1rem] xl:text-sm 2xl:text-lg ${
                activeLink.startsWith(item.path)
                  ? "bg-sky-500 text-white rounded-r-full xl:mr-4 xl:w-full  "
                  : "text-black hover:bg-gray-200 rounded-r-full"
              }`}
            >
              {item.name}
            </div>
          </Link>
        ))}
      </nav>
    </aside>
  );
};

export default Navigation;
