/**
 * Command Palette — static entry list.
 *
 * Source of truth for the Cmd+K palette. The palette component imports
 * `PALETTE_ENTRIES` and filters/scores this list. This file does NOT
 * import from the sidebar — keep them independent so the palette
 * works even if the sidebar is restructured.
 *
 * Entries are grouped by the new admin IA (see
 * docs/superpowers/specs/2026-06-17-admin-redesign.md §4):
 *   Workspace · Operations · Communications · Growth ·
 *   Tracking · Insights · Settings · Public
 *
 * `type` distinguishes pages (jump to a route) from quick actions
 * (a route + query string that opens a creation flow / composer).
 */

export type PaletteEntryType = "page" | "action";

export type PaletteEntry = {
  /** Stable id, used as React key. */
  id: string;
  /** "page" = nav to route, "action" = nav to a creation flow / composer. */
  type: PaletteEntryType;
  /** Primary text shown in the result row. */
  label: string;
  /** Route to navigate to when selected. */
  href: string;
  /** Sidebar group (Pages) or "Quick action" (Actions). */
  category: string;
  /** Lucide icon name (PascalCase, e.g. "ShoppingCart"). */
  iconName: string;
  /** Extra search terms (lowercase, comma-separated in code). */
  keywords?: string[];
};

export const PALETTE_ENTRIES: PaletteEntry[] = [
  // ── Workspace ──────────────────────────────────────────────────────
  {
    id: "page-dashboard",
    type: "page",
    label: "Dashboard",
    href: "/admin",
    category: "Workspace",
    iconName: "LayoutDashboard",
    keywords: ["home", "overview"],
  },
  // ── Operations ─────────────────────────────────────────────────────
  {
    id: "page-orders",
    type: "page",
    label: "Orders",
    href: "/admin/orders",
    category: "Operations",
    iconName: "ShoppingCart",
    keywords: ["sales", "purchases", "invoices"],
  },
  {
    id: "page-stops",
    type: "page",
    label: "Stops & Routes",
    href: "/admin/stops",
    category: "Operations",
    iconName: "MapPin",
    keywords: ["schedule", "pickup locations", "calendar"],
  },
  {
    id: "page-products",
    type: "page",
    label: "Products",
    href: "/admin/products",
    category: "Operations",
    iconName: "Package",
    keywords: ["catalog", "sku", "inventory"],
  },
  {
    id: "page-pickup",
    type: "page",
    label: "Driver Pickup",
    href: "/admin/pickup",
    category: "Operations",
    iconName: "Truck",
    keywords: ["fulfillment", "driver"],
  },
  {
    id: "page-shipping",
    type: "page",
    label: "Shipping",
    href: "/admin/shipping",
    category: "Operations",
    iconName: "Send",
    keywords: ["shipments", "labels", "fedex"],
  },

  // ── Communications ─────────────────────────────────────────────────
  {
    id: "page-communications",
    type: "page",
    label: "Harvest Reach",
    href: "/admin/communications",
    category: "Communications",
    iconName: "Megaphone",
    keywords: ["email", "sms", "campaigns", "templates", "contacts", "blasts"],
  },
  {
    id: "page-communications-templates",
    type: "page",
    label: "Email Templates",
    href: "/admin/communications?tab=templates",
    category: "Communications",
    iconName: "FileText",
    keywords: ["harvest reach", "templates"],
  },
  {
    id: "page-communications-contacts",
    type: "page",
    label: "Contacts",
    href: "/admin/communications?tab=contacts",
    category: "Communications",
    iconName: "Users",
    keywords: ["harvest reach", "audience", "subscribers"],
  },
  {
    id: "page-communications-logs",
    type: "page",
    label: "Message Logs",
    href: "/admin/communications?tab=logs",
    category: "Communications",
    iconName: "ScrollText",
    keywords: ["harvest reach", "history", "delivered"],
  },

  // ── Growth ─────────────────────────────────────────────────────────
  {
    id: "page-wholesale",
    type: "page",
    label: "Wholesale",
    href: "/admin/wholesale",
    category: "Growth",
    iconName: "Store",
    keywords: ["b2b", "buyers", "deposits"],
  },
  {
    id: "page-import",
    type: "page",
    label: "Import Center",
    href: "/admin/import",
    category: "Growth",
    iconName: "Upload",
    keywords: ["csv", "bulk", "upload"],
  },
  {
    id: "page-ai",
    type: "page",
    label: "AI Intelligence",
    href: "/admin/advanced",
    category: "Growth",
    iconName: "Sparkles",
    keywords: ["automation", "assistant", "smart", "claude"],
  },

  // ── Tracking ───────────────────────────────────────────────────────
  {
    id: "page-time-tracking",
    type: "page",
    label: "Time Tracking",
    href: "/admin/time-tracking",
    category: "Tracking",
    iconName: "Clock",
    keywords: ["workers", "pins", "tasks", "shifts"],
  },
  {
    id: "page-water-log",
    type: "page",
    label: "Water Log",
    href: "/admin/water-log",
    category: "Tracking",
    iconName: "Droplets",
    keywords: ["irrigation", "usage"],
  },
  {
    id: "page-route-trace",
    type: "page",
    label: "Route Trace",
    href: "/admin/route-trace",
    category: "Tracking",
    iconName: "Route",
    keywords: ["trace", "map", "gps"],
  },

  // ── Insights ───────────────────────────────────────────────────────
  {
    id: "page-reports",
    type: "page",
    label: "Reports",
    href: "/admin/reports",
    category: "Insights",
    iconName: "BarChart3",
    keywords: ["analytics", "kpi"],
  },
  {
    id: "page-taxes",
    type: "page",
    label: "Tax Dashboard",
    href: "/admin/taxes",
    category: "Insights",
    iconName: "Receipt",
    keywords: ["taxes", "compliance", "1099"],
  },

  // ── Settings ───────────────────────────────────────────────────────
  {
    id: "page-settings",
    type: "page",
    label: "General Settings",
    href: "/admin/settings",
    category: "Settings",
    iconName: "Settings",
    keywords: ["config", "preferences"],
  },
  {
    id: "page-settings-brand",
    type: "page",
    label: "Brand Settings",
    href: "/admin/settings/brand",
    category: "Settings",
    iconName: "Tag",
    keywords: ["branding", "logo", "name"],
  },
  {
    id: "page-settings-billing",
    type: "page",
    label: "Billing",
    href: "/admin/settings/billing",
    category: "Settings",
    iconName: "CreditCard",
    keywords: ["subscription", "plan", "invoice", "stripe"],
  },
  {
    id: "page-users",
    type: "page",
    label: "Users & Permissions",
    href: "/admin/users",
    category: "Settings",
    iconName: "Users",
    keywords: ["team", "roles", "admins"],
  },
  {
    id: "page-integrations",
    type: "page",
    label: "Integrations",
    href: "/admin/settings/integrations",
    category: "Settings",
    iconName: "Plug",
    keywords: ["stripe", "square", "resend", "connect"],
  },
  {
    id: "page-payments",
    type: "page",
    label: "Payments",
    href: "/admin/settings/payments",
    category: "Settings",
    iconName: "Wallet",
    keywords: ["processor", "stripe", "square"],
  },
  {
    id: "page-shipping-settings",
    type: "page",
    label: "Shipping Settings",
    href: "/admin/settings/shipping",
    category: "Settings",
    iconName: "Truck",
    keywords: ["zones", "rates", "fedex"],
  },
  {
    id: "page-addons",
    type: "page",
    label: "Add-ons",
    href: "/admin/settings/apps",
    category: "Settings",
    iconName: "Puzzle",
    keywords: ["features", "extensions", "apps"],
  },

  // ── Public storefronts ─────────────────────────────────────────────
  {
    id: "page-storefront-tuxedo",
    type: "page",
    label: "Tuxedo Storefront",
    href: "/tuxedo",
    category: "Public",
    iconName: "Store",
    keywords: ["public", "site", "shop"],
  },
  {
    id: "page-storefront-indian-river",
    type: "page",
    label: "Indian River Direct",
    href: "/indian-river-direct",
    category: "Public",
    iconName: "Store",
    keywords: ["public", "site", "shop"],
  },

  // ── Quick actions ──────────────────────────────────────────────────
  {
    id: "action-new-order",
    type: "action",
    label: "Create new order",
    href: "/admin/orders?new=true",
    category: "Quick action",
    iconName: "PlusCircle",
    keywords: ["new", "add", "order"],
  },
  {
    id: "action-new-product",
    type: "action",
    label: "Add new product",
    href: "/admin/products/new",
    category: "Quick action",
    iconName: "PlusCircle",
    keywords: ["new", "add", "product", "sku"],
  },
  {
    id: "action-new-stop",
    type: "action",
    label: "Add new stop",
    href: "/admin/stops/new",
    category: "Quick action",
    iconName: "PlusCircle",
    keywords: ["new", "add", "stop", "location"],
  },
  {
    id: "action-send-campaign",
    type: "action",
    label: "Send campaign",
    href: "/admin/communications/compose",
    category: "Quick action",
    iconName: "Send",
    keywords: ["email", "sms", "blast", "harvest reach"],
  },
  {
    id: "action-open-billing",
    type: "action",
    label: "Open billing",
    href: "/admin/settings/billing",
    category: "Quick action",
    iconName: "CreditCard",
    keywords: ["subscription", "plan", "stripe"],
  },
  {
    id: "action-invite-user",
    type: "action",
    label: "Invite team member",
    href: "/admin/users",
    category: "Quick action",
    iconName: "UserPlus",
    keywords: ["user", "team", "admin"],
  },
  {
    id: "action-sync-square",
    type: "action",
    label: "Sync Square",
    href: "/admin/settings/square-sync",
    category: "Quick action",
    iconName: "RefreshCw",
    keywords: ["sync", "square", "inventory"],
  },
  {
    id: "action-generate-report",
    type: "action",
    label: "Generate report",
    href: "/admin/reports",
    category: "Quick action",
    iconName: "FileText",
    keywords: ["report", "export", "analytics"],
  },
];

/**
 * Map from PaletteEntry.iconName (PascalCase lucide name) to the imported
 * component. Centralized here so the palette component doesn't have to
 * know about every icon — it just looks up the component by string.
 *
 * The component imports lucide-react icons lazily (only the ones we
 * actually use). Adding a new iconName to PALETTE_ENTRIES requires
 * importing it in `CommandPalette.tsx` and adding it to the map here.
 */
export const PALETTE_ICON_NAMES = PALETTE_ENTRIES.reduce<string[]>((acc, e) => {
  if (!acc.includes(e.iconName)) acc.push(e.iconName);
  return acc;
}, []);
