<app-common-dialog [dialogContent]="dialogContent" [dialogRef]="dialogRef">
  <ng-template #dialogContent>
    <form appFormSubmit (ngSubmit)="addSSHkey()"
          [formGroup]="sshKeyForm" class="fl-content">
      <app-form-errors #formErrors [formGroup]="sshKeyForm"></app-form-errors>
      <app-credit-warning resourceName="SSH key" i18n-resourceName></app-credit-warning>
      <div layoutDirection="column">
        <app-user-autocomplete *ngIf="sshKeyForm.contains('user')"
                               [control]="sshKeyForm.controls.user"
                               [customSwitchMapHandler]="userOptionsSwitchMap"></app-user-autocomplete>
        <mat-form-field>
          <mat-label i18n>Name</mat-label>
          <input matInput placeholder="Name" i18n-placeholder type="text" formControlName="name" required>
          <mat-error>{{backendErrors['name']}}</mat-error>
        </mat-form-field>
        <mat-form-field>
          <mat-label i18n>Key content</mat-label>
          <textarea matInput rows="10" #publicKey
                    placeholder="Key content" i18n-placeholder type="text" formControlName="public_key" required>
          </textarea>
          <mat-error>{{backendErrors['public_key']}}</mat-error>
        </mat-form-field>
        <a *ngIf="generatedKey" mat-button color="primary" class="fl-margin-bottom"
                (click)="clipboard.copyTextAreaToClipboard(publicKey)" i18n>
          Copy public key to clipboard
        </a>
        <ng-container *ngIf="generatedKey">
          <mat-form-field>
            <mat-label i18n>Private key</mat-label>
            <p class="fl-detail" i18n>Private key. You should save this key locally, it will not be saved on server.</p>
            <textarea matInput rows="10" #privateKey
                      placeholder="Private key" i18n-placeholder type="text" formControlName="private_key" readonly>
            </textarea>
          </mat-form-field>
          <a mat-button color="primary" (click)="clipboard.copyTextAreaToClipboard(privateKey)" i18n>
            Copy private key to clipboard
          </a>
        </ng-container>
      </div>
    </form>
  </ng-template>
</app-common-dialog>
