import { Component, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { DatasetStatus } from '@app/core/common/enum/dataset-status';
import { DatasetService } from '@app/core/services/dataset/dataset.service';
import { BaseComponent } from '@common/base/base.component';

@Component({
	selector: 'app-dmp-finalize-dialog-component',
	templateUrl: 'dmp-finalize-dialog.component.html',
	styleUrls: ['./dmp-finalize-dialog.component.scss']
})
export class DmpFinalizeDialogComponent extends BaseComponent implements OnInit {

	inputModel: DmpFinalizeDialogInput;
	outputModel: DmpFinalizeDialogOutput;

	constructor(
		public router: Router,
		public dialogRef: MatDialogRef<DmpFinalizeDialogComponent>,
		public datasetService: DatasetService,
		@Inject(MAT_DIALOG_DATA) public data: any
	) {
		super();
		this.inputModel = data['dialogInputModel'];
		this.outputModel = { datasetsToBeFinalized: [] };
	}

	ngOnInit(): void { }

	onSubmit() {
		this.dialogRef.close(this.outputModel);
	}

	getFinalizedDatasets() {
		return this.inputModel.datasets.filter(x => x.status === DatasetStatus.Finalized);
	}

	getDraftDatasets() {
		return this.inputModel.datasets.filter(x => x.status === DatasetStatus.Draft);
	}

	close() {
		this.dialogRef.close({ cancelled: true } as DmpFinalizeDialogOutput);
	}
}

export interface DmpFinalizeDialogInput {
	dmpLabel: string;
	dmpDescription: string;
	datasets: DmpFinalizeDialogDataset[];
}

export interface DmpFinalizeDialogDataset {
	label: string;
	id?: string;
	status: DatasetStatus;
}

export interface DmpFinalizeDialogOutput {
	cancelled?: boolean;
	datasetsToBeFinalized?: string[];
}
