"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: "Meldungseingänge ", path: "/digitalInputs" }, //vorher Digitale Ein -und Ausgänge
    { name: "Schaltausgänge ", path: "/digitalOutputs", disabled: false }, //vorher Digitale Ein -und Ausgänge
    { name: "Messwerteingänge  ", path: "/analogeEingaenge" }, //vorher Analoge Eingänge
    { name: "Berichte ", path: "/meldungen" },
    { name: "System ", path: "/system" },
    { name: "Einstellungen ", path: "/einstellungen" },
    //{ name: "Zutriffskontrolle", path: "/zutrittskontrolle" },

    // Weitere Menüpunkte hier
  ];

  return (
    <aside>
      <nav className={`h-full flex-shrink-0 mt-16 ${className || "w-48"}`}>
        {menuItems.map((item) => (
          <div key={item.name}>
            {item.disabled ? (
              <div className="block px-4 py-2 mb-4 font-bold whitespace-nowrap text-gray-400 cursor-not-allowed text-[1rem] sm:text-[1rem] md:text-[1rem] lg:text-[1rem] xl:text-sm 2xl:text-lg">
                {item.name}
              </div>
            ) : (
              <Link href={formatPath(item.path)}>
                <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>
            )}
          </div>
        ))}
      </nav>
    </aside>
  );
};

export default Navigation;
