import { describe, it, expect, beforeEach } from 'vitest';
import { magneticHover } from './magnetic-hover.js';
import { mountHost, connectTrait, resetDOM } from '../test-helpers.js';

describe('magnetic-hover', () => {
  beforeEach(resetDOM);

  it('pointermove sets data-magnetic-hover-active', () => {
    const host = mountHost();
    connectTrait(magneticHover, host);
    host.dispatchEvent(new PointerEvent('pointermove', { clientX: 50, clientY: 50, bubbles: true }));
    expect(host.hasAttribute('data-magnetic-hover-active')).toBe(true);
  });

  it('pointerleave clears active + resets translate', () => {
    const host = mountHost();
    connectTrait(magneticHover, host);
    host.dispatchEvent(new PointerEvent('pointermove', { clientX: 50, clientY: 50, bubbles: true }));
    host.dispatchEvent(new PointerEvent('pointerleave', { bubbles: true }));
    expect(host.hasAttribute('data-magnetic-hover-active')).toBe(false);
  });

  it('disconnect clears all listeners + active state', () => {
    const host = mountHost();
    const inst = connectTrait(magneticHover, host);
    host.dispatchEvent(new PointerEvent('pointermove', { clientX: 0, clientY: 0, bubbles: true }));
    inst.disconnect(host);
    expect(host.hasAttribute('data-magnetic-hover-active')).toBe(false);
  });
});
