import { server } from '../chunk-7XKCG5CT.js';
import { setupBrowserMocks } from '../chunk-HJ4CJIWN.js';
import { mockUseAuth } from '../chunk-DRQPEMJI.js';
import '../chunk-I2KLQ2HA.js';
import '@testing-library/jest-dom/vitest';
import { cleanup } from '@testing-library/react';
import { vi, beforeAll, afterEach, afterAll, expect } from 'vitest';

setupBrowserMocks();
vi.mock("@workos-inc/authkit-react", () => ({
  useAuth: () => mockUseAuth
}));
vi.mock("@elevasis/ui/auth/context", () => ({
  useAuthContext: () => mockUseAuth,
  AuthProvider: ({ children }) => children
}));
vi.mock("@elevasis/ui/router/context", () => ({
  useRouterContext: () => ({
    currentPath: "/",
    navigate: vi.fn(),
    Link: "a"
  }),
  RouterProvider: ({ children }) => children
}));
vi.doMock("@elevasis/ui/organization", () => ({
  useOrganization: () => ({
    currentWorkOSOrganizationId: "test-org-id",
    currentSupabaseOrganizationId: "test-supabase-org-id",
    currentMembership: { id: "test-membership-id", organizationId: "test-org-id" },
    memberships: [],
    switchOrganization: vi.fn()
  }),
  OrganizationProvider: ({ children }) => children,
  OrganizationSwitcher: () => null
}));
var mockApiUrl = "https://api.elevasis.io";
async function mockApiRequest(endpoint, options = {}) {
  const response = await fetch(`${mockApiUrl}/api${endpoint}`, {
    headers: {
      ...options.body ? { "Content-Type": "application/json" } : {},
      ...options.headers
    },
    ...options
  });
  if (!response.ok) {
    throw new Error(`HTTP ${response.status}`);
  }
  if (response.status === 204) {
    return void 0;
  }
  return response.json();
}
vi.doMock("@elevasis/ui/api", () => ({
  useApiClient: () => ({
    apiRequest: mockApiRequest,
    deferredApiRequest: mockApiRequest,
    isOrganizationReady: true,
    isInitializing: false
  }),
  ApiClientProvider: ({ children }) => children,
  useApiClientContext: vi.fn()
}));
var isIntegrationTest = () => {
  try {
    return expect.getState().testPath?.includes("integration.test") ?? false;
  } catch {
    return false;
  }
};
if (!isIntegrationTest()) {
  beforeAll(() => {
    server.listen({ onUnhandledRequest: "warn" });
  });
  afterEach(() => {
    cleanup();
    server.resetHandlers();
  });
  afterAll(() => {
    server.close();
  });
} else {
  afterEach(() => {
    cleanup();
  });
}
