// Test setup file for Vitest

import { vi } from "vitest";

// Setup window.__TAURI_OS_PLUGIN_INTERNALS__ before any imports
if (typeof window !== "undefined") {
  Object.defineProperty(window, "__TAURI_OS_PLUGIN_INTERNALS__", {
    writable: true,
    configurable: true,
    value: {
      platform: "linux",
    },
  });
}

// Mock SvelteKit environment
vi.mock("$app/environment", () => ({
  browser: true,
  dev: false,
  building: false,
  version: "test",
}));

// Mock Tauri API
vi.mock("@tauri-apps/api/core", () => ({
  invoke: vi.fn(),
}));

// Mock Tauri event API
vi.mock("@tauri-apps/api/event", () => ({
  listen: vi.fn(),
  emit: vi.fn(),
}));

// Mock Tauri OS plugin
vi.mock("@tauri-apps/plugin-os", () => ({
  platform: vi.fn(() => "linux"),
}));

// Setup global test utilities
global.ResizeObserver = vi.fn().mockImplementation(() => ({
  observe: vi.fn(),
  unobserve: vi.fn(),
  disconnect: vi.fn(),
}));

// 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(),
  })),
});
