import {
  FolderKanban,
  Globe2,
  ImageIcon,
  LayoutDashboard,
  Mail,
  PlusSquare,
  ShieldAlert,
  SwatchBook,
  Tags,
  Type,
  type LucideIcon,
} from "lucide-react";
import { getAdminAppPath } from "@/lib/admin-routing";

type AdminNavigationCopy = {
  overview: string;
  maintenance: string;
  uiKit: string;
  portfolio: string;
  media: string;
  siteSettings: string;
  marquee?: string;
  smtp?: string;
  contactProtection?: string;
};

export type AdminNavItem = {
  label: string;
  href: string;
  icon: LucideIcon;
  active?: boolean;
  expanded?: boolean;
  children?: AdminNavItem[];
};

export function getAdminNavigation(
  copy: AdminNavigationCopy,
  active: "overview" | "maintenance" | "ui-kit" | "portfolio" | "media" | "site-settings" | "smtp" | "marquee",
  smtpChild?: "settings" | "contact-protection",
  portfolioChild?: "overview" | "projects" | "new-project" | "categories",
): AdminNavItem[] {
  return [
    {
      label: copy.overview,
      href: getAdminAppPath("/"),
      icon: LayoutDashboard,
      active: active === "overview",
    },
    {
      label: copy.maintenance,
      href: getAdminAppPath("/maintenance"),
      icon: ShieldAlert,
      active: active === "maintenance",
    },
    {
      label: copy.uiKit,
      href: getAdminAppPath("/ui-kit"),
      icon: SwatchBook,
      active: active === "ui-kit",
    },
    {
      label: copy.media,
      href: getAdminAppPath("/media"),
      icon: ImageIcon,
      active: active === "media",
    },
    {
      label: copy.siteSettings,
      href: getAdminAppPath("/site-settings"),
      icon: Globe2,
      active: active === "site-settings",
    },
    {
      label: copy.marquee ?? "Marquee",
      href: getAdminAppPath("/marquee"),
      icon: Type,
      active: active === "marquee",
    },
    {
      label: copy.smtp ?? "SMTP",
      href: getAdminAppPath("/smtp"),
      icon: Mail,
      active: active === "smtp" && !smtpChild,
      expanded: active === "smtp",
      children: [
        {
          label: copy.smtp ?? "SMTP",
          href: getAdminAppPath("/smtp"),
          icon: Mail,
          active: smtpChild === "settings" || (!smtpChild && active === "smtp"),
        },
        {
          label: copy.contactProtection ?? "Contact Protection",
          href: getAdminAppPath("/smtp/contact-protection"),
          icon: ShieldAlert,
          active: smtpChild === "contact-protection",
        },
      ],
    },
    {
      label: copy.portfolio,
      href: getAdminAppPath("/portfolio"),
      icon: FolderKanban,
      active: active === "portfolio" && !portfolioChild,
      expanded: active === "portfolio",
      children: [
        {
          label: "Projects",
          href: getAdminAppPath("/portfolio"),
          icon: FolderKanban,
          active: portfolioChild === "overview" || portfolioChild === "projects",
        },
        {
          label: "Add Project",
          href: getAdminAppPath("/portfolio/projects/new"),
          icon: PlusSquare,
          active: portfolioChild === "new-project",
        },
        {
          label: "Add Category",
          href: getAdminAppPath("/portfolio/categories"),
          icon: Tags,
          active: portfolioChild === "categories",
        },
      ].filter((item, index, array) => array.findIndex((entry) => entry.href === item.href) === index),
    },
  ];
}
