import '@testing-library/jest-dom/vitest';

Object.defineProperty(HTMLCanvasElement.prototype, 'getContext', {
  value: () => ({
    fillStyle: '',
    fillRect: () => undefined,
    clearRect: () => undefined,
    getImageData: () => ({ data: new Uint8ClampedArray(4) }),
    putImageData: () => undefined,
    createImageData: () => ({ data: new Uint8ClampedArray(4) }),
    setTransform: () => undefined,
    drawImage: () => undefined,
    save: () => undefined,
    fillText: () => undefined,
    restore: () => undefined,
    beginPath: () => undefined,
    moveTo: () => undefined,
    lineTo: () => undefined,
    closePath: () => undefined,
    stroke: () => undefined,
    translate: () => undefined,
    scale: () => undefined,
    rotate: () => undefined,
    arc: () => undefined,
    fill: () => undefined,
    measureText: () => ({ width: 0 }),
    transform: () => undefined,
    rect: () => undefined,
    clip: () => undefined
  })
});

class TestResizeObserver {
  observe() {
    return undefined;
  }
  unobserve() {
    return undefined;
  }
  disconnect() {
    return undefined;
  }
}

Object.defineProperty(window, 'ResizeObserver', { value: TestResizeObserver });
Object.defineProperty(globalThis, 'ResizeObserver', { value: TestResizeObserver });

Object.defineProperty(navigator, 'clipboard', {
  configurable: true,
  value: {
    writeText: () => Promise.resolve()
  }
});

Object.defineProperty(window, 'matchMedia', {
  value: (query: string) => ({
    matches: false,
    media: query,
    onchange: null,
    addListener: () => undefined,
    removeListener: () => undefined,
    addEventListener: () => undefined,
    removeEventListener: () => undefined,
    dispatchEvent: () => false
  })
});

Object.defineProperty(URL, 'createObjectURL', {
  configurable: true,
  value: () => 'blob:test'
});

Object.defineProperty(URL, 'revokeObjectURL', {
  configurable: true,
  value: () => undefined
});

document.createRange = () => ({
  setStart: () => undefined,
  setEnd: () => undefined,
  selectNodeContents: () => undefined,
  detach: () => undefined,
  commonAncestorContainer: document.body,
  getBoundingClientRect: () => ({
    bottom: 0,
    height: 0,
    left: 0,
    right: 0,
    top: 0,
    width: 0,
    x: 0,
    y: 0,
    toJSON: () => undefined
  }),
  getClientRects: () => ({
    length: 0,
    item: () => null,
    [Symbol.iterator]: function* iterator() {
      return undefined;
    }
  })
} as unknown as Range);
