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

@Component({
  selector: 'art-checker-upload',
  template: `
  <div class="row p-5">
    <art-upload-box #raw  [domain]="domain.raw" i18n-name name="线稿(必选)自动转svg" acceptText="svg/png/jpeg" accept="image/svg+xml,image/png,image/jpeg, image/jpg" ></art-upload-box>
  </div>
  <div>
    <button class="btn btn-primary"  type="submit" (click)="data.emit(rawFis)" [disabled]="!rawFis || rawFis.length <= 0" i18n>确定</button>
    <button class="btn btn-primary"  type="cancel" (click)="cancel.emit()" i18n>取消</button>
  </div>
  `,
  styles: [
    `
    .row{
      display:flex;
      flex-direction:row;
      justify-content:center;
      align-items: center;
    }
   
    `
  ]
})
export class CheckerUploadComponent implements OnInit {

  @Output('data') data: EventEmitter<FileInfo[]> = new EventEmitter();
  @Output('cancel') cancel: EventEmitter<void> = new EventEmitter();

  @ViewChild('raw') raw: UploadBoxComponent;

  domain = FileDomain;
  
  rawFis: FileInfo[] = [];

  constructor() { }

  ngOnInit() {
    this.raw._onChange.subscribe((fis: FileInfo[]) => {
      this.rawFis = fis;
    })
  }


}
