import { Component, inject } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { ZXingScannerModule } from '@zxing/ngx-scanner';
import { CommonModule } from '@angular/common';
import { IonicModule } from '@ionic/angular';
import { BarcodeFormat } from '@zxing/library';

@Component({
  selector: 'app-qr-scanner',
  templateUrl: './qr-scanner.component.html',
  styleUrls: ['./qr-scanner.component.scss'],
  standalone: true,
  imports: [CommonModule, IonicModule, ZXingScannerModule]
})
export class QrScannerComponent {
  private modalCtrl = inject(ModalController);
  public allowedFormats = [BarcodeFormat.QR_CODE];

  onCodeResult(result: string) {
    if (result) {
      this.modalCtrl.dismiss(result);
    }
  }

  cancel() {
    this.modalCtrl.dismiss();
  }
}
