{% extends 'dashboard/layout.html' %}
{% load currency_filters %}
{% load i18n %}

{% block body_class %}users{% endblock %}

{% block title %}
{% blocktrans with email=customer.email %}{{ email }}{% endblocktrans %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
<ul class="breadcrumb">
    <li>
	<a href="{% url dashboard:index %}">{% trans "Dashboard" %}</a>
        <span class="divider">/</span>
    </li>
    <li>
	<a href="{% url dashboard:users-index %}">{% trans "Customers" %}</a>
        <span class="divider">/</span>
    </li>
	<li class="active"><a href=".">{% blocktrans with email=customer.email %}{{ email }}{% endblocktrans %}</a></li>
</ul>
{% endblock %}

{% block header %}
    <div class="page-header">
		<h1>{% blocktrans with email=customer.email %}{{ email }}{% endblocktrans %}</h1>
    </div>
{% endblock header %}

{% block dashboard_content %}
<div class="row-fluid">
    <div class="span3">
		<h2>{% trans "General" %}</h2>
        <div id="user_details" class="well well-info">
            <ul>
				<li>{% trans "Email:" %} {{ customer.email }}</li>
				<li>{% trans "First name:" %} {{ customer.first_name|default:"-" }}</li>
				<li>{% trans "Last name:" %} {{ customer.last_name|default:"-" }}</li>
				<li>
					{% if customer.is_active %}
					{% trans "This customer is active" %}
					{% else %}
					{% trans "This customer is inactive" %}
					{% endif %}
				</li>
                {% if customer.is_superuser %}
				<li><strong>{% trans "Superuser" %}</strong></li>
                {% endif %}
            </ul>
        </div>
    </div>

    <div class="span9">
		<h2>{% trans "Detailed information" %}</h2>
        <div id="user_order_details" class="row-fluid">
            <div class="span4">
                <div class="well well-info">
					<h3>{% trans "General" %}</h3>
                    <ul>
						<li>{% trans "Last login:" %} {{ customer.last_login }}</li>
						<li>{% trans "Date joined:" %} {{ customer.date_joined }}</li>
						<li>{% trans "Number of viewed products:" %} {{ customer.userrecord.num_product_views|default:0 }}</li>
                    </ul>
                </div>
            </div>

            <div class="span4">
                <div class="well well-info">
					<h3>{% trans "Orders" %}</h3>
                    <ul>
						<li>{% trans "Number of orders:" %} {{ customer.userrecord.num_orders|default:0 }}</li>
						<li>{% trans "Number of ordered items:" %} {{ customer.userrecord.num_order_items|default:0 }}</li>
						<li>{% trans "Total spent:" %} {{ customer.userrecord.total_spent|default:0|currency }}</li>
						<li>{% trans "Date of last order:" %} {{ customer.userrecord.date_last_order|default:"-" }}</li>
                    </ul>
                </div>
            </div>

            <div class="span4">
                <div class="well well-info">
					<h3>{% trans "Reviews" %}</h3>
                    <ul>
						<li>{% trans "Number of reviews:" %} {{ customer.reviews.count }}</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>


<div class="tabbable dashboard">
	<ul class="nav nav-tabs">
		<li class="active"><a href="#user_orders" data-toggle="tab">{% trans "Orders" %}</a></li>
		<li><a href="#user_addresses" data-toggle="tab">{% trans "Addresses" %}</a></li>
		<li><a href="#user_reviews" data-toggle="tab">{% trans "Reviews" %}</a></li>
	</ul>

	<div class="tab-content">
        <div id="user_orders" class="tab-pane active">
			<h2>{% trans "Orders" %}</h2>
            {% if customer.orders.count %}
             <table class="table table-striped table-bordered">
                 <tr>
					 <th>{% trans "Order Number" %}</th>
					 <th>{% trans "Num items" %}</th>
					 <th>{% trans "Total value" %}</th>
					 <th>{% trans "Date placed" %}</th>
					 <th>{% trans "Status" %}</th>
                     <th></th>
                 </tr>
                 {% for order in customer.orders.all %}
                 <tr>
                     <td>{{ order.number }}</td>
                     <td>{{ order.num_items }}</td>
                     <td>{{ order.basket_total_incl_tax|currency }}</td>
                     <td>{{ order.date_placed|date:"d/m/y H:s" }}</td>
                     <td>{{ order.status }}</td>
					 <td><a href="{% url dashboard:order-detail order.number %}" class="btn btn-info">{% trans "View" %}</a></td>
                 </tr>
                 {% endfor %}
             </table>
            {% else %}
			<p>{% trans "This customer has not placed any orders yet." %}</p>
            {% endif %}
        </div>

        <div id="user_addresses" class="tab-pane">
			<h2>{% trans "Addresses" %}</h2>
            <div class="row-fluid">
        	{% for address in customer.addresses.all %}

                <div class="span3">
            	    <div class="well well-info">
            			{% for field in address.active_address_fields %}
            			{{ field }}<br/>
            			{% endfor %}
            		</div>
            	</div>
                {% if forloop.counter|divisibleby:4 %}
					</div>
					{% if not forloop.last %}
					<div class="row-fluid">
					{% endif %}
                {% endif %}
			{% empty %}
			<p>{% trans "This customer has not saved any addresses." %}</p>
        	{% endfor %}
            </div>
        </div>

        <div id="user_reviews" class="tab-pane">
            <div class="sub-header">
				<h2>{% trans "Reviews" %}</h2>
            </div>
            {% if customer.reviews.count %}
            <table class="table table-striped table-bordered">
                <tr>
					<th>{% trans "Product ID" %}</th>
					<th>{% trans "Score" %}</th>
					<th>{% trans "Title" %}</th>
					<th>{% trans "Body" %}</th>
					<th>{% trans "Date created" %}</th>
                </tr>
                {% for review in customer.reviews.all %}
                <tr>
                    <td>{{ review.product_id }}</td>
                    <td>{{ review.score }}</td>
                    <td>{{ review.title }}</td>
                    <td>{{ review.body }}</td>
                    <td>{{ review.date_created }}</td>
                </tr>
                {% endfor %}
            </table>
            {% else %}
			<p>{% trans "This customer has not written any reviews yet." %}</p>
            {% endif %}
        </div>

    </div>
</div>
{% endblock dashboard_content %}
