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

{{!--
  Exists as a "middleman" between AllocationStatusRow and IndividualAllocation
  only when showSummaries in AllocationStatusRow is true (i.e. when the math of how
  many allocations to show in each block is done x minWidth of each alloc exceeds
  available space)
--}}

<div
  class="allocation-status-block {{unless this.countToShow "rest-only"}}"
  style={{html-safe (concat "width: " @width "px")}}
>
  {{#if this.countToShow}}
    <div class="ungrouped-allocs">
      {{#each (range 0 this.countToShow) as |i|}}
        <JobStatus::IndividualAllocation
          @allocation={{get @allocs i}}
          @status={{@status}}
          @health={{@health}}
          @canary={{@canary}}
          @steady={{@steady}}
        />
      {{/each}}
    </div>
  {{/if}}
  {{#if this.remaining}}

    <ConditionalLinkTo
      @condition={{not (eq @status "unplaced")}}
      @route="jobs.job.allocations"
      @model={{@allocs.0.job}}
      @query={{hash status=(concat '["' @status '"]') version=(concat '[' @allocs.0.jobVersion ']')}}
      @class="represented-allocation rest {{@status}} {{@health}} {{@canary}}"
      @label="View all {{@status}} allocations"
    >
      <span class="rest-count">{{#if this.countToShow}}+{{/if}}{{this.remaining}}</span>
      {{#unless @steady}}
        {{#if (eq @canary "canary")}}
          <span class="alloc-canary-indicator" />
        {{/if}}
        {{#if (eq @status "running")}}
          <span class="alloc-health-indicator">
            {{#if (eq @health "healthy")}}
              <Hds::Icon @name="check" @color="#25ba81" @isInline={{true}} />
            {{else if (eq @health "unhealthy")}}
              <Hds::Icon @name="x" @color="#c84034" @isInline={{true}} />
            {{else}}
              <Hds::Icon @name="running" @color="black" @isInline={{true}} />
            {{/if}}
          </span>
        {{/if}}
      {{/unless}}
    </ConditionalLinkTo>
  {{/if}}
</div>