<div class="modal-header">
  <h4 i18n="form title|Example: Create Pool@@formTitle"
      class="modal-title pull-left">{{ action | titlecase }} {{ resource | upperFirst }}</h4>
  <button type="button"
          class="close pull-right"
          aria-label="Close"
          (click)="bsModalRef.hide()">
    <span aria-hidden="true">&times;</span>
  </button>
</div>
<form class="form-horizontal"
      #frm="ngForm"
      [formGroup]="formGroup"
      novalidate>
  <div class="modal-body">

    <!-- Username -->
    <div class="form-group"
         [ngClass]="{'has-error': formGroup.showError('user', frm)}">
      <label class="control-label col-sm-3"
             for="user">
        <ng-container i18n>Username</ng-container>
        <span class="required"
              *ngIf="!viewing">
        </span>
      </label>
      <div class="col-sm-9">
        <input id="user"
               class="form-control"
               type="text"
               *ngIf="viewing"
               [readonly]="true"
               formControlName="user">
        <select id="user"
                class="form-control"
                formControlName="user"
                *ngIf="!viewing"
                autofocus>
          <option i18n
                  *ngIf="userCandidates !== null"
                  [ngValue]="null">-- Select a username --</option>
          <option *ngFor="let userCandidate of userCandidates"
                  [value]="userCandidate">{{ userCandidate }}</option>
        </select>
        <span class="help-block"
              *ngIf="formGroup.showError('user', frm, 'required')"
              i18n>This field is required.</span>
      </div>
    </div>

    <!-- Auto-generate key -->
    <div class="form-group"
         *ngIf="!viewing">
      <div class="col-sm-offset-3 col-sm-9">
        <div class="checkbox checkbox-primary">
          <input id="generate_key"
                 type="checkbox"
                 formControlName="generate_key">
          <label for="generate_key"
                 i18n>Auto-generate key</label>
        </div>
      </div>
    </div>

    <!-- Access key -->
    <div class="form-group"
         [ngClass]="{'has-error': formGroup.showError('access_key', frm)}"
         *ngIf="!formGroup.getValue('generate_key')">
      <label class="control-label col-sm-3"
             for="access_key">
        <ng-container i18n>Access key</ng-container>
        <span class="required"
              *ngIf="!viewing">
        </span>
      </label>
      <div class="col-sm-9">
        <div class="input-group">
          <input id="access_key"
                 class="form-control"
                 type="password"
                 [readonly]="viewing"
                 formControlName="access_key">
          <span class="input-group-btn">
            <button type="button"
                    class="btn btn-default"
                    cdPasswordButton="access_key">
            </button>
            <button type="button"
                    class="btn btn-default"
                    cdCopy2ClipboardButton="access_key">
            </button>
          </span>
        </div>
        <span class="help-block"
              *ngIf="formGroup.showError('access_key', frm, 'required')"
              i18n>This field is required.</span>
      </div>
    </div>

    <!-- Secret key -->
    <div class="form-group"
         [ngClass]="{'has-error': formGroup.showError('secret_key', frm)}"
         *ngIf="!formGroup.getValue('generate_key')">
      <label class="control-label col-sm-3"
             for="secret_key">
        <ng-container i18n>Secret key</ng-container>
        <span class="required"
              *ngIf="!viewing">
        </span>
      </label>
      <div class="col-sm-9">
        <div class="input-group">
          <input id="secret_key"
                 class="form-control"
                 type="password"
                 [readonly]="viewing"
                 formControlName="secret_key">
          <span class="input-group-btn">
            <button type="button"
                    class="btn btn-default"
                    cdPasswordButton="secret_key">
            </button>
            <button type="button"
                    class="btn btn-default"
                    cdCopy2ClipboardButton="secret_key">
            </button>
          </span>
        </div>
        <span class="help-block"
              *ngIf="formGroup.showError('secret_key', frm, 'required')"
              i18n>This field is required.</span>
      </div>
    </div>

  </div>
  <div class="modal-footer">
    <cd-submit-button
      *ngIf="!viewing"
      (submitAction)="onSubmit()"
      i18n="form action button|Example: Create Pool@@formActionButton"
      [form]="formGroup">{{ action | titlecase }} {{ resource | upperFirst }}</cd-submit-button>
    <cd-back-button [back]="bsModalRef.hide"></cd-back-button>
  </div>
</form>
