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

{{! template-lint-configure simple-unless "warn" }}
<Toolbar>
  {{#unless (and (eq @mode "show") @isWriteWithoutRead)}}
    <ToolbarFilters>
      <Toggle
        @name="json"
        @status="success"
        @size="small"
        @disabled={{and (eq @mode "show") @secretDataIsAdvanced}}
        @checked={{@showAdvancedMode}}
        @onChange={{action @editActions.toggleAdvanced}}
      >
        <span class="has-text-grey">JSON</span>
      </Toggle>
    </ToolbarFilters>
  {{/unless}}
  <ToolbarActions>
    {{#if (eq @mode "show")}}
      <SecretDeleteMenu
        @modelForData={{@modelForData}}
        @model={{@model}}
        @isV2={{@isV2}}
        @refresh={{action @editActions.refresh}}
        @canReadSecretMetadata={{@canReadSecretMetadata}}
      />
    {{/if}}
    {{#if (and (eq @mode "show") @canUpdateSecretData)}}
      {{! TODO kv engine cleanup - remove @isV2 logic }}
      {{#unless (and @isV2 (or @isWriteWithoutRead @modelForData.destroyed @modelForData.deleted))}}
        <CopySecretDropdown
          @clipboardText={{stringify @modelForData.secretData}}
          @onWrap={{perform this.wrapSecret}}
          @isWrapping={{this.wrapSecret.isRunning}}
          @wrappedData={{this.wrappedData}}
          @onClose={{this.clearWrappedData}}
        />
      {{/unless}}
    {{/if}}

    {{#if (and (eq @mode "show") @isV2 (not @model.failedServerRead))}}
      <SecretVersionMenu @version={{@modelForData}} @onRefresh={{action @editActions.refresh}} @model={{@model}} />
    {{/if}}

    {{#if (and (eq @mode "show") @canUpdateSecretData)}}
      {{#let (concat "vault.cluster.secrets.backend." (if (eq @mode "show") "edit" "show")) as |targetRoute|}}
        {{#if @isV2}}
          <ToolbarLink
            {{! Always create new version from latest if no metadata read access }}
            @route={{targetRoute}}
            @model={{@model.id}}
            @query={{hash version=(if @model.canReadMetadata @modelForData.version "")}}
            @replace={{true}}
            @type="add"
            data-test-secret-edit="true"
          >
            Create new version
          </ToolbarLink>
        {{else}}
          <ToolbarLink @route={{targetRoute}} @model={{@model.id}} @replace={{true}} data-test-secret-edit="true">
            Edit secret
          </ToolbarLink>
        {{/if}}
      {{/let}}
    {{/if}}
  </ToolbarActions>
</Toolbar>