{% macro render_nested_sections(options_dict, var_path, depth, parent_var_name) -%}
{% if options_dict %}
{% for option_name, option_spec in options_dict.items() %}
{% set heading_level = "####" if depth == 1 else "#####" if depth == 2 else "######" %}
{% set anchor_id = var_path + "-sub-" + option_name %}
{% set display_name = parent_var_name + "['" + option_name + "']" %}
{{ heading_level }} `{{ display_name }}`<a id="{{ anchor_id }}"></a>

[*⇑ Back to ToC ⇑*](#toc)

{{ option_spec.description | format_description }}

- **Type**: `{{ option_spec.type }}`
- **Required**: {{ 'Yes' if option_spec.required else 'No' }}
{% if option_spec.default is not none %}
- **Default**: {{ option_spec.default | format_default }}
{% endif %}
{% if option_spec.choices %}
- **Choices**: {{ option_spec.choices | map('string') | map('code_escape') | join(', ') }}
{% endif %}
{% if option_spec.elements %}
- **List Elements**: `{{ option_spec.elements }}`
{% endif %}

{% if depth < 3 and option_spec.options %}
{{ render_nested_sections(option_spec.options, anchor_id, depth + 1, display_name) }}
{% elif depth >= 3 and option_spec.options %}
> **Note**: This option has more options but this README shows nested options up to level 3. Please refer to the argument_specs file for complete details.

{% endif %}
{% endfor %}
{% endif %}
{%- endmacro %}

## Role variables<a id="variables"></a>

{% if has_options %}
The following variables can be configured for this role:

| Variable | Type | Required | Default | Description (abstract) |
|----------|------|----------|---------|------------------------|
{% for var_name, var_spec in options.items() %}
| `{{ var_name | ansible_escape }}` | `{{ var_spec.type }}` | {{ 'Yes' if var_spec.required else 'No' }} | {{ var_spec.default | format_default }} | {{ var_spec.description | format_table_description(var_name) }} |
{% endfor %}

{% for var_name, var_spec in options.items() %}
### `{{ var_name }}`<a id="variable-{{ var_name }}"></a>

[*⇑ Back to ToC ⇑*](#toc)

{{ var_spec.description | format_description }}

- **Type**: `{{ var_spec.type }}`
- **Required**: {{ 'Yes' if var_spec.required else 'No' }}
{% if var_spec.default is not none %}
- **Default**: {{ var_spec.default | format_default }}
{% endif %}
{% if var_spec.choices %}
- **Choices**: {{ var_spec.choices | map('string') | map('code_escape') | join(', ') }}
{% endif %}
{% if var_spec.elements %}
- **List Elements**: `{{ var_spec.elements }}`
{% endif %}

{{ render_nested_sections(var_spec.options, "variable-" + var_name, 1, var_name) }}

{% endfor %}
{% else %}
No variables are defined for this role.
{% endif %}
