{% from "macro_restriction.html" import restriction with context %}

{%- macro tabbed_section(operator, current_node) -%}
    {% include "tabbed_section.html" %}
{%- endmacro -%}

{%- macro content(schema, skip_headers=False) -%}
    {% set keys = schema.keywords %}

    {# Resolve type #}
    {%- set type_name = schema.type_name -%}

    {% if not skip_headers %}
        {%- if config.show_breadcrumbs -%}
            {%- include "breadcrumbs.html" -%}
        {%- endif -%}

        {%- if schema.title -%}
            {%- if schema.depth == 0 %}{{ " " }}<h1>{{ schema.title }}</h1>{% else %}<h4>{{ schema.title }}</h4>{%- endif -%}
        {%- endif -%}

        {# Display type #}
        {%- if not schema is combining -%}
            <span class="badge badge-dark value-type">Type: {{ type_name }}</span>
        {%- endif -%}

        {%- if schema.format -%}
            <span class="badge badge-info value-type">Format: {{ schema.format }}</span>
        {%- endif -%}

        {# Display default #}
        {%- set default_value = schema.default_value -%}
        {%- if default_value -%}
            {{ " " }}<span class="badge badge-success default-value">Default: {{ default_value }}</span>
        {%- endif -%}
        <br/>

        {%- set description = (schema | get_description) -%}
        {%- include "section_description.html" -%}
    {%- endif -%}


    {%- if schema.should_be_a_link(config) -%}
        <a href="#{{ schema.links_to.html_id }}" onclick="anchorLink('{{ schema.links_to.html_id }}')" class="ref-link">Same definition as {{ schema.links_to.link_name }}</a>
    {%- elif schema.refers_to -%}
        {{ content(schema.refers_to_merged, True) }}
    {%- else -%}
        {%- if schema.explicit_no_additional_properties -%}
            {{ " " }}<span class="badge badge-info no-additional">No Additional Properties</span>
        {%- endif -%}

        {# Combining: allOf, anyOf, oneOf, not #}
        {%- if schema.kw_all_of -%}
            <div class="all-of-value" id="{{ schema.kw_all_of.html_id }}">{{ tabbed_section("allOf", schema.kw_all_of) }}</div>
        {%- endif -%}
        {%- if schema.kw_any_of -%}
            <div class="any-of-value" id="{{ schema.kw_any_of.html_id }}">{{ tabbed_section("anyOf", schema.kw_any_of) }}</div>
        {%- endif -%}
        {%- if schema.kw_one_of -%}
            <div class="one-of-value" id="{{ schema.kw_one_of.html_id }}">{{ tabbed_section("oneOf", schema.kw_one_of) }}</div>
        {%- endif -%}
        {%- if schema.kw_not -%}
            {% include "section_not.html" %}
        {%- endif -%}

        {# Enum and const #}
        {%- if schema.kw_enum -%}
            <div class="enum-value" id="{{ schema.kw_enum.html_id }}">
            <h4>Must be one of:</h4>
            <ul class="list-group">
            {%- for enum_choice in schema.kw_enum.array_items -%}
                <li class="list-group-item enum-item">
                    {%- if schema.kw_meta_enum -%}<strong>{%- endif -%}
                    {{ enum_choice.literal | python_to_json }}
                    {%- if schema.kw_meta_enum -%}</strong>
                        : {{ (schema.enum_description(enum_choice.literal) | get_description_literal) }}
                    {%- endif -%}
                </li>
            {%- endfor -%}
            </ul>
            </div>
        {%- endif -%}
        {%- if schema.kw_const -%}
            <span class="const-value" id="{{ schema.kw_const.html_id }}">Specific value: <code>{{ schema.kw_const.raw | python_to_json }}</code></span>
        {%- endif -%}

        {# Pattern (Regular Expression) #}
        {%- if schema.kw_pattern -%}
            <span class="pattern-value" id="{{ schema.kw_pattern.html_id }}">Must match regular expression: <code>{{ schema.kw_pattern.literal | escape }}</code></span>
        {%- endif -%}

        {# Conditional subschema, or if-then-else section #}
        {%- if schema.has_conditional -%}
            {% include "section_conditional_subschema.html" %}
        {%- endif -%}

        {# Required properties that are not defined under "properties". They will only be listed #}
        {% include "section_undocumented_required_properties.html" %}

        {# Show the requested type(s) #}
        {% include "badge_type.html" %}

        {# Show array restrictions #}
        {%- if type_name.startswith("array") -%}
            {% include "section_array.html" %}
        {%- endif -%}

        {# Display examples #}
        {%- set examples = schema.examples -%}
        {%- if examples -%}
            {% include "section_examples.html" %}
        {%- endif -%}

        {# Properties, pattern properties, additional properties #}
        {%- for sub_property in schema.iterate_properties -%}
            {% include "section_properties.html" %}
        {%- endfor -%}
    {%- endif -%}
{%- endmacro -%}
