{# Variables in this template:

    data_controller="one two three" | optional

    field_type = singleline | multiline | parent

    singleline_suffix

    field_editable=true/false | optional

    field_class_name | optional
    field_input_name
    field_name
    field_label | optional
    field_value
    errors

    field_actions={
      'delete':true,
      'move_up':true,
      'move_down':true,
    } | optional

#}

{% if field_required is not defined -%}
{% set field_required=false -%}
{%- endif -%}

<sdoc-form-row
  {% if data_controller is defined -%}
    data-controller="{{ data_controller }}"
  {%- endif -%}
>
  <sdoc-form-row-aside>
    {%- if field_actions is defined -%}
      {% if field_actions.move_up is defined and field_actions.move_up is sameas true -%}
        <button
          class="field_action"
          title="Move this {{ field_name|default('FIELD', true) }} up"
          data-action-type="move_up"
          data-js-move-up-field-action
          data-turbo-action="replace"
          data-turbo="false"
          data-testid="form-move-up-{{ field_input_name|default('FIELD', true) }}-field-action"
        >{% include "_res/svg_ico16_move_up.jinja.html" %}</button>
      {%- endif -%}

      {% if field_actions.move_down is defined and field_actions.move_down is sameas true -%}
        <button
          class="field_action"
          title="Move this {{ field_name|default('FIELD', true) }} down"
          data-action-type="move_down"
          data-js-move-down-field-action
          data-turbo-action="replace"
          data-turbo="false"
          data-testid="form-move-down-{{ field_input_name|default('FIELD', true) }}-field-action"
        >{% include "_res/svg_ico16_move_down.jinja.html" %}</button>
      {%- endif -%}
    {%- endif -%}
  </sdoc-form-row-aside>

  <sdoc-form-row-main>
    {%- if errors|length > 0 -%}
      {%- for error in errors -%}
      <sdoc-form-error>
        {{ error }}
      </sdoc-form-error>
      {%- endfor -%}
    {%- endif -%}

    <sdoc-form-field>
      <sdoc-contenteditable
        data-controller="editablefield"
        {% if field_required %}required{% endif %}
        role="textbox"
        data-field-type="{{ field_type }}"
        {%- if field_editable is defined and not field_editable -%}
          contenteditable="false"
        {%- else -%}
          contenteditable="true"
        {%- endif -%}
        id="{{ field_input_name }}"
        placeholder="Enter {{ field_name|default('FIELD_NAME', true) }} here..."
        data-field-label="{{ field_label if field_label is defined else field_name }}{% if field_required %} *{% endif %}"
        {%- if field_type == "singleline" and singleline_suffix is defined -%}
          data-field-suffix="{{ singleline_suffix }}"
        {%- endif -%}
        {%- if field_class_name is defined -%}
          class="{{ field_class_name }}"
        {%- endif -%}
        data-testid="form-field-{{ field_input_name }}"
      >
        {%- if true -%}
          {{ field_value }}
        {%- endif -%}
      </sdoc-contenteditable>

      {%- if field_type == "parent" -%}
        <input type="hidden" name="{{ field_input_name }}" value="{{ field_value }}" {% if field_required %}required{% endif %}/>
      {%- endif -%}

      {%- if field_type == "singleline" -%}
        <input type="hidden" name="{{ field_input_name }}" value="{{ field_value }}" {% if field_required %}required{% endif %}/>
      {%- endif -%}

      {%- if field_type == "multiline" -%}
        <textarea hidden name="{{ field_input_name }}" {% if field_required %}required{% endif %}>
          {%- if true -%}
          {{ field_value }}
          {%- endif -%}
        </textarea>
      {%- endif -%}
    </sdoc-form-field>

  </sdoc-form-row-main>

  <sdoc-form-row-aside>
    {%- if field_actions is defined -%}
      {% if field_actions.delete is defined and field_actions.delete is sameas true -%}
        <button
          class="field_action"
          title="Delete this {{ field_name|default('FIELD', true) }}"
          data-action-type="delete"
          data-js-delete-field-action
          data-turbo-action="replace"
          data-turbo="false"
          data-testid="form-delete-{{ field_input_name|default('FIELD', true) }}-field-action"
        >{% include "_res/svg_ico16_delete.jinja.html" %}</button>
      {%- endif -%}

      {% if field_actions.reset is defined and field_actions.reset is sameas true -%}
        <a
          class="field_action"
          href="/reset_uid?reference_mid={{ reference_mid }}"
          mid="{{ field_mid }}"
          title="Reset UID to default"
          data-action-type="reset"
          data-turbo-action="replace"
          data-turbo="true"
          data-testid="reset-uid-field-action"
        >{% include "_res/svg_ico16_reset.jinja" %}</a>
      {%- endif -%}

    {%- endif -%}
  </sdoc-form-row-aside>
</sdoc-form-row>
