import type { ReactNode } from 'react';

// ── Navigation ───────────────────────────────────────────────────────────────

export interface NavItem {
  href: string;
  label: string;
  icon?: ReactNode;
  badge?: string | number;
  /** Hide this item from nav (useful for feature-flag gating) */
  hidden?: boolean;
}

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

// ── User ─────────────────────────────────────────────────────────────────────

export interface ShellUser {
  id: string;
  name: string;
  email: string;
  avatarUrl?: string;
  role?: string;
}

// ── Features ─────────────────────────────────────────────────────────────────

export interface ShellFeatures {
  /** Show profile page link in user menu (default: true) */
  profile?: boolean;
  /** Show billing page link in user menu (default: false) */
  billing?: boolean;
  /** Show settings page link in sidebar (default: true) */
  settings?: boolean;
  /** Show notifications icon in top bar (default: false) */
  notifications?: boolean;
  /** Show dark/light theme toggle (default: false) */
  themeToggle?: boolean;
}

// ── Shell Config ─────────────────────────────────────────────────────────────

export interface DashboardShellProps {
  /** Product display name shown in sidebar header */
  productName: string;
  /** Product logo element (replaces text name if provided) */
  logo?: ReactNode;
  /** Product version shown in sidebar footer */
  version?: string;
  /** Navigation items or sections */
  nav: NavItem[] | NavSection[];
  /** Current pathname for active state (if not using internal detection) */
  pathname?: string;
  /** Currently logged-in user */
  user?: ShellUser;
  /** Feature toggles for built-in pages */
  features?: ShellFeatures;
  /** Called when user clicks Sign Out */
  onSignOut?: () => void;
  /** Called when a nav item is clicked (for SPA routers) */
  onNavigate?: (href: string) => void;
  /**
   * Prefix applied to all built-in route hrefs (`/profile`, `/billing`,
   * `/settings`). For example, `routePrefix="/app"` produces
   * `/app/profile`, `/app/billing`, `/app/settings`. Defaults to `""`
   * (no prefix — preserves pre-0.2.0 behavior).
   *
   * @since 0.2.0
   */
  routePrefix?: string;
  /** Sidebar footer content (replaces default) */
  sidebarFooter?: ReactNode;
  /** Content to render in the top bar (right side) */
  topBarActions?: ReactNode;
  /** Dashboard page content */
  children: ReactNode;
}

// ── Sidebar Props ────────────────────────────────────────────────────────────

export interface SidebarProps {
  productName: string;
  logo?: ReactNode;
  version?: string;
  nav: NavItem[] | NavSection[];
  pathname: string;
  features?: ShellFeatures;
  onNavigate?: (href: string) => void;
  footer?: ReactNode;
  collapsed?: boolean;
  onToggleCollapse?: () => void;
  /** See {@link DashboardShellProps.routePrefix}. @since 0.2.0 */
  routePrefix?: string;
}

// ── Top Bar Props ────────────────────────────────────────────────────────────

export interface TopBarProps {
  user?: ShellUser;
  features?: ShellFeatures;
  onSignOut?: () => void;
  onNavigate?: (href: string) => void;
  actions?: ReactNode;
  onToggleSidebar?: () => void;
  /** See {@link DashboardShellProps.routePrefix}. @since 0.2.0 */
  routePrefix?: string;
}

// ── Built-in Page Props ──────────────────────────────────────────────────────

export interface ProfilePageProps {
  user: ShellUser;
  onUpdateProfile?: (data: { name: string; email: string }) => void;
  isLoading?: boolean;
  error?: string;
  success?: string;
}

export interface BillingPageProps {
  currentPlan?: string;
  status?: 'active' | 'trialing' | 'past_due' | 'canceled';
  trialEndsAt?: string;
  onManageBilling?: () => void;
  plans?: Array<{
    name: string;
    price: string;
    features: string[];
    current?: boolean;
  }>;
}

export interface SettingsPageProps {
  productName: string;
  sections?: SettingsSection[];
}

export interface SettingsSection {
  title: string;
  description?: string;
  content: ReactNode;
}
