{#- Template for TwinCAT variable sections.

This template renders TwinCAT variable sections.

Context:
  data: The object containing variable sections to render.
  heading_level (int): The HTML heading level to use.
  config (dict): The configuration options.
-#}


{% if variable_sections %}
    {% for section in variable_sections %}
        {% if config.variable_section_style == "table" %}
        {% block table_style scoped %}
            {#- Block for the `table` section style. -#}
            <p><span class="doc-section-title">{{ section.section_type }}</span></p>
            <table>
            <thead>
                <tr>
                <th>"Name"</th>
                <th>"Type"</th>
                <th>"Description"</th>
                <th>"Default"</th>
                <th>"Attributes"</th>
                </tr>
            </thead>
            <tbody>
                {% for var in section.variables %}
                <tr class="doc-section-item">
                    <td>
                    {% if config.variable_headings %}
                        {% filter heading(
                            heading_level + 1,
                            role="var",
                            id=html_id ~ "(" ~ var.name ~ ")",
                            class="doc doc-heading doc-heading-variable",
                            toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-variable"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + var.name,
                        ) %}
                        <code>{{ var.name }}</code>
                        {% endfilter %}
                    {% else %}
                        <code>{{ var.name }}</code>
                    {% endif %}
                    </td>
                    <td>
                    <code>{{ var.type }}</code>
                    </td>
                    <td>
                    <div class="doc-md-description">
                        {% if var.comment %}
                            {{ var.comment|convert_markdown(heading_level, html_id, autoref_hook=autoref_hook) }}
                        {% endif %}
                    </div>
                    </td>
                    <td>
                        {% if var.initial_value %}
                           <code>{{ var.initial_value }}</code>
                        {% endif %}
                    </td>
                    <td>
                        {% if var.attributes %}
                            {% for attr_name, attr_value in var.attributes.items() %}
                            <code>{{ attr_name }}</code>{% if attr_value %}: {{ attr_value }}{% endif %}
                            {% endfor %}
                        {% endif %}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
            </table>
        {% endblock table_style %}
        {% elif config.variable_section_style == "list" %}
        {% block list_style scoped %}
            {#- Block for the `list` section style. -#}
            <p><span class="doc-section-title">{{ section.section_type }}</span></p>
            <ul>
            {% for var in section.variables %}
                <li class="doc-section-item field-body">
                {% if config.variable_headings %}
                    {% filter heading(
                        heading_level + 1,
                        role="var",
                        id=html_id ~ "(" ~ var.name ~ ")",
                        class="doc doc-heading doc-heading-variable",
                        toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-variable"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + var.name,
                    ) %}
                    <b><code>{{ var.name }}</code></b>
                    {% endfilter %}
                {% else %}
                    <b><code>{{ var.name }}</code></b>
                {% endif %}
                <code>{{ var.type }}</code>
                {% if var.comment %}
                –
                    <div class="doc-md-description">
                        {{ var.comment|convert_markdown(heading_level, html_id, autoref_hook=autoref_hook) }}
                    </div>
                {% endif %}
                </li>
            {% endfor %}
            </ul>
        {% endblock list_style %}
        {% endif %}
    {% endfor %}
{% endif %}