import {
  Bell,
  BookOpen,
  Building2,
  CalendarRange,
  FileText,
  Gauge,
  Heart,
  Import,
  LayoutGrid,
  LayoutList,
  type LucideIcon,
  MapPinned,
  MessageSquare,
  Plane,
  Route as RouteIcon,
  Settings,
  ShieldCheck,
  Sparkles,
  Users,
  UsersRound,
  Wallet,
} from "lucide-react";

export interface NavItem {
  label: string;
  to: string;
  icon: LucideIcon;
}

export interface NavSection {
  label: string;
  items: NavItem[];
}

export const NAV_SECTIONS: NavSection[] = [
  {
    label: "Overview",
    items: [{ label: "Dashboard", to: "/", icon: Gauge }],
  },
  {
    label: "Travel",
    items: [
      { label: "Tours", to: "/tours", icon: MapPinned },
      { label: "Trips", to: "/trips", icon: CalendarRange },
      { label: "Itineraries", to: "/itineraries", icon: LayoutList },
      { label: "Destinations", to: "/destinations", icon: RouteIcon },
    ],
  },
  {
    label: "People",
    items: [
      { label: "Guests", to: "/guests", icon: Users },
      { label: "Bookings", to: "/bookings", icon: BookOpen },
      { label: "Tour Managers", to: "/tour-managers", icon: UsersRound },
    ],
  },
  {
    label: "Operations",
    items: [
      { label: "Hotels", to: "/hotels", icon: Building2 },
      { label: "Flights", to: "/flights", icon: Plane },
      { label: "Transport", to: "/transport", icon: RouteIcon },
      { label: "Documents", to: "/documents", icon: FileText },
      { label: "Payments", to: "/payments", icon: Wallet },
    ],
  },
  {
    label: "Experience",
    items: [
      { label: "Loyalty", to: "/loyalty", icon: Heart },
      { label: "Community", to: "/community", icon: MessageSquare },
      { label: "Content", to: "/content", icon: Sparkles },
      { label: "Notifications", to: "/notifications", icon: Bell },
    ],
  },
  {
    label: "Insights",
    items: [
      { label: "Reports", to: "/reports", icon: Gauge },
      { label: "Import Centre", to: "/imports", icon: Import },
    ],
  },
  {
    label: "Admin",
    items: [
      { label: "Users & Roles", to: "/users", icon: ShieldCheck },
      { label: "Audit Log", to: "/audit", icon: ShieldCheck },
      { label: "Master Types", to: "/master-types", icon: LayoutGrid },
      { label: "Settings", to: "/settings", icon: Settings },
    ],
  },
];

const EXTRA_TITLES: Record<string, string> = {
  "/referrals": "Referrals",
  "/wishlist": "Wishlist",
  "/moderation": "Moderation",
};

export const ROUTE_TITLES: Record<string, string> = {
  ...Object.fromEntries(NAV_SECTIONS.flatMap((s) => s.items.map((i) => [i.to, i.label]))),
  ...EXTRA_TITLES,
};

/** Breadcrumb trail for a pathname, e.g. /trips/KV-2026-4501 */
export function breadcrumbs(pathname: string): { label: string; to?: string }[] {
  if (pathname === "/") return [{ label: "Dashboard" }];
  const parts = pathname.split("/").filter(Boolean);
  const trail: { label: string; to?: string }[] = [];
  let acc = "";
  parts.forEach((part, i) => {
    acc += `/${part}`;
    const isLast = i === parts.length - 1;
    const label = ROUTE_TITLES[acc] ?? decodeURIComponent(part);
    trail.push(isLast ? { label } : { label, to: acc });
  });
  return trail;
}
