{{!
  Copyright IBM Corp. 2016, 2025
  SPDX-License-Identifier: BUSL-1.1
}}
<div class="has-border-bottom-light">
  <Clients::PageHeader
    @billingStartTime={{this.formattedBillingStartDate}}
    @retentionMonths={{@config.retentionMonths}}
    @activityTimestamp={{@activity.responseTimestamp}}
    @startTimestamp={{@startTimestamp}}
    @endTimestamp={{@endTimestamp}}
    @upgradesDuringActivity={{this.upgradesDuringActivity}}
    @noData={{not @activity.total.clients}}
    @onChange={{this.onDateChange}}
  />
</div>

<div class="has-top-bottom-margin">
  <Hds::Text::Body @tag="p" @size="100" class="has-bottom-margin-s">
    This is the dashboard for your overall client count usage. Review Vault's
    <Hds::Link::Inline @href={{doc-link "/vault/docs/concepts/client-count"}} @isHrefExternal={{true}}>
      client counting documentation</Hds::Link::Inline>
    for more information.
  </Hds::Text::Body>

  {{#if (eq @activity.id "no-data")}}
    <Clients::NoData @config={{@config}} />
  {{else if @activityError}}
    <Clients::Counts::Error @error={{@activityError}} />
  {{else}}
    {{#if (eq @config.enabled "Off")}}
      <Hds::Alert @type="inline" @color="warning" class="has-bottom-margin-s" as |A|>
        <A.Title data-test-counts-disabled>Tracking is disabled</A.Title>
        <A.Description>
          Tracking is currently disabled and data is not being collected. Historical data can be searched, but you will need
          to
          <Hds::Link::Inline @route="vault.cluster.clients.edit">edit the configuration</Hds::Link::Inline>
          to enable tracking again.
        </A.Description>
      </Hds::Alert>
    {{/if}}

    {{#if @activity.total}}
      {{#if this.upgradeExplanations}}
        <Hds::Alert data-test-clients-upgrade-warning @type="inline" @color="warning" class="has-bottom-margin-m" as |A|>
          <A.Title>
            Client count data contains
            {{pluralize this.upgradeExplanations.length "upgrade"}}
          </A.Title>
          <A.Description>
            Vault was upgraded during this time period. Keep this in mind while looking at the data. Visit our
            <Hds::Link::Inline
              @isHrefExternal={{true}}
              @href={{doc-link
                "/vault/docs/concepts/client-count/faq#q-which-vault-version-reflects-the-most-accurate-client-counts"
              }}
            >
              Client count FAQ
            </Hds::Link::Inline>
            for more information.
          </A.Description>
          <A.Description>
            <ul class="bullet">
              {{#each this.upgradeExplanations as |info|}}
                <li>{{info}}</li>
              {{/each}}
            </ul>
          </A.Description>
        </Hds::Alert>
      {{/if}}

      {{#if (and this.version.isEnterprise (not this.flags.isHvdManaged))}}
        {{! The "Client list" tab only renders for enterprise versions so there is no need for the nav bar }}
        {{! The "Client list" tab is hidden on HVD managed clusters (for now) because the "Month" filter for that page
        uses the `client_first_used_time` timestamp. This timestamp tracks when a client is FIRST seen in the queried date range (i.e. billing period). 
        This is useful for self-managed customers who are billed on monthly NEW clients, but not for HVD users who are billed on TOTAL clients per 
        month regardless of whether the client was seen in a previous month. }}
        <Clients::Counts::NavBar />
      {{/if}}

      {{! CLIENT COUNT PAGE COMPONENTS RENDER HERE }}
      {{yield}}
    {{else if (and this.version.isCommunity (or (not @startTimestamp) (not @endTimestamp)))}}
      {{! Empty state for community without start or end query param }}
      <EmptyState
        @title="Input the start and end dates to view client attribution by path."
        @message="Only historical data may be queried. No data is available for the current month."
      />
    {{else}}
      <EmptyState
        @title="No data received"
        @message={{if
          this.version.isCommunity
          "Select a start and end date above to query client count data."
          "Select a different date range to view client count data."
        }}
      />
    {{/if}}
  {{/if}}
</div>