<!--
  ~ Copyright (C) 2017/2021 e-voyageurs technologies
  ~
  ~ 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.
  -->
<nb-card status="info">
  <nb-card-header>Add Entity</nb-card-header>
  <nb-card-body class="content">
    <p
      *ngIf="error"
      class="error"
    >
      {{ error }}
    </p>

    <p>
      <label>Select existing Entity:</label><br />

      <ng-container *ngIf="entityTypes">
        <span
          *ngFor="let e of entityTypes"
          nbTooltip="Select {{ e.qualifiedName(state.user) }}"
          (click)="onSelect(e)"
          class="tag"
          [style.background-color]="e === entityType ? '' : e.qualifiedEntityColor(state.user)"
        >
          {{ e.qualifiedName(state.user) }}
        </span>
      </ng-container>
    </p>

    <div class="form-group">
      <span>Or create: </span>
      <input
        nbInput
        placeholder="Entity Type"
        [(ngModel)]="type"
        (keyup)="onTypeKeyUp($event)"
      />
    </div>
    <div class="form-group">
      <label> With role: </label>
      <input
        nbInput
        placeholder="Role"
        [(ngModel)]="role"
        (keyup)="onRoleKeyUp($event)"
      />
    </div>
  </nb-card-body>
  <nb-card-footer class="footer">
    <button
      nbButton
      size="small"
      (click)="dialogRef.close('cancel')"
    >
      Cancel
    </button>
    <button
      nbButton
      size="small"
      class="submit-button"
      status="success"
      (click)="save()"
    >
      Add
    </button>
  </nb-card-footer>
</nb-card>
