<!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="utf-8" />
    {% load staticfiles %}
    <link rel="stylesheet" href="{% static 'css/style.css' %}">
    <link href="{% static 'images/favicon.ico' %}" rel="shortcut icon">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>{{ settings.title }}</title>

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

    <!-- Clipboard.js -->
    <script src="https://cdn.jsdelivr.net/clipboard.js/1.5.8/clipboard.min.js"></script>

    <script language='javascript' type="text/javascript">
        var url = location.protocol + '//' + location.host + '/start';

        function getUserUrl(token) {
            return url + "?token=" + token;
        }
    </script>
</head>

<body>

<div class="container">
    <img src="{{ settings.logo }}" class="mainLogo">
    <h1>{{ settings.title }}</h1>
    <p>Welcome to the statistic backend!</p>
    <hr/>
    <div class="margin50" ></div>

    <h2>Users</h2>
    <table class="table">
        <tr class="table_headline">
            <td>name</td>
            <td>questions answered</td>
            <td>last seen</td>
            <td>url (click to copy)</td>
        </tr>
    {% for user in users %}
        <tr>
            <td>{{ user.name }}</td>
            <td>{{ user.questions_answered }}</td>
            <td>{{ user.last_seen }}</td>
            <td><a class="userlink" id="userlink{{ user.token }}" href="javascript:void(0)"></a></td>
            <script>document.getElementById("userlink{{ user.token }}").innerHTML = getUserUrl('{{ user.token }}')</script>
        </tr>
    {% endfor %}
    </table>

    <div class="margin50" ></div>

    <h2>Questions</h2>
    <table class="table">
        <tr class="table_headline">
            <td>title</td>
            <td>answers</td>
            <td>correct</td>
            <td>correct percentage</td>
        </tr>
        {% for question in questions %}
        <tr>
            <td>{{ question.title }}</td>
            <td>{{ question.answers }}</td>
            <td>{{ question.correct_answers }}</td>
            <td>{{ question.correct_answers_percentage }}</td>
        </tr>
        {% endfor %}
    </table>

    <div class="margin50" ></div>
    <hr/>
    <div class="container footer">
        {{ settings.footer }}
    </div>

    <script language='javascript' type="text/javascript">
        new Clipboard('.userlink', {
            text: function(trigger) {
                return trigger.text;
            }
        });
    </script>
</div>

</body>
</html>