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

{% block content %}

{% if request.user == object %}
	<h1>{% trans "Welcome Back" %} {% if object.first_name %}, {{ object.first_name }}{% endif %}!</h1>
{% else %}
	<h1>{% blocktrans with name=object.get_full_name %}Account Profile for {{ name }}{% endblocktrans %}</h1>
{% endif %}

<div class="btn-group" role="group">
	<a class="btn btn-outline-secondary" href="{% url 'registration' %}">{% trans "Register for Classes" %}</a>
	{% if request.user == object %}
		{% if perms.core.view_registration_summary %}
			<a class="btn btn-outline-secondary" href="{% url 'viewregistrations_selectevent' %}">{% trans "View Registrations" %}</a>
		{% endif %}
		{% if perms.core.view_staff_directory %}
			<a class="btn btn-outline-secondary" href="{% url 'staffDirectory' %}">{% trans "Staff Directory" %}</a>
		{% endif %}
		{% if request.user.staffmember %}
			{% if perms.core.view_own_instructor_stats %}
				<a class="btn btn-outline-secondary" href="{% url 'staffMemberStats' %}">{% trans "Your Instructor Stats" %}</a>
			{% endif %}
			{% if core.view_own_instructor_finances %}
				<a class="btn btn-outline-secondary" href="{% url 'staffMemberPayments' %}">{% trans "Your Payment History" %}</a>
			{% endif %}
			{% if perms.core.update_instructor_bio %}
				<a class="btn btn-outline-secondary" href="{% url 'staffBioChange' %}">{% trans "Update Your Contact Info" %}</a>
			{% endif %}
		{% endif %}
		<a class="btn btn-outline-secondary" href="{% url 'account_change_password' %}">{% trans "Change Password" %}</a>
	{% endif %}
</div>

{% if staffmember or perms.cms.change_static_placeholder %}
	{% static_placeholder 'staffmember_profile_placeholder' %}
{% endif %}

{% if staffmember %}

	<h3 class="mt-4">{% trans "Current and Upcoming Series" %}</h3>

	<table class="table table-striped table-bordered">
	<thead>
		<tr>
			<th>{% trans "Month" %}</th><th>{% trans "Series/Event Name" %}</th><th>{% if staffmember.instructor %}{% trans "Teaching Partner" %}{% else %}{% trans "Other Staff" %}{% endif %}</th><th>{% trans "Location" %}</th><th>{% trans "Start Time" %}</th><th>{% trans "Students Registered" %}</th>
		</tr>
	</thead>
	<tbody>
	{% for series in upcoming_events %}
		<tr>
			<td>{{ series.month|readable_month }} {{ series.year }}</td>
			<td>{{ series.classDescription.title }}</td>
			<td>
			{% for this_instructor in series.teachers %}
				{% if this_instructor.fullName != staffmember.fullName %}
					{{ this_instructor.fullName }}&nbsp;
				{% endif %}
			{% endfor %}
			</td>
			<td>{{ series.location.name }}{% if series.room.name %} - {{ series.room.name }}{% endif %}</td>
			<td>{{ series.startTime|date:'l, h:i A' }}</td>
			<td>{{ series.numRegistered }}</td>
	</tr>
	{% endfor %}
	</tbody>
	</table>

{% endif %}

{% if customer or perms.cms.change_static_placeholder %}
	{% static_placeholder 'customer_profile_placeholder' %}
{% endif %}

{% if customer %}

	{% if customer.user != request.user %}
		<h2>{% if staffmember %}{% trans "Customer" %} {% endif %}{% blocktrans with name=object.get_full_name %}Summary Statistics for {{ name }}{% endblocktrans %}</h2>
	{% endif %}

	<h3 class="mt-4">
		{% if staffmember %}
			{% trans "Basic Customer Information" %}
		{% else %}
			{% trans "Basic Information" %}
		{% endif %}
	</h3>

	<dl>
		<dt>{% trans "Customer Since" %}:</dt>
			<dd>{{ customer.eventregistration_set.first.event.month|readable_month }} {{ customer.eventregistration_set.first.event.year }}</dd>
		<dt>{% trans "Registration History" %}:</dt>
			{% if customer.numClassSeries > 0 %}<dd>{% trans "Class Series" %}: {{ customer.numClassSeries }}</dd>{% endif %}
			{% if customer.numPublicEvents > 0 %}<dd>{% trans "Events" %}: {{ customer.numPublicEvents }}</dd>{% endif %}
			{% if customer.numDropIns > 0 %}<dd>{% trans "Drop-ins" %}: {{ customer.numDropIns }}</dd>{% endif %}
		{% if referralVoucherId %}
		<dt>{% trans "Customer Referral ID" %}:
			<dd>{{ referralVoucherId }}</dd>
		<dt>{% trans "Available Referral Credits" %}:</dt>
			<dd>${{ customer.getAvailableCredits|floatformat:2 }}</dd>
		{% endif %}
	</dl>

	<h3 class="mt-4">{% trans "Class Series Taken" %}</h3>

	<table class="table table-striped table-bordered">
	<thead>
		<tr>
			<th>{% trans "Month" %}</th><th>{% trans "Series Name" %}</th><th>{% trans "Location" %}</th><th>{% trans "Class Time" %}</th><th>{% trans "Instructors" %}</th>
		</tr>
	</thead>
	<tbody>
	{% for eventreg in customer_eventregs|dictsortreversed:'event.startTime' %}
		<tr {% if forloop.counter > 5 %}class="prior_events collapse"{% endif %}>
			{% with eventreg.event as event %}
			<td>{{ event.month|readable_month }} {{ event.year }}</td>
			<td>{{ event.name }}</td>
			<td>{{ event.location.name }}{% if event.room.name %} - {{ event.room.name }}{% endif %}</td>
			<td>{{ event.startTime|date:'D., h:i A' }}</td>
			<td>
			{% for instructor in event.teachers %}
				{{ instructor.fullName }}{% if not forloop.last %}, {% endif %}
			{% endfor %}
			</td>
			{% endwith %}
		</tr>
		{% if forloop.counter == 5 %}
		<tr id="showMoreClassesRow" class="table-active">
			<td colspan="5"><a href="" id="showMoreClasses" data-toggle="collapse" data-target=".prior_events" aria-expanded="false" aria-controls="prior_events">{% trans "Show all" %}&nbsp;<i class="fa fa-chevron-down" aria-hidden="true"></i></a></td>
		</tr>
		{% endif %}
	{% endfor %}
	</tbody>
	</table>

	{% addtoblock "js" %}
		<script type="text/javascript">
		$( document ).ready(function() {
			$('#showMoreClasses').click(function(event) {
				event.preventDefault();
				$('#showMoreClassesRow').fadeOut();
			});	
		});
		</script>
	{% endaddtoblock %}
{% else %}
	{% url 'registration' as registration_url %}
	<p>{% blocktrans %}It looks like you are not yet a customer.  Perhaps you would like to <a href="{{ registration_url }}">register for some classes</a>?{% endblocktrans %}</p>

