@let previouslyCouldArchive = !(userCanArchive$ | async) && config?.originalCipher?.archivedDate;

<popup-page>
  <popup-header
    slot="header"
    [pageTitle]="headerText"
    [backAction]="handleBackButton"
    showBackButton
  >
    @if (config?.originalCipher?.archivedDate && (archiveFlagEnabled$ | async)) {
      <ng-container slot="end">
        <span bitBadge variant="secondary" [appA11yTitle]="'archived' | i18n">
          {{ "archived" | i18n }}
        </span>
      </ng-container>
    }
    <app-pop-out slot="end" />
  </popup-header>

  <vault-cipher-form
    *ngIf="!loading"
    formId="cipherForm"
    [config]="config"
    (cipherSaved)="onCipherSaved($event)"
    [beforeSubmit]="checkFido2UserVerification"
    [submitBtn]="submitBtn"
  >
    <app-open-attachments
      slot="attachment-button"
      [cipherId]="originalCipherId"
    ></app-open-attachments>
  </vault-cipher-form>

  <popup-footer slot="footer">
    <button bitButton type="submit" form="cipherForm" buttonType="primary" #submitBtn>
      {{ (previouslyCouldArchive ? "unarchiveAndSave" : "save") | i18n }}
    </button>

    <button (click)="handleBackButton()" bitButton type="button" buttonType="secondary">
      {{ "cancel" | i18n }}
    </button>

    <ng-container slot="end">
      @if (canDeleteCipher$ | async) {
        <button
          [bitAction]="delete"
          type="button"
          buttonType="danger"
          bitIconButton="bwi-trash"
          [label]="'delete' | i18n"
        ></button>
      }
    </ng-container>
  </popup-footer>
</popup-page>
