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

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

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

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

{% block content %}

{% if settings.showcase_enabled %}
<div class="hero-unit">
    <h1>{{ settings.showcase_heading }}</h1>
    <p>{{ settings.showcase_text }}</p>
    <p><a class="btn btn-alt btn-primary btn-large" href="{{ settings.showcase_button_url }}">{{ settings.showcase_button_title }}</a></p>
</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>{% trans 'Tickets waiting your reply' %}</h2>
</header>
<section id="slimScroll1">
    <table class="table table-striped table-bordered table-condensed table-hover">
        <thead>
        <tr>
            <th>{% trans 'Id' %}</th>
            <th>{% trans 'Subject' %}</th>
            <th>{% trans 'Help desk' %}</th>
            <th>{% trans 'Status' %}</th>
            <th>{% trans 'Submitted' %}</th>
            <th>{% trans 'Actions' %}</th>
        </tr>
        </thead>
        <tbody>
        {% for i, ticket in tickets.list %}

        <tr class="{{ cycle(['odd', 'even'], i) }}">
            <td>{{ticket.id}}</td>
            <td><a href="{{ 'support/ticket'|link }}/{{ticket.id}}">{{ticket.subject}}</a></td>
            <td>{{ticket.helpdesk.name}}</td>
            <td><span class="label">{{mf.status_name(ticket.status)}}</span></td>
            <td>{{ticket.created_at|bb_date}}</td>
            <td><a href="{{ 'support/ticket'|link }}/{{ticket.id}}" class="btn btn-small btn-inverse">{% trans 'Reply' %}</a></td>
        </tr>

        {% else %}

        <tr>
            <td colspan="5">{% trans 'The list is empty' %}</td>
        </tr>

        {% endfor %}

        </tbody>
    </table>
</section>
</div>
</article>
</div>
{% endif %}

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

<article class="span6 data-block decent">
    <div class="data-container">
        <header>
            <h2>{% trans 'Invoices' %}</h2>
            <ul class="data-header-actions">
                <li>
                    <a class="btn btn-alt btn-inverse" href="{{ 'invoice'|link }}">{% trans 'All Invoices' %}</a>
                </li>
            </ul>
        </header>
        <section>
            <dl class="dl-horizontal">
                <dt>{% trans 'Total' %}</dt>
                    <dd>{{ client.invoice_get_list().total }}</dd>
                <dt>{% trans 'Paid' %}</dt>
                    <dd>{{ client.invoice_get_list({"status":"paid"}).total }}</dd>
                <dt>{% trans 'Unpaid' %}</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>{% trans 'Orders' %}</h2>
            <ul class="data-header-actions">
                <li>
                    <a class="btn btn-alt btn-info order-button" href="{{ 'order'|link }}">{% trans 'New order' %}</a>
                    <a class="btn btn-alt btn-inverse" href="{{ 'order/service'|link }}">{% trans 'All orders' %}</a>
                </li>
            </ul>
        </header>
        <section>
            <dl class="dl-horizontal">
                <dt>{% trans 'Total' %}</dt>
                <dd>{{ client.order_get_list({"hide_addons":1}).total }}</dd>
                <dt>{% trans 'Active' %}</dt>
                <dd>{{ client.order_get_list({"hide_addons":1, "status":"active"}).total }}</dd>
                <dt>{% trans 'Expiring' %}</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>{% trans 'Tickets' %}</h2>
            <ul class="data-header-actions">
                <li>
                    <a class="btn btn-alt btn-info" href="{{ 'support'|link({'ticket' : 1}) }}">{% trans 'New ticket' %}</a>
                    <a class="btn btn-alt btn-inverse" href="{{ 'support'|link }}">{% trans 'All tickets' %}</a>
                </li>
            </ul>
        </header>
        <section>
            <dl class="dl-horizontal">
                <dt>{% trans 'Total' %}</dt>
                <dd>{{ client.support_ticket_get_list().total }}</dd>
                <dt>{% trans 'Open' %}</dt>
                <dd>{{ client.support_ticket_get_list({"status":'open'}).total }}</dd>
                <dt>{% trans 'On Hold' %}</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>{% trans 'Recent orders' %}</h2>
        </header>
        <section>
            <table class="table table-striped table-bordered table-condensed table-hover">
                <tbody>
                {% for i, order in client.order_get_list({"per_page":5, "page":request.page, "hide_addons":1}).list %}
                <tr class="{{ cycle(['odd', 'even'], i) }}">
                    <td><a href="{{ 'order/service/manage'|link }}/{{order.id}}">{{ order.title|truncate(30) }}</a></td>
                    <td><span class="label {% if order.status == 'active'%}label-success{% elseif order.status == 'pending_setup' %}label-warning{% endif %}">{{ mf.status_name(order.status) }}</span></td>
                </tr>
                {% else %}
                <tr>
                    <td colspan="3">{% trans 'The list is empty' %}</td>
                </tr>
                {% endfor %}
                </tbody>
            </table>
        </section>
    </div>
</article>

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

</div>

{% endif %}
{% endblock %}