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

{% block meta_title %}{{ 'Client Area'|trans }}{% endblock %}
{% block page_header %}{{ 'Dashboard'|trans }}{% endblock %}

{% block body_class %}dashboard{% endblock %}

{% block breadcrumbs %}
    {% if not settings.hide_dashboard_breadcrumb %}
        <ul class="breadcrumb">
            <li class="breadcrumb-item"><a href="{{ '/'|link }}">{{ 'Home'|trans }}</a> <span class="dropdown-divider">/</span></li>
            <li class="active breadcrumb-item">{{ 'Dashboard'|trans }}</li>
        </ul>
    {% endif %}
{% endblock %}

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

{% block content %}
    {% if settings.showcase_enabled %}
    <div class="hero-unit">
        <p>{{ settings.showcase_text |markdown }}</p>
        {% if (settings.showcase_button_url) and (settings.showcase_button_title) %}
        <p><a class="btn btn-primary btn-large" href="{{ settings.showcase_button_url }}">{{ settings.showcase_button_title }}</a></p>
        {% endif %}
    </div>
    {% endif %}

{% if client %}
{% set tickets = client.support_ticket_get_list({ "status": 'on_hold' }) %}
{% if tickets.total > 0 %}
<div class="row">
<article class="span12 data-block">
<div class="data-container">
<header>
    <h2>{{ 'Tickets waiting your reply'|trans }}</h2>
</header>
<section id="slimScroll1">
    <table class="table table-striped table-bordered table-sm table-hover">
        <thead>
        <tr>
            <th>{{ 'Id'|trans }}</th>
            <th>{{ 'Subject'|trans }}</th>
            <th>{{ 'Help desk'|trans }}</th>
            <th>{{ 'Status'|trans }}</th>
            <th>{{ 'Last Updated'|trans }}</th>
            <th>{{ 'Actions'|trans }}</th>
        </tr>
        </thead>
        <tbody>
        {% for i, ticket in tickets.list %}
        <tr>
            <td>{{ ticket.id }}</td>
            <td><a href="{{ 'support/ticket'|link }}/{{ticket.id}}">{{ ticket.subject }}</a></td>
            <td>{{ ticket.helpdesk.name }}</td>
            <td><span class="badge">{{ mf.status_name(ticket.status) }}</span></td>
            <td title="{{ ticket.updated_at|format_datetime }}">{{ ticket.updated_at|timeago }} {{ 'ago'|trans }}</td>
            <td><a href="{{ 'support/ticket'|link }}/{{ticket.id}}" class="btn btn-small btn-dark">{{ 'Reply'|trans }}</a></td>
        </tr>
        {% else %}
        <tr>
            <td colspan="5">{{ 'The list is empty'|trans }}</td>
        </tr>
        {% endfor %}
        </tbody>
    </table>
</section>
</div>
</article>
</div>
{% endif %}

<div class="row">
{% set profile = client.profile_get %}
<article class="span6 data-block decent">
    <div class="data-container">
        <header>
            <h2>{{ 'Profile'|trans }}</h2>
            <ul class="data-header-actions">
                <li>
                    <a class="btn btn-dark" href="{{ 'client/profile'|link }}">{{ 'Update'|trans }}</a>
                </li>
            </ul>
        </header>
        <section>
            <dl class="row">
                <dt>{{ 'Client ID'|trans }}</dt>
                <dd>#{{ profile.id }}</dd>
                <dt>{{ 'Email'|trans }}</dt>
                <dd>{{ profile.email }}</dd>
                <dt>{{ 'Balance'|trans }}</dt>
                <dd>{{ profile.balance | money(profile.currency) }}</dd>
            </dl>
        </section>
    </div>
</article>

