{% extends "events/base.html" %}
{% load event_tags %}
{% load styled_forms %}
{% load avatar_tags %}
{% load base_filters %}
{% load i18n %}

{% block title %}{{ block.super }}{% trans "Registration Confirmation" %} {{ event.title }} {{ event.start_dt|date:"M j, Y" }}{% endblock %}

{% block extra_head %}
{{ block.super }}
<link rel="stylesheet" href="{{ STATIC_URL }}css/events.css">
<link rel="stylesheet" href="{{ STATIC_URL }}css/events-register_confirm.css">
{% endblock %}

{% block body %}

<div class="t">    
    {% event_nav user event %}
    <h1>{% trans "Registration" %}</h1>

    <div class="registration-status">

        {% if registration.canceled %}
            <div class="not-registered">{% trans "Registration cancelled." %}</div>
        {% endif %}

        {% if registration.status == 'payment-required' %}
            <div class="almost-registered">{% trans "Almost registered. Payment is still required." %}"

            {% if event.registration_configuration.can_pay_online %}
            <a href="{% url payment.pay_online registration.invoice.pk registration.invoice.guid %}">
                {% trans "Complete registration." %}</a>
            {% endif %}
            </div>

        {% endif %}

        {% if registration.status == 'registered-with-balance' %}
    <div class="registered">{% blocktrans with registration.invoice.balance as regbal %}You are registered. Balance is ${{ regbal }}. {% endblocktrans %}

            {% if event.registration_configuration.can_pay_online and registration.invoice.balance > 0 %}
            <a href="{% url payment.pay_online registration.invoice.pk registration.invoice.guid %}">
                {% trans "Pay online." %}</a>
            {% endif %}
            </div>

        {% endif %}

        {% if registration.status == 'registered' %}
            <div class="registered">{% trans "You are registered. Enjoy the event!" %}</div>
        {% endif %}

    </div>


	{% if count_registrants == 1 and registration.canceled %}
		<div class="cancel-notice">
			{% blocktrans with registrant.cancel_dt|date_short as cancel_dt %}Registration Canceled on {{ cancel_dt }}{% endblocktrans %}
		</div>
	{% endif %}

	<div class="regconf-section event">
		<h2>{% trans "Event Details" %}</h2>
		<h3>{{ event.title }}</h3>

		<div class="event-url">
			<a href="{% url event event.pk %}">
				{{ SITE_GLOBAL_SITEURL }}{% url event event.pk %}
			</a>
		</div>

        {% if event.description|striptags|wordcount > 50 %}
		  <div class="event-desc-short">{{ event.description|striptags|truncatewords:"50"|safe }}</div>
          <div class="event-desc-long">{{ event.description|safe }}</div>
        {% else %}
          <div class="event-desc-short">{{ event.description|safe }}</div>
        {% endif %}
        {% if event.description|striptags|wordcount > 50 %}
          <div><a class="event-desc-toggle" href="#">{% trans "Full Description" %}</a></div>
        {% endif %}
	</div>

	<div class="regconf-section registration">
		<h2>{% trans "Your Details" %}</h2>
		<h3>
            {% trans "Registration Number: " %}{{ registration.pk }}
        </h3>

		{% if not registration.canceled %}
			<div>
			 <a href="{% if hash %}{% url event.registration_edit registration.pk, hash %}{% else %}{% url event.registration_edit registration.pk %}{% endif %}">Edit Registrant(s) Info</a>
			{% if registrants_count >= 1 or registration.reg_conf_price.quantity > 1 %}
					&nbsp;&nbsp;
			      {% if user.is_authenticated %}
			          <a href="{% url event.cancel_registration event.pk registration.pk %}">{% trans "Cancel Registation" %}</a>
			      {% else %}
			          <a href="{% url event.cancel_registration event.pk registration.pk registration.hash %}">{% trans "Cancel Registation" %}</a>
			      {% endif %}
		     {% endif %}
		      </div>
	     {% endif %}
	     
	    {% if not registration.is_table %}
	    {% if registrants_count > 1 %}
	    	<div style="font-weight: bold;">{% trans "Registrants" %} ... ({{ registrants_count }})</div>
	    {% endif %}
	    
	    {% else %}
	    <table width="100%" border="0" cellspaceing="0" cellpadding="0">
	    	<tr>
	    		<td style="font-weight: bold; padding-left: 8px;">
	    			{% trans "Table/Team of " %}{{ registrants_count }}
	    		</td>
	    		<td  style="text-align: right;padding:0 20px; font-weight:bold;">
	    			{% if registration.override_table %}<span class="override-symbol">*</span>{% endif %}
	    			 {% if registration.invoice.discount_amount > 0 %}<span class="discount-symbol">d</span>{% endif %}
	    			{% with registrants|first as registrant %}{{ registrant.amount|format_currency }}{% endwith %}
	    		</td>
	    	</tr>
	    	{% if registration.reg_conf_price %}
	    	<tr>
	    		<td colspan="2" style="padding-left: 8px;">
	    			(Registered as {{ registration.reg_conf_price.title }})
	    		</td>
	    	</tr>
			{% endif %}
	
	    </table>
	    	
	    {% endif %}
    	<table class="registrants-table" border="0" cellspaceing="0" cellpadding="0">
 	
        {% for registrant in registrants %}
        <tr>
            <td width="80%">
                <span{% if registrant.cancel_dt %} class="canceled"{% endif %}>
                {% if registrant.name %}
                    {{ registrant.name }}
                {% else %}
                    {% trans "Guest #" %}{{ forloop.counter0 }}
                {% endif %}
                
                {% if not registration.is_table and registrant.pricing %}
                (registered as {{ registrant.pricing.title }})
                {% endif %}
                </span>
                {% if registrant.cancel_dt %}
                    <span class="cancel-notice2">
                        {% blocktrans with registrant.cancel_dt|date_short as cancel_date %} Canceled on {{ cancel_date }}{% endblocktrans %}
                    </span>
                {% else %}
                    {% if not registration.is_table %}
                      {% if user.is_authenticated %}
                          <a href="{% url event.cancel_registrant event.pk registrant.pk %}">{% trans "Cancel" %}</a>
                      {% else %}
                          <a href="{% url event.cancel_registrant event.pk registrant.hash %}">{% trans "Cancel" %}</a>
                      {% endif %}
                    {% endif %}
                {% endif %}
                {% if registrant.custom_reg_form_entry %}
                {% with registrant.custom_reg_form_entry.roster_field_entry_list as roster_field_list %}
                    {% for field in roster_field_list %}
                        {% if field.value %}
                            <div>{{ field.label }}: {{ field.value }}</div>
                        {% endif %}
                    {% endfor %}
                {% endwith %}
                {% endif %}
            </td>
            <td class="td-right" width="20%">
            	{% if not registration.is_table %}
                <span{% if registrant.cancel_dt %} class="canceled"{% endif %}>
                {% if registrant.override %}<span class="override-symbol">*</span>{% endif %} 
                {% if registrant.discount_amount > 0 %}<span class="discount-symbol">d</span>{% endif %}
                       {{ registrant.amount|format_currency }} 
                </span>
                {% endif %}
            </td>
        </tr>
        {% endfor %}
        
        {% if registration.has_overridden %}
        <tr>
        	 <td class="td-right" colspan="2">
        	 <span class="override-symbol">*</span> price overridden
        	 </td>
        </tr>
        {% endif %}
        
         {% if registration.invoice.discount_amount > 0 %}
        <tr>
        	 <td class="td-right" colspan="2">
        	 <span class="discount-symbol">d</span> discount applied (discount code: <a href="{{ registration.invoice.get_discount_url }}">{{ registration.invoice.discount_code }}</a>)
        	 </td>
        </tr>
        {% endif %}
        
    	</table>
        
		<div class="register-more">
            <a href="{% url event event.pk %}">{% trans "Register More People" %}</a>
        </div>
        
        <div style="font-weight: bold;">{% trans "Addons" %} ... ({{ addons.count }})</div>       
        <table class="registrants-table" border="0" cellspaceing="0" cellpadding="0">
    		{% for addon in addons %}
    		<tr>
    			<td>
					{{ addon.addon.title }}
                    ({% for option in addon.regaddonoption_set.all %}{{ option.option.title }}{% if not forloop.last %}, {% endif %}{% endfor %})
                </td>
                <td class="td-right">
					<span>{{ addon.amount|format_currency }}</span>
    			</td>
    		</tr>
    		{% endfor %}
    	</table>
	</div>

	<div class="regconf-section payment">
		<h2>{% trans "Payment Details" %}</h2>

        <div class="payment-links">
            
            
            <p>{% trans "Payment Method: " %}{{ registration.payment_method }}</p>
            
        	{% if registration.invoice %}
            <a href="{% url invoice.view registration.invoice.pk registration.invoice.guid %}">{% trans "View invoice" %}</a>
            {% endif %}

            {% if registration.invoice and event.registration_configuration.can_pay_online and registration.invoice.balance > 0 %}
                <a href="{% url payment.pay_online registration.invoice.pk registration.invoice.guid %}">{% trans "Pay online" %}</a>
            {% endif %}
        </div>

        <div class="payment-accounting">
            {% if registration.invoice.discount_amount > 0 %}
            <div>{% blocktrans with registration.invoice.discount_amount|floatformat:"2" as discount %}Discount Applied ${{ discount }}{% endblocktrans %}</div>
            {% endif %}
            <div>{% blocktrans with registration.invoice.total|floatformat:"2" as total %}Total ${{ total }}{% endblocktrans %}</div>
            <div><strong>{% blocktrans with registration.invoice.balance|floatformat:"2" as balance %}Balance ${{ balance }}{% endblocktrans %}</strong></div>
        </div>

		<div style="clear:both;"></div>
	</div>
</div>
{% endblock %}

{% block extra_body %}
    {{ block.super }}
    <script type="text/javascript">
        $(document).ready(function(){
            // speaker description toggle
            $('a.event-desc-toggle').click(function() {
                var _this = $(this);
                var event_wrap = _this.parents('.regconf-section');

                _this.hide();
                event_wrap.find('div.event-desc-short').hide();
                event_wrap.find('div.event-desc-long').show();
                return false;
            });
        });
    </script>
{% endblock %}
