{% extends "call_base.html" %}
{% block body %}

    {% set typ = func.type %}

    <h2>
        {% if typ == 'module' %}
            Execution of module:
        {% else %}
            Call to function:
        {% endif %}

        <a class="code-font"
           href="{{ url_for('func_view', path=func.file, func_name=func.name) }}">
            {% if typ == 'module' %}
                {{ short_path }}
            {% else %}
                {{ func.name }}
            {% endif %}
        </a>
    </h2>

    {% if typ == 'function' %}
        <p><strong>Line: </strong>{{ func.lineno }}</p>
    {% endif %}

    <p><strong>Full file path: </strong><a href="{{ url_for('file_view', path=func.file) }}">{{ func.file }}</a></p>

    {% if typ == 'function' %}
        {% if call.arguments_list %}
            <p><strong>Arguments:</strong></p>
            <table class="code-font table table-bordered table-striped args-table">
                {% for k, v in call.arguments_list %}
                    <tr>
                        <td>{{ k }}</td>
                        <td>{{ v }}</td>
                    </tr>
                {% endfor %}
            </table>
        {% else %}
            <p><strong>No arguments</strong></p>
        {% endif %}
    {% endif %}

    <p>
        <strong>Start time:</strong> {{ call.pretty_start_time }}
    </p>
    <p><strong>Result:</strong>
        {% if call.success %}
            <span class="code-font">{{ call.result }}</span></p>
        {% else %}
            </p>
            <pre>{{ call.traceback }}</pre>
        {% endif %}
    <p><strong>Code:</strong></p>

    {% from 'info_panel.html' import info_panel %}

    <div id="new-call">
        {% call info_panel() %}
            <a id="new-call-link" href="#">
                <i class="glyphicon glyphicon-play-circle"></i> Go to newest call
            </a>
        {% endcall %}
    </div>

    <script>
        (function () {
            var shown = false;
            var notNewest = location.search.indexOf('not-newest=1') >= 0;

            function checkLatest() {
                $.get(
                    "{{ url_for('latest_call', path=func.file, func_name=func.name) }}"
                ).done(function (data) {
                    if (data.url === location.pathname) {
                        return;
                    }
                    $('#new-call').show();
                    $('#new-call-link').attr('href', data.url);

                    if (shown || notNewest) {
                        return;
                    }
                    shown = true;

                    function bounce() {
                        $('#new-call').toggleClass('animate', true);
                    }

                    if (document.hasFocus()) {
                        bounce();
                    } else {
                        window.addEventListener('focus', bounce, false);
                    }
                });
            }

            $(function () {
                checkLatest();
                setInterval(checkLatest, 1000);
            });
        })();
    </script>
{% endblock %}
{% block after_container %}
    {% include "call_core.html" %}
{% endblock %}