import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Inject, Component } from '@angular/core';


@Component({
	selector: 'app-dialog-confirmation-upload',
	templateUrl: './dialog-confirmation-upload-profiles.component.html',
	styleUrls: ['./dialog-confirmation-upload-profiles.component.scss']
})
export class DialodConfirmationUploadDmpProfiles {

	sizeError = false;
	btnColore:String="primary";
	selectFile =false;
	maxFileSize: number = 1048576;

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


	selectXML(event) {
		const file: FileList = event.target.files;
		const size: number = file[0].size;  // Get file size.
		this.sizeError = size > this.maxFileSize;  // Checks if file size is valid.
		const formdata: FormData = new FormData();
		if (!this.sizeError) {
			this.data.file = file;
			this.selectFile=true;
			this.btnColore="primary";
		}else{
			this.btnColore="warn";
		}
		this.data.name = file[0].name;
	}

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

	confirm() {
		this.data.name = this.data.name;
		this.data.sucsess = true;
		this.dialogRef.close(this.data);
	}

	hasProfile():boolean{
		return (this.selectFile && !this.sizeError);
	}

}
