{{ define "items:fields" }}

{{ range (index .FieldsSection .uisection) }}
{{ $field := .}}
{{ $values := (index $.FieldsValues .Type_field_id)}}

{{ if eq .Is_multiple 1}}
<fieldset>
  <label>{{ .Title }}</label>
  <div id="fields-{{ .Type_field_id }}">
  {{ $g_counter := 0 }}
  {{ range $counter, $value := $values}}
  <input type="hidden" id="FieldsValuesToRemove-{{$field.Type_field_id}}-{{$counter}}" name="FieldsValuesToRemove-{{$field.Type_field_id}}-{{$counter}}" value="0"/>
  <div class="field">
    <div id="FieldsValues-{{$field.Type_field_id}}-{{$counter}}" class="field-value">{{ field_widget $field.Widget $field.Type_field_id $counter "" $value $field.Valid_values ""}}</div>
    <div class="field-buttons">
      <button onclick="bm_item_field_delete(this, '{{$field.Type_field_id}}-{{$counter}}')" id="Delete-{{$field.Type_field_id}}-{{$counter}}" class="delete"  type="button"><i class="bi bi-dash-square" title="Remove"></i></button>
      <button onclick="bm_item_field_undelete(this, '{{$field.Type_field_id}}-{{$counter}}')" id="Undelete-{{$field.Type_field_id}}-{{$counter}}" hidden class="main" type="button"><i class="bi bi-arrow-counterclockwise" title="Undo"></i></button>
    </div>
  </div>
  {{ $g_counter = $counter}}
  {{ end }}
  </div>

  <span class="hide" id="fields-{{.Type_field_id}}-counter">{{incr $g_counter }}</span>
  <button type="button" onclick="bm_item_field_add('{{.Type_field_id}}', '{{.Widget}}')" class="main"><i class='bi bi-plus-square-fill'></i> <span> Add value</span></button>
</fieldset>
{{ else }}
  <p>
    {{ $value := ""}}
    {{ if gt (len $values) 0 }}
      {{ $value = index $values 0 }}
    {{ end }}
    {{ field_widget .Widget .Type_field_id 0 .Title $value .Valid_values ""}}
  </p>
{{ end }}
{{ end }}

{{ end }}