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

<Page::Header @title="Generate Credentials">
  <:breadcrumbs>
    <KmipBreadcrumb @scope={{@scopeName}} @role={{@roleName}} @currentRoute="Generate Credentials" />
  </:breadcrumbs>
</Page::Header>

{{#if this.credentials}}
  <DetailsCredentials
    @credentials={{this.credentials}}
    @capabilities={{@capabilities}}
    @roleName={{@roleName}}
    @scopeName={{@scopeName}}
  />
{{else}}
  <form {{on "submit" (perform this.generate)}}>
    <div class="box is-sideless is-fullwidth is-marginless">
      <MessageError @errorMessage={{this.errorMessage}} />
      <Hds::Form::Select::Field
        {{on "change" (pipe (pick "target.value") (fn (mut this.format)))}}
        data-test-field="format"
        as |F|
      >
        <F.Label>Certificate format</F.Label>
        <F.Options>
          <option value="pem" selected data-test-format="pem">pem</option>
          <option value="der" data-test-format="der">der</option>
          <option value="pem_bundle" data-test-format="pem_bundle">pem_bundle</option>
        </F.Options>
      </Hds::Form::Select::Field>
    </div>

    <FormSaveButtons
      @isSaving={{this.generate.isRunning}}
      @onCancel={{transition-to "vault.cluster.secrets.backend.kmip.credentials.index"}}
    >
      <:error>
        {{#if this.invalidFormAlert}}
          <AlertInline @type="danger" class="has-top-padding-s" @message={{this.invalidFormAlert}} />
        {{/if}}
      </:error>
    </FormSaveButtons>
  </form>
{{/if}}