{%- import "helper/code.html" as code %}
{%- import "helper/util.html" as util %}

{%- macro diff_code_commented(objects, prefix="", suffix="", pad_length=0) -%}
    {%- for  object in objects -%}
        {%- if object.value.type|lower == "object" %}
    <tr class="diff_version {%- if object.value.optional %} optional{% endif %}" data-version="{{ object.versions|join(" ") }}">
        <td>{{ code.indent(pad_length) }}{{ prefix }}<span class="pun">{</span>{{ util.constraints(object.value) }}</td>
        <td class="com">{{ util.none_to_empty(object.value.description) }}</td>
    </tr>
            {%- for (property_name, property_value) in object.value.properties.items()|sort %}
                {%- if loop.last %}
                    {{- diff_code_commented(property_value, code.property_name_decorator(property_name), "", pad_length + 1) }}
                {%- else %}
                    {{- diff_code_commented(property_value, code.property_name_decorator(property_name), "<span class=\"pun\">,</span>", pad_length + 1) }}
                {%- endif %}
            {%- endfor %}
    <tr class="diff_version" data-version="{{ object.versions|join(" ") }}">
        <td>{{ code.indent(pad_length) }}<span class="pun">}</span>{{ suffix }}</td>
        <td></td>
    </tr>
        {%- elif object.value.type|lower == "array" %}
    <tr class="diff_version {%- if object.value.optional %} optional{% endif %}" data-version="{{ object.versions|join(" ") }}">
        <td>{{ code.indent(pad_length) }}{{ prefix }}<span class="pun">[</span>{{ util.constraints(object.value) }}</td>
        <td class="com">{{ util.none_to_empty(object.value.description) }}</td>
    </tr>
            {{- diff_code_commented(object.value.items, "", "", pad_length+1) }}
    <tr class="diff_version" data-version="{{ object.versions|join(" ") }}">
        <td>{{ code.indent(pad_length) }}<span class="pun">]</span>{{ suffix }}</td>
        <td></td>
    </tr>
        {%- elif object.value.type|lower in ("number", "integer", "string", "boolean") %}
    <tr class="diff_version {%- if object.value.optional %} optional{% endif %}" data-version="{{ object.versions|join(" ") }}">
        <td>{{ code.indent(pad_length) }}{{ prefix }}<span class="typ">{{ object.value.type|lower }}</span>{{ suffix }}{{ util.constraints(object.value) }}</td>
        <td class="com">{{ util.none_to_empty(object.value.description) }}</td>
    </tr>
        {%- elif object.value.type|lower == "none" %}
    <tr class="diff_version {%- if object.value.optional %} optional{% endif %}" data-version="{{ object.versions|join(" ") }}">
        <td>{{ code.indent(pad_length) }}{{ prefix }}<span class="typ">null</span>{{ suffix }}{{ util.constraints(object.value) }}</td>
        <td class="com">{{ util.none_to_empty(object.value.description) }}</td>
    </tr>
        {%- elif object.value.type|lower == "const" %}
    <tr class="diff_version {%- if object.value.optional %} optional{% endif %}" data-version="{{ object.versions|join(" ") }}">
        <td>{{ code.indent(pad_length) }}{{ prefix }}
        {%- if object.value.const_type|lower == "number" %}<span class="lit">{{ object.value.value }}</span>
        {%- elif object.value.const_type|lower == "integer" %}<span class="lit">"{{ object.value.value }}"</span>
        {%- elif object.value.const_type|lower == "string" %}<span class="str">"{{ object.value.value }}"</span>
        {%- elif object.value.const_type|lower == "boolean" %}<span class="lit">{{ object.value.value }}</span>
        {%- endif %}{{ suffix }}{{ util.constraints(object.value) }}</td>
        <td class="com">{{ util.none_to_empty(object.value.description) }}</td>
    </tr>
        {%- elif object.value.type|lower == "enum" %}
    <tr class="diff_version {%- if object.value.optional %} optional{% endif %}" data-version="{{ object.versions|join(" ") }}">
        <td>{{ code.indent(pad_length) }}{{ prefix }}<span class="typ">enum</span>{{ suffix }}{{ util.constraints(object.value) }}</td>
        <td class="com">{{ util.none_to_empty(object.value.description) }} (
            {%- for value in object.value.values|sort %}
                {%- if loop.first -%}
                    <span class="diff_version" data-version="{{ value.versions|join(" ") }}">{{ value.value }}</span>
                {%- else -%}
                    <span class="diff_version" data-version="{{ value.versions|join(" ") }}">, {{ value.value }}</span>
                {%- endif -%}
            {%- endfor -%}
        )</td>
    </tr>
        {%- elif object.value.type|lower == "dynamic" %}
    <tr class="diff_version {%- if object.value.optional %} optional{% endif %}" data-version="{{ object.versions|join(" ") }}">
        <td>{{ code.indent(pad_length) }}{{ prefix }}<span class="pun">{</span><{{ util.constraints(object.value) }}/td>
        <td class="com">{{ util.none_to_empty(object.value.description) }}</td>
    </tr>
    <tr class="diff_version {%- if object.value.optional %} optional{% endif %}" data-version="{{ object.versions|join(" ") }}">
        <td>{{ code.indent(pad_length + 1) }}<span class="typ">string</span><span class="pun">: </span><span class="typ">{{ object.items }}</span>{{ util.constraints(object.value) }}</td>
        <td class="com">{{ util.none_to_empty(object.value.description) }}</td>
    </tr>
    <tr class="diff_version" data-version="{{ object.versions|join(" ") }}">
            <td>{{ code.indent(pad_length) }}<span class="pun">}</span>{{ suffix }}</td>
        <td></td>
    </tr>
        {%- elif object.value.type|lower == "type" %}
    <tr class="diff_version {%- if object.value.optional %} optional{% endif %}" data-version="{{ object.versions|join(" ") }}">
        <td>{{ code.indent(pad_length) }}{{ prefix }}<span class="typ"><a href="javascript:navigateTo({type: '{{object.value.type_object.name}}'}, ['category', 'method'])">{{ object.value.type_object.name }}</a></span>{{ suffix }}{{ util.constraints(object.value) }}</td>
        <td class="com">{{ util.none_to_empty(object.value.description) }}</td>
    </tr>
        {%- endif %}
    {%- endfor %}
{%- endmacro -%}