<div class="dynamic-form-section row" [id]="this.form.get('id').value">
	<mat-accordion class="col-12">
		<mat-expansion-panel class="row expansion-panel toc-section-header" [id]="pathName" [(expanded)]="panelExpanded">
			<mat-expansion-panel-header>
				<mat-panel-title>
					<h6 class='panel-title'>{{tocentry? tocentry.numbering :form.get('numbering').value}}. {{form.get('title').value}}</h6>
				</mat-panel-title>
			</mat-expansion-panel-header>
			<mat-panel-description class="col-12">
				<h6 class='panel-desc' *ngIf="form.get('description').value" [innerHTML]="form.get('description').value"></h6>
			</mat-panel-description>
			<ng-container *ngIf="!tocentry else tocentryCase">
			<div *ngFor="let compositeFieldFormGroup of form.get('compositeFields')['controls']; let i = index;" class="col-12">
				<!-- <div *ngIf="isElementVisible(compositeField)" class="row"> -->
				<!-- *ngIf="this.visibilityRulesService.checkElementVisibility(compositeFieldFormGroup.get('id').value)" -->
				<div class="row" *ngIf="this.visibilityRulesService.checkElementVisibility(compositeFieldFormGroup.get('id').value) && this.visibilityRulesService.scanIfChildsOfCompositeFieldHasVisibleItems(compositeFieldFormGroup)">

					<div class="col-12">
						<div class="row">
							<app-form-composite-field class="align-self-center col" [form]="compositeFieldFormGroup" [datasetProfileId]="datasetProfileId"
								[isChild]="false" [showDelete]="(compositeFieldFormGroup.get('multiplicityItems').length) > 0"></app-form-composite-field>
						</div>
					</div>

					<div *ngIf="compositeFieldFormGroup" class="col-12">
						<div class="row">
							<div class="col-12" *ngFor="let multipleCompositeFieldFormGroup of compositeFieldFormGroup.get('multiplicityItems')['controls']; let j = index">
								<div class="row">
									<app-form-composite-field class=" align-self-center col" [form]="multipleCompositeFieldFormGroup" [datasetProfileId]="datasetProfileId"
									 [isChild]="true" [showDelete]="true"></app-form-composite-field>
								</div>
							</div>
							<div *ngIf="(compositeFieldFormGroup.get('multiplicity').value.max - 1) > (compositeFieldFormGroup.get('multiplicityItems').length)"
							 class="col-12 mt-1 ml-0 mr-0 addOneFieldButton">
								<span class="pointer d-inline-flex align-items-center" (click)="addMultipleField(i)">
									<button mat-icon-button color="primary" [disabled]="compositeFieldFormGroup.disabled">
										<mat-icon>add_circle</mat-icon>
									</button>
									<span class="mt-1" *ngIf="compositeFieldFormGroup.get('multiplicity').value.placeholder">{{compositeFieldFormGroup.get('multiplicity').value.placeholder}}</span>
									<span class="mt-1" *ngIf="!compositeFieldFormGroup.get('multiplicity').value.placeholder">{{'DATASET-PROFILE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.MULTIPLICITY-ADD-ONE-FIELD' | translate}}</span>
								</span>
							</div>
							<div *ngIf="compositeFieldFormGroup.get('hasCommentField').value" class="col-12">
<!--								<input matInput formControlName="commentFieldValue" placeholder="{{'DATASET-PROFILE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.COMMENT-PLACEHOLDER' | translate}}">-->
								<rich-text-editor-component [parentFormGroup]="compositeFieldFormGroup" [controlName]="'commentFieldValue'"
															[id]="'editor1'" [placeholder]="'DATASET-PROFILE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.COMMENT-PLACEHOLDER' | translate"
															[wrapperClasses]="'mb-2'">
								</rich-text-editor-component>
<!--								<mat-hint>{{'DATASET-PROFILE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.COMMENT-HINT' | translate}}</mat-hint>-->
							</div>
							<!-- <div class="col"></div>
							<button class="col-auto" mat-icon-button type="button" (click)="next(compositeField)">
								<mat-icon>expand_more</mat-icon>
							</button> -->
						</div>
					</div>

				</div>
			</div>
			<div *ngIf="form.get('sections')" class="col-12">
				<div *ngFor="let subSectionFormGroup of form.get('sections')['controls']; let j = index;" class="row">
					<app-form-section class="col-12" [form]="subSectionFormGroup" [path]="path+'.'+(j+1)" [pathName]="pathName+'.sections.'+j" [linkToScroll]="subsectionLinkToScroll"
					 [datasetProfileId]="datasetProfileId"></app-form-section>
				</div>
			</div>
			</ng-container>
		</mat-expansion-panel>
	</mat-accordion>
</div>








<!-- WORKING WITH TOCENTRIES -->

