{#
  required variables:

  sdoc_entity.reserved_mid :
     document.reserved_mid
     section.reserved_mid
     requirement.reserved_mid
  sdoc_entity.get_type_string():
      document
      section
      requirement
#}

{# djlint:off H025 #}
<sdoc-node-controls>
{# djlint:on #}
  {% if sdoc_entity.get_type_string() == 'document' -%}

  {# META #}
  <a
    href="/actions/document/edit_config?document_mid={{ view_object.document.reserved_mid }}"
    class="action_button"
    data-turbo-action="replace"
    data-turbo="true"
    title="Edit title and meta"
    data-testid="document-edit-config-action"
  >{% include "_res/svg_ico16_edit.jinja.html" %}</a>
  {%- endif -%}

  {# EDIT & DELETE:
    + section
    + requirement
    - NOT document
  #}
{%- if sdoc_entity.get_type_string() != 'document' -%}
  {% if not sdoc_entity.is_root_included_document %}
  <a
    href="/actions/document/edit_{{ sdoc_entity.get_type_string() }}?node_id={{sdoc_entity.reserved_mid}}&context_document_mid={{ view_object.document.reserved_mid }}"
    class="action_button"
    data-turbo-action="replace"
    data-turbo="true"
    title="Edit"
    data-testid="node-edit-action"
  >{% include "_res/svg_ico16_edit.jinja.html" %}</a>
  <a
    href="/actions/document/delete_{{ sdoc_entity.get_type_string() }}?node_id={{ sdoc_entity.reserved_mid }}&context_document_mid={{ view_object.document.reserved_mid }}"
    class="action_button"
    data-turbo-method="delete"
    data-turbo="true"
    title="Delete"
    data-testid="node-delete-action"
  >{% include "_res/svg_ico16_delete.jinja.html" %}</a>
  {% else %}
    <a
      href="/actions/document/edit_included_document?document_mid={{sdoc_entity.reserved_mid}}&context_document_mid={{ view_object.document.reserved_mid }}"
      class="action_button"
      data-turbo-action="replace"
      data-turbo="true"
      title="Edit"
      data-testid="node-edit-action"
    >{% include "_res/svg_ico16_edit.jinja.html" %}</a>
  {% endif %}
{% endif %}

  {# CLONE:
    - NOT section
    + requirement
    - NOT document
  #}
{%- if sdoc_entity.get_type_string() == 'requirement' -%}
  <a
    href="/actions/document/clone_requirement?reference_mid={{ sdoc_entity.reserved_mid }}&context_document_mid={{view_object.document.reserved_mid}}"
    class="action_button"
    {# data-turbo-action="replace" #}
    {# data-turbo-method="delete" #}
    data-turbo="true"
    title="Clone"
    data-testid="node-clone-action"
  >{% include "_res/svg_ico16_copy.jinja" %}</a>
{%- endif -%}

  {# ADD NODES menu:
    + section
    + requirement
    + document ONLY 'not document.section_contents'
  #}
  {%- if sdoc_entity.get_type_string() != 'document' or not view_object.document.section_contents -%}

  {# ADD NODES: dropdown menu #}
  {# djlint:off H025 #}
  <sdoc-menu
    js-dropdown-menu
    data-controller="dropdown_menu"
    class="add_node"
  >
  {# djlint:on #}
    <sdoc-menu-handler
      js-dropdown-menu-handler
      aria-expanded="false"
    >
      <a
        class="action_button"
        title="Add node"
        data-testid="node-menu-handler"
      >{% include "_res/svg_ico16_add.jinja.html" %}</a>
    </sdoc-menu-handler>

    <sdoc-menu-list>
      <menu
        js-dropdown-menu-list
        aria-hidden="true"
      >
        <header>Add node</header>

        {# *** Document node *** #}
        {%- if sdoc_entity.get_type_string() == 'document' -%}
          {# Add first document Section & Requirement, on CONFIG #}

          {# 0 • There should be a line for the node type: #}
          {% if view_object.should_display_old_section_as_deprecated() %}
          <li class="viewtype__menu_header">Section&nbsp;(DEPRECATED):</li>
          {% else %}
          <li class="viewtype__menu_header">Section:</li>
          {% endif %}

          {# There should be 3 places for the buttons: #}
          <li>{# 1 • Document -> add Section #}</li>
          <li>{# 2 • Document -> add Section #}</li>
          <li>{# 3 • Document -> add Section #}
            <a
              href="/actions/document/new_section?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=child&context_document_mid={{view_object.document.reserved_mid}}"
              data-turbo-action="replace"
              data-turbo="true"
              title="Add first child SECTION"
              data-testid="node-add-section-DEPRECATED-first-action"
            >{% include "_res/svg_ico16_add_child.jinja" %}</a>
          </li>

          {% for element_ in view_object.get_grammar_elements() %}
            {# 0 • There should be a line for the node type: #}
            <li class="viewtype__menu_header">{{ element_.tag }}:</li>

            {# There should be 3 places for the buttons: #}
            <li>{# 1 • Document -> add Requirement #}</li>
            <li>{# 2 • Document -> add Requirement #}</li>
            <li>{# 3 • Document -> add Requirement #}
              <a
                  href="/actions/document/new_requirement?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=child&element_type={{ element_.tag }}&context_document_mid={{ view_object.document.reserved_mid }}"
                  data-turbo-action="replace"
                  data-turbo="true"
                  title="Add first child {{ element_.tag }}"
                  data-testid="node-add-{{ element_.get_tag_lower() }}-first-action"
                >{% include "_res/svg_ico16_add_child.jinja" %}</a>
            </li>
          {%- endfor -%}

        {# // Document node #}
        {%- endif -%}

        {# *** Section node *** #}
        {%- if sdoc_entity.get_type_string() == 'section' -%}

          {# 0 • There should be a line for the node type: #}
          {% if view_object.should_display_old_section_as_deprecated() %}
          <li class="viewtype__menu_header">Section&nbsp;(DEPRECATED):</li>
          {% else %}
          <li class="viewtype__menu_header">Section:</li>
          {% endif %}

          {# There should be 3 places for the buttons: #}
          <li>{# 1 • Section -> add Section #}
            <a
              href="/actions/document/new_section?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=before&context_document_mid={{view_object.document.reserved_mid}}"
              data-turbo-action="replace"
              data-turbo="true"
              title="Add SECTION above"
              data-testid="node-add-section-DEPRECATED-above-action"
            >{% include "_res/svg_ico16_add_above.jinja" %}</a>
          </li>
          <li>{# 2 • Section -> add Section #}
            <a
              href="/actions/document/new_section?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=child&context_document_mid={{view_object.document.reserved_mid}}"
              data-turbo-action="replace"
              data-turbo="true"
              title="Add child SECTION"
              data-testid="node-add-section-child-action"
            >{% include "_res/svg_ico16_add_child.jinja" %}</a>
          </li>
          <li>{# 3 • Section -> add Section #}
            <a
              href="/actions/document/new_section?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=after&context_document_mid={{view_object.document.reserved_mid}}"
              data-turbo-action="replace"
              data-turbo="true"
              title="Add SECTION below"
              data-testid="node-add-section-DEPRECATED-below-action"
            >{% include "_res/svg_ico16_add_below.jinja" %}</a>
          </li>

          {# 0 • There should be a line for the node type: #}
          {% for element_ in view_object.get_grammar_elements() %}
            <li class="viewtype__menu_header">{{ element_.tag }}:</li>

            {# There should be 3 places for the buttons: #}
            <li>{# 1 • Section -> add Requirement #}
              <a
                href="/actions/document/new_requirement?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=before&element_type={{ element_.tag }}&context_document_mid={{view_object.document.reserved_mid}}"
                data-turbo-action="replace"
                data-turbo="true"
                title="Add {{ element_.tag }} above"
                data-testid="node-add-{{ element_.get_tag_lower() }}-above-action"
              >{% include "_res/svg_ico16_add_above.jinja" %}</a>
            </li>
            <li>{# 2 • Section -> add Requirement #}
              <a
                  href="/actions/document/new_requirement?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=child&element_type={{ element_.tag }}&context_document_mid={{view_object.document.reserved_mid}}"
                  data-turbo-action="replace"
                  data-turbo="true"
                  title="Add child {{ element_.tag }}"
                  data-testid="node-add-{{ element_.get_tag_lower() }}-child-action"
                >{% include "_res/svg_ico16_add_child.jinja" %}</a>
            </li>
            <li>{# 3 • Section -> add Requirement #}
              <a
                href="/actions/document/new_requirement?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=after&element_type={{ element_.tag }}&context_document_mid={{view_object.document.reserved_mid}}"
                data-turbo-action="replace"
                data-turbo="true"
                title="Add {{ element_.tag }} below"
                data-testid="node-add-{{ element_.get_tag_lower() }}-below-action"
              >{% include "_res/svg_ico16_add_below.jinja" %}</a>
            </li>
          {% endfor %}

        {# // Section node *** #}
        {%- endif -%}

        {# *** Requirement node *** #}
        {%- if sdoc_entity.get_type_string() == 'requirement' -%}

          {# 0 • There should be a line for the node type: #}
          {% if view_object.should_display_old_section_as_deprecated() %}
          <li class="viewtype__menu_header">Section&nbsp;(DEPRECATED):</li>
          {% else %}
          <li class="viewtype__menu_header">Section:</li>
          {% endif %}

          {# There should be 3 places for the buttons: #}
          <li>{# 1 • Requirement -> add Section #}</li>
          <li>{# 2 • Requirement -> add Section #}
            <a
              href="/actions/document/new_section?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=before&context_document_mid={{view_object.document.reserved_mid}}"
              data-turbo-action="replace"
              data-turbo="true"
              title="Add SECTION above"
              data-testid="node-add-section-DEPRECATED-above-action"
            >{% include "_res/svg_ico16_add_above.jinja" %}</a>
          </li>
          <li>{# 3 • Requirement -> add Section #}
            <a
              href="/actions/document/new_section?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=after&context_document_mid={{view_object.document.reserved_mid}}"
              data-turbo-action="replace"
              data-turbo="true"
              title="Add SECTION below"
              data-testid="node-add-section-DEPRECATED-below-action"
            >{% include "_res/svg_ico16_add_below.jinja" %}</a>
          </li>

          {# 0 • There should be a line for the node type: #}
          {% for element_ in view_object.get_grammar_elements() %}
            <li class="viewtype__menu_header">{{ element_.tag }}:</li>

            {# There should be 3 places for the buttons: #}
            {% if not sdoc_entity.is_composite %}
              <li></li>
            {% endif %}
            <li>{# 1 • Requirement -> add Requirement #}
              <a
                href="/actions/document/new_requirement?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=before&element_type={{ element_.tag }}&context_document_mid={{view_object.document.reserved_mid}}"
                data-turbo-action="replace"
                data-turbo="true"
                title="Add {{ element_.tag }} above"
                data-testid="node-add-{{ element_.get_tag_lower() }}-above-action"
              >{% include "_res/svg_ico16_add_above.jinja" %}</a>
            </li>
            {% if sdoc_entity.is_composite %}
            <li>{# 2 • Requirement -> add Requirement #}
              <a
                href="/actions/document/new_requirement?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=child&element_type={{ element_.tag }}&context_document_mid={{view_object.document.reserved_mid}}"
                data-turbo-action="replace"
                data-turbo="true"
                title="Add child {{ element_.tag }}"
                data-testid="node-add-{{ element_.get_tag_lower() }}-child-action"
              >{% include "_res/svg_ico16_add_child.jinja" %}</a>
            </li>
            {% endif %}
            <li>{# 3 • Requirement -> add Requirement #}
              <a
                href="/actions/document/new_requirement?reference_mid={{ sdoc_entity.reserved_mid }}&whereto=after&element_type={{ element_.tag }}&context_document_mid={{view_object.document.reserved_mid}}"
                data-turbo-action="replace"
                data-turbo="true"
                title="Add {{ element_.tag }} below"
                data-testid="node-add-{{ element_.get_tag_lower() }}-below-action"
              >{% include "_res/svg_ico16_add_below.jinja" %}</a>
            </li>
          {%- endfor -%}

        {# // Requirement node *** #}
        {%- endif -%}

      </menu>
    </sdoc-menu-list>
  </sdoc-menu>
  {%- endif -%}

</sdoc-node-controls>
