{% extends request.ajax ? 'layout_blank.phtml' : 'layout_default.phtml' %}

{% import 'macro_functions.phtml' as mf %}

{% block meta_title %}{{ 'Invoices'|trans }}{% endblock %}

{% block content_before %}
    <h1>{{ 'Invoices'|trans }}</h1>
    <p class="text-secondary">{{ 'List of invoices'|trans }}</p>
{% endblock %}

{% block content %}
    <div class="row mb-3">
        <div class="col-lg-12">
            {% if client.invoice_get_list({ 'status': 'unpaid' }).total > 0 %}
                <div>
                    <h3>{{ 'Unpaid'|trans }}</h3>
                    <div class="list-group">
                        {% set unpaid_invoices = client.invoice_get_list({ 'status': 'unpaid' }).list %}
                        
                        {% for i, invoice in unpaid_invoices %}
                            <a href="{{ 'invoice'|link }}/{{ invoice.hash }}" class="list-group-item list-group-item-danger d-flex justify-content-between align-items-center">
                                #{{ invoice.id }} - {{ 'Issue Date'|trans }}: {{ invoice.created_at|date('Y-m-d h:i') }}, {{ 'Due Date'|trans }}: {{ invoice.due_at|date('Y-m-d h:i') }}
                                <span class="pull-right btn btn-danger btn-xs" title="{{ 'Pay'|trans }}"><strong>{{ invoice.total | money(invoice.currency) }}</strong></span>
                            </a>
                        {% else %}
                            <p class="text-secondary text-center">{{ 'The list is empty'|trans }}</p>
                        {% endfor %}
                    </div>
                </div>
                <hr>
            {% endif %}
    
            <h3>{{ 'Paid'|trans }}</h3>
            <div class="list-group">
                {% set paid_invoices = client.invoice_get_list({ 'per_page': 10, 'page': request.page, 'status': 'paid' }) %}
                
                {% for i, invoice in paid_invoices.list %}
                    <a href="{{ 'invoice'|link }}/{{ invoice.hash }}" class="list-group-item list-group-item-success d-flex justify-content-between align-items-center">
                        #{{ invoice.id }} - {{ 'Issue Date'|trans }}: {{ invoice.created_at|date('Y-m-d h:i') }} - {{ 'Paid at'|trans }}: {{ invoice.paid_at|date('Y-m-d h:i') }}
                        <span class="pull-right btn btn-success btn-xs" title="{{ 'Paid'|trans }}"><strong>{{ invoice.total|money(invoice.currency) }}</strong></span>
                    </a>
                {% else %}
                    <p class="text-secondary text-center">{{ 'The list is empty'|trans }}</p>
                {% endfor %}
            </div>
            {% include '_pagination.phtml' with { 'list': paid_invoices } %}
        </div>
    </div>
    
    <div class="text-center">
        <a href="{{ '/client/balance'|link }}" title="{{ 'Payment history'|trans }}" class="btn btn-success">
            <i class="fa fa-archive me-2"></i>{{ 'Payment history'|trans }}</a>
    </div>
{% endblock %}
