import {
  describe,
  it,
  expect,
  vi
} from 'vitest';
import { Injector, runInInjectionContext } from '@angular/core';

import { initializeAppI18nForTests, provideAppI18nForTests } from '../../../core/i18n/app-i18n.testing';
import { ModalBackdropComponent } from './modal-backdrop.component';

function createComponent(): ModalBackdropComponent {
  const injector = Injector.create({
    providers: [...provideAppI18nForTests(), ModalBackdropComponent]
  });

  initializeAppI18nForTests(injector);

  return runInInjectionContext(injector, () => injector.get(ModalBackdropComponent));
}

describe('ModalBackdropComponent', () => {
  it('exposes consistent defaults (centered z-index, blurred, dismissable)', () => {
    const component = createComponent();

    expect(component.zIndex()).toBe(50);
    expect(component.blur()).toBe(true);
    expect(component.dismissable()).toBe(true);
    expect(component.ariaLabel()).toBe('Close');
  });

  it('emits dismissed when the backdrop is dismissed', () => {
    const component = createComponent();
    const handler = vi.fn();

    component.dismissed.subscribe(handler);

    component.dismiss();

    expect(handler).toHaveBeenCalledTimes(1);
  });
});
