import { describe, it, expect, beforeEach } from 'vitest';
import { glowFocus } from './glow-focus.js';
import { mountHost, connectTrait, resetDOM } from '../test-helpers.js';

describe('glow-focus', () => {
  beforeEach(resetDOM);

  it('focus sets data-glow-focus-active and applies box-shadow', () => {
    const host = mountHost();
    connectTrait(glowFocus, host);
    host.dispatchEvent(new FocusEvent('focus'));
    expect(host.hasAttribute('data-glow-focus-active')).toBe(true);
    expect(host.style.boxShadow).toContain('rgba(59, 130, 246');
  });

  it('blur clears active + restores box-shadow', () => {
    const host = mountHost();
    connectTrait(glowFocus, host);
    host.dispatchEvent(new FocusEvent('focus'));
    host.dispatchEvent(new FocusEvent('blur'));
    expect(host.hasAttribute('data-glow-focus-active')).toBe(false);
  });

  it('disconnect mid-focus clears active', () => {
    const host = mountHost();
    const inst = connectTrait(glowFocus, host);
    host.dispatchEvent(new FocusEvent('focus'));
    inst.disconnect(host);
    expect(host.hasAttribute('data-glow-focus-active')).toBe(false);
  });
});
