{% extends "cms/home.html" %}
{% load danceschool_tags crispy_forms_tags cms_tags i18n %}

{% block title %}{% trans "Complete Your Registration" %}{% endblock %}

{% block content %}

{# Display any warning or error messages associated with the previous form submission #}
<div id="message-alerts">
{% for message in messages %}
    <div class="alert {% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}alert-danger{% elif message.level == DEFAULT_MESSAGE_LEVELS.WARNING %}alert-warning{% else %}alert-info{% endif %}">{{ message }}</div>
{% endfor %}
</div>

<div class="regsummary">
	{% block summary %}

	    <h2>
	    	{% blocktrans with name=invoice.firstName|default_if_none:"Friend" %}
	    	Hi {{ name }}!
	    	{% endblocktrans %}
	    </h2>
	    
	    <p>{% trans "You have selected the following" %}:</p>

	    <table class="table classregsummary">
		    <tr>
		        <th>{% trans "Description" %}</th>
		        <th>{% trans "Date(s)" %}</th>
		        <th>{% trans "Time" %}</th>
		        <th>{% trans "Role" %}</th>
		        <th>{% trans "Price" %}</th>
		    </tr>

		    {% for item in invoice.invoiceitem_set.all %}
		    <tr>
				{% with item.eventRegistration as er %}
				{% if er %}
					<td>{% if er.dropIn %}{% trans "DROP IN" %}: {% endif %}{{ er.event.name }}</td>
			        <td>
					{% if er.event.eventoccurrence_set.count == 4 and not er.event.series.special %}
						{% blocktrans with weekday=er.event.startTime|date:"l" month=er.event.month|readable_month startTime=er.event.startTime|date:"F jS" %}
						{{ weekday }}s in {{ month }}, starting {{ startTime }}
						{% endblocktrans %}
					{% else %}
						{% for occ in er.event.eventoccurrence_set.all reversed %}
							{{ occ.startTime|date:"D. F jS" }}{% if not forloop.last %}, {% endif %}
						{% endfor %}
					{% endif %}
					</td>
					<td>{{ er.event.startTime|date:"P" }}</td>
					<td>{{ er.role.name|default:"N/A" }}</td>
				{% else %}
					<td>{{ item.description }}</td>
					<td></td>
					<td></td>
					<td></td>
				{% endif %}
				{% endwith %}
				<td>{{ currencySymbol }}{{ item.grossTotal|floatformat:"-2" }}</td>
		    </tr>
		    {% endfor %}
	    </table>

		{% if addonItems %}
		<p>
			{% for addon in addonItems %}
				<strong>{% trans "Free Add-On" %}:</strong>&nbsp;{{ addon.name }}
			{% endfor %}
		</p>
		{% endif %}

		<p>
			{% if total_discount_amount > 0 %}
				{% for code in discount_codes %}
					<strong>{% trans "Discount Code Applied" %}:</strong> {{ code.0 }}, {{ currencySymbol }}{{ code.2|floatformat:"-2" }}<br />
				{% endfor %}
				{% if discount_codes %}<br />{% endif %}

				{% if vouchers.items %}
					<strong>{% trans "Vouchers Applied" %}:</strong>
					{% for v in vouchers.items %}
						{{ v.name }}{% if not forloop.last %}, {% endif %}
					{% endfor %}<br /><br />
				{% endif %}

				<strong>{% trans "Total Discounts Applied" %}:</strong> {{ currencySymbol }}{{ total_discount_amount|floatformat:"-2" }} <br /><br />
			{% endif %}

			{# Add taxes if they are not included in the published price #}
			{% if invoice.adjustments or invoice.amountPaid or invoice.taxes and invoice.buyerPaysSalesTax %}
				<strong>{% trans "Subtotal" %}:</strong> {{ currencySymbol }}{{ invoice.total|floatformat:"-2" }}<br>			
			{% endif  %}
			{% if invoice.taxes %}
				<strong>{% trans "Taxes" %}:</strong> {{ currencySymbol }}{{ invoice.taxes|floatformat:"-2" }}<br>
			{% endif %}
			{% if invoice.amountPaid %}
				<strong>{% trans "Previous Payments" %}:</strong> -&nbsp;{{ currencySymbol }}{{ invoice.amountPaid|floatformat:"-2" }}<br>
			{% endif %}

	        <div style="font-size: 1.2em;"><strong><em>{% trans "Total" %}:</em></strong> {{ currencySymbol }}{{ invoice.outstandingBalance|floatformat:"-2" }}</div>
	    </p>

	{% endblock %}

	{% block payment_info %}
	     {% if is_complete or zero_balance %}
			<p>{% trans "Thanks! You're all set." %}</p>

			<p><a href="{{ returnPage }}" class="btn btn-primary btn-lg">{% trans "Return" %}</a></p>
		 {% else %}
		 	<p>
			 {% trans "In order to complete your registration you must click on the button below to make a payment." %}
			</p>

		 	{% if payAtDoor %}
				{% static_placeholder "registration_payatdoor_placeholder" %}
				{% static_placeholder "registration_invoice_placeholder" %}
			{% else %}
				{% static_placeholder "registration_payment_placeholder" %}
			{% endif %}
	    {% endif %}

	{% endblock %}

	{% block disclaimer %}
		{% static_placeholder "registration_summary_disclaimer" %}
	{% endblock %}

</div>
{% endblock %}
