"use client";

import Link from "next/link";
import { usePathname } from "next/navigation";

const links = [
  { href: "/admin/dashboard", label: "Обзор" },
  { href: "/admin/courses", label: "Курсы" },
  { href: "/admin/categories", label: "Категории" },
  { href: "/admin/users", label: "Пользователи" },
  { href: "/curator/homework", label: "ДЗ на проверку" },
  { href: "/admin/questions", label: "Вопросы" },
  { href: "/admin/quizzes", label: "Тесты" },
  { href: "/admin/comments", label: "Комментарии" },
  { href: "/admin/import-export", label: "Импорт / Экспорт" },
  { href: "/admin/settings", label: "Настройки" },
];

export function AdminNav({ questionsBadge = 0 }: { questionsBadge?: number }) {
  const pathname = usePathname();

  return (
    <>
      {links.map(({ href, label }) => {
        const active =
          pathname === href ||
          (href !== "/admin/dashboard" && href !== "/curator/homework" && pathname.startsWith(href)) ||
          (href === "/curator/homework" && pathname.startsWith("/curator/homework"));
        return (
          <Link
            key={href}
            href={href}
            className="admin-sidebar-nav-link"
            style={
              active
                ? {
                    color: "#E8F0D8",
                    borderLeftColor: "#E8F0D8",
                    backgroundColor: "var(--sidebar-surface)",
                  }
                : undefined
            }
          >
            <span className="flex items-center justify-between w-full">
              {label}
              {href === "/admin/questions" && questionsBadge > 0 && (
                <span
                  className="ml-2 inline-flex items-center justify-center rounded-full text-xs font-bold leading-none"
                  style={{
                    minWidth: "1.25rem",
                    height: "1.25rem",
                    padding: "0 0.3rem",
                    backgroundColor: "var(--destructive)",
                    color: "#fff",
                  }}
                >
                  {questionsBadge}
                </span>
              )}
            </span>
          </Link>
        );
      })}
    </>
  );
}
