{% import "helpers/code.html.nunj" as codeMacro %}
{% import "helpers/type.html.nunj" as typeMacro %}
{% import "helpers/declaration-modifiers.html.nunj" as tagsMacro %}
{% import "helpers/parameters.html.nunj" as parametersMacro %}
{% import "helpers/decorators.html.nunj" as decoratorsMacro %}
{% import "helpers/no-content.html.nunj" as noContentMacro %}
{% import "helpers/overload.html.nunj" as overloadMacro %}
{% import "helpers/status.html.nunj" as statusMacro %}

{% macro render(method, origin) %}
    {% set parameters = method.getParameters() %}
    {% set methodChain = method | getMethodChain %}
    {% set inheritedFrom = method | getInheritedParent(origin) %}
    {% set overriddenMember = method | getOverriddenMember %}
    {% set implementedMember = method | getImplementedMember %}
    {% set docNode = methodChain | firstNodeWithComment %}
    {% set overloads = method.getOverloads() if method.getOverloads else [] %}
    {% set returnsTag = docNode | getJsDocTag('returns') %}

    <table class="{{ statusMacro.class(method) }}">
        <thead>
        <tr>
            <th indexable="false">
                {{ decoratorsMacro.render(method.getDecorators()) if method.getDecorators }}
                {{ tagsMacro.render(method, 'modifier') }}
                <h3 dataSlugType="member">{{ method.getName() }}()</h3>
                <div class="ng-doc-node-details">
                    {%- if inheritedFrom %}
                        inherited from <code>{{ inheritedFrom.getName() }}</code>
                    {%- elseif overriddenMember %}
                        overrides <code>{{ (overriddenMember | getMemberParent).getName() }}</code>
                    {%- elseif implementedMember %}
                        implements
                        <code>{{ (implementedMember | getMemberParent).getName() }}</code>
                    {%- endif %}
                </div>
            </th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>
                <div class="ng-doc-api-status">
                    {{ statusMacro.render(method) }}
                </div>

                {% set description = docNode | getJsDocDescription %}

                {{ description if description else noContentMacro.render('No documentation has been provided.') }}

                {% include "parts/member-remarks.html.nunj" %}
            </td>
        </tr>
        <tr>
            <td>
                <h5 class="no-anchor ng-doc-secondary-heading" indexable="false">Presentation</h5>
                {{ codeMacro.render(method | methodPresentation, "typescript", false) }}
            </td>
        </tr>
        <tr>
            <td>
                {%- if parameters.length %}
                    <h5 class="no-anchor ng-doc-secondary-heading" indexable="false">Parameters</h5>
                    {{ parametersMacro.render(parameters, docNode) }}
                {%- endif %}
                <h5 class="no-anchor ng-doc-secondary-heading" indexable="false">Returns</h5>

                <div class="ng-doc-returns">
                    {{ typeMacro.returnType(method) }}
                    {%- if returnsTag.length %}
                        <span> - </span>
                        {{ returnsTag | markdownToHtml }}
                    {%- endif %}
                </div>
            </td>
        </tr>

        {% include "parts/member-examples.html.nunj" %}

        {% if overloads.length %}
            <tr>
                <td>
                    {{ overloadMacro.render(overloads) }}
                </td>
            </tr>
        {% endif %}
        </tbody>
    </table>
{% endmacro %}
