import { beforeEach } from 'vitest';
import '@testing-library/jest-dom/vitest';

// jsdom polyfills for react-flow
if (typeof window !== 'undefined') {
  if (!window.matchMedia) {
    window.matchMedia = (query) => ({
      matches: false,
      media: query,
      onchange: null,
      addEventListener: () => {},
      removeEventListener: () => {},
      addListener: () => {},
      removeListener: () => {},
      dispatchEvent: () => false,
    });
  }
  if (!window.ResizeObserver) {
    window.ResizeObserver = class {
      observe() {}
      unobserve() {}
      disconnect() {}
    };
  }
  if (!window.DOMMatrixReadOnly) {
    window.DOMMatrixReadOnly = class {
      constructor() {}
      m22 = 1;
    };
  }
}

beforeEach(() => {
  localStorage.clear();
});
