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

{% block header_buttons %}
    {% if not ledger_model.is_locked %}
        <a href="{{ ledger_model.get_journal_entry_create_url }}"
           class="button is-success  is-outlined">
            <span class="icon">{% icon 'bi:plus-lg' 20 %}</span>
            <span>{% trans 'Create Entry' %}</span>
        </a>
    {% endif %}
    <a class="button is-info  is-outlined"
       href="{{ ledger_model.get_action_lock_journal_entries_url }}">
        <span class="icon">{% icon 'bi:lock-fill' 16 %}</span>
        <span>{% trans 'Lock All' %}</span>
    </a>
    <a class="button is-warning  is-outlined"
       href="{{ ledger_model.get_action_post_journal_entries_url }}">
        <span class="icon">{% icon 'bi:cloud-upload-fill' 16 %}</span>
        <span>{% trans 'Post All' %}</span>
    </a>
    <a class="button is-dark  is-outlined"
       href="{{ ledger_model.get_list_url }}">
        <span class="icon">{% icon 'bi:arrow-left' 16 %}</span>
        <span>{% trans 'Ledgers' %}</span>
    </a>
{% endblock %}

{% block view_content %}
    <div class="level mb-4">
        <div class="level-left">
            {# Standardized list header #}
        </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 'bi:arrow-left-circle' 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 ledger_pk=view.kwargs.ledger_pk %}">
                        <span>{{ next_month | date:'F Y' }}</span>
                        <span class="icon is-small">{% icon 'bi:arrow-right-circle' 16 %}</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 ledger_pk=view.kwargs.ledger_pk %}">
                        <span class="icon is-small">{% icon 'bi:arrow-left-circle' 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 ledger_pk=view.kwargs.ledger_pk %}">
                        <span>{{ next_year | date:'Y' }}</span>
                        <span class="icon is-small">{% icon 'bi:arrow-right-circle' 16 %}</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 'bi:arrow-left' 16 %}</span>
                        </a>
                    </div>
                {% endif %}
                <div class="level-item">
                    <p class="is-italic is-size-7">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 'bi:arrow-right' 16 %}</span>
                        </a>
                    </div>
                {% endif %}
            {% endif %}
        </div>
    </div>

    {% jes_table journal_entry_qs %}

    <div class="box has-background-light mt-4">
        {% if year %}
            <h5 class="title is-6 mb-2">{% trans 'Go to month:' %}</h5>
            <div class="buttons are-small">
                <a class="button is-white" href="{{ ledger_model.get_journal_entry_list_url }}">
                    {% trans 'All' %}
                </a>
                {% for date in date_list %}
                    <a class="button is-info is-light" href="{% url 'django_ledger:je-list-month' entity_slug=view.kwargs.entity_slug ledger_pk=view.kwargs.ledger_pk year=date.year month=date.month %}">
                        {{ date | date:'F' }}
                    </a>
                {% endfor %}
            </div>
        {% else %}
            <h5 class="title is-6 mb-2">{% trans 'Go to year:' %}</h5>
            <div class="buttons are-small">
                <a class="button is-white" href="{{ ledger_model.get_journal_entry_list_url }}">
                    {% trans 'All' %}
                </a>
                {% for date in date_list %}
                    <a class="button is-info is-light" href="{% url 'django_ledger:je-list-year' entity_slug=view.kwargs.entity_slug ledger_pk=view.kwargs.ledger_pk year=date.year %}">
                        {{ date.year }}
                    </a>
                {% endfor %}
            </div>
        {% endif %}
    </div>
{% endblock %}
