import { Component, inject, input, output } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { DialogModule } from 'primeng/dialog';
import { ButtonModule } from 'primeng/button';
import { PosReceiptService } from '../../services/pos-receipt.service';

@Component({
  selector: 'app-receipt-preview',
  standalone: true,
  imports: [CommonModule, TranslateModule, DialogModule, ButtonModule],
  templateUrl: './receipt-preview.component.html',
  styleUrl: './receipt-preview.component.scss',
})
export class ReceiptPreviewComponent {
  private readonly receiptService = inject(PosReceiptService);

  readonly receiptHtml = input<string>('');
  readonly visible = input<boolean>(false);

  readonly closed = output<void>();
  readonly printed = output<void>();

  print(): void {
    const html = this.receiptHtml();
    if (html) {
      this.receiptService.printReceipt(html);
      this.printed.emit();
    }
  }

  onHide(): void {
    this.closed.emit();
  }
}
