import { Component, EventEmitter, Output, Input } from '@angular/core';

@Component({
  selector: 'app-file-upload',
  templateUrl: './file-upload.component.html',
  styleUrls: ['./file-upload.component.scss'],
})
export class FileUploadComponent {
  @Output() uploadFile = new EventEmitter<{
    type: string;
    file: File | null;
  }>();
  @Input() name: string = '';
  isUploaded: { isLoad: boolean; type: string } = {
    isLoad: false,
    type: this.name,
  };

  onChangeFile(event: any): void {
    this.uploadFile.emit({ file: event.target.files[0], type: this.name });
    this.isUploaded = {
      isLoad: true,
      type: this.name,
    };
  }

  onRemoveFile(): void {
    this.uploadFile.emit({ file: null, type: this.name });
    this.isUploaded = {
      isLoad: false,
      type: this.name,
    };
  }
}
