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

<Hds::Card::Container
  class="has-top-padding-m has-bottom-padding-m side-padding-24"
  @hasBorder={{true}}
  @level="mid"
  ...attributes
  data-test-card-container={{@index}}
>
  <Hds::Layout::Flex @justify="space-between" class="has-bottom-margin-xs">
    <Hds::Text::Body @tag="p" @weight="semibold" @color="strong">
      Rule
    </Hds::Text::Body>
    <Hds::Form::Toggle::Field {{on "input" this.togglePreview}} data-test-toggle-input="preview" as |F|>
      <F.Label data-test-form-field-label="preview">{{if this.showPreview "Hide" "Show"}} preview</F.Label>
    </Hds::Form::Toggle::Field>
  </Hds::Layout::Flex>

  {{#if this.showPreview}}
    <Hds::CodeBlock
      @language="hcl"
      @value={{@stanza.preview}}
      @hasLineNumbers={{false}}
      @hasCopyButton={{true}}
      data-test-field="preview"
    />
  {{else}}
    <Hds::Layout::Flex @gap="8">
      <Hds::Form::TextInput::Base
        @type="text"
        @value={{@stanza.path}}
        aria-label="Resource path"
        name="path-{{@index}}"
        {{on "input" this.setPath}}
        autocomplete="off"
        placeholder="Enter a resource path"
        data-test-input="path"
      />
      <Hds::Button
        @icon="trash"
        @isIconOnly={{true}}
        @text="Delete"
        @color="critical"
        {{on "click" @onDelete}}
        data-test-button="Delete"
      />
    </Hds::Layout::Flex>

    <Hds::Form::Checkbox::Group @layout="horizontal" as |G|>
      <G.Legend class="has-top-padding-m">Capabilities</G.Legend>
      {{#each this.permissions as |capability|}}
        <G.CheckboxField
          checked={{this.hasCapability capability}}
          @value={{capability}}
          {{on "input" this.setPermissions}}
          data-test-checkbox={{capability}}
          as |F|
        >
          <F.Label data-test-form-field-label={{capability}}>{{capability}}</F.Label>
        </G.CheckboxField>
      {{/each}}
    </Hds::Form::Checkbox::Group>
  {{/if}}

</Hds::Card::Container>