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

{{#if (gt this.key.keysForEncryption.length 1)}}
  <div class="field" data-test-transit-key-version-select={{true}}>
    <label for="key_version" class="is-label">Key version</label>
    <div class="control is-expanded">
      <div class="select is-fullwidth">
        <select name="key_version" id="key_version" onchange={{action this.onVersionChange value="target.value"}}>
          {{#each this.key.keysForEncryption as |version|}}
            {{#if (eq version this.key.latestVersion)}}
              <option
                selected={{if this.key_version (eq version this.key_version) (eq version this.key.latestVersion)}}
                value={{0}}
              >
                {{version}}
                (latest)
              </option>
            {{else}}
              <option
                selected={{if this.key_version (eq version this.key_version) (eq version this.key.latestVersion)}}
                value={{version}}
              >
                {{version}}
              </option>
            {{/if}}
          {{/each}}
        </select>
      </div>
    </div>
  </div>
{{/if}}