{% 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">{% blocktrans with email=customer.email %}{{ email }}{% endblocktrans %}</li>	  	
</ul>
{% endblock %}

{% block headertext %}
{% blocktrans with email=customer.email %}{{ email }}{% endblocktrans %}
{% endblock %}

{% block dashboard_content %}
<div class="row-fluid">
    <div class="span3">
        <div class="table-header">
            <h2>{% trans "General" %}</h2>
        </div>
        <div id="user_details" class="well">
            <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">
        <table class="table table-striped table-bordered table-hover">
            <caption>{% trans "Detailed information" %}</caption>
            <tr>
                <th>{% trans "General" %}</th>
                <th>{% trans "Orders" %}</th>
                <th>{% trans "Reviews" %}</th>
            </tr>
            <tr>
                <td>
                    <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>
                </td>
                <td>
                    <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>
                </td>
                <td>
                    <ul>
                        <li>{% trans "Number of reviews:" %} {{ customer.reviews.count }}</li>
                    </ul>
                </td>
            </tr>
        </table>
    </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">
             <table class="table table-striped table-bordered table-hover">
                 <caption>{% trans "Orders" %}</caption>
                 {% if customer.orders.count %}
                 <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 %}
                 {% else %}
     			    <tr><td>{% trans "This customer has not placed any orders yet." %}</td></tr>
                 {% endif %}
             </table>

        </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">
            <table class="table table-striped table-bordered table-hover">
                <caption>{% trans "Reviews" %}</caption>
                {% if customer.reviews.count %}
                <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 %}
                {% else %}
    			<tr><td>{% trans "This customer has not written any reviews yet." %}</td></tr>
                {% endif %}
            </table>

        </div>

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