export type NavItem = {
  label: string; // i18n key under "nav.*"
  href: string;
  protected?: boolean; // Requires authentication
  public?: boolean; // Accessible without auth
  onlyPublic?: boolean; // Visible only when NOT logged in
  visible?: boolean; // false = exists as route but hidden from nav
  children?: NavItem[];
  icon?: string; // icon identifier for visual enhancement
};

/**
 * Returns nav items filtered by auth state and visibility.
 */
export function getVisibleNavItems(
  items: NavItem[],
  isAuthenticated: boolean,
): NavItem[] {
  return items
    .filter((item) => {
      // Hidden items never show in nav
      if (item.visible === false) return false;
      // onlyPublic items hide when authenticated
      if (item.onlyPublic && isAuthenticated) return false;
      // Protected items hide when not authenticated
      if (item.protected && !isAuthenticated) return false;
      return true;
    })
    .map((item) => {
      // Recursively filter children if they exist
      if (item.children) {
        return {
          ...item,
          children: getVisibleNavItems(item.children, isAuthenticated),
        };
      }
      return item;
    });
}

export const NAV_ITEMS: NavItem[] = [
  // Public — always visible in nav
  { label: "home", href: "/home", public: true },
  { label: "matches", href: "/matches", public: true },
  { label: "leagues", href: "/leagues", public: true },
  { label: "h2h", href: "/h2h", public: true },

  // Protected — grouped for cleaner nav
  { label: "dashboard", href: "/dashboard", protected: true, visible: false },
  {
    label: "predictions",
    href: "/predictions",
    protected: true,
    visible: false,
  },

  // Coupon dropdown group
  {
    label: "coupons",
    href: "/coupon-builder",
    protected: true,
    children: [
      { label: "coupon-builder", href: "/coupon-builder", protected: true },
      {
        label: "coupon-history",
        href: "/coupon-history",
        protected: true,
        visible: false,
      },
    ],
  },

  // Analysis dropdown group
  {
    label: "tools",
    href: "/analysis",
    protected: true,
    visible: false,
    children: [
      { label: "analysis", href: "/analysis", protected: true, visible: false },
      {
        label: "spor-toto",
        href: "/spor-toto",
        protected: true,
        visible: false,
      },
    ],
  },

  // Hidden routes (exist as routes but not in nav)
  { label: "profile", href: "/profile", protected: true, visible: false },
  { label: "admin", href: "/admin", protected: true, visible: false },

  // Only public — hidden when logged in
  {
    label: "how-it-works",
    href: "/how-it-works",
    onlyPublic: true,
    visible: false,
  },
  { label: "pricing", href: "/pricing", public: true, icon: "pricing" },
  { label: "contact", href: "/contact", onlyPublic: true, visible: false },

  // Hidden routes (no nav entry, but route exists)
  {
    label: "privacy-and-security-policy",
    href: "/privacy-and-security-policy",
    visible: false,
  },
  { label: "information-notice", href: "/information-notice", visible: false },
  { label: "terms-of-use", href: "/terms-of-use", visible: false },
];
