{%- extends "components/form/row/index.jinja" %}

{% assert form_object is defined, "form_object must be defined." %}
{% assert form_object.errors is defined, "form_object: errors must be defined." %}
{% assert form_object.field is defined, "form_object: field must be defined." %}

{% block row_form_attributes %}
  data-controller="deletable_field movable_field"
{% endblock row_form_attributes %}

{% block row_left %}
  {%- set action_button_context = namespace() %}
  {%- set action_button_context.field_actions = {"move_down": true} %}
  {%- set action_button_context.field_name = form_object.field.field_name %}
  {%- set action_button_context.field_input_name = form_object.field.get_input_field_name() %}
  {%- set action_button_context.mid = form_object.field.field_mid %}
  {%- set action_button_context.testid_postfix = "custom-field" %}
  {%- include "components/form/field_action_button/index.jinja" -%}

  {%- set action_button_context = namespace() %}
  {%- set action_button_context.field_actions = {"move_up": true} %}
  {%- set action_button_context.field_name = form_object.field.field_name %}
  {%- set action_button_context.field_input_name = form_object.field.get_input_field_name() %}
  {%- set action_button_context.mid = form_object.field.field_mid %}
  {%- set action_button_context.testid_postfix = "custom-field" %}
  {%- include "components/form/field_action_button/index.jinja" -%}
{% endblock row_left %}

{% block row_content scoped %}

{%- set _name_errors = form_object.get_errors(form_object.field.get_input_field_name()) %}
{%- set _human_name_errors = form_object.get_errors(form_object.field.get_input_field_human_title()) %}
<sdoc-form-field-group
  data-field-label="Custom field"
  {% if _name_errors|length or _human_name_errors|length -%}
    errors="true"
  {%- endif -%}
>

  {# FIXME: This will become a proper checkbox field eventually. #}
  <input
    type="hidden"
    value="{{ form_object.field.get_input_field_required_value() }}"
    name="{{ form_object.field.get_input_field_required() }}"
  />

  {%- set placeholder_name = form_object.field.field_name|default('custom field name', true) %}
  {# field_placeholder = "Enter "~placeholder_name~" here...", #}
  {%- with
    field_class_name = "monospace",
    field_editable = true,
    field_required = form_object.field.field_required,
    field_input_name = form_object.field.get_input_field_name(),
    field_label = "Field name",
    field_placeholder = "Enter field name here...",
    field_type = "singleline",
    field_value = form_object.field.field_name,
    mid = form_object.field.field_mid,
    testid_postfix = "reserved_field_name",
    errors = _name_errors
  %}
    {%- include "components/form/field/contenteditable/index.jinja" %}
  {%- endwith -%}
  {%- set human_title_value = form_object.field.field_human_title if form_object.field.field_human_title else "" -%}
  {%- with
    field_class_name = "monospace",
    field_editable = true,
    field_required = false,
    field_input_name = form_object.field.get_input_field_human_title(),
    field_label = "Field human name",
    field_placeholder = "Enter human readable field name here...",
    field_type = "singleline",
    field_value = human_title_value,
    mid = form_object.field.field_mid,
    testid_postfix = "reserved_field_human_title",
    errors = _human_name_errors
  %}
    {%- include "components/form/field/contenteditable/index.jinja" %}
  {%- endwith -%}
</sdoc-form-field-group>
{% endblock row_content %}

{% block row_right %}

  {%- set action_button_context = namespace() %}
  {%- set action_button_context.field_actions = {"delete": true} %}
  {%- set action_button_context.field_name = "custom field" %}
  {%- set action_button_context.mid = form_object.field.field_mid %}
  {%- set action_button_context.testid_postfix = "custom-field" %}
  {%- include "components/form/field_action_button/index.jinja" -%}

{% endblock row_right %}
