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

{% assert comment_field_row_context is defined, "row_with_comment: row_context must be defined." %}

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

{%- set row_context = comment_field_row_context -%}
{%- set row_context.field_actions = { 'delete':true } -%}

{# FIXME: Rewrite everything to just form_object. #}
{%- set form_object = comment_field_row_context -%}

{% block row_form_attributes %}
  data-controller="deletable_field"
  data-testid="requirement-form-comment-row"
  mid="{{ comment_field_row_context.field.field_mid }}"
{% endblock row_form_attributes %}

{% block row_left %}
  {# Explicitly nothing. #}
{% endblock row_left %}

{% block row_content scoped %}
  {%- if form_object.errors|length > 0 -%}
    {%- for error_ in form_object.errors -%}
    <sdoc-form-error>
      {{ error_ }}
    </sdoc-form-error>
    {%- endfor -%}
  {%- endif -%}
  {%- with
    field_class_name = none,
    field_editable = comment_field_row_context.field_editable,
    field_input_name = comment_field_row_context.field.get_input_field_name(),
    field_label = comment_field_row_context.field.field_name,
    field_placeholder = "Enter comment here...",
    field_type = "multiline",
    field_value = comment_field_row_context.field.field_value,
    mid = comment_field_row_context.field.field_mid,
    testid_postfix = "COMMENT"
  %}
  {%- include "components/form/field/contenteditable/index.jinja" %}
  {%- endwith -%}

  <input
    type="hidden"
    name="{{ comment_field_row_context.field.get_input_field_type_name() }}"
    value="{{ comment_field_row_context.field.field_name }}"
  />

{% endblock row_content %}

{% block row_right %}

  {%- set action_button_context = namespace() %}
  {%- set action_button_context.field_actions = {"delete": true} %}
  {# TODO ? field_name = "requirement comment" #}
  {%- set action_button_context.field_name = "requirement comment" %}
  {%- set action_button_context.mid = comment_field_row_context.field.field_mid %}
  {%- set action_button_context.testid_postfix = "comment" %}
  {%- include "components/form/field_action_button/index.jinja" -%}

{% endblock row_right %}