{% endif %}


{# Other Series Registered From Verified Email Addresses #}
{% if verified_eventregs %}
	<h3 class="mt-4">{% trans "Series Registered From Other Email Addresses" %}</h3>

	<table class="table table-striped table-bordered">
	<thead>
		<tr>
			<th>{% trans "Month" %}</th><th>{% trans "Series Name" %}</th><th>{% trans "Location" %}</th><th>{% trans "Class Time" %}</th><th>{% trans "Instructors" %}</th>
		</tr>
	</thead>
	<tbody>
	{% for eventreg in verified_eventregs|dictsortreversed:'event.startTime' %}
		<tr {% if forloop.counter > 5 %}class="prior_verified collapse"{% endif %}>
			{% with eventreg.event as event %}
			<td>{{ event.month|readable_month }} {{ event.year }}</td>
			<td>{{ event.name }}</td>
			<td>{{ event.location.name }}{% if event.room.name %} - {{ event.room.name }}{% endif %}</td>
			<td>{{ event.startTime|date:'D., h:i A' }}</td>
			<td>
			{% for instructor in event.teachers %}
				{{ instructor.fullName }}{% if not forloop.last %}, {% endif %}
			{% endfor %}
			</td>
			{% endwith %}
		</tr>
		{% if forloop.counter == 5 %}
		<tr id="showMoreVerifiedRow" class="table-active">
			<td colspan="5"><a href="" id="showMoreVerified" data-toggle="collapse" data-target=".prior_verified" aria-expanded="false" aria-controls="prior_verified">{% trans "Show all" %}&nbsp;<i class="fa fa-chevron-down" aria-hidden="true"></i></a></td>
		</tr>
		{% endif %}
	{% endfor %}
	</tbody>
	</table>

	{% addtoblock "js" %}
		<script type="text/javascript">
		$( document ).ready(function() {
			$('#showMoreVerified').click(function(event) {
				event.preventDefault();
				$('#showMoreVerifiedRow').fadeOut();
			});	
		});
		</script>
	{% endaddtoblock %}
{% endif %}




{# Series Registered By This Person #}
{% if submitted_eventregs %}
	<h3 class="mt-4">{% trans "Other Series Registered By You" %}</h3>

	<table class="table table-striped table-bordered">
	<thead>
		<tr>
			<th>{% trans "Registered As" %}</th><th>{% trans "Month" %}</th><th>{% trans "Series Name" %}</th><th>{% trans "Location" %}</th><th>{% trans "Class Time" %}</th><th>{% trans "Instructors" %}</th>
		</tr>
	</thead>
	<tbody>
	{% for eventreg in submitted_eventregs|dictsortreversed:'event.startTime' %}
		<tr {% if forloop.counter > 5 %}class="prior_submitted collapse"{% endif %}>
			<td>{{ eventreg.customer.fullName }}: {{ eventreg.customer.email }}</td>
			{% with eventreg.event as event %}
			<td>{{ event.month|readable_month }} {{ event.year }}</td>
			<td>{{ event.name }}</td>
			<td>{{ event.location.name }}{% if event.room.name %} - {{ event.room.name }}{% endif %}</td>
			<td>{{ event.startTime|date:'D., h:i A' }}</td>
			<td>
			{% for instructor in event.teachers %}
				{{ instructor.fullName }}{% if not forloop.last %}, {% endif %}
			{% endfor %}
			</td>
			{% endwith %}
		</tr>
		{% if forloop.counter == 5 %}
		<tr id="showMoreSubmittedRow" class="table-active">
			<td colspan="6"><a href="" id="showMoreSubmitted" data-toggle="collapse" data-target=".prior_submitted" aria-expanded="false" aria-controls="prior_submitted">{% trans "Show all" %}&nbsp;<i class="fa fa-chevron-down" aria-hidden="true"></i></a></td>
		</tr>
		{% endif %}
	{% endfor %}
	</tbody>
	</table>

	{% addtoblock "js" %}
		<script type="text/javascript">
		$( document ).ready(function() {
			$('#showMoreSubmitted').click(function(event) {
				event.preventDefault();
				$('#showMoreSubmittedRow').fadeOut();
			});	
		});
		</script>
	{% endaddtoblock %}
{% endif %}

{% endblock %}