{% extends request.ajax ? "layout_blank.html.twig" : "layout_default.html.twig" %}

{% import "macro_functions.html.twig" as mf %}

{% block meta_title %}{{ 'My Products & Services'|trans }}{% endblock %}

{% block body_class %}order-list{% endblock %}
{% block breadcrumb %}
    <li class="breadcrumb-item active" aria-current="page">{{ 'Services'|trans }}</li>
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col-md-12">
            <div class="card mb-4">
                <div class="card-header py-3 py-3">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <h1 class="mb-1">{{ 'Services'|trans }}</h1>
                            <span class="small text-muted">{{ 'All of your orders are displayed here. Click on any service to get full information about it.'|trans }}</span>
                        </div>
                    </div>
                </div>
                <div class="card-body table-responsive">
                    {% set orders = client.order_get_list({"per_page":10, "page":request.page, "hide_addons":1}) %}
                    {% if orders.list %}
                        <table class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>{{ 'Order ID'|trans }}</th>
                                <th>{{ 'Product/Service'|trans }}</th>
                                <th>{{ 'Price'|trans }}</th>
                                <th>{{ 'Next due date'|trans }}</th>
                                <th>{{ 'Status'|trans }}</th>
                                <th>{{ 'Actions'|trans }}</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for i, order in orders.list %}
                                <tr>
                                    <td><a href="{{ '/order/service/manage'|link }}/{{ order.id }}">#{{ order.id }}</a></td>
                                    <td>
                                        <span>{{ order.title }}</span>
                                    </td>
                                    <td>{{ order.total | money(order.currency) }} {% if order.period %}{{ order.period | period_title }}{% endif %}</td>
                                    <td>{% if order.expires_at %}{{ order.expires_at|format_date }}{% else %}-{% endif %}</td>
                                    <td>
                                    <span
                                        class="badge {% if order.status == 'active' %}bg-success{% elseif order.status == 'pending_setup' %}bg-warning{% elseif order.status == 'failed_setup' or order.status == 'suspended' or order.status == 'failed_renew' %}bg-danger{% elseif order.status == 'canceled' %}bg-secondary{% endif %}">{{ mf.status_name(order.status) }}</span>
                                    </td>
                                    <td class="actions">
                                        <a class="btn btn-sm btn-outline-primary"
                                           href="{{ '/order/service/manage'|link }}/{{ order.id }}">Manage</a>
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    {% else %}
                        <div class="d-flex justify-content-center my-2 py-4">
                            <span class="m-0">{{ 'No orders yet'|trans }}</span>
                        </div>
                    {% endif %}
                    {{ include('partial_pagination.html.twig', { 'list': orders }) }}
                </div>
            </div>
        </div>
    </div>
{% endblock %}
