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

{{#if this.model.replicationAttrs.isPrimary}}
  <Toolbar>
    <ToolbarActions>
      {{#if this.model.replicationAttrs.knownSecondaries.length}}
        {{#if this.model.canRevokeSecondary}}
          <ToolbarLink @route="mode.secondaries.revoke" @model={{this.replicationMode}}>
            Revoke secondary
          </ToolbarLink>
        {{/if}}
      {{/if}}
      {{#if this.model.canAddSecondary}}
        <ToolbarLink @route="mode.secondaries.add" @model={{this.replicationMode}} @type="add" data-test-secondary-add>
          Add secondary
        </ToolbarLink>
      {{/if}}
    </ToolbarActions>
  </Toolbar>
  {{#if this.model.replicationAttrs.knownSecondaries.length}}
    {{#each this.model.replicationAttrs.knownSecondaries as |secondary|}}
      <div class="list-item-row overflow-wrap" data-test-secondary-name={{secondary}}>
        <div class="columns is-mobile">
          <div class="column is-10">
            {{secondary}}
          </div>
          <div class="column has-text-right">
            {{#if (or (eq this.replicationMode "performance") this.model.canRevokeSecondary)}}
              <Hds::Dropdown @isInline={{true}} @listPosition="bottom-right" as |dd|>
                <dd.ToggleIcon
                  @icon="more-horizontal"
                  @text="Secondary popup nav menu"
                  @hasChevron={{false}}
                  data-test-popup-menu-trigger
                />
                {{#if (eq this.replicationMode "performance")}}
                  <dd.Interactive
                    @route="mode.secondaries.config-show"
                    @models={{array this.replicationMode secondary}}
                    data-test-replication-path-filter-link
                  >Path filter config</dd.Interactive>
                {{/if}}
                {{#if this.model.canRevokeSecondary}}
                  <dd.Interactive
                    @color="critical"
                    {{on "click" (fn (mut this.secondaryToRevoke) secondary)}}
                  >Revoke</dd.Interactive>
                {{/if}}
              </Hds::Dropdown>
            {{/if}}
          </div>
        </div>
      </div>
      <hr class="is-marginless" />
    {{/each}}
  {{else}}
    <EmptyState
      @title="No known {{this.performanceMode}} secondary clusters associated with this cluster"
      @message="Associated secondary clusters will be listed here. Add your first secondary cluster to get started."
    >
      <Hds::Link::Standalone
        @icon="docs-link"
        @iconPosition="trailing"
        @text="Replication documentation"
        @href={{doc-link "/vault/docs/internals/replication"}}
      />
    </EmptyState>
  {{/if}}
{{/if}}

{{#if this.secondaryToRevoke}}
  <ConfirmModal
    @color="critical"
    @confirmTitle="Revoke token?"
    @confirmMessage="This will revoke this secondary token."
    @onClose={{fn (mut this.secondaryToRevoke) null}}
    @onConfirm={{action "onSubmit" "revoke-secondary" "primary" (hash id=this.secondaryToRevoke)}}
  />
{{/if}}