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

{{#if @model.id}}
  {{! Model only has ID once form has been submitted and saved }}
  <Toolbar />
  <main data-test-sign-intermediate-result>
    <div class="box is-sideless is-fullwidth is-shadowless">
      <Hds::Alert @type="inline" @color="highlight" class="has-bottom-margin-s" as |A|>
        <A.Title>Next steps</A.Title>
        <A.Description>
          The CA Chain and Issuing CA values will only be available once. Make sure you copy and save it now.
        </A.Description>
      </Hds::Alert>
      {{#each this.showFields as |fieldName|}}
        {{#let (find-by "name" fieldName @model.allFields) as |attr|}}
          <InfoTableRow @label={{or attr.options.label (humanize (dasherize attr.name))}} @value={{get @model attr.name}}>
            {{#if (and attr.options.isCertificate (get @model attr.name))}}
              <CertificateCard @data={{get @model attr.name}} />
            {{else if (eq attr.name "serialNumber")}}
              <LinkTo
                @route="certificates.certificate.details"
                @model={{@model.serialNumber}}
              >{{@model.serialNumber}}</LinkTo>
            {{else}}
              <Icon @name="minus" />
            {{/if}}
          </InfoTableRow>
        {{/let}}
      {{/each}}
      <ParsedCertificateInfoRows @model={{@model.parsedCertificate}} />
    </div>
  </main>
{{else}}
  <form {{on "submit" (perform this.save)}} data-test-sign-intermediate-form>
    <div class="box is-sideless is-fullwidth is-marginless">
      <MessageError @errorMessage={{this.errorBanner}} class="has-top-margin-s" />
      <NamespaceReminder @mode={{"create"}} @noun="signed intermediate" />
      {{#each @model.formFields as |attr|}}
        <FormField
          data-test-field={{attr}}
          @attr={{attr}}
          @model={{@model}}
          @modelValidations={{this.modelValidations}}
          @showHelpText={{false}}
        >
          {{! attr customTtl has editType yield and will show this component }}
          <PkiNotValidAfterForm @attr={{attr}} @model={{@model}} />
        </FormField>
      {{/each}}

      <PkiGenerateToggleGroups @model={{@model}} @groups={{this.groups}} />
    </div>

    <Hds::ButtonSet class="has-top-padding-s">
      <Hds::Button
        @text="Save"
        @icon={{if this.save.isRunning "loading"}}
        type="submit"
        disabled={{this.save.isRunning}}
        data-test-pki-sign-intermediate-save
      />
      <Hds::Button
        @text="Cancel"
        @color="secondary"
        class="has-left-margin-s"
        disabled={{this.save.isRunning}}
        {{on "click" this.cancel}}
        data-test-pki-sign-intermediate-cancel
      />
    </Hds::ButtonSet>
    {{#if this.inlineFormAlert}}
      <div class="control">
        <AlertInline @type="danger" class="has-top-padding-s" @message={{this.inlineFormAlert}} data-test-form-error />
      </div>
    {{/if}}

  </form>
{{/if}}