/**
 * Browser Mocks for Testing
 *
 * Centralized browser API mocks for testing React components in jsdom environment.
 * These mocks are required for Mantine components and other UI libraries.
 *
 * @note This file is only used in test environments with jsdom.
 */

/* eslint-disable @typescript-eslint/no-explicit-any */

/**
 * Mock window.matchMedia for testing
 * Required for Mantine components that use media queries
 */
export function setupMatchMedia(): void {
  const win = (globalThis as any).window
  if (typeof win === 'undefined') return

  Object.defineProperty(win, 'matchMedia', {
    writable: true,
    value: (query: string) => ({
      matches: false,
      media: query,
      onchange: null,
      addListener: () => {},
      removeListener: () => {},
      addEventListener: () => {},
      removeEventListener: () => {},
      dispatchEvent: () => true
    })
  })
}

/**
 * Mock ResizeObserver for testing
 * Required for Mantine components that observe element size changes
 */
export function setupResizeObserver(): void {
  ;(globalThis as any).ResizeObserver = class ResizeObserver {
    observe() {}
    unobserve() {}
    disconnect() {}
  }
}

/**
 * Setup all browser mocks at once
 * Convenience function for test setup files
 */
export function setupBrowserMocks(): void {
  setupMatchMedia()
  setupResizeObserver()
}
