{% extends "base.html" %}
{% block head %}
    <script>
        $(function () {
            $('.call-row td').wrapInner(function () {
                return "<a href='/call/" + this.parentNode.dataset.id + "'></a>";
            })
        });
    </script>
{% endblock %}
{% block body %}
    <h2>Function: <span class="code-font">{{ func.name }}</span></h2>
    <p><strong>File: </strong><a href="{{ url_for('file_view', path=func.file) }}">{{ func.file }}</a></p>
    {% if calls %}{# if there are no calls then this may not be the most recent function object #}
        <p><strong>Line: </strong>{{ func.lineno }}</p>
    {% endif %}

    <h3>Calls:</h3>
    {% if calls %}
        <table class="table table-hover table-bordered table-striped">
            <thead>
            <tr>
                <th></th>
                <th>Start time</th>
                <th>Arguments</th>
                <th>Result</th>
            </tr>
            </thead>
            <tbody>
                {% for call in calls %}
                    <tr data-id="{{ call.id }}" class="call-row">
                        <td>
                            {{ call.state_icon }}
                        </td>
                        <td>
                            {{ call.pretty_start_time }}
                        </td>
                        <td>
                            {% if call.arguments_list %}
                                <ul>
                                    {% for k, v in call.arguments_list %}
                                        <li class="code-font">
                                            {{ k }} = {{ v }}
                                        </li>
                                    {% endfor %}
                                </ul>
                            {% else %}
                                -
                            {% endif %}
                        </td>
                        <td class="code-font">
                            {{ call.result }}
                        </td>
                    </tr>
                {% endfor %}

            </tbody>
        </table>
    {% else %}
        <p>No calls yet</p>
    {% endif %}
{% endblock %}