<!--
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)
-->
<form [formGroup]="projectForm" (ngSubmit)="projectAction(getProjectType)">
  <div class="modal-header">
    <h4 class="modal-title" id="modal-basic-title">{{ (getProjectType == 'Add' ? 'NEW' : 'EDIT') | translate}}
      {{'PROJECT' | translate}}</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>
  <div class="modal-body modal-body-custom-height">
    <div class="row" *ngIf="getProjectType === 'Add'">
      <label class="col-xs-10 col-sm-10 col-md-10 col-lg-10 col-xl-10">{{'RECENTLY' | translate}}
        {{'CREATED' | translate}} {{'PROJECT' | translate}}:
        <b>{{(recentProject)?recentProject.name:''}}</b>
      </label>
    </div>
    <div class="form-group row">
      <label class="col-sm-12 col-form-label mandatory-label"
        [ngClass]="{'text-danger': projectForm.invalid === true && submitted === true}">{{'MANDATORYCHECK' | translate}}</label>
      <label class="col-sm-4 col-form-label">{{'PROJECT' | translate}} {{'NAME' | translate}}*</label>
      <div class="col-sm-4">
        <input placeholder="{{'PROJECT' | translate}} {{'NAME' | translate}}" type="text" class="form-control"
          formControlName="project_name" [ngClass]="{ 'is-invalid': submitted && f.project_name.errors }" required>
      </div>
    </div>
    <div class="form-group row" *ngIf="getProjectType === 'Add'">
      <label class="col-sm-4 col-form-label">{{'DOMAIN' | translate}} {{'NAME' | translate}}</label>
      <div class="col-sm-4">
        <ng-select [clearable]="false" placeholder="{{'SELECT' | translate}}" [items]="domains" bindLabel="title"
          bindValue="value" formControlName="domain_name" id="domain_name"
          [ngClass]="{ 'is-invalid': submitted && f.domain_name.errors }"></ng-select>
      </div>
    </div>
    <div class="form-check form-check-inline ml-2">
      <input class="form-check-input" type="checkbox" formControlName="enable_quota" (change)="checkQuota()"
        id="quotaCheck" *ngIf="getProjectType === 'Add' || quotaRefs === null">
      <label class="form-check-label" for="quotaCheck"><b>{{'PAGE.PROJECT.QUOTA' | translate}}</b></label>
    </div>
    <div class="row mt-1" [ngbCollapse]="!f.enable_quota.value">
      <div class="form-group col-sm-6" *ngFor="let quota of quotaItems;">
        <div class="row">
          <label class="col-sm-7 col-form-label">{{quota.title | translate}}*</label>
          <div class="col-sm-5">
            <input placeholder="{{'COUNT' | translate}}" type="number"
              class="form-control" [formControlName]="quota.value" [ngClass]="{ 'is-invalid': submitted && f[quota.value].errors }">
          </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">{{(getProjectType == 'Add' ? 'CREATE' : 'APPLY') | translate}}</button>
  </div>
</form>
<app-loader [waitingMessage]="message" *ngIf="isLoadingResults"></app-loader>