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

<SyncHeader
  @icon={{get (find-by "type" @destination.type (sync-destinations)) "icon"}}
  @title={{@destination.name}}
  @breadcrumbs={{array
    (hash label="Secrets Sync" route="secrets.overview")
    (hash label="Destinations" route="secrets.destinations")
    (hash label="Destination")
  }}
/>

{{#if @destination.purge_initiated_at}}
  <Hds::Alert
    data-test-delete-status-banner
    @type="inline"
    class="has-bottom-margin-m"
    @color={{if @destination.purge_error "critical" "neutral"}}
    @icon={{unless @destination.purge_error "loading-static"}}
    as |A|
  >
    {{#if @destination.purge_error}}
      <A.Title>Deletion failed</A.Title>
      <A.Description>
        There was a problem with the delete purge initiated at
        {{date-format @destination.purge_initiated_at "MMM dd, yyyy 'at' hh:mm:ss aaa"}}.
      </A.Description>
      <A.Description>
        {{@destination.purge_error}}
      </A.Description>
    {{else}}
      <A.Title>Deletion in progress</A.Title>
      <A.Description>
        Purge initiated on
        {{date-format @destination.purge_initiated_at "MMM dd, yyyy 'at' hh:mm:ss aaa"}}. This process may take some time
        depending on how many secrets must be un-synced from this destination.
      </A.Description>
    {{/if}}
  </Hds::Alert>
{{/if}}

<div class="tabs-container box is-bottomless is-marginless is-paddingless">
  <nav class="tabs" aria-label="destination tabs">
    <ul>
      <li><LinkTo @route="secrets.destinations.destination.secrets" data-test-tab="Secrets">Secrets</LinkTo></li>
      <li><LinkTo @route="secrets.destinations.destination.details" data-test-tab="Details">Details</LinkTo></li>
    </ul>
  </nav>
</div>

<Toolbar>
  {{#if @refreshList}}
    <ToolbarFilters>
      <Hds::Button
        @text="Refresh list"
        @icon="reload"
        @color="secondary"
        class="toolbar-button"
        data-test-refresh-list
        {{on "click" @refreshList}}
      />
    </ToolbarFilters>
  {{/if}}
  <ToolbarActions>
    {{#if (has-capability @capabilities "delete" pathKey="syncDestination" params=@destination)}}
      <Hds::Button
        data-test-toolbar="Delete destination"
        @text="Delete destination"
        @color="secondary"
        class="toolbar-button"
        {{on "click" (fn (mut this.isDeleteModalOpen) true)}}
      />
      {{#if (or this.showSyncBtn this.showEditBtn)}}
        <div class="toolbar-separator"></div>
      {{/if}}
    {{/if}}
    {{#if this.showSyncBtn}}
      <Hds::Button
        data-test-toolbar="Sync secrets"
        @text="Sync secrets"
        @icon="chevron-right"
        @iconPosition="trailing"
        @color="secondary"
        class="toolbar-button"
        @route="secrets.destinations.destination.sync"
      />
    {{/if}}
    {{#if this.showEditBtn}}
      <Hds::Button
        data-test-toolbar="Edit destination"
        @text="Edit destination"
        @icon="chevron-right"
        @iconPosition="trailing"
        @color="secondary"
        class="toolbar-button"
        @route="secrets.destinations.destination.edit"
      />
    {{/if}}
  </ToolbarActions>
</Toolbar>

<ConfirmationModal
  @title="Delete destination?"
  @onClose={{fn (mut this.isDeleteModalOpen) false}}
  @isActive={{this.isDeleteModalOpen}}
  @confirmText="DELETE"
  @toConfirmMsg="— this is case-sensitive."
  @onConfirm={{this.deleteDestination}}
>
  <p>
    The destination will be permanently deleted and all of its secrets will be un-synced. This cannot be undone.
  </p>
</ConfirmationModal>