{"size": 902, "ext": "js", "max_stars_repo_path": "tests/dummy/app/components/barcodes.js", "max_stars_repo_name": "bgantzler/ember-barcode-scanner", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/dummy/app/components/barcodes.js", "max_issues_repo_name": "bgantzler/ember-barcode-scanner", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/dummy/app/components/barcodes.js", "max_forks_repo_name": "bgantzler/ember-barcode-scanner", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.976744186, "max_line_length": 83, "alphanum_fraction": 0.6596452328}
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

export default class BarcodesComponent extends Component {
  @service('EmberBarcodeScanner@scanner')
  scannerService;

  @service('EmberGs1Parser@barcodeParser')
  gs1ParserService;

  @tracked
  barcodes = [];

  constructor() {
    super(...arguments);
  }

  @action
  onClear() {
    this.barcodes = [];
  }

  @action
  restartScanner() {
    this.scannerService.reset();
  }

  @action
  onScan(data) {
    console.log(data);

    // this is a "hack" to not allow parsing of smaller barcodes with a length < 20
    if (data.length > 19) {
      const bc = this.gs1ParserService.parseBarcode(
        this.gs1ParserService.replaceSeparators(data)
      );
      this.barcodes = [...this.barcodes, bc];
    }
  }
}
