import { Component, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { DmpService } from '../../../../../core/services/dmp/dmp.service';

@Component({
	selector: 'dmp-upload-dialogue',
	templateUrl: './dmp-upload-dialogue.component.html',
	styleUrls: ['./dmp-upload-dialogue.component.scss']
})
export class DmpUploadDialogue {
	dmpTitle: string;


	constructor(
		public dialogRef: MatDialogRef<DmpUploadDialogue>,
		@Inject(MAT_DIALOG_DATA) public data: any,
	) {}

	cancel() {
		this.data.success = false;
		this.dialogRef.close(this.data);
	}

	confirm() {
		this.data.success = true;
		this.data.dmpTitle = this.dmpTitle;
		this.dialogRef.close(this.data);
	}

	uploadFile(event) {
		const fileList: FileList = event.target.files
		this.data.fileList = fileList;
		if (this.data.fileList.length > 0) {
			this.dmpTitle = fileList.item(0).name;
		}
	}
}
