{% load danceschool_tags i18n %}

{% if category_list %}
	<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-8 col-md-6 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>

							{% if event.partnerRequired %}
							<div class="card-text reg-partner-required">{% trans "Partner required" %}</div>
							{% endif %}

	                        <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-4 col-md-6 ml-md-auto mt-4 mt-md-0 reg-event-register">
							{% get_field_for_object event.polymorphic_ctype.model 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>
				</div> 
			{% endfor %}
		</div>
	</div>
{% endif %}