{% extends 'evictionsplit/base.html' %}
{% load i18n %}
{% load smooth_timedelta %}

{% block details %}
    {% if unknown_change %}
        <div class="alert alert-dismissible alert-warning">
            <h4 class="alert-heading">Error!</h4>
            <p>Unknown argument received: {{ unknown_change }}</p>
        </div>

    {% endif %}

    <h2 class="page-header text-center">{{ eviction.name | capfirst }}</h2>

    <div class="panel panel-success">
        <div class="panel-heading" style="display: flex;">
            <h3 class="panel-title">Your status</h3>
        </div>
        <div class="panel-body text-center">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-6">
                        {% if eviction.active %}
                            <form method="post" action="{% url 'evictionsplit:change_clocking' eviction.id %}">
                                {% csrf_token %}
                                <input type="hidden" name="clocking_type" value="SP">
                                <input type="hidden" name="origin" value="eviction">
                                {% if is_standby %}
                                    <input type="hidden" name="change" value="stop">
                                    <input type="submit" class="btn btn-lg btn-success" value="Currently on standby for pings">
                                {% else %}
                                    <input type="hidden" name="change" value="start">
                                    <input type="submit" class="btn btn-lg btn-danger" value="Currently not on standby for ping">
                                {% endif %}
                            </form>
                        {% else %}
                            <button class="btn btn-lg btn-danger disabled">Eviction is over</button>
                        {% endif %}
                    </div>
                    <div class="col-md-6">
                        {% if eviction.active %}
                            <form method="post" action="{% url 'evictionsplit:change_clocking' eviction.id %}">
                                {% csrf_token %}
                                <input type="hidden" name="clocking_type" value="DS">
                                <input type="hidden" name="origin" value="eviction">
                                {% if is_doorstop %}
                                    <input type="hidden" name="change" value="stop">
                                    <input type="submit" class="btn btn-lg btn-success" value="Currently on doorstop">
                                {% else %}
                                    <input type="hidden" name="change" value="start">
                                    <input type="submit" class="btn btn-lg btn-danger" value="Currently not on doorstop">
                                {% endif %}
                            </form>
                        {% else %}
                            <button class="btn btn-lg btn-danger disabled">Eviction is over</button>
                        {% endif %}
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <p>{{ time_standby | smooth_timedelta }}</p>
                    </div>
                    <div class="col-md-6">
                        <p>{{ time_doorstop | smooth_timedelta }}</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="panel panel-primary">
        <div class="panel-heading">
            <h3 class="panel-title">Eviction status:</h3>
        </div>
        <div class="panel-body">
            {% if user_has_manager_permission %}
                <span data-toggle="modal" data-target="#exportActivity">
                    <button class='btn btn-xs btn-success' id="exportActivityButton" style="margin-top: -2px;" data-toggle="tooltip" data-placement="top" title="Export activity">Export activity</button>
                </span>
            {% endif %}
            <table class="table table-striped">
                <thead>
                <tr>
                    <th>Name</th>
                    <th>On standby</th>
                    <th>On doorstop</th>
                </tr>
                </thead>
                <tbody>
                {% for participant in participants %}
                    <tr>
                        <td>
                            <img src="{{ participant.portrait_url }}" class="ra-avatar img-circle">
                            &nbsp;
                            {{ participant.name }}
                        </td>
                        <td>
                            {% if participant.is_standby %}
                                <button class="btn btn-success disabled"><i class="fa fa-check"></i></button>
                            {% else %}
                                <button class="btn btn-danger disabled"><i class="fa fa-times"></i></button>
                            {% endif %}
                        </td>
                        <td>
                            {% if participant.is_doorstop %}
                                <button class="btn btn-success disabled"><i class="fa fa-check"></i></button>
                            {% else %}
                                <button class="btn btn-danger disabled"><i class="fa fa-times"></i></button>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>


    {% if user_has_manager_permission  %}
        <div class="modal fade" id="exportActivity" role="dialog" tabindex="-1" aria-labelledby="modalTitle">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="modalTitle">Export data</h4>
                    </div>
                    <div class="modal-body">
                        <textarea style="width: 100%; height: 100%;" rows="25" onclick="this.select()" readonly>{{ eviction.spreadsheet_export }}</textarea>
                    </div>
                </div>
            </div>
        </div>
    {% endif %}

{% endblock %}
