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

<OverviewCard
  @cardTitle="Accounts checked-out"
  @subText="The accounts that are currently on lease with this token or exist in a library set with check-in enforcement disabled."
  class="has-padding-l"
  ...attributes
>
  <:content>
    <hr class="has-background-gray-200" />

    {{#if @isLoadingStatuses}}
      <div class="has-padding-l flex is-centered">
        <Hds::Icon @name="loading" @color="neutral" @size="24" />
      </div>
    {{else if this.filteredAccounts}}
      <Hds::Table @model={{this.filteredAccounts}} @columns={{this.columns}}>
        <:body as |Body|>
          <Body.Tr>
            <Body.Td data-test-checked-out-account={{Body.data.account}}>{{Body.data.account}}</Body.Td>
            {{#if @showLibraryColumn}}
              <Body.Td data-test-checked-out-library={{Body.data.account}}>{{Body.data.library}}</Body.Td>
            {{/if}}
            <Body.Td>
              <Hds::Button
                @icon="queue"
                @text="Check-in"
                @color="tertiary"
                disabled={{this.disableCheckIn Body.data.library}}
                data-test-checked-out-account-action={{Body.data.account}}
                {{on "click" (fn (mut this.selectedStatus) Body.data)}}
              />
            </Body.Td>
          </Body.Tr>
        </:body>
      </Hds::Table>
    {{else}}
      <EmptyState
        @title="No accounts checked out yet"
        @message="There is no account that is currently in use."
        class="is-shadowless"
      />
    {{/if}}
  </:content>
</OverviewCard>

{{#if this.selectedStatus}}
  <Hds::Modal id="account-check-in-modal" @onClose={{fn (mut this.selectedStatus) undefined}} as |M|>
    <M.Header>
      Account Check-in
    </M.Header>
    <M.Body>
      <p>
        This action will check-in account
        {{this.selectedStatus.account}}
        back to the library. Do you want to proceed?
      </p>
    </M.Body>
    <M.Footer>
      <Hds::ButtonSet>
        <Hds::Button
          @icon={{if this.save.isRunning "is-loading"}}
          disabled={{this.checkIn.isRunning}}
          data-test-check-in-confirm
          {{on "click" (perform this.checkIn)}}
          @text="Confirm"
        />
        <Hds::Button
          @icon={{if this.save.isRunning "is-loading"}}
          @color="secondary"
          disabled={{this.checkIn.isRunning}}
          {{on "click" (fn (mut this.selectedStatus) "")}}
          @text="Cancel"
        />

      </Hds::ButtonSet>
    </M.Footer>
  </Hds::Modal>
{{/if}}