/**
 * Mock implementation of IntersectionObserver for jsdom testing environment.
 *
 * jsdom does not implement IntersectionObserver, so this mock allows testing
 * components that rely on intersection detection (e.g., lazy loading, view tracking).
 *
 * @example
 * ```typescript
 * import {
 *   setupIntersectionObserverMock,
 *   teardownIntersectionObserverMock,
 *   resetIntersectionObserverMock,
 *   triggerIntersection,
 *   triggerAllIntersections,
 * } from '../test-utils/IntersectionObserverMock';
 *
 * describe('MyComponent', () => {
 *   beforeAll(() => {
 *     setupIntersectionObserverMock();
 *   });
 *
 *   afterAll(() => {
 *     teardownIntersectionObserverMock();
 *   });
 *
 *   beforeEach(() => {
 *     resetIntersectionObserverMock();
 *   });
 *
 *   it('tracks element visibility', async () => {
 *     render(<MyComponent />);
 *     const element = screen.getByTestId('tracked-element');
 *
 *     triggerIntersection(element);
 *
 *     expect(onVisibleSpy).toHaveBeenCalled();
 *   });
 * });
 * ```
 */
// Track all observer instances so we can trigger intersections on any of them
const observerInstances = new Set();
class MockIntersectionObserverInstance {
    constructor(callback) {
        this.root = null;
        this.rootMargin = '';
        this.thresholds = [];
        this.observedElements = new Set();
        this.callback = callback;
        observerInstances.add(this);
    }
    observe(target) {
        this.observedElements.add(target);
    }
    unobserve(target) {
        this.observedElements.delete(target);
    }
    disconnect() {
        this.observedElements.clear();
        observerInstances.delete(this);
    }
    takeRecords() {
        return [];
    }
    /**
     * Test helper: trigger intersection for a specific element on this observer.
     * Calls the observer callback with isIntersecting: true for the given element.
     */
    triggerIntersection(element) {
        if (!this.observedElements.has(element)) {
            return;
        }
        const entry = {
            target: element,
            isIntersecting: true,
            intersectionRatio: 1,
            boundingClientRect: element.getBoundingClientRect(),
            intersectionRect: element.getBoundingClientRect(),
            rootBounds: null,
            time: Date.now(),
        };
        this.callback([entry], this);
    }
    /**
     * Test helper: trigger intersection for all observed elements on this observer.
     */
    triggerAllIntersections() {
        this.observedElements.forEach((element) => this.triggerIntersection(element));
    }
}
/**
 * Trigger intersection for a specific element across all observer instances.
 * Use this when you know which element you want to mark as visible.
 */
export const triggerIntersection = (element) => {
    observerInstances.forEach((observer) => observer.triggerIntersection(element));
};
/**
 * Trigger intersection for all observed elements across all observer instances.
 * Use this to simulate all tracked elements becoming visible at once.
 */
export const triggerAllIntersections = () => {
    observerInstances.forEach((observer) => observer.triggerAllIntersections());
};
/**
 * Set up the IntersectionObserver mock on the global object.
 * Call this in beforeAll() before your tests run.
 */
export const setupIntersectionObserverMock = () => {
    observerInstances.clear();
    global.IntersectionObserver = MockIntersectionObserverInstance;
};
/**
 * Tear down the IntersectionObserver mock from the global object.
 * Call this in afterAll() after your tests complete.
 */
export const teardownIntersectionObserverMock = () => {
    observerInstances.clear();
    delete global.IntersectionObserver;
};
/**
 * Reset all observer instances between tests.
 * Call this in beforeEach() to ensure test isolation.
 */
export const resetIntersectionObserverMock = () => {
    observerInstances.clear();
};
/**
 * Get all currently active observer instances.
 * Useful for debugging or advanced test scenarios.
 */
export const getObserverInstances = () => observerInstances;
//# sourceMappingURL=IntersectionObserverMock.js.map