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

<h5 class="stack title"></h5>
{% if method.description %}
<div class="description stack">
    {% for description in method.description %}
    <div class="diff_version" data-version="{{ description.versions|join(" ") }}">
        {{- description.value -}}
    </div>
    {%- endfor -%}
</div>
{%- endif -%}
<div class="request stack">
    <h5><i class="i-request"></i> Request: </h5>
    <h6>Resource: </h6>
{% for uri in method.full_uri %}
    <code  class="diff_version" data-version="{{ uri.versions|join(" ") }}"><span class="hur">{{ uri.value }}</span></code>
{%- endfor -%}

{%- if method.request_uri_parameters %}
    <h6>URI Parameters: </h6>
    {%- call util.render_table([{"name": "Parameter"},
        {"width": "160px", "name": "Type"},
        {"width": "70px", "name": "Optional"},
        {"width": "50%", "name": "Description"}]) %}
        {%- for parameter in method.request_uri_parameters|sort %}
        <tr class="diff_version {% if parameter.value.generic %}generic{% endif %}" data-version="{{ parameter.versions|join(" ") }}">
            <td><span class="str">{{ util.none_to_empty(parameter.value.name) }}</span></td>
            <td><span class="typ">
            {%- if parameter.value.type != None %}
                {%- if not parameter.value.is_internal %}
                    <a href="javascript:navigateTo({type: '{{parameter.value.type}}'}, ['category', 'method'])">{{parameter.value.type}}</a>
                {%- else -%}
                    {{- parameter.value.type -}}
                {%- endif -%}
            {%- endif -%}
            <td><span class="lit">{% if parameter.value.optional %}Optional{% endif %}</span></td>
            <td><span class="com">{{ util.none_to_empty(parameter.value.description) }}</span></td>
        </tr>
        {%- endfor %}
    {%- endcall %}
{%- endif %}

{%- if method.request_query_string_parameters %}
    <h6>Query String Parameters: </h6>
    {%- call util.render_table([{"name": "Parameter"},
        {"width": "160px", "name": "Type"},
        {"width": "70px", "name": "Optional"},
        {"width": "50%", "name": "Description"}]) %}
        {%- for parameter in method.request_query_string_parameters|sort %}
        <tr class="diff_version {% if parameter.value.generic %}generic{% endif %}" data-version="{{ parameter.versions|join(" ") }}">
            <td><span class="str">{{ util.none_to_empty(parameter.value.name) }}</span></td>
            <td><span class="typ">
            {%- if parameter.value.type != None %}
                {%- if not parameter.value.is_internal %}
                    <a href="javascript:navigateTo({type: '{{parameter.value.type}}'}, ['category', 'method'])">{{parameter.value.type}}</a>
                {%- else -%}
                    {{- parameter.value.type -}}
                {%- endif -%}
            {%- endif -%}
            <td><span class="lit">{% if parameter.value.optional %}Optional{% endif %}</span></td>
            <td><span class="com">{{ util.none_to_empty(parameter.value.description) }}</span></td>
        </tr>
        {%- endfor %}
    {%- endcall %}
{%- endif %}

{%- if method.request_headers %}
    <h6>Headers: </h6>
    {%- call util.render_table([{"name": "Parameter"},
        {"width": "160px", "name": "Type"},
        {"width": "50%", "name": "Description"}]) %}
        {%- for parameter in method.request_headers|sort %}
        <tr class="diff_version {% if parameter.value.generic %}generic{% endif %}" data-version="{{ parameter.versions|join(" ") }}">
            <td><span class="str">{{ util.none_to_empty(parameter.value.name) }}</span></td>
            <td><span class="typ">
            {%- if parameter.value.type != None %}
                {%- if not parameter.value.is_internal %}
                    <a href="javascript:navigateTo({type: '{{parameter.value.type}}'}, ['category', 'method'])">{{parameter.value.type}}</a>
                {%- else -%}
                    {{- parameter.value.type -}}
                {%- endif -%}
            {%- endif -%}</span></td>
            <td><span class="com">{{ util.none_to_empty(parameter.value.description) }}</span></td>
        </tr>
        {%- endfor %}
    {%- endcall %}
{%- endif %}

{%- if method.request_body %}
    <h6>Body: </h6>
    <div class="code"><table class="table-hover">
        <colgroup>
            <col width="50%%"></col>
            <col width="50%%"></col>
        </colgroup>
        <tbody>
{{ diff.diff_code_commented(method.request_body) }}
        </tbody>
    </table></div>
{%- endif %}
</div>

<div class="response stack">
    <h5><i class="i-response"></i> Response: </h5>
{%- if method.response_body %}
    <h6>Body: </h6>
    <div class="code"><table class="table-hover">
        <colgroup>
            <col width="50%%"></col>
            <col width="50%%"></col>
        </colgroup>
        <tbody>
{{ diff.diff_code_commented(method.response_body) }}
        </tbody>
    </table></div>
{%- endif %}

{%- if method.response_codes %}
    <h6>Codes: </h6>
{%- call util.render_table([{"width": "50px", "name": "Code"},
    {"name": "Message"},
    {"width": "50%", "name": "Description"}]) %}
    {%- for parameter in method.response_codes|sort %}
        <tr class="diff_version {% if parameter.value.generic %}generic{% endif %}" data-version="{{ parameter.versions|join(" ") }}">
            <td><span class="lit">{{ util.none_to_empty(parameter.value.code) }}</span></td>
            <td><span class="str">{{ util.none_to_empty(parameter.value.message) }}</span></td>
            <td><span class="com">{{ util.none_to_empty(parameter.value.description) }}</span></td>
        </tr>
    {%- endfor %}
{%- endcall %}
{%- endif %}
</div>