<Toolbar>
  <ToolbarActions>
    {{#if @role.canDelete}}
      <ConfirmAction
        @buttonClasses="toolbar-link"
        @onConfirmAction={{this.deleteRole}}
        @confirmTitle="Delete role?"
        @confirmButtonText="Delete"
        data-test-pki-role-delete
      >
        Delete
      </ConfirmAction>
      <div class="toolbar-separator"></div>
    {{/if}}
    {{#if @role.canGenerateCert}}
      <LinkTo class="toolbar-link" @route="roles.role.generate" @model={{@role.id}} data-test-pki-role-generate-cert>
        Generate Certificate
        <Icon @name="chevron-right" />
      </LinkTo>
    {{/if}}
    {{#if @role.canSign}}
      <LinkTo class="toolbar-link" @route="roles.role.sign" @model={{@role.id}} data-test-pki-role-sign-cert>
        Sign Certificate
        <Icon @name="chevron-right" />
      </LinkTo>
    {{/if}}
    {{#if @role.canEdit}}
      <LinkTo class="toolbar-link" @route="roles.role.edit" @model={{@role.id}} data-test-pki-role-edit-link>
        Edit
        <Icon @name="chevron-right" />
      </LinkTo>
    {{/if}}
  </ToolbarActions>
</Toolbar>
{{#each @role.formFieldGroups as |fg|}}
  {{#each-in fg as |group fields|}}
    {{#if (not-eq group "default")}}
      <h3 class="is-size-4 has-text-semibold has-top-margin-m">{{group}}</h3>
    {{/if}}
    {{#each fields as |attr|}}
      {{#let (get @role attr.name) as |val|}}
        {{#if (eq attr.name "issuerRef")}}
          <InfoTableRow
            @label={{capitalize (or attr.options.detailsLabel attr.options.label (humanize (dasherize attr.name)))}}
            @value={{val}}
            @alwaysRender={{true}}
          >
            <LinkTo @route="issuers.issuer.details" @model={{val}}>{{val}}</LinkTo>
          </InfoTableRow>
        {{else if (includes attr.name this.arrayAttrs)}}
          <InfoTableRow
            @label={{capitalize (or attr.options.detailsLabel attr.options.label (humanize (dasherize attr.name)))}}
            @value={{val}}
            @alwaysRender={{true}}
          >
            {{#if (gt val.length 0)}}
              {{#each val as |key|}}
                <span>{{key}}, </span>
              {{/each}}
            {{else}}
              None
            {{/if}}
          </InfoTableRow>
        {{else if (eq attr.name "noStore")}}
          <InfoTableRow
            @label={{capitalize (or attr.options.detailsLabel attr.options.label (humanize (dasherize attr.name)))}}
            @value={{not val}}
            @alwaysRender={{true}}
          />
        {{else if (eq attr.name "customTtl")}}
          {{! Show either notAfter or ttl }}
          <InfoTableRow
            @label={{capitalize (or attr.options.detailsLabel attr.options.label (humanize (dasherize attr.name)))}}
            @value={{or @role.notAfter @role.ttl}}
            @alwaysRender={{true}}
            @formatDate={{if @role.notAfter "MMM d yyyy HH:mm zzzz"}}
            @formatTtl={{@role.ttl}}
          />
        {{else}}
          <InfoTableRow
            @label={{capitalize (or attr.options.detailsLabel attr.options.label (humanize (dasherize attr.name)))}}
            @value={{val}}
            @alwaysRender={{true}}
            @type={{or attr.type attr.options.type}}
            @defaultShown={{attr.options.defaultShown}}
            @formatTtl={{eq attr.options.editType "ttl"}}
          />
        {{/if}}
      {{/let}}
    {{/each}}
  {{/each-in}}
{{/each}}