<turbo-frame id="article-{{ document.reserved_mid }}">
<sdoc-form>

  <form
    method="POST"
    data-turbo="true"
    action="/actions/document/save_config"
    data-controller="scroll_into_view tabs"
  >
    <input type="hidden" id="document_mid" name="document_mid" value="{{ form_object.document_mid }}"/>

    {# Document TAB #}
    <sdoc-tab-content id="Document" active>
      <sdoc-form-grid>

      {%- with
        field_type="singleline",
        field_name="TITLE",
        field_input_name="document[TITLE]",
        field_value=form_object.document_title,
        errors=form_object.get_errors("TITLE")
      -%}
        {% include "components/form/field/text/index.jinja" %}
      {%- endwith -%}

      {%- with
        field_type="singleline",
        field_name="UID",
        field_input_name="document[UID]",
        field_value=form_object.document_uid,
        errors=form_object.get_errors("UID")
      -%}
        {% include "components/form/field/text/index.jinja" %}
      {%- endwith -%}

      {%- with
        field_type="singleline",
        field_name="VERSION",
        field_input_name="document[VERSION]",
        field_value=form_object.document_version,
        errors=form_object.get_errors("VERSION")
      -%}
        {% include "components/form/field/text/index.jinja" %}
      {%- endwith -%}

      {%- with
        field_type="singleline",
        field_name="CLASSIFICATION",
        field_input_name="document[CLASSIFICATION]",
        field_value=form_object.document_classification,
        errors=form_object.get_errors("CLASSIFICATION")
      -%}
        {% include "components/form/field/text/index.jinja" %}
      {%- endwith -%}

      {%- with
        field_type="singleline",
        field_name="PREFIX",
        field_input_name="document[PREFIX]",
        field_value=form_object.document_requirement_prefix,
        errors=form_object.get_errors("PREFIX")
      -%}
        {% include "components/form/field/text/index.jinja" %}
      {%- endwith -%}

      </sdoc-form-grid>

    </sdoc-tab-content>

    {# Metadata TAB #}
    <sdoc-tab-content id="Metadata">
      <sdoc-form-grid>

        <div style="display: contents;" id="document_{{ form_object.document_mid }}__new_metadata">
          {% set custom_metadata_row_context = namespace() %}
          {% for metadata_field in form_object.custom_metadata_fields %}
            {% set custom_metadata_row_context.field = metadata_field %}
            {% set custom_metadata_row_context.form_object = form_object %}
            {% set custom_metadata_row_context.errors = form_object.get_errors("METADATA["~ metadata_field.field_mid ~"]") %}
            {% include "components/form/row/row_with_metadata.jinja" %}
          {%- endfor -%}
        </div>
      </sdoc-form-grid>

      <sdoc-form-footer>

      <a
        class="action_button"
        href="/actions/document/new_metadata?document_mid={{ form_object.document_mid }}"
        data-turbo-action="replace"
        data-turbo="true"
        data-action-type="add_field"
        data-testid="form-action-add-metadata-field"
      >{% include "_res/svg_ico16_add.jinja.html" %} Add new metadata value</a>
      </sdoc-form-footer>

    </sdoc-tab-content>   

    <sdoc-form-footer>
      {% include "components/button/submit.jinja" %}
      {%- with cancel_href="/actions/document/cancel_edit_config?document_mid="~form_object.document_mid -%}
        {% include "components/button/cancel.jinja" %}
      {%- endwith -%}
    </sdoc-form-footer>

  </form>

</sdoc-form>
</turbo-frame>
