import { Bell, Boxes, Coins, Cookie, CreditCard, Heart, LayoutDashboard, ListFilter, MailCheck, PackagePlus, Palette, Search, Server, ShieldCheck, ShoppingCart, SquareMousePointer, Truck, UserRoundPlus, Users, type LucideIcon, } from "lucide-react"; import type { PageId } from "@/contexts/navigation-context"; export interface FeatureDestination { pageId: PageId; title: string; group?: string; icon: LucideIcon; keywords: string[]; proOnly?: boolean; } /** Shared merchant-facing labels; existing route IDs and saved settings stay unchanged. */ export const featureDestinations: FeatureDestination[] = [ { pageId: "dashboard", title: "Dashboard", icon: LayoutDashboard, keywords: ["home", "overview"], }, { pageId: "products/bundles", title: "Product Bundles", group: "Products", icon: Boxes, keywords: ["bundle", "discount"], }, { pageId: "products/addons", title: "Product Addons", group: "Products", icon: PackagePlus, keywords: ["options", "extras", "add-ons"], }, { pageId: "products/subscriptions", title: "Subscriptions", group: "Products", icon: CreditCard, keywords: ["recurring", "renewals", "plans"], }, { pageId: "products/quantity-limits", title: "Quantity Limits", group: "Products", icon: ListFilter, keywords: ["minimum", "maximum", "quantity"], }, { pageId: "products/wishlist", title: "Wishlist", group: "Products", icon: Heart, keywords: ["favorites", "saved products"], }, { pageId: "products/ajax-search", title: "Ajax Search", group: "Products", icon: Search, keywords: ["product search", "live search"], }, { pageId: "notifications/back-in-stock", title: "Back In Stock", group: "Sales Recovery", icon: Bell, keywords: ["restock", "stock notifications"], }, { pageId: "notifications/abandoned-cart", title: "Cart Recovery", group: "Sales Recovery", icon: ShoppingCart, keywords: ["abandoned cart", "reminders", "emails"], }, { pageId: "customization/registration-form", title: "Registration Form", group: "Customers", icon: UserRoundPlus, keywords: ["signup", "sign up", "account", "customization"], }, { pageId: "spam/email-verification", title: "Email Verification", group: "Customers", icon: MailCheck, keywords: ["verify", "registration", "spam", "account"], }, { pageId: "spam/recaptcha", title: "reCAPTCHA", group: "Security & Privacy", icon: ShieldCheck, keywords: ["captcha", "bots", "spam", "protection"], }, { pageId: "compliance/cookie-consent", title: "Cookie Consent", group: "Security & Privacy", icon: Cookie, keywords: ["privacy", "compliance", "gdpr", "cookies"], }, { pageId: "popups/added-to-cart", title: "Add to Cart Popup", icon: SquareMousePointer, keywords: ["added to cart", "popup", "confirmation"], }, { pageId: "shipping/tracking", title: "Tracking", icon: Truck, keywords: ["shipment", "shipping", "delivery", "order tracking"], }, { pageId: "currencies/switcher", title: "Currency Switcher", icon: Coins, keywords: ["currencies", "exchange rates", "conversion"], }, { pageId: "checkout/field-editor", title: "Checkout Fields", icon: ListFilter, keywords: ["field editor", "checkout", "billing", "shipping address"], }, { pageId: "globals", title: "Global Styles", icon: Palette, keywords: ["globals", "colors", "fonts", "typography", "design tokens"], proOnly: true, }, { pageId: "system/info", title: "System Info", icon: Server, keywords: ["diagnostics", "status", "support"], }, ]; const groups = [ { title: "Products", icon: Boxes }, { title: "Sales Recovery", icon: ShoppingCart }, { title: "Customers", icon: Users }, { title: "Security & Privacy", icon: ShieldCheck }, ]; export function routeHref(page: PageId, tab?: string) { return `#${page}${tab ? `?${new URLSearchParams({ tab })}` : ""}`; } export interface FeatureNavItem { title: string; icon: LucideIcon; url: string; pageId?: PageId; isActive: boolean; items?: { title: string; url: string; pageId: PageId; isActive: boolean }[]; } export function featureSidebarItems(currentPage: PageId): FeatureNavItem[] { const link = (feature: FeatureDestination): FeatureNavItem => ({ title: feature.title, icon: feature.icon, pageId: feature.pageId, url: routeHref(feature.pageId), isActive: currentPage === feature.pageId || (feature.pageId === "dashboard" && currentPage.startsWith("dashboard/")), }); return [ link(featureDestinations[0]), ...groups.map((group) => { const items = featureDestinations .filter((feature) => feature.group === group.title) .map((feature) => ({ title: feature.title, pageId: feature.pageId, url: routeHref(feature.pageId), isActive: currentPage === feature.pageId, })); return { title: group.title, icon: group.icon, url: items[0].url, isActive: items.some((item) => item.isActive), items, }; }), ...featureDestinations .filter( (feature) => !feature.group && !["dashboard", "globals", "system/info"].includes(feature.pageId), ) .map(link), ]; } export function featureBreadcrumbs(page: PageId) { const feature = featureDestinations.find((item) => item.pageId === page); if (feature) return { title: feature.title, group: feature.group, siblings: feature.group ? featureDestinations.filter((item) => item.group === feature.group) : [], }; if (page.startsWith("dashboard/")) return { title: page === "dashboard/analytics" ? "Analytics" : page === "dashboard/reports" ? "Reports" : "Overview", group: "Dashboard", siblings: [], }; return { title: page === "orders" ? "Orders" : page === "products" ? "Products" : "Dashboard", siblings: [], }; } export function searchableFeatures(isPro: boolean) { return featureDestinations.filter((feature) => !feature.proOnly || isPro); } /** Match task words and aliases, not scattered letters across unrelated keywords. */ export function featureSearchScore(value: string, query: string) { const normalize = (text: string) => text.toLowerCase().replace(/[-_]/g, " "); const haystack = normalize(value); return normalize(query) .trim() .split(/\s+/) .every((word) => haystack.includes(word)) ? 1 : 0; }