{% extends 'babybuddy/page.html' %}
{% load bootstrap datetime duration i18n widget_tweaks %}

{% block title %}{% trans "Sleep" %}{% endblock %}

{% block breadcrumbs %}
    <li class="breadcrumb-item active" aria-current="page">{% trans "Sleep" %}</li>
{% endblock %}

{% block content %}
    <h1>
        {% trans "Sleep" %}
        {% if perms.core.add_sleep %}
            <a href="{% url 'core:sleep-add' %}" class="btn btn-sm btn-success">
                <i class="icon-sleep" aria-hidden="true"></i> {% trans "Add Sleep" %}
            </a>
        {% endif %}
    </h1>
    {% include 'babybuddy/filter.html' %}
    <div class="table-responsive">
        <table class="table table-instances table-borderless table-striped table-hover align-middle">
            <thead>
                <tr>
                    <th>{% trans "Actions" %}</th>
                    <th>{% trans "Start" %}</th>
                    <th>{% trans "End" %}</th>
                    {% if not unique_child %}
                        <th>{% trans "Child" %}</th>
                    {% endif %}
                    <th>{% trans "Duration" %}</th>
                    <th class="text-center">{% trans "Nap" %}</th>
                    <th>{% trans "Tags" %}</th>
                </tr>
            </thead>
            <tbody>
                {% for sleep in object_list %}
                    <tr>
                        <td>
                            <div class="btn-group btn-group-sm" role="group" aria-label="{% trans "Actions" %}">

                                {% if perms.core.change_sleep %}
                                    <a href="{% url 'core:sleep-update' sleep.id %}" class="btn btn-primary">
                                        <i class="icon-update" aria-hidden="true"></i>
                                    </a>
                                {% endif %}

                                {% if perms.core.delete_sleep %}
                                    <a href="{% url 'core:sleep-delete' sleep.id %}" class="btn btn-danger">
                                        <i class="icon-delete" aria-hidden="true"></i>
                                    </a>
                                {% endif %}

                            </div>
                        </td>
                        <th scope="row">{{ sleep.start|datetime_short }}</th>
                        <td>{{ sleep.end|datetime_short }}</td>
                        {% if not unique_child %}
                            <td><a href="{% url 'core:child' sleep.child.slug %}">{{ sleep.child }}</a></td>
                        {% endif %}
                        <td>{{ sleep.duration|duration_string }}</td>
                        <td class="text-center">{{ sleep.nap|bool_icon }}</td>
                        <td>
                            {% include "core/render_tag_list.html" with tags=sleep.tags.all %}
                        </td>
                    </tr>
                    {% if sleep.notes %}
                        <tr class="{{ row_class }} row-details">
                            <td colspan="7"><i class="icon-note me-2" aria-hidden="true"></i>{{ sleep.notes }}</td>
                        </tr>
                    {% endif %}
                {% empty %}
                    <tr>
                        <th colspan="7">{% trans "No sleep entries found." %}</th>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
    {% include 'babybuddy/paginator.html' %}
{% endblock %}