<article class="span6 data-block decent">
    <div class="data-container">
        <header>
            <h2>{{ 'Invoices'|trans }}</h2>
            <ul class="data-header-actions">
                <li>
                    <a class="btn btn-dark" href="{{ 'invoice'|link }}">{{ 'All Invoices'|trans }}</a>
                </li>
            </ul>
        </header>
        <section>
            <dl class="row">
                <dt>{{ 'Total'|trans }}</dt>
                    <dd>{{ client.invoice_get_list().total }}</dd>
                <dt>{{ 'Paid'|trans }}</dt>
                    <dd>{{ client.invoice_get_list({ "status": "paid" }).total }}</dd>
                <dt>{{ 'Unpaid'|trans }}</dt>
                    <dd>{{ client.invoice_get_list({ "status": "unpaid" }).total }}</dd>
            </dl>
        </section>
    </div>
</article>
</div>

<div class="row">
    <article class="span6 data-block decent">
        <div class="data-container">
            <header>
                <h2>{{ 'Orders'|trans }}</h2>
                <ul class="data-header-actions">
                    <li>
                        <a class="btn btn-info order-button" href="{{ 'order'|link }}">{{ 'New Order'|trans }}</a>
                        <a class="btn btn-dark" href="{{ 'order/service'|link }}">{{ 'All orders'|trans }}</a>
                    </li>
                </ul>
            </header>
            <section>
                <dl class="row">
                    <dt>{{ 'Total'|trans }}</dt>
                    <dd>{{ client.order_get_list({ "hide_addons": 1}).total }}</dd>
                    <dt>{{ 'Active'|trans }}</dt>
                    <dd>{{ client.order_get_list({ "hide_addons": 1, "status": "active" }).total }}</dd>
                    <dt>{{ 'Expiring'|trans }}</dt>
                    <dd>{{ client.order_get_list({ "expiring": 1 }).total }}</dd>
                </dl>
            </section>
        </div>
    </article>

    <article class="span6 data-block decent">
        <div class="data-container">
            <header>
                <h2>{{ 'Tickets'|trans }}</h2>
                <ul class="data-header-actions">
                    <li>
                        <a class="btn btn-info" href="{{ 'support'|link({ 'ticket': 1 }) }}">{{ 'New ticket'|trans }}</a>
                        <a class="btn btn-dark" href="{{ 'support'|link }}">{{ 'All tickets'|trans }}</a>
                    </li>
                </ul>
            </header>
            <section>
                <dl class="row">
                    <dt>{{ 'Total'|trans }}</dt>
                    <dd>{{ client.support_ticket_get_list().total }}</dd>
                    <dt>{{ 'Open'|trans }}</dt>
                    <dd>{{ client.support_ticket_get_list({ "status": 'open' }).total }}</dd>
                    <dt>{{ 'On Hold'|trans }}</dt>
                    <dd>{{ client.support_ticket_get_list({ "status": 'on_hold' }).total }}</dd>
                </dl>
            </section>
        </div>
    </article>
</div>

<div class="row">
    <article class="span6 data-block decent">
        <div class="data-container">
            <header>
                <h2>{{ 'Recent orders'|trans }}</h2>
            </header>
            <section>
                <table class="table table-striped table-bordered table-sm table-hover">
                    <tbody>
                    {% for i, order in client.order_get_list({ "per_page": 5, "page": request.page, "hide_addons": 1 }).list %}
                    <tr>
                        <td>
                            <a href="{{ 'order/service/manage'|link }}/{{ order.id }}">{{ order.title|truncate(30) }}</a>
                        </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>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="3">{{ 'The list is empty'|trans }}</td>
                    </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </section>
        </div>
    </article>

    <article class="span6 data-block decent">
        <div class="data-container">
            <header>
                <h2>{{ 'Recent emails'|trans }}</h2>
            </header>
            <section>
                <table class="table table-striped table-bordered table-sm table-hover">
                    <tbody>
                    {% for i, email in client.email_get_list({ "per_page": 5 }).list %}
                    <tr>
                        <td><a href="{{ 'email'|link }}/{{ email.id }}">{{ email.subject|truncate(30) }}</a></td>
                        <td title="{{ email.created_at|format_datetime }}">{{ email.created_at|timeago }} {{ 'ago'|trans }}</td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="2">{{ 'The list is empty'|trans }}</td>
                    </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </section>
        </div>
    </article>
</div>
{% endif %}
{% endblock %}
