"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]);

  // Dynamische Anpassung der Pfade mit oder ohne .html
  const isProduction = process.env.NEXT_PUBLIC_NODE_ENV === "production";
  const menuItems = [
    { name: "Übersicht", path: "/dashboard" },
    { name: "Kabelüberwachung", path: "/kabelueberwachung" },
    // Weitere Menüpunkte hier
  ];

  return (
    <aside>
      <nav className="w-64 flex-shrink-0 mt-32 overflow-hidden">
        {menuItems.map((item) => (
          <Link
            href={`${item.path}${isProduction ? ".html" : ""}`}
            key={item.name}
          >
            <div
              className={`block px-4 py-2 mb-4 font-bold whitespace-nowrap transition duration-300 ${
                activeLink.startsWith(item.path) ||
                activeLink.startsWith(item.path + ".html")
                  ? "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;
