<!--
Copyright 2020 TATA ELXSI

Licensed under the Apache License, Version 2.0 (the 'License');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
-->
<div class="modal-header">
    <h4 class="modal-title" id="modal-basic-title">{{title}}</h4>
    <button class="button-xs" type="button" class="close" aria-label="Close" (click)="activeModal.close()">
        <i class="fas fa-times-circle text-danger"></i>
    </button>
</div>
<form [formGroup]="pduInstancesForm" (ngSubmit)="createPDUInstances()" autocomplete="off">
    <div class="modal-body">
        <div class="form-group row">
            <label class="col-sm-12 col-form-label mandatory-label" [ngClass]="{'text-danger': pduInstancesForm.invalid === true && submitted === true}">{{'MANDATORYCHECK' | translate}}</label>
            <label class="col-sm-3 col-form-label" for="name">{{'NAME' | translate}}*</label>
            <div class="col-sm-3">
                <input placeholder="{{'NAME' | translate}}" type="text" class="form-control" formControlName="name" id="name" [ngClass]="{ 'is-invalid': submitted && f.name.errors }"
                    required>
            </div>
            <label class="col-sm-3 col-form-label" for="type">{{'PAGE.PDUINSTANCE.PDUTYPE' | translate}}*</label>
            <div class="col-sm-3">
                <input placeholder="{{'PAGE.PDUINSTANCE.PDUTYPE' | translate}}" type="text" class="form-control" formControlName="type" id="type" [ngClass]="{ 'is-invalid': submitted && f.type.errors }">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-3 col-form-label" for="vim_accounts">{{'VIMACCOUNTS' | translate}}*</label>
            <div class="col-sm-9">
                <ng-select placeholder="{{'VIMACCOUNTS' | translate}}" [items]="vimAccountSelect" multiple="true" bindLabel="name" bindValue="_id" formControlName="vim_accounts" id="vim_accounts"
                    [ngClass]="{ 'is-invalid': submitted && f.vim_accounts.errors }" [(ngModel)]="selectedVIM">
                </ng-select>
            </div>
        </div>
        <div class="form-group row p-2 bg-light text-dark">
            <div class="col-sm-7 align-self-center"><span>{{'PAGE.PDUINSTANCE.PARAMETERS' | translate}}</span></div>
            <div class="col-sm-5">
                <button type="button" class="btn btn-primary" (click)="createInterfaces()">
                    <i class="fas fa-plus-square"></i> {{'PAGE.PDUINSTANCE.ADDINSTANCEPARAMS' | translate}}</button>
            </div>
        </div>
        <div formArrayName="interfaces" *ngFor="let params of getControls(); let i = index;">
            <div class="form-group" [formGroupName]="i">
                <div class="row">
                    <div class="col-sm-11">
                        <div class="row">
                            <label class="col-sm-2 col-form-label" for="name_{{i}}">{{'NAME' | translate}}*</label>
                            <div class="col-sm-4">
                                <input placeholder="{{'NAME' | translate}}" type="text" class="form-control" formControlName="name" id="name_{{i}}" [ngClass]="{ 'is-invalid': submitted && params.controls.name.errors }">
                            </div>
                            <label class="col-sm-2 col-form-label padLeft0 padRight0" for="ipAddress{{i}}">{{'IPADDRESS' | translate}}*</label>
                            <div class="col-sm-4">
                                <input placeholder="{{'IPADDRESS' | translate}}" type="text" class="form-control" formControlName="ip-address" id="ipAddress{{i}}" [ngClass]="{ 'is-invalid': submitted && params.controls['ip-address'].errors }">
                                <div *ngIf="pduInstancesForm.invalid" class="invalid-feedback">
                                    <div *ngIf="params.controls['ip-address'].errors && params.controls['ip-address'].value">{{'DOMVALIDATIONS.INVALIDIPADDRESS' | translate}}</div>
                                </div>
                            </div>
                        </div>
                        <div class="row mr-top-5">
                            <label class="col-sm-2 col-form-label" for="mgmt{{i}}">{{'MGMT' | translate}}*</label>
                            <div class="col-sm-4">
                                <ng-select placeholder="{{'SELECT' | translate}} {{'MGMT' | translate}}" [items]="mgmtState" bindLabel="name" bindValue="value" formControlName="mgmt" id="mgmt{{i}}" [(ngModel)]="selectedMgmt" [ngClass]="{ 'is-invalid': submitted && params.controls.mgmt.errors }"></ng-select>
                            </div>
                            <label class="col-sm-2 col-form-label padLeft0 padRight0" for="vimNetName{{i}}">{{'NETNAME' | translate}}*</label>
                            <div class="col-sm-4">
                                <input placeholder="{{'NETNAME' | translate}}" type="text" class="form-control" formControlName="vim-network-name" id="vimNetName{{i}}" [ngClass]="{ 'is-invalid': submitted && params.controls['vim-network-name'].errors }">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-1 remove-params" [hidden]="i==0">
                        <button type="button" class="btn btn-sm btn-danger remove-mapping" (click)="removeInterfaces(i)">
                            <i class="fas fa-times-circle"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-danger" (click)="activeModal.close()">{{'CANCEL' | translate}}</button>
        <button type="submit" class="btn btn-primary">{{'CREATE' | translate}}</button>
    </div>
</form>
<app-loader [waitingMessage]="message" *ngIf="isLoadingResults"></app-loader>