<ng-template #tocentryCase>

	<ng-container [ngSwitch]="tocentry.subEntriesType">
		<ng-container *ngSwitchCase="tocentriesType.FieldSet">

			<!-- FIELDSET CASE -->
			<div *ngFor="let fieldsetEntry of tocentry.subEntries; let i = index;" class="col-12" [id]="TOCENTRY_ID_PREFIX+fieldsetEntry.id" (click)="onAskedToScroll(fieldsetEntry.id)">
				<!-- <div *ngIf="isElementVisible(compositeField)" class="row"> -->
				<!-- *ngIf="this.visibilityRulesService.checkElementVisibility(compositeFieldFormGroup.get('id').value)" -->
				<div class="row" *ngIf="(this.visibilityRulesService.checkElementVisibility(fieldsetEntry.form.get('id').value) && this.visibilityRulesService.scanIfChildsOfCompositeFieldHasVisibleItems(fieldsetEntry.form)) && !hiddenEntriesIds.includes(fieldsetEntry.id)">

					<div class="col-12">
						<div class="row">
							<app-form-composite-field [tocentry]="fieldsetEntry" class="align-self-center col" [form]="fieldsetEntry.form" [datasetProfileId]="datasetProfileId"
								[isChild]="false" [showDelete]="(fieldsetEntry.form.get('multiplicityItems').length) > 0"></app-form-composite-field>
						</div>
					</div>

					<div *ngIf="fieldsetEntry.form" class="col-12">
						<div class="row">
							<div class="col-12" *ngFor="let multipleCompositeFieldFormGroup of fieldsetEntry.form.get('multiplicityItems')['controls']; let j = index">
								<div class="row">
									<app-form-composite-field class=" align-self-center col" [form]="multipleCompositeFieldFormGroup" [datasetProfileId]="datasetProfileId"
									 [isChild]="true" [showDelete]="true"></app-form-composite-field>
								</div>
							</div>
							<div *ngIf="(fieldsetEntry.form.get('multiplicity').value.max - 1) > (fieldsetEntry.form.get('multiplicityItems').length)"
							 class="col-12 mt-1 ml-0 mr-0 addOneFieldButton">
								<span class="pointer d-inline-flex align-items-center" (click)="addMultipleField(i)">
									<button mat-icon-button color="primary" [disabled]="fieldsetEntry.form.disabled">
										<mat-icon>add_circle</mat-icon>
									</button>
									<span class="mt-1" *ngIf="fieldsetEntry.form.get('multiplicity').value.placeholder">{{fieldsetEntry.form.get('multiplicity').value.placeholder}}</span>
									<span class="mt-1" *ngIf="!fieldsetEntry.form.get('multiplicity').value.placeholder">{{'DATASET-PROFILE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.MULTIPLICITY-ADD-ONE-FIELD' | translate}}</span>
								</span>
							</div>
							<div *ngIf="fieldsetEntry.form.get('hasCommentField').value" class="col-12">
<!--								<input matInput formControlName="commentFieldValue" placeholder="{{'DATASET-PROFILE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.COMMENT-PLACEHOLDER' | translate}}">-->
								<rich-text-editor-component [parentFormGroup]="fieldsetEntry.form" [controlName]="'commentFieldValue'"
															[id]="'editor1'" [placeholder]="'DATASET-PROFILE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.COMMENT-PLACEHOLDER' | translate"
															[wrapperClasses]="' mb-2'">
								</rich-text-editor-component>
<!--								<mat-hint>{{'DATASET-PROFILE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.COMMENT-HINT' | translate}}</mat-hint>-->
							</div>
							<!-- <div class="col"></div>
							<button class="col-auto" mat-icon-button type="button" (click)="next(compositeField)">
								<mat-icon>expand_more</mat-icon>
							</button> -->
						</div>
					</div>

				</div>
			</div>

		</ng-container>

		<ng-container *ngSwitchCase="tocentriesType.Section">
			<!-- SECTION CASE -->

			<div *ngIf="form.get('sections')" class="col-12"><!-- MAYBEE NOT NEEDED-->
				<ng-container *ngFor="let sectionEntry of tocentry.subEntries; let j = index;">
					<div class="row" *ngIf="!hiddenEntriesIds.includes(sectionEntry.id)">
						<app-form-section [TOCENTRY_ID_PREFIX]="TOCENTRY_ID_PREFIX" class="col-12" [tocentry]="sectionEntry" [form]="sectionEntry.form" [path]="path+'.'+(j+1)" [pathName]="pathName+'.sections.'+j" [linkToScroll]="subsectionLinkToScroll"
						 [datasetProfileId]="datasetProfileId"
						 (askedToScroll)="onAskedToScroll($event)"
						 [hiddenEntriesIds]="hiddenEntriesIds"
						 ></app-form-section>
					</div>
				</ng-container>
			</div>
		</ng-container>

	</ng-container>

</ng-template>
