import type { NavItemConfig } from '@/types/nav';
import { paths } from '@/paths';
import type { User } from '@/types/user';

interface NavItem {
  key: string;
  title: string;
  href?: string;
  icon?: string;
  items?: NavItem[];
}

// Navigation items visible to all logged-in users
const commonNavItems: NavItem[] = [
  { key: 'overview', title: 'Overview', href: paths.dashboard.overview, icon: 'chart-pie' },
  { key: 'customers', title: 'Patients', href: paths.dashboard.customers, icon: 'users' },
  { key: 'providers', title: 'Providers', href: paths.dashboard.providers, icon: 'stethoscope' },
  { key: 'appointments', title: 'Appointments', href: paths.dashboard.appointments, icon: 'users' },
];

// Navigation items specific to the 'admin' role
const adminNavItems: NavItem[] = [
  { key: 'companies', title: 'Companies', href: paths.dashboard.companies, icon: 'buildings' },

  { key: 'managers', title: 'Managers', href: paths.dashboard.managers, icon: 'users' },

  { key: 'account', title: 'Account', href: paths.dashboard.account, icon: 'user' },
  // Add more admin-specific items here if needed
];

// Navigation items specific to the 'manager' role (can be empty or have manager-specific items)
const managerNavItems: NavItem[] = [
  { key: 'visitTypes', title: 'Visit Types', href: paths.dashboard.visittypes, icon: 'appointment' },
  { key: 'providerAreas', title: 'Provider Areas', href: paths.dashboard.providerareas, icon: 'map' },
  { key: 'chats', title: 'Chats', href: paths.dashboard.chats, icon: 'chat' },

  { key: 'patientTagSetting', title: 'Patient Tag Settings', href: paths.dashboard.patienttags, icon: 'tag' },
  { key: 'providerTagSetting', title: 'Provider Tag Settings', href: paths.dashboard.providertags, icon: 'tag' },
  { key: 'reports', title: 'Reports', href: paths.dashboard.reports, icon: 'report' },





];

export const getNavItems = (user: User | null): NavItemConfig[] => {
  if (!user) {
    return [];
  }

  let navItems: NavItem[] = [...commonNavItems];

  if (user.role === 'admin') {
    navItems = [...navItems, ...adminNavItems];
  } else if (user.role === 'manager') {
    navItems = [...navItems, ...managerNavItems];
    // Managers also see the common items
  }

  // Convert back to NavItemConfig[] to satisfy the type
  return navItems.map(item => ({
    key: item.key,
    title: item.title,
    href: item.href,
    icon: item.icon,
    items: item.items,
  }));
};