{# needs sdoc_entity #}

{#
  This template can be included directly, and it will in turn include an entity.
  In this case you must use it with the variable:
      {%- with sdoc_entity = requirement -%}
      {% include "components/node/index.jinja" %}
      {%- endwith -%}

  This template can also be used as a base template.
  Then the {% block sdoc_entity %} block will overwrite the included entity
  in the extending template.
#}

{% set node_type = sdoc_entity.get_type_string() %}
{% set is_not_standalone = view_object.project_config.is_running_on_server and not view_object.standalone %}
{% set is_root_section = (sdoc_entity.root_section is defined and sdoc_entity.root_section == true) %}
{% set is_included = sdoc_entity.document_is_included() %}

<turbo-frame
{%- if is_not_standalone %}
  id="article-{{ sdoc_entity.reserved_mid }}"
{% endif -%}
>

  <sdoc-node
    {%- if is_not_standalone %}
      data-editable_node="on"
      {%- if sdoc_entity.is_section %}
      data-controller="anchor_controller"
      {%- endif %}
    {%- endif %}
    node-role="{{ node_type }}"
    data-included-document="{{ is_included }}"
    {%- if is_root_section %}
      data-included-root-section="{{ is_root_section }}"
    {%- endif %}
    data-testid="node-{{ node_type }}"
  >

    {# TODO #fragment #}
    {# TEMP #}
    {# {% if is_included %}
      <div style="color:green">My home doc is <b>"{{ sdoc_entity.document.title }}"</b>.</div>
      <div style="color:blue">My including doc is <b>"{{ sdoc_entity.parent_or_including_document.title }}"</b>.</div>
      {% if root_section %}
      <div style="color:red">I am a fragment!</div>
      {% endif %}
    {% else %}
      <div style="color:rgb(255, 200, 0)">I'm just a simple node!</div>
    {% endif %} #}
    {# // TEMP #}

    {# anchor #}
    {% include "components/anchor/index.jinja" %}

    {#
      copy_to_clipboard must be defined befor sdoc_entity block,
      and define them in node components that have editing options:
      node & root
    #}
    {%- set copy_to_clipboard = True -%}

    {# sdoc_entity #}
    {% block sdoc_entity %}
    {% include "components/"~node_type~"/index.jinja" %}
    {% endblock sdoc_entity %}

    {# node_controls #}
    {%- if is_not_standalone and not is_root_section -%}
    {% include "components/node/node_controls/index.jinja" %}
    {%- endif -%}

  </sdoc-node>
</turbo-frame>
