import {
  BadgeDollarSign,
  BookmarkCheck,
  CalendarDays,
  Car,
  ChartNoAxesColumn,
  Contact,
  Handshake,
  LayoutDashboard,
  type LucideIcon,
  Settings,
  ShieldCheck,
  UserCog,
  UserRound,
  UsersRound,
} from "lucide-react";
import { type Permission } from "@/lib/auth/permissions";

export type AdminNavItem = {
  label: string;
  href: string;
  icon: LucideIcon;
  /** Se muestra si el usuario tiene al menos uno de estos permisos. */
  anyOf: readonly Permission[];
  /** Fase del roadmap en la que se construye el módulo; null = ya disponible. */
  phase: number | null;
};

export const ADMIN_NAV: readonly AdminNavItem[] = [
  {
    label: "Dashboard",
    href: "/admin",
    icon: LayoutDashboard,
    anyOf: ["dashboard.read", "dashboard.read.own"],
    phase: null,
  },
  { label: "Vehículos", href: "/admin/vehiculos", icon: Car, anyOf: ["vehicles.read"], phase: 8 },
  {
    label: "Leads",
    href: "/admin/leads",
    icon: Contact,
    anyOf: ["leads.read", "leads.read.own"],
    phase: 9,
  },
  {
    label: "Clientes",
    href: "/admin/clientes",
    icon: UserRound,
    anyOf: ["customers.read", "customers.read.own"],
    phase: 10,
  },
  {
    label: "Citas",
    href: "/admin/citas",
    icon: CalendarDays,
    anyOf: ["appointments.read", "appointments.read.own"],
    phase: 10,
  },
  {
    label: "Consignaciones",
    href: "/admin/consignaciones",
    icon: Handshake,
    anyOf: ["consignments.read", "consignments.read.own"],
    phase: 10,
  },
  {
    label: "Reservas",
    href: "/admin/reservas",
    icon: BookmarkCheck,
    anyOf: ["reservations.write", "reservations.write.own"],
    phase: 10,
  },
  {
    label: "Ventas",
    href: "/admin/ventas",
    icon: BadgeDollarSign,
    anyOf: ["sales.read", "sales.read.own"],
    phase: 10,
  },
  {
    label: "Asesores",
    href: "/admin/asesores",
    icon: UsersRound,
    anyOf: ["advisors.read"],
    phase: 10,
  },
  {
    label: "Reportes",
    href: "/admin/reportes",
    icon: ChartNoAxesColumn,
    anyOf: ["reports.read", "commissions.read", "commissions.read.own"],
    phase: 11,
  },
  { label: "Usuarios", href: "/admin/usuarios", icon: UserCog, anyOf: ["users.read"], phase: null },
  {
    label: "Auditoría",
    href: "/admin/auditoria",
    icon: ShieldCheck,
    anyOf: ["audit.read"],
    phase: 13,
  },
  {
    label: "Configuración",
    href: "/admin/configuracion",
    icon: Settings,
    anyOf: ["settings.read"],
    phase: 8,
  },
];

export function visibleNavItems(permissions: ReadonlySet<string>): AdminNavItem[] {
  return ADMIN_NAV.filter((item) => item.anyOf.some((permission) => permissions.has(permission)));
}
