{{!
  Copyright (c) HashiCorp, Inc.
  SPDX-License-Identifier: BUSL-1.1
~}}

<PageHeader as |p|>
  <p.top>
    <nav class="key-value-header breadcrumb">
      <ul>
        <li>
          <span class="sep">&#x0002f;</span>
          <LinkTo @route="vault.cluster.storage">
            Raft Storage
          </LinkTo>
        </li>
      </ul>
    </nav>
  </p.top>
  <p.levelLeft>
    <h1 class="title is-3">
      Restore Snapshot
    </h1>
  </p.levelLeft>
</PageHeader>

<form {{action (perform this.restore this.file) on="submit"}}>
  <MessageError @errors={{this.errors}} />

  {{#if this.isUploading}}
    <div class="box is-sideless is-fullwidth is-marginless">
      <Hds::Alert @type="inline" @color="warning" class="has-bottom-margin-s" as |A|>
        <A.Title>Uploading your file...</A.Title>
        <A.Description>Raft snapshots can be very large files. Uploading the snapshot may take some time.</A.Description>
      </Hds::Alert>
    </div>
    <div class="box is-fullwidth is-shadowless">
      <button type="button" class="button" onclick={{action "cancelUpload"}}>
        Cancel upload
      </button>
    </div>
  {{else}}
    <div class="box is-sideless is-fullwidth is-marginless">
      <Hds::Alert @type="inline" @color="warning" class="has-bottom-margin-s" as |A|>
        <A.Title>This might take a while</A.Title>
        <A.Description>Raft snapshots can be very large files. Uploading the snapshot may take some time.</A.Description>
      </Hds::Alert>
      <FileToArrayBuffer @onChange={{action (mut this.file)}} />
      <div class="b-checkbox">
        <input
          type="checkbox"
          id="force-restore"
          class="styled"
          checked={{this.forceRestore}}
          onchange={{action (mut this.forceRestore) value="target.checked"}}
        />
        <label for="force-restore" class="is-label">
          Force restore
        </label>
        <p class="checkbox-help-text">
          Bypass checks to ensure the AutoUnseal or Shamir keys are consistent with the snapshot data.
        </p>
      </div>
    </div>
    <FormSaveButtons
      @saveButtonText="Restore"
      @isSaving={{this.restore.isRunning}}
      @cancelLinkParams={{array "vault.cluster.storage"}}
    />
  {{/if}}
</form>