import { Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { <%= classify(name) %> } from './<%= dasherize(name) %>';

@Component({
  imports: [<%= classify(name) %>],
  template: `
    <<%= selector %>
      title="Comprovante da transferência"
      reference="PIX-2026-0001"
      currencyCode="BRL"
      [amount]="250.75"
      (referenceCopy)="copiedReference = $event"
      (receiptDownload)="downloaded = true"
    />
  `,
})
class HostComponent {
  copiedReference = '';
  downloaded = false;
}

describe('<%= classify(name) %>', () => {
  let fixture: ComponentFixture<HostComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({ imports: [HostComponent] }).compileComponents();
    fixture = TestBed.createComponent(HostComponent);
    fixture.detectChanges();
  });

  function article(): HTMLElement {
    return fixture.nativeElement.querySelector('article');
  }

  function buttons(): HTMLButtonElement[] {
    return Array.from(fixture.nativeElement.querySelectorAll('button'));
  }

  it('renders a labelled receipt with reference, date, amount, and parties', () => {
    const heading = fixture.nativeElement.querySelector('h2');
    const time = fixture.nativeElement.querySelector('time');
    const amount = fixture.nativeElement.querySelector('data');

    expect(article().getAttribute('aria-labelledby')).toBe(heading.id);
    expect(heading.textContent).toContain('Comprovante da transferência');
    expect(fixture.nativeElement.textContent).toContain('PIX-2026-0001');
    expect(time.getAttribute('datetime')).toBe('2026-07-26T12:00:00Z');
    expect(amount.getAttribute('value')).toBe('250.75');
    expect(fixture.nativeElement.textContent).toContain('R$250.75');
  });

  it('emits copy and download actions and announces copy status', () => {
    const [copyButton, downloadButton] = buttons();

    copyButton.click();
    downloadButton.click();
    fixture.detectChanges();

    expect(fixture.componentInstance.copiedReference).toBe('PIX-2026-0001');
    expect(fixture.componentInstance.downloaded).toBe(true);
    expect(fixture.nativeElement.querySelector('[role="status"]').textContent).toContain('Referência copiada.');
  });
});
