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

<Hds::Text::Body class="has-top-margin-l has-bottom-margin-m" @tag="p" @size="100" @color="faint">The client list data below
  comes from the
  <Hds::Link::Inline
    @icon="docs-link"
    @iconPosition="trailing"
    @isHrefExternal={{true}}
    @href={{doc-link "/vault/api-docs/system/internal-counters#activity-export"}}
  >
    Activity Export API
  </Hds::Link::Inline>. It may take up to ten minutes for new client IDs to appear in the export data.
</Hds::Text::Body>

<Clients::CountsCard data-test-card="Export activity data">
  <:subheader>
    <Clients::FilterToolbar
      @dataset={{@exportData}}
      @onFilter={{this.handleFilter}}
      @filterQueryParams={{@filterQueryParams}}
      @isExportData={{true}}
    />
  </:subheader>

  <:table>
    <Hds::Tabs @onClickTab={{this.onClickTab}} @selectedTabIndex={{this.selectedTabIndex}} as |T|>
      {{#each-in this.exportDataByTab as |tabName exportData|}}
        {{#let (this.filterData exportData) as |tableData|}}
          <T.Tab @count={{or tableData.length "0"}} data-test-tab={{tabName}}>{{tabName}}</T.Tab>
          <T.Panel>
            <div class="has-top-margin-xs">
              {{#if this.filtersAreApplied}}
                <Hds::Text::Body @tag="p" @color="faint" class="has-bottom-margin-xs" data-test-table-summary={{tabName}}>
                  Summary:
                  {{pluralize tableData.length "client"}}
                  {{if (eq tableData.length 1) "matches" "match"}}
                  the filter criteria.
                </Hds::Text::Body>
              {{/if}}

              {{! Elements "behind" tabs always render on the DOM and are just superficially hidden/shown. }}
              {{! The export data can be many rows so for performance only render the currently selected tab }}
              {{#if (eq tabName this.selectedTab)}}
                <Clients::Table
                  data-test-table="attribution"
                  @data={{tableData}}
                  @columns={{this.tableColumns tabName}}
                  @setPageSize={{50}}
                  @showPaginationSizeSelector={{true}}
                >

                  <:emptyState>
                    {{#if (and (eq tabName "Secret sync") (not this.flags.secretsSyncIsActivated))}}
                      <Hds::ApplicationState as |A|>
                        <A.Header @title="No secret sync clients" />
                        <A.Body @text="No data is available because Secrets Sync has not been activated." />
                        <A.Body>
                          <Hds::Link::Standalone
                            @icon="chevron-right"
                            @iconPosition="trailing"
                            @text="Activate Secrets Sync"
                            @route="vault.cluster.sync.secrets.overview"
                          />
                        </A.Body>
                      </Hds::ApplicationState>
                    {{else}}
                      <Hds::ApplicationState as |A|>
                        <A.Header @title="No data found" />
                        <A.Body
                          @text="Select another client type {{if
                            this.filtersAreApplied
                            'or update filters'
                            ''
                          }} to view client count data."
                        />
                      </Hds::ApplicationState>
                    {{/if}}
                  </:emptyState>
                </Clients::Table>
              {{/if}}
            </div>
          </T.Panel>
        {{/let}}
      {{/each-in}}
    </Hds::Tabs>
  </:table>
</Clients::CountsCard>