"use client";

import Link from "next/link";
import { usePathname } from "next/navigation";
import { AppWindow, Globe, LayoutDashboard, Settings } from "lucide-react";
import { cn } from "@/lib/cn";

const links = [
  { href: "/", label: "Dashboard", icon: LayoutDashboard },
  { href: "/apps", label: "Apps", icon: AppWindow },
  { href: "/domains", label: "Domains", icon: Globe },
  { href: "/settings", label: "Monitoring Settings", icon: Settings, adminOnly: true },
];

export function NavLinks({ editable }: { editable: boolean }) {
  const pathname = usePathname();

  return (
    <nav className="flex gap-1 md:flex-col" aria-label="Main">
      {links.filter((link) => editable || !link.adminOnly).map(({ href, label, icon: Icon }) => {
        const active = href === "/" ? pathname === "/" : pathname.startsWith(href);
        return (
          <Link
            key={href}
            href={href}
            aria-current={active ? "page" : undefined}
            className={cn(
              "flex items-center gap-2.5 whitespace-nowrap rounded-md px-3 py-2 text-sm font-medium transition-colors",
              active ? "bg-slate-100 text-slate-900" : "text-slate-600 hover:bg-slate-50 hover:text-slate-900",
            )}
          >
            <Icon className="size-4 shrink-0" aria-hidden />
            {label}
          </Link>
        );
      })}
    </nav>
  );
}
