{% load danceschool_tags i18n %}

{% if category_list %}
	<input class="btn btn-outline-secondary mb-2 float-right" type="submit" value="{% trans 'Register now' %} &raquo;" />
	<h2 class="mt-4 reg-section-header">{{ category_list.grouper.name }}</h2>
	<hr />

	<div class="reg-section">
		<div class="reg-event-group mt-4">
		{% regroup month.list|dictsort:"weekday" by weekday as weekday_list %}
			{% for event in category_list.list %}
				<h3 class="reg-weekday-header">{% if event.numOccurrences > 1 %}{% trans "Begins" %} {% endif %}{{ event.firstOccurrenceTime|date:"N j" }}</h3>
				<div class="card reg-weekday-group">
					<a name="{{ event.slug }}"></a>
					
					<h5 class="card-header reg-event-header">
						{{ event.startTime|date:"g:i A" }} - {{ event.endTime|date:"g:i A" }}
					</h5>

					<div class="card-body row reg-event" id="reg-event-{{ event.id}}">
						<div class="col-lg-9 col-md-8 reg-event-info">

							<h3 class="card-title reg-event-title">{{ event.name }}</h3>
							
							<h6 class="card-subtitle text-muted reg-event-details">
								{% if event.teachers %}
									{% trans "with" %} {{ event.teachers|join:" &amp; "}}
								{% endif %}
								at
									{% if directions_url %}
									<a href = "{{ directions_url }}#{{ event.location.name|slugify }}">
										{{ event.location.name }}{% if event.room.name %} - {{ event.room.name }}{% endif %}
									</a>
									{% else %}
										{{ event.location.name }}{% if event.room.name %} - {{ event.room.name }}{% endif %}
									{% endif %}

	                                {% if event.url %}<small><a href="{{ event.url }}">{% trans "more info" %}</a></small>{% endif %}
							</h6>
	                        
	                        <div class="card-text reg-event-pricing mt-4">
	                        	{% if event.pricingTier and event.registrationOpen %}
									<a class="pricingPopover seriestype" data-container="body" data-toggle="popover" data-placement="bottom" title="<strong>{{ event.pricingTier.name }}</strong>" data-html="true" href="#" data-content="<em>{% trans 'Pre-Registered' %}</em><br />{{ currencySymbol }}{{ event.pricingTier.onlinePrice|floatformat:2 }}<br /><em>{% trans 'At the Door' %}</em><br />{{ currencySymbol }}{{ event.pricingTier.doorPrice|floatformat:2 }}">{{ event.pricingTier.name }}</a>
	                        	{% endif %}
							</div>
	                        
	                        <div class="card-text reg-event-dates">
								{% for occurrence in event.eventoccurrence_set.all %}
									{% if occurrence.startTime.date == occurrence.endTime.date and event.numOccurrences == 1 %}
										{{ occurrence.startTime|date:"g:i A" }}
									{% else %}
										{{ occurrence.startTime|date:"D. N j, g:i A" }}
									{% endif %}
									-
									{% if occurrence.startTime.date == occurrence.endTime.date %}
										{{ occurrence.endTime|date:"g:i A" }}
									{% else %}
										{{ occurrence.endTime|date:"D. N j, g:i A" }}
									{% endif %}<br />
								{% endfor %}
							</div>
						</div>
						<div class="col-lg-3 col-md-4 reg-event-register pt-3">
							{% get_field_for_object 'event' event.id form as field %}
	                    	{{ field }}
	                        {% if validationStr %}
							<div class="alert alert-danger">
								{{ field.errors }}
							</div>
	                        {% endif %}
						</div>
						{% if event.soldOut %}
							<div class="col-12 reg-event-soldout pt-3">
								<h5 class="card-title">{% trans "Sold Out!" %}</h5>
								<h6 class="card-subtitle">{% trans "Please join us for another class, another month, or schedule a private lesson!" %}</h6>
							</div>
						{% endif %}					
					</div>
					{% endfor %}
				</div> 
			{% endfor %}
		</div>
	</div>
{% endif %}