{% extends "index.twig" %}

{% block title %}Super Stars{% endblock %}

{% block content %}
<div class="uk-container uk-margin">
    <h1 class="uk-article-title">Super Stars</h1>
    {{ block("messages_queue", "message_queue.twig") }}
    <a class="uk-button uk-button-default" href="{{ route() }}edit?task=create">Create</a>
    {% if list %}
        <table class="uk-table uk-table-justify uk-table-divider">
            <thead>
            <tr>
                <th>Name</th>
                <th class="uk-width-small">Age</th>
                <th>Sport</th>
                <th>ID</th>
                <th class="uk-width-small">Action</th>
            </tr>
            </thead>
            <tbody>
            {% for item in list %}
                <tr>
                    <td>{{ item.name }}</td>
                    <td>{{ item.age }}</td>
                    <td>{{ item.sport }}</td>
                    <td>{{ item.id }}</td>
                    <td>
                        <div class="uk-button-group uk-width-1-1">
                            <a class="uk-button uk-button-default uk-button-small" href="{{ route() }}edit?id={{ item.id }}&task=edit">Edit</a>
                            <button class="uk-button uk-button-default uk-button-small" onclick="confirmDeletion('{{ item.name }}', {{ item.id }});">Delete</button>
                        </div>
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
        <a class="uk-button uk-button-default" href="{{ route() }}edit?task=create">Create</a>
    {% else %}
        <div class="uk-alert-primary" uk-alert>
            <p>There has no athletes been added, click create to add some.</p>
        </div>
    {% endif %}
</div>
<script>
    function confirmDeletion(name, id){
        UIkit.modal.confirm('You are about to permanently delete <b>' + name + '</b>?').then(function () {
            window.open("{{ route() }}edit?id=" + id + "&task=delete", "_self")
        }, function () {
            // we do nothing ;)
        });
    }
</script>
{% endblock %}