import { AfterViewInit, Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core';
import { ArtMeta, ArtUpload, FileDomain, FileInfo, PreCheckResult } from './interfaces';
import { UploadBoxComponent } from './upload-box.component';

@Component({
  selector: 'app-prechecker-upload',
  template: `
  <div class="d-flex flex-row justify-content-center align-items-center p-5">
    <art-upload-box #raw  [domain]="domain.raw" [preCheck]="true" (onCheck)="onCheck($event)" (onDetail)="next()" ></art-upload-box>
  </div>
  <div class="text-center">
    <button class="btn btn-primary" [disabled]="!isReady"  (click)="next()" i18n>查看详情</button>
  </div>
  `,
  styles: [
  ]
})
export class PrecheckerUploadComponent implements OnInit, AfterViewInit {

  @ViewChild('raw') raw: UploadBoxComponent;

  @Output('data') data = new EventEmitter<PreCheckResult>();

  result: PreCheckResult;

  constructor() {
   
  }

  next() {
    this.data.emit(this.result);
  }

  domain = FileDomain; 

  rawFis: FileInfo[] = [];

  ngOnInit() {

  }

  
  ngAfterViewInit() {
    this.raw._onChange.subscribe((e) => {
      this.rawFis = e as FileInfo[];
    });
  }


  /**
   * 所有文件都已经处理完毕
   */
  get isReady() {
    return this.raw?.isChecked;
  }

  onCheck(result: PreCheckResult) {
    this.result = result;
  }

}
