class MockPerformanceObserver {
  callback;
  constructor(callback) {
    this.callback = callback;
    global.__performanceObserver = this;
  }
  observe() {
  }
  disconnect() {
  }
}
const mockMarks = /* @__PURE__ */ new Map();
const mockMeasures = [];
const originalPerformance = global.performance;
function setupPerformanceMock() {
  global.PerformanceObserver = MockPerformanceObserver;
  global.performance = {
    ...originalPerformance,
    timeOrigin: 16094592e5,
    // January 1, 2021 00:00:00 UTC
    now: jest.fn(() => 1e3),
    // Return fixed value for consistent testing
    mark: jest.fn((name, options) => {
      const mark = {
        name,
        entryType: "mark",
        startTime: 1e3,
        duration: 0,
        detail: options?.detail,
        toJSON: () => ({})
      };
      mockMarks.set(name, mark);
      return mark;
    }),
    measure: jest.fn((name, options) => {
      const measure = {
        name,
        entryType: "measure",
        startTime: 1e3,
        duration: 100,
        detail: options?.detail,
        toJSON: () => ({})
      };
      mockMeasures.push(measure);
      const observer = global.__performanceObserver;
      if (observer) {
        const list = {
          getEntries: () => [measure],
          getEntriesByName: () => [measure],
          getEntriesByType: () => [measure]
        };
        setTimeout(() => observer.callback(list, observer), 0);
      }
      return measure;
    }),
    clearMarks: jest.fn((name) => {
      if (name) {
        mockMarks.delete(name);
      } else {
        mockMarks.clear();
      }
    }),
    getEntriesByName: jest.fn((name, type) => {
      if (type === "mark") {
        const mark = mockMarks.get(name);
        return mark ? [mark] : [];
      }
      return mockMeasures.filter((m) => m.name === name);
    })
  };
}
function clearPerformanceMock() {
  mockMarks.clear();
  mockMeasures.length = 0;
}
function restorePerformance() {
  if (originalPerformance) {
    global.performance = originalPerformance;
  }
  delete global.__performanceObserver;
}
export {
  MockPerformanceObserver,
  clearPerformanceMock,
  mockMarks,
  mockMeasures,
  originalPerformance,
  restorePerformance,
  setupPerformanceMock
};
