import { Component, Input, Output, EventEmitter } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { Router } from '@angular/router';
import { BaseComponent } from '@common/base/base.component';
import { GuidedTourService } from '@app/library/guided-tour/guided-tour.service';
import { GuidedTour, Orientation } from '@app/library/guided-tour/guided-tour.constants';
import { TranslateService } from '@ngx-translate/core';
import { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile';
import { takeUntil } from 'rxjs/operators';

@Component({
	selector: 'app-dataset-editor-component',
	templateUrl: 'dataset-editor.component.html',
	styleUrls: ['./dataset-editor.component.scss']
})
export class DatasetEditorComponent extends BaseComponent {

	@Input() formGroup: FormGroup;
	// @Input() formGroup: FormGroup = null;
	@Input() availableProfiles: DatasetProfileModel[];
	@Input() dmpId: string;
	showUri: boolean = false;
	dmpText: string = null;
	viewOnly = false;

	constructor(
		private router: Router,
		private guidedTourService: GuidedTourService,
		private language: TranslateService
	) { super(); }

	public dashboardTourDmp: GuidedTour = {
		tourId: 'only-dmp-tour',
		useOrb: true,
		steps: [
			{
				title: this.dmpText,
				content: 'Step 1',
				orientation: Orientation.Bottom,
				highlightPadding: 3,
				isStepUnique: true,
				customTopOffset: 8
			}
		]
	};

	getDmpText(): string {
		return this.language.instant('DMP-LISTING.TEXT-INFO') + '\n\n' +
			this.language.instant('DMP-LISTING.TEXT-INFO-QUESTION') + ' ' +
			this.language.instant('DMP-LISTING.LINK-ZENODO') + ' ' +
			this.language.instant('DMP-LISTING.GET-IDEA');
	}

	setDashboardTourDmp(label: string): void {
		this.dashboardTourDmp.steps[0].title = this.getDmpText();
		this.dashboardTourDmp.steps[0].selector = '.dmp-tour-' + label;
	}

	public restartTour(label: string): void {
		this.setDashboardTourDmp(label);
		this.guidedTourService.startTour(this.dashboardTourDmp);

	}

	public cancel(): void {
		this.router.navigate(['/datasets']);
	}

	public compareWith(object1: any, object2: any) {
		return object1 && object2 && object1.id === object2.id;
	}
}
