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

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

{{#if @destination.purgeInitiatedAt}}
  <Hds::Alert
    data-test-delete-status-banner
    @type="inline"
    class="has-bottom-margin-m"
    @color={{if @destination.purgeError "critical" "neutral"}}
    @icon={{unless @destination.purgeError "loading-static"}}
    as |A|
  >
    {{#if @destination.purgeError}}
      <A.Title>Deletion failed</A.Title>
      <A.Description>
        There was a problem with the delete purge initiated at
        {{date-format @destination.purgeInitiatedAt "MMM dd, yyyy 'at' hh:mm:ss aaa"}}.
      </A.Description>
      <A.Description>
        {{@destination.purgeError}}
      </A.Description>
    {{else}}
      <A.Title>Deletion in progress</A.Title>
      <A.Description>
        Purge initiated on
        {{date-format @destination.purgeInitiatedAt "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 @destination.canDelete}}
      <Hds::Button
        data-test-toolbar="Delete destination"
        @text="Delete destination"
        @color="secondary"
        class="toolbar-button"
        {{on "click" (fn (mut this.isDeleteModalOpen) true)}}
      />
      {{#if (or @destination.canSync @destination.canEdit)}}
        <div class="toolbar-separator"></div>
      {{/if}}
    {{/if}}
    {{#if @destination.canSync}}
      <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 @destination.canEdit}}
      <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>