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

<form>
  {{!-- fieldsets already converted to components --}}
  {{#if (not (token/is-legacy @item))}}
    <Consul::Token::Fieldsets
      @item={{@item}}
      @create={{@create}}
      @local={{@local}}
      @dc={{@dc}}
      @partition={{@partition}}
      @nspace={{@nspace}}
      @onChange={{@onChange}}
    />
  {{else}}
    <Consul::Token::FieldsetsLegacy
      @item={{@item}}
      @create={{@create}}
      @name={{@name}}
      @onChange={{@onChange}}
    />
  {{/if}}

  <div>
    <Hds::ButtonSet>
      {{#if (and @create (can "create tokens")) }}
        <Hds::Button
          @text='Save'
          type='submit'
          {{on 'click' @onCreate}}
          disabled={{if (or (and (token/is-legacy @item) @item.isPristine) @item.isInvalid) 'disabled'}}
        />
      {{ else }}
        {{#if (can "write token" item=@item)}}
          <Hds::Button
            @text='Save'
            type='submit'
            {{on 'click' @onUpdate}}
            disabled={{if @item.isInvalid 'disabled'}}
          />
        {{/if}}
      {{/if}}

      <Hds::Button
        @text='Cancel'
        @color='secondary'
        type='reset'
        {{on 'click' @onCancel}}
      />

      {{# if (and (not @create) (can "delete token" item=@item token=@token) ) }}
        <ConfirmationDialog @message="Are you sure you want to delete this Token?">
          <BlockSlot @name="action" as |confirm|>
            <Hds::Button
              @text='Delete'
              @color='critical'
              {{on 'click' confirm}}
              data-test-delete
            />
          </BlockSlot>
          <BlockSlot @name="dialog" as |execute cancel message|>
            <DeleteConfirmation @message={{message}} @execute={{queue execute (fn @onDelete @item)}} @cancel={{cancel}} />
          </BlockSlot>
        </ConfirmationDialog>
      {{/if}}
    </Hds::ButtonSet>
  </div>
</form>