{# ------------------------ #}
{# Available Variables #}
{# ------------------------ #}
{# Attributes: #}
{# type, name, handle, instructions, attribute, default, feed, feedData #}
{# ------------------------ #}
{# Fields: #}
{# name, handle, instructions, feed, feedData, field, fieldClass #}
{# ------------------------ #}

{% import 'feed-me/_macros' as feedMeMacro %}
{% import '_includes/forms' as forms %}

{# Special case when inside another complex field (Matrix) #}
{% if parentPath is defined %}
  {% set prefixPath = parentPath %}
{% else %}
  {% set prefixPath = [handle] %}
{% endif %}

{% set classes = ['complex-field'] %}

<tr class="complex-field complex-field-header">
  <td class="col-field" colspan="3">
    <div class="field">
      <div class="heading">
        <label class="">{{ name }}</label>
      </div>

      <div class="additional-mapping-fields">
        {% namespace 'fieldMapping[' ~ prefixPath|join('][') ~ ']' %}
          <input type="text" name="field" value="{{ className(field) }}">
        {% endnamespace %}
      </div>
    </div>
  </td>
</tr>

{% set subfields = [
  {
    key: 'type',
    label: 'Type',
    required: true,
    default: {
      type: 'select',
      options: field.enabledLinkTypes.displayNames,
    }
  },
  { key: 'ariaLabel', label: 'Aria label'},
  { key: 'customQuery', label: 'Custom query' },
  { key: 'customText', label: 'Custom text'},
  { key: 'linkedId', label: 'Linked id' },
  { key: 'linkedSiteId', label: 'Linked site id' },
  { key: 'linkedUrl', label: 'Linked url' },
  { key: 'target', label: 'Target'},
  { key: 'title', label: 'Title'},
] %}

{% for subfield in subfields %}
  {% set default = subfield.default ?? { type: 'text' } %}
  {% set instructionsHandle = handle ~ '[' ~ subfield.key ~ ']' %}
  {% set nameLabel = subfield.label %}
  {% set path = prefixPath|merge ([ 'fields', subfield.key ]) %}
  {% set required = subfield.required ?? false %}

  {% embed 'feed-me/_includes/fields/_base' %}
    {% block additionalFieldSettings %}{% endblock %}
    {% block fieldSettings %}{% endblock %}
  {% endembed %}
{% endfor %}
