{% extends 'django_ledger/layouts/content_layout_1.html' %}
{% load static %}
{% load django_ledger %}
{% load i18n %}

{% block view_content %}
    <div class="columns">
        <div class="column">
            <div class="card">
                <div class="card-content">
                    <div class="level">
                        <div class="level-left">
                            <div class="level-item">
                                {% if month %}
                                    <h1 class="is-size-1 has-text-weight-thin">{{ month | date:'F Y' }}</h1>
                                {% elif year %}
                                    <h1 class="is-size-1 has-text-weight-thin">Year {{ year | date:'Y' }}
                                        Ledgers</h1>
                                {% else %}
                                    <h1 class="is-size-1 has-text-weight-thin">{{ header_subtitle }}</h1>
                                {% endif %}
                            </div>
                            <div class="level-item">
                                <a href="{% url 'django_ledger:ledger-create' entity_slug=view.kwargs.entity_slug %}">
                                    <span class="icon is-large has-text-success">{% icon 'carbon:add-alt' 60 %}</span></a>
                            </div>
                        </div>
                        <div class="level-right">
                            {% if previous_month %}
                                <div class="level-item">
                                    <a class="button is-small is-dark is-outlined"
                                       href="{% url 'django_ledger:ledger-list-month' year=previous_month.year month=previous_month.month entity_slug=view.kwargs.entity_slug %}">
                                        <span class="icon is-small">{% icon 'ant-design:left-circle-outlined' 16 %}</span>
                                        <span>{{ previous_month | date:'F Y' }}</span>
                                    </a>
                                </div>
                            {% endif %}

                            {% if next_month %}
                                <div class="level-item">
                                    <a class="button is-small is-dark is-outlined"
                                       href="{% url 'django_ledger:ledger-list-month' year=next_month.year month=next_month.month entity_slug=view.kwargs.entity_slug %}">
                                        <span class="icon is-small">{% icon 'ant-design:right-circle-outlined' 16 %}</span>
                                        <span>{{ next_month | date:'F Y' }}</span>
                                    </a>
                                </div>
                            {% endif %}

                            {% if previous_year %}
                                <div class="level-item">
                                    <a class="button is-small is-dark is-outlined"
                                       href="{% url 'django_ledger:ledger-list-year' year=previous_year.year entity_slug=view.kwargs.entity_slug %}">
                                        <span class="icon is-small">{% icon 'ant-design:left-circle-outlined' 16 %}</span>
                                        <span>{{ previous_year | date:'Y' }}</span>
                                    </a>
                                </div>
                            {% endif %}

                            {% if next_year %}
                                <div class="level-item">
                                    <a class="button is-small is-dark is-outlined"
                                       href="{% url 'django_ledger:ledger-list-year' year=next_year.year entity_slug=view.kwargs.entity_slug %}">
                                        <span class="icon is-small">{% icon 'ant-design:right-circle-outlined' 16 %}</span>
                                        <span>{{ next_year | date:'Y' }}</span>
                                    </a>
                                </div>
                            {% endif %}

                            {% if page_obj %}
                                {% if page_obj.has_previous %}
                                    <div class="level-item">
                                        <a href="?page={{ page_obj.previous_page_number }}"
                                           class="button is-small is-dark is-outlined">
                                            <span class="icon is-small">{% icon 'ant-design:left-circle-outlined' 24 %}</span>
                                        </a>
                                    </div>
                                {% endif %}
                                <div class="level-item">
                                    <p class="is-italic">page {{ page_obj.number }}
                                        of {{ page_obj.paginator.num_pages }}</p>
                                </div>
                                {% if page_obj.has_next %}
                                    <div class="level-item">
                                        <a href="?page={{ page_obj.next_page_number }}"
                                           class="button is-small is-dark is-outlined">
                                            <span class="icon is-small">{% icon 'ant-design:right-circle-outlined' 24 %}</span>
                                        </a>
                                    </div>
                                {% endif %}

                            {% endif %}
                        </div>
                    </div>

                    {% ledgers_table ledger_list %}

                    {% if year %}
                        <h5 class="is-size-5">{% trans 'Go to month:' %}</h5>
                        <p>
                            <a href="{% url 'django_ledger:ledger-list' entity_slug=view.kwargs.entity_slug %}">
                                {% trans 'All' %} |
                            </a>
                            {% for date in date_list %}
                                <a href="{% url 'django_ledger:ledger-list-month' entity_slug=view.kwargs.entity_slug year=date.year month=date.month %}">
                                    {{ date | date:'F' }} {% if not forloop.last %}>{% endif %}
                                </a>
                            {% endfor %}
                        </p>
                    {% else %}
                        <h5 class="is-size-5">{% trans 'Go to year:' %}</h5>
                        <p>
                            <a href="{% url 'django_ledger:ledger-list' entity_slug=view.kwargs.entity_slug %}">
                                {% trans 'All' %} |
                            </a>
                            {% for date in date_list %}
                                <a href="{% url 'django_ledger:ledger-list-year' entity_slug=view.kwargs.entity_slug year=date.year %}">
                                    {{ date.year }} {% if not forloop.last %}>{% endif %}
                                </a>
                            {% endfor %}
                        </p>
                    {% endif %}
                    <div class="container">
                        <div class="columns is-centered">
                            <div class="column is-3">
                                {% if not view.show_all %}
                                    <a class="button is-info is-fullwidth my-1"
                                       href="{% url 'django_ledger:ledger-list-all' entity_slug=view.kwargs.entity_slug %}">{% trans 'Show All Ledgers' %}</a>
                                {% endif %}
                                {% if not view.show_visible %}
                                    <a class="button is-info is-fullwidth my-1"
                                       href="{% url 'django_ledger:ledger-list-visible' entity_slug=view.kwargs.entity_slug %}">{% trans 'Show Only Visible Ledgers' %}</a>
                                {% endif %}
                                {% if not view.show_current %}
                                    <a class="button is-info is-fullwidth my-1"
                                       href="{% url 'django_ledger:ledger-list' entity_slug=view.kwargs.entity_slug %}">{% trans 'Show Current Ledgers' %}</a>
                                {% endif %}
                                <a class="button is-dark is-fullwidth mt-2"
                                   href="{% url 'django_ledger:entity-dashboard' entity_slug=view.kwargs.entity_slug %}">{% trans 'Back to Dashboard' %}</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
