{{!
  Copyright IBM Corp. 2016, 2025
  SPDX-License-Identifier: BUSL-1.1
}}

<PageHeader as |p|>
  <p.top>
    <Hds::Breadcrumb>
      <Hds::Breadcrumb::Item @text="Raft Storage" @route="vault.cluster.storage" />
      <Hds::Breadcrumb::Item @text="Restore Snapshot" @current={{true}} />
    </Hds::Breadcrumb>
  </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">
      <Hds::Button @text="Cancel upload" @color="secondary" {{on "click" (action "cancelUpload")}} />
    </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 @label="Choose a file..." @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>