{#- Template for TwinCAT DUTs (Data Unit Types).

This template renders a TwinCAT DUT (Struct, Enum, Union, etc.).

Context:
  data: The DUT object to render.
  root (bool): Whether this is the root object, injected with `:::` in a Markdown page.
  heading_level (int): The HTML heading level to use.
  config (dict): The configuration options.
-#}

{% block title %}{{ data.name }} - TwinCAT DUT Documentation{% endblock %}

{% block content %}
<div class="doc doc-object doc-dut">
  {% with obj = data, html_id = data.get_identifier() %}

    {% if root %}
      {% set show_full_path = config.show_root_full_path %}
      {% set root_members = True %}
    {% elif root_members %}
      {% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %}
      {% set root_members = False %}
    {% else %}
      {% set show_full_path = config.show_object_full_path %}
    {% endif %}

    {% set dut_name = data.get_identifier() if show_full_path else data.name %}

    {% if not root or config.show_root_heading %}
      {% filter heading(
          heading_level,
          role="dut",
          id=html_id,
          class="doc doc-heading",
          toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-dut"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else data.name),
        ) %}

        {% block heading scoped %}
          {#- Heading block.

          This block renders the heading for the DUT.
          -#}
          {% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-dut"></code>{% endif %}
          <span class="doc doc-object-name doc-dut-name">{{ config.heading if config.heading and root else dut_name }}</span>
        {% endblock heading %}

        {% block labels scoped %}
          {#- Labels block.

          This block renders the labels for the DUT.
          -#}
          <span class="doc doc-label doc-label-dut">DUT</span>
        {% endblock labels %}

      {% endfilter %}
    {% else %}
      {% if config.show_root_toc_entry %}
        {% filter heading(heading_level,
            role="dut",
            id=html_id,
            toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-dut"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else data.name),
            hidden=True,
          ) %}
        {% endfilter %}
      {% endif %}
      {% set heading_level = heading_level - 1 %}
    {% endif %}

    <div class="doc doc-contents {% if root %}first{% endif %}">
      {% block contents scoped %}
        {#- Contents block.

        This block renders the contents of the DUT.
        It contains other blocks that users can override.
        Overriding the contents block allows to rearrange the order of the blocks.
        -#}
        
        {% block docstring scoped %}
          {#- Docstring block.

          This block renders the documentation for the DUT.
          -#}
          {% include "tcdocumentation.html.jinja" %}
        {% endblock docstring %}

        {% block declaration scoped %}
          {#- Declaration block.

          This block renders the declaration for the DUT.
          -#}
          {% if data.declaration %}
            <div class="doc doc-section">
              <h{{ heading_level + 1 }} class="doc doc-heading">Declaration</h{{ heading_level + 1 }}>
              <div class="doc doc-contents">
                <pre><code class="language-twincat">{{ data.declaration }}</code></pre>
              </div>
            </div>
          {% endif %}
        {% endblock declaration %}

        {% block variables scoped %}
          {#- Variables block.

          This block renders the variables for the DUT.
          -#}
          {% include "tcvariable_section.html.jinja" %}
        {% endblock variables %}
      {% endblock contents %}
    </div>

  {% endwith %}
</div>
{% endblock %}
