import {
  LayoutDashboard,
  Users,
  UserCog,
  ShieldCheck,
  Settings,
  Key,
  Smartphone,
  User,
  LogOut,
  BarChart3,
  FileText,
  Bell,
} from 'lucide-react';
import { Role } from '@/types';

export interface NavItem {
  key: string;
  label: string;
  href: string;
  icon: any;
  roles: Role[];
  badge?: string;
  children?: NavItem[];
}

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

export const navigation: NavSection[] = [
  // ---------------------------------------------------------------
  // Section 1 — Tang Studio Platform (data for dashboard.tang-studio.com)
  // ---------------------------------------------------------------
  {
    title: 'Tang Studio',
    items: [
      {
        key: 'overview',
        label: 'Overview',
        href: '/dashboard',
        icon: LayoutDashboard,
        roles: ['master-admin', 'admin', 'operator'],
      },
      {
        key: 'analytics',
        label: 'Analytics',
        href: '/dashboard/analytics',
        icon: BarChart3,
        roles: ['master-admin', 'admin'],
      },
      {
        key: 'content',
        label: 'Content',
        href: '/dashboard/content',
        icon: FileText,
        roles: ['master-admin', 'admin', 'operator'],
      },
      {
        key: 'notifications',
        label: 'Notifications',
        href: '/dashboard/notifications',
        icon: Bell,
        roles: ['master-admin', 'admin', 'operator'],
      },
    ],
  },
  // ---------------------------------------------------------------
  // Section 2 — User Access Management
  // ---------------------------------------------------------------
  {
    title: 'Access Management',
    items: [
      {
        key: 'users',
        label: 'All Users',
        href: '/dashboard/users',
        icon: Users,
        roles: ['master-admin', 'admin'],
      },
      {
        key: 'admins',
        label: 'Admins',
        href: '/dashboard/users?role=admin',
        icon: ShieldCheck,
        roles: ['master-admin', 'admin'],
      },
      {
        key: 'operators',
        label: 'Operators',
        href: '/dashboard/users?role=operator',
        icon: UserCog,
        roles: ['master-admin', 'admin'],
      },
    ],
  },
  // ---------------------------------------------------------------
  // Section 3 — Account (always visible)
  // ---------------------------------------------------------------
  {
    title: 'Account',
    items: [
      {
        key: 'profile',
        label: 'My Profile',
        href: '/dashboard/profile',
        icon: User,
        roles: ['master-admin', 'admin', 'operator'],
      },
      {
        key: 'security',
        label: 'Security & 2FA',
        href: '/dashboard/profile/security',
        icon: Key,
        roles: ['master-admin', 'admin', 'operator'],
      },
      {
        key: 'devices',
        label: 'Devices',
        href: '/dashboard/profile/devices',
        icon: Smartphone,
        roles: ['master-admin', 'admin', 'operator'],
      },
    ],
  },
];

export function filterNavForRole(role: Role): NavSection[] {
  return navigation
    .map((section) => ({
      ...section,
      items: section.items.filter((item) => item.roles.includes(role)),
    }))
    .filter((section) => section.items.length > 0);
}
