{% extends 'base.html' %}

{% load i18n %}
{% load static %}
{% load hitcount_tags %}
{% load forum_filter %}

{% block extra_js %}
<script src="{% static 'js/hitcount/django-hitcount.js' %}"></script>
<script type="text/javascript">
    $('[data-toggle="tooltip"]').tooltip();
</script>
<script src="{% static 'js/js/forum.js' %}"></script>
{% endblock %}

{% block content %}

<div class="container">

	{% if user.id %}
		{% include "musette/notification.html" %}
	{% endif %}

	{% get_hit_count_js_variables for forum as hitcount %}
	{% get_hit_count for forum as total_hits %}

	{% if forum.moderators_id == user.id %}
		{% if forum.is_moderate %}
			{% if forum|get_tot_topics_moderate > 0 %}
				<div class="alert alert-success" role="alert">
					<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
					<p>{% trans "The forum "%} {{forum.name}} {% trans "is pending moderations" %}</p>
				</div>
			{% endif %}
		{% endif %}
	{% endif %}

	<div class="panel panel-default">
		<div class="panel-heading">
			<div class="span4 offset4 text-left">
				<h4>{% trans "Forum" %}: {{forum.name}}
				{% if total_hits|add:"0" > 1 %}
					<span style="font-size: 0.7em">({% trans "This forum has" %} {{ total_hits }} {% trans "views" %})</span>
				{% else %}
					<span style="font-size: 0.7em">({% trans "This forum has" %} {{ total_hits }} {% trans "view" %})</span>
				{% endif %}
				</h4>
			</div>
		</div>
	  	<div class="panel-body">
	    	<p>{{forum.description|safe}}</p>
    		<a href="/newtopic/{{forum.name}}/" class="btn btn-success btn-sm"><i class="glyphicon glyphicon-plus"></i> {% trans "New topic" %}</a>
    		<hr>
    		<div class="table-responsive">
				<table class="table table-striped">
				    <thead>
				      <tr>
				        <th>{% trans "Title" %}</th>
				        <th>{% trans "Users" %}</th>
				    	<th>{% trans "Responses" %}</th>
				    	<th>{% trans "Views" %}</th>
				        <th>{% trans "Date" %}</th>
				      </tr>
				    </thead>
				    <tbody>
				    	{% for topic in topics %}
				    		{% if topic.moderate %}
							    <tr>
							        <td><a href="/topic/{{forum.name}}/{{topic.slug}}/{{topic.idtopic}}/"
							        	data-toggle="tooltip" data-placement="bottom" title="{% trans 'Views' %}: {% get_tot_views topic.idtopic %}">
							        	{{topic.title}}
							        </a></td>
							        <td>{{topic|get_tot_users_comments|safe}}</td>
							        <td>{{topic.idtopic|get_tot_comments}}</td>
							        <td>{% get_tot_views topic.idtopic %}</td>
							        <td>{{topic.date}}</td>
							    </tr>
						    {% endif %}
					    {% endfor %}
				    </tbody>
				</table>
			</div>

			<div class="pull-left">
				<b>{% trans "Topics" %}: {{forum.topics_count}}</b>
				{% if forum.is_moderate %}
					{% if forum|get_tot_topics_moderate > 0 %}
						<b> ({% trans "Missing for moderate" %}: {{forum|get_tot_topics_moderate}})</b>
					{% endif %}
				{% endif %}
				<br>
				<p>{% trans "Created" %}: {{forum.date}}</p>

			</div>

			<ul class="pagination" style="float: right">
		        <li>
		            {% if paginator.has_prev %}
		            <a href="/forum/{{forum.name}}/?page={{ paginator.firstPage }}"> << </a>
		            <a href="/forum/{{forum.name}}/?page={{ paginator.prev_page }}"> < </a>
		            {% else %}
		            <a style="color:gray; cursor:not-allowed"> << </a>
		            <a style="color:gray; cursor:not-allowed"> < </a>
		            {% endif %}
		            {% if paginator.has_next %}
		            <a href="/forum/{{forum.name}}/?page={{ paginator.next_page }}"> > </a>
		            <a href="/forum/{{forum.name}}/?page={{ paginator.pages }}"> >> </a>
		            {% else %}
		            <a style="color:gray; cursor:not-allowed"> > </a>
		            <a style="color:gray; cursor:not-allowed"> >> </a>
		            {% endif %}
		        </li>
		        <p>{% trans "Page" %} <{{paginator.page}} {% trans "of" %} {{paginator.pages}}> </p>
		    </ul>
	  	</div>
	</div>

</div>

{% endblock %}

{% block hitcount_javascript %}
{% insert_hit_count_js_variables for forum %}
{% endblock %}