import React from 'react';
import { describe, expect, it, vi } from 'vitest';
import { render, screen } from '@testing-library/react';

const navigateMock = vi.fn();

vi.mock('react-router-dom', () => ({
  useNavigate: () => navigateMock,
  useParams: () => ({}),
  useLocation: () => ({ search: '' }),
}));

vi.mock('react-i18next', () => ({
  useTranslation: () => ({
    t: (key: string, fallback?: string | Record<string, unknown>) => {
      if (typeof fallback === 'string') {
        return fallback;
      }
      if (fallback && typeof fallback === 'object' && typeof fallback.defaultValue === 'string') {
        return fallback.defaultValue;
      }
      return key;
    },
  }),
}));

vi.mock('../../api', () => ({
  listNotificationLogs: vi.fn().mockResolvedValue([]),
  markNotificationLogs: vi.fn(),
  getEvents: vi.fn().mockResolvedValue([]),
}));

vi.mock('../../auth/tokens', () => ({
  isAuthError: () => false,
}));

vi.mock('../../lib/apiError', () => ({
  getApiErrorMessage: () => 'error',
}));

vi.mock('../lib/notificationGrouping', () => ({
  groupNotificationsByScope: () => [],
}));

vi.mock('../lib/notificationUnread', () => ({
  collectUnreadIds: () => [],
}));

vi.mock('../lib/relativeTime', () => ({
  formatRelativeTime: () => 'now',
}));

vi.mock('../lib/haptics', () => ({
  triggerHaptic: () => undefined,
}));

vi.mock('../hooks/useBackNavigation', () => ({
  useBackNavigation: () => undefined,
}));

vi.mock('framer-motion', () => ({
  motion: {
    div: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
  },
  useAnimationControls: () => ({ start: vi.fn() }),
}));

vi.mock('@tamagui/react-native-web-lite', () => ({
  Pressable: ({ children, onPress }: { children: React.ReactNode; onPress?: () => void }) => (
    <button type="button" onClick={onPress}>
      {children}
    </button>
  ),
}));

vi.mock('@tamagui/stacks', () => ({
  YStack: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
  XStack: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));

vi.mock('@tamagui/text', () => ({
  SizableText: ({ children }: { children: React.ReactNode }) => <span>{children}</span>,
}));

vi.mock('@tamagui/toggle-group', () => ({
  ToggleGroup: Object.assign(({ children }: { children: React.ReactNode }) => <div>{children}</div>, {
    Item: ({ children }: { children: React.ReactNode }) => <button type="button">{children}</button>,
  }),
}));

vi.mock('../components/MobileShell', () => ({
  MobileShell: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
  HeaderActionButton: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));

vi.mock('../components/Primitives', () => ({
  MobileCard: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
  PillBadge: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
  SkeletonCard: () => <div>Loading...</div>,
  CTAButton: ({ label }: { label: string }) => <button type="button">{label}</button>,
}));

vi.mock('../components/FormControls', () => ({
  MobileSelect: ({ children }: { children: React.ReactNode }) => <select>{children}</select>,
}));

vi.mock('../components/Sheet', () => ({
  MobileSheet: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));

vi.mock('../theme', () => ({
  useAdminTheme: () => ({
    textStrong: '#111827',
    text: '#111827',
    muted: '#6b7280',
    subtle: '#94a3b8',
    border: '#e5e7eb',
    primary: '#ff5a5f',
    danger: '#dc2626',
    successBg: '#dcfce7',
    successText: '#166534',
    infoBg: '#e0e7ff',
    infoText: '#3730a3',
  }),
}));

import MobileNotificationsPage from '../NotificationsPage';

describe('MobileNotificationsPage', () => {
  it('shows empty state when no notifications are available', async () => {
    render(<MobileNotificationsPage />);

    expect(await screen.findByText('All caught up')).toBeInTheDocument();
  });
});
