import type { LucideIcon } from "lucide-react";
import {
  Award,
  BarChart3,
  Building2,
  Coins,
  Gift,
  Handshake,
  LayoutDashboard,
  Megaphone,
  Puzzle,
  Share2,
  Shield,
  SlidersHorizontal,
  Sparkles,
  Users,
  Wallet,
} from "lucide-react";

export type LoyaltyPortalId = "engage";

export type PortalNavItem = {
  id: string;
  label: string;
  href: string;
  shortcut?: string;
};

export type PortalNavGroup = {
  id: string;
  label: string;
  icon: LucideIcon;
  href?: string;
  items?: PortalNavItem[];
};

export const LOYALTY_PORTALS: {
  id: LoyaltyPortalId;
  label: string;
  description: string;
  basePath: string;
  icon: LucideIcon;
}[] = [
  {
    id: "engage",
    label: "تعامل و وفاداری",
    description: "عضویت، امتیاز، پاداش، کمپین، معرفی و کیف پول مشتری",
    basePath: "/loyalty/engage/dashboard/executive",
    icon: Handshake,
  },
];

export const ENGAGE_NAV: PortalNavGroup[] = [
  {
    id: "dashboards",
    label: "داشبوردها",
    icon: LayoutDashboard,
    items: [
      { id: "executive", label: "مدیریتی", href: "/loyalty/engage/dashboard/executive" },
      { id: "member-dashboard", label: "عضو", href: "/loyalty/engage/dashboard/member-dashboard" },
      { id: "gamification", label: "گیمیفیکیشن", href: "/loyalty/engage/dashboard/gamification" },
      { id: "retention", label: "نگهداشت", href: "/loyalty/engage/dashboard/retention" },
      { id: "engagement", label: "تعامل", href: "/loyalty/engage/dashboard/engagement" },
      {
        id: "campaign-performance",
        label: "عملکرد کمپین",
        href: "/loyalty/engage/dashboard/campaign-performance",
      },
      { id: "clv", label: "ارزش طول عمر مشتری", href: "/loyalty/engage/dashboard/clv" },
    ],
  },
  {
    id: "membership",
    label: "عضویت",
    icon: Users,
    items: [
      { id: "programs", label: "برنامه‌ها", href: "/loyalty/engage/programs" },
      { id: "tiers", label: "سطوح عضویت", href: "/loyalty/engage/tiers" },
      { id: "members", label: "اعضا", href: "/loyalty/engage/members" },
      { id: "customer-profile", label: "پروفایل مشتری", href: "/loyalty/engage/customer-profile" },
      { id: "membership-cards", label: "کارت عضویت", href: "/loyalty/engage/membership-cards" },
      { id: "digital-cards", label: "کارت دیجیتال", href: "/loyalty/engage/digital-cards" },
      { id: "qr-cards", label: "کارت QR", href: "/loyalty/engage/qr-cards" },
    ],
  },
  {
    id: "points",
    label: "امتیاز",
    icon: Coins,
    items: [
      { id: "point-accounts", label: "حساب‌های امتیاز", href: "/loyalty/engage/point-accounts" },
      { id: "point-transactions", label: "تراکنش امتیاز", href: "/loyalty/engage/point-transactions" },
      { id: "point-rules", label: "قوانین امتیاز", href: "/loyalty/engage/point-rules" },
      { id: "earning-rules", label: "قوانین کسب امتیاز", href: "/loyalty/engage/earning-rules" },
      {
        id: "redemption-rules",
        label: "قوانین استفاده از امتیاز",
        href: "/loyalty/engage/redemption-rules",
      },
      { id: "expiration-rules", label: "قوانین انقضا", href: "/loyalty/engage/expiration-rules" },
    ],
  },
  {
    id: "rewards",
    label: "پاداش‌ها",
    icon: Gift,
    items: [
      { id: "reward-catalog", label: "کاتالوگ پاداش", href: "/loyalty/engage/reward-catalog" },
      { id: "rewards", label: "پاداش‌ها", href: "/loyalty/engage/rewards" },
      { id: "coupons", label: "کوپن‌ها", href: "/loyalty/engage/coupons" },
      { id: "vouchers", label: "واچرها", href: "/loyalty/engage/vouchers" },
      { id: "gift-cards", label: "کارت هدیه", href: "/loyalty/engage/gift-cards" },
    ],
  },
  {
    id: "campaigns",
    label: "کمپین‌ها",
    icon: Megaphone,
    items: [
      { id: "campaigns", label: "کمپین‌ها", href: "/loyalty/engage/campaigns" },
      { id: "promotions", label: "تبلیغات فعال", href: "/loyalty/engage/promotions" },
      { id: "challenges", label: "چالش‌ها", href: "/loyalty/engage/challenges" },
      { id: "missions", label: "مأموریت‌ها", href: "/loyalty/engage/missions" },
      { id: "achievements", label: "دستاوردها", href: "/loyalty/engage/achievements" },
      { id: "badges", label: "نشان‌ها", href: "/loyalty/engage/badges" },
    ],
  },
  {
    id: "referrals",
    label: "معرفی و ارجاع",
    icon: Share2,
    items: [
      { id: "referral-programs", label: "برنامه‌های معرفی", href: "/loyalty/engage/referral-programs" },
      { id: "referral-codes", label: "کدهای معرفی", href: "/loyalty/engage/referral-codes" },
      { id: "referrals", label: "ارجاعات", href: "/loyalty/engage/referrals" },
      { id: "referral-rewards", label: "پاداش معرفی", href: "/loyalty/engage/referral-rewards" },
    ],
  },
  {
    id: "wallet",
    label: "کیف پول",
    icon: Wallet,
    items: [
      { id: "wallets", label: "کیف پول‌ها", href: "/loyalty/engage/wallets" },
      { id: "benefits", label: "مزایا", href: "/loyalty/engage/benefits" },
    ],
  },
  {
    id: "audience",
    label: "مخاطبان",
    icon: Puzzle,
    items: [
      { id: "segments", label: "سگمنت‌ها", href: "/loyalty/engage/segments" },
      { id: "audience-builder", label: "سازنده مخاطب", href: "/loyalty/engage/audience-builder" },
    ],
  },
  {
    id: "rules",
    label: "قوانین",
    icon: SlidersHorizontal,
    items: [
      { id: "discount-rules", label: "قوانین تخفیف", href: "/loyalty/engage/discount-rules" },
      { id: "renewal-rules", label: "قوانین تمدید", href: "/loyalty/engage/renewal-rules" },
    ],
  },
  {
    id: "partners",
    label: "شرکا",
    icon: Building2,
    items: [
      { id: "partner-programs", label: "برنامه‌های شریک", href: "/loyalty/engage/partner-programs" },
      { id: "branches", label: "شعب", href: "/loyalty/engage/branches" },
    ],
  },
  {
    id: "analytics",
    label: "گزارش‌ها",
    icon: BarChart3,
    items: [
      { id: "reports", label: "گزارش‌ها", href: "/loyalty/engage/reports" },
      { id: "analytics", label: "تحلیل‌ها", href: "/loyalty/engage/analytics" },
    ],
  },
  {
    id: "admin",
    label: "مدیریت",
    icon: Shield,
    items: [
      { id: "notifications", label: "اعلان‌ها", href: "/loyalty/engage/notifications" },
      { id: "audit-logs", label: "لاگ ممیزی", href: "/loyalty/engage/audit-logs" },
      { id: "permissions", label: "دسترسی‌ها", href: "/loyalty/engage/permissions" },
      { id: "roles", label: "نقش‌ها", href: "/loyalty/engage/roles" },
      { id: "api-keys", label: "کلید API", href: "/loyalty/engage/api-keys" },
      { id: "integrations", label: "یکپارچه‌سازی", href: "/loyalty/engage/integrations" },
      { id: "health", label: "سلامت سرویس", href: "/loyalty/engage/health" },
      { id: "capabilities", label: "قابلیت‌ها", href: "/loyalty/engage/capabilities" },
    ],
  },
];

export function navForPortal(portalId: LoyaltyPortalId): PortalNavGroup[] {
  if (portalId === "engage") return ENGAGE_NAV;
  return [];
}

export function detectPortal(pathname: string): LoyaltyPortalId | null {
  if (pathname.startsWith("/loyalty/engage")) return "engage";
  return null;
}

/** Keyboard shortcuts map */
export const LOYALTY_SHORTCUTS: Record<string, string> = {
  "g h": "/loyalty/hub",
  "g m": "/loyalty/engage/members",
  "g p": "/loyalty/engage/programs",
  "g r": "/loyalty/engage/rewards",
  "g c": "/loyalty/engage/campaigns",
  "g w": "/loyalty/engage/wallets",
};

/** Icon export used by hub cards elsewhere. */
export const LOYALTY_HUB_ICON: LucideIcon = Sparkles;
export const LOYALTY_AWARD_ICON: LucideIcon = Award;
