/// <reference types="vitest/globals" />
import { beforeAll, afterEach, afterAll } from 'vitest';
import { setupServer } from 'msw/node';
import { http, HttpResponse } from 'msw';

// Mock API responses globally for frontend tests
const server = setupServer(
  http.get('/api/admin/companies', () => HttpResponse.json([
      { id: '1', company_name: 'Test Co', status: 'ACTIVE' }
    ])),
  http.get('/api/admin/users', () => HttpResponse.json([
      { id: '1', full_name: 'Admin User', email: 'admin@example.com', status: 'ACTIVE' }
    ])),
  http.get('/api/admin/jobs', () => HttpResponse.json([
      { id: '1', title: 'Developer', status: 'OPEN' }
    ])),
  http.get('/api/admin/leads', () => HttpResponse.json([
      { id: '1', title: 'Need a developer', status: 'PENDING' }
    ]))
);

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

// Mock window.matchMedia
Object.defineProperty(window, 'matchMedia', {
  writable: true,
  value: vi.fn().mockImplementation(query => ({
    matches: false,
    media: query,
    onchange: null,
    addListener: vi.fn(),
    removeListener: vi.fn(),
    addEventListener: vi.fn(),
    removeEventListener: vi.fn(),
    dispatchEvent: vi.fn(),
  })),
});

// Mock IntersectionObserver
(global as any).IntersectionObserver = class IntersectionObserver {
  root = null;
  rootMargin = '';
  thresholds: number[] = [];
  constructor() {}
  disconnect() {}
  observe() {}
  unobserve() {}
  takeRecords() { return []; }
};

// Mock ResizeObserver
global.ResizeObserver = class ResizeObserver {
  constructor() {}
  observe() {}
  unobserve() {}
  disconnect() {}
};
