<cd-modal [modalRef]="activeModal">
  <ng-container i18n="form title"
                class="modal-title">{{ action | titlecase }} {{ resource | upperFirst }}</ng-container>

  <ng-container class="modal-content">
    <form name="snapshotForm"
          #formDir="ngForm"
          [formGroup]="snapshotForm"
          novalidate>
      <div class="modal-body">
        <!-- Name -->
        <div class="form-group row">
          <label class="cd-col-form-label required"
                 for="snapshotName"
                 i18n>Name</label>
          <div class="cd-col-form-input">
            <input class="form-control"
                   type="text"
                   placeholder="Snapshot name..."
                   id="snapshotName"
                   name="snapshotName"
                   [attr.disabled]="((mirroring === 'snapshot') ? true : null) && (snapshotForm.getValue('mirrorImageSnapshot') === true) ? true: null"
                   formControlName="snapshotName"
                   autofocus>
            <span class="invalid-feedback"
                  *ngIf="snapshotForm.showError('snapshotName', formDir, 'required')"
                  i18n>This field is required.</span>
            <span *ngIf="((mirroring === 'snapshot') ? true : null) && (snapshotForm.getValue('mirrorImageSnapshot') === true) ? true: null"
                  i18n>Snapshot mode is enabled on image <b>{{ imageName }}</b>: snapshot names are auto generated</span>
            <span *ngIf="snapshotForm.showError('snapshotName', formDir, 'pattern')"
                  class="invalid-feedback"
                  i18n>The snapshot name cannot start with "." and cannot contain "/" and "@".</span>
          </div>
        </div>
        <ng-container *ngIf="(mirroring === 'snapshot') ? true : null">
          <div class="form-group row"
               *ngIf="peerConfigured$ | async as peerConfigured">
            <div class="cd-col-form-offset">
              <div class="custom-control custom-checkbox">
                <input type="checkbox"
                       class="custom-control-input"
                       formControlName="mirrorImageSnapshot"
                       name="mirrorImageSnapshot"
                       id="mirrorImageSnapshot"
                       [attr.disabled]="!(peerConfigured.length > 0) ? true : null"
                       (change)="onMirrorCheckBoxChange()">
                <label for="mirrorImageSnapshot"
                       class="custom-control-label"
                       i18n>Mirror Image Snapshot</label>
                <cd-helper i18n
                           *ngIf="!peerConfigured.length > 0">The peer must be registered to do this action.</cd-helper>
              </div>
            </div>
          </div>
        </ng-container>
      </div>
      <div class="modal-footer">
        <cd-form-button-panel (submitActionEvent)="submit()"
                              [form]="snapshotForm"
                              [submitText]="(action | titlecase) + ' ' + (resource | upperFirst)"></cd-form-button-panel>
      </div>
    </form>
  </ng-container>
</cd-modal>
