<div class="main-content">
	<div class="container-fluid dataset-profile-editor" *ngIf="form" [formGroup]='form'>
		<h3 *ngIf="isNew && !isClone && !isNewVersion">{{'DATASET-PROFILE-EDITOR.TITLE.NEW-PROFILE' | translate}}</h3>
		<h3 *ngIf="isNew && isClone">
			<span *ngIf="isClone">{{'DATASET-PROFILE-EDITOR.TITLE.NEW-PROFILE-CLONE' | translate}}</span>
			{{form.get('label').value}}
		</h3>
		<h3 *ngIf="isNew && isNewVersion">
			<span *ngIf="isNewVersion">{{'DATASET-PROFILE-EDITOR.TITLE.NEW-PROFILE-VERSION' | translate}}</span>
			{{form.get('label').value}}
		</h3>

		<h3 *ngIf="!isNew">{{form.get('label').value}}</h3>
		<mat-form-field class="full-width">
			<input matInput formControlName="label" placeholder="{{'DATASET-PROFILE-EDITOR.FIELDS.DATASET-TITLE' | translate}}" required>
			<mat-error *ngIf="form.get('label').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}
			</mat-error>
		</mat-form-field>

		<mat-form-field class="full-width">
			<input matInput formControlName="description" placeholder="{{'DATASET-PROFILE-EDITOR.FIELDS.DATASET-DESCRIPTION' | translate}}" required>
			<mat-error *ngIf="form.get('description').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}
			</mat-error>
		</mat-form-field>

		<mat-form-field class="full-width">
			<!-- <input matInput formControlName="description" placeholder="{{'DATASET-PROFILE-EDITOR.FIELDS.DATASET-DESCRIPTION' | translate}}" required> -->
			<mat-select formControlName="language">
				<mat-option *ngFor="let lang of getLanguageInfos()" [value]="lang.code">
					{{ lang.name }}
				</mat-option>
			</mat-select>
			<mat-error *ngIf="form.get('language').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}
			</mat-error>
		</mat-form-field>

		<div class="d-flex justify-content-end pb-3" *ngIf="form.get('status').value==1">
			<button mat-raised-button color="primary" (click)="downloadXML();" type="button">{{ 'DATASET-WIZARD.ACTIONS.DOWNLOAD-XML' | translate }}</button>
		</div>
		<mat-horizontal-stepper [linear]="true" #stepper>
			<mat-step>
				<ng-template matStepLabel>{{'DATASET-PROFILE-EDITOR.STEPS.PAGES.TITLE' | translate}}</ng-template>
				<div class="row">
					<app-dataset-profile-editor-page-component class="col-12" [form]="form.get('pages')" [viewOnly]="viewOnly"></app-dataset-profile-editor-page-component>
					<div class="col-12">
						<button mat-button class="full-width" (click)="addPage()" [disabled]="viewOnly">{{'DATASET-PROFILE-EDITOR.ACTIONS.ADD-PAGE' | translate}}</button>
					</div>
				</div>
			</mat-step>
			<mat-step>
				<ng-template matStepLabel>{{'DATASET-PROFILE-EDITOR.STEPS.FORM.TITLE' | translate}}</ng-template>
				<div class="row">
					<mat-accordion class="col-12" [multi]="true">
						<mat-expansion-panel *ngFor="let section of dataModel.sections; let i=index;" #panel>
							<mat-expansion-panel-header>
								<mat-panel-title>{{i + 1}}. {{form.get('sections').get(''+i).get('title').value}}
								</mat-panel-title>
								<button mat-icon-button type="button" class="deleteBtn" (click)="DeleteSection(i);" [disabled]="viewOnly">
									<mat-icon>delete</mat-icon>
								</button>
							</mat-expansion-panel-header>
							<div id="{{'s' + i}}" class="row" *ngIf="panel.expanded">
								<app-dataset-profile-editor-section-component class="col-12" [form]="form.get('sections').get(''+i)" [dataModel]="section" [indexPath]="'s' + i" [viewOnly]="viewOnly">
								</app-dataset-profile-editor-section-component>
							</div>
						</mat-expansion-panel>
					</mat-accordion>
					<div class="col-12">
						<button mat-button (click)="addSection()" class="full-width" [disabled]="viewOnly">{{'DATASET-PROFILE-EDITOR.ACTIONS.ADD-SECTION' | translate}}</button>
					</div>
				</div>
			</mat-step>
			<!-- <mat-step>
				<ng-template matStepLabel>{{'DATASET-PROFILE.PREVIEW' | translate}}</ng-template>
				<div *ngIf='this.isStepActive(2)'>
					<app-dynamic-form *ngIf="dataWizardModel && previewerFormGroup" [form]="this.previewerFormGroup" [dataModel]="dataWizardModel"></app-dynamic-form>
				</div>
			</mat-step> -->
		</mat-horizontal-stepper>
		<div class="d-flex">
			<!-- SAVE BUTTON -->
			<div class="col-6 d-flex" *ngIf="!viewOnly">
				<div class="row mt-4">
					<button mat-raised-button class="col-auto mr-2" color="primary" type="button col-auto" (click)='checkFormValidation()' [disabled]="form.valid">{{'DATASET-PROFILE-EDITOR.ACTIONS.VALIDATE' | translate}}</button>
					<button mat-raised-button class="col-auto mr-2" color="primary" type="button col-auto" (click)='onSubmit()' [disabled]="!form.valid">{{'DATASET-PROFILE-EDITOR.ACTIONS.SAVE' | translate}}</button>
					<button mat-raised-button class="col-auto" color="primary" type="button col-auto" (click)='finalize()' [disabled]="!form.valid">{{'DATASET-PROFILE-EDITOR.ACTIONS.FINALIZE' | translate}}</button>
				</div>
			</div>
			<!-- SAVE BUTTON  WHEN FINALIZED-->
			<div class="col-6 d-flex" *ngIf="showUpdateButton()">
				<div class="row mt-4">
					<button mat-raised-button class="col-auto mr-2" color="primary" type="button col-auto" (click)='checkFormValidation()' [disabled]="form.valid">{{'DATASET-PROFILE-EDITOR.ACTIONS.VALIDATE' | translate}}</button>
					<button mat-raised-button class="col-auto mr-2" color="primary" type="button col-auto" (click)='updateFinalized()' [disabled]="!form.valid">{{'DATASET-PROFILE-EDITOR.ACTIONS.UPDATE' | translate}}</button>
				</div>
			</div>
			<!-- DELETE BUTTON -->
			<div class="col-6 d-flex justify-content-end" *ngIf="!isNew">
				<div class="row mt-4">
					<button mat-raised-button color="primary" (click)="delete()">
						<mat-icon>delete</mat-icon>{{'DATASET-PROFILE-EDITOR.ACTIONS.DELETE' | translate}}
					</button>
				</div>
			</div>
		</div>
	</div>
</div>
