{% extends "app_home/base.html" %}
{% load static %}
{% load i18n %}

{% block navbar_app %}
{% include 'app_home/_sidebar.html' %}
{% endblock %}

{% block title %}
{% if page.is_enabled %}
<h2>
	{{ page.title }} - <span class="badge text-bg-{{ page.bgcolor }}">{{ page.category }} - {{ page.severity }}</span>	
</h2>
{% else %}
<h2><i class="fa fa-archive"></i> 
	{% translate 'ARCHIVE' %} - 
	{{ page.title }} - <span class="badge text-bg-{{ page.bgcolor }}">{{ page.category }} - {{ page.severity }}</span>	
</h2>
{% endif %}
<hr>
{% endblock %}



{% block content %}

{% if page.is_enabled %}
	{% if 'p_sirene_update' in aaa.perms %}		
		<a class="btn btn-outline-dark me-2" href="{% url 'app_sirene:update' page.id %}" role="button">
		<i class="fa fa-pencil me-2"></i>{% translate 'Post an Update' %}</a>
	{% endif %}
	{% if 'p_sirene_archive' in aaa.perms %}
	<button class="btn btn-outline-danger me-2" data-bs-toggle="modal" data-bs-target="#closeConfirmModal">
	<i class="fa fa-times me-2"></i>	{% translate 'Close message' %}</button>
	{% endif %}
{% else %}
	{% if 'p_sirene_update' in aaa.perms %}
	<button class="btn btn-danger me-2" data-bs-toggle="modal" data-bs-target="#reopenConfirmModal">
		<i class="fa fa-pencil me-2"></i>{% translate 'Reopen' %}</button>
	{% endif %}
{% endif %}



<!-- MESSAGE -->
<hr>
<p>
	<b>{% translate 'Initial message on' %} {{ page.created_at }} ({{ page.created_by }})		
	</b>
</p>
<div class="border border-secondary rounded cv-sirene-msg-body">
	<div class="mx-3 my-3">
		{{ page.body | safe | default:" "}}
	</div>
</div>
{% if page.sms_body %}
<div class="border border-secondary rounded my-1 cv-sirene-msg-sms">
	<div class="mx-3">
		<b>SMS</b>: {{ page.sms_body | safe}}
	</div>
</div>
{% endif %}
<div class="text-muted text-end">
	{{ page.email_count|default:0 }} emails - {{ page.sms_count|default:0 }} sms
</div>


<!-- UPDATES -->
 {% if updates %}
 <hr>
 {% for upd in updates %}
<p><b>{% translate 'Update' %} #{{ forloop.revcounter }} - {{ upd.created_at }} ({{ upd.created_by }})</b></p>
<div class="border border-secondary rounded cv-sirene-msg-update">
	<div class="mx-3 my-3">
	{{ upd.content|safe}}
	</div>
</div>
{% if upd.has_sms %}
<div class="border border-secondary rounded my-1 cv-sirene-msg-update-sms">
	<div class="mx-3">
	<b>SMS</b>: {{ upd.sms_content|safe}}
	</div>
</div>
{% endif %}
<div class="text-muted text-end">
	{{ upd.email_count|default:0 }} emails - {{ upd.sms_count|default:0 }} sms
</div>

<br>

{% endfor %}
{% endif %}

<!-- TECH INFO -->
<hr>
<table class="table small table-striped table-hover table-sm">
	<tr><th>{% translate 'Message ID' %}</th><td>{{ page.id }}</td></tr>
	<tr><th>{% translate 'Message Key' %}</th><td>{{ page.keyname }}</td></tr>
	<tr><th>{% translate 'Template' %}</th><td>{{ page.template|default:"n/a" }}</td></tr>
	<tr><th>{% translate 'Title' %}</th><td>{{ page.title }}</td></tr>
	<tr><th>{% translate 'Created' %} ({% translate 'date' %})</th><td>{{ page.created_at }}</td></tr>
	<tr><th>{% translate 'Created' %} ({% translate 'author' %})</th><td>{{ page.created_by }}</td></tr>
	<tr><th>{% translate 'Updated' %} ({% translate 'date' %})</th><td>{{ page.updated_at }}</td></tr>
	<tr><th>{% translate 'Updated' %} ({% translate 'author' %})</th><td> {{ page.updated_by }}</td></tr>
	<tr><th>{% translate 'Removed' %} ({% translate 'date' %})</th><td>{{ page.removed_at }}</td></tr>
	<tr><th>{% translate 'Removed' %} ({% translate 'author' %})</th><td>{{ page.removed_by }}</td></tr>
	<tr><th>{% translate 'Public Page' %}</th><td>{{ page.publicpage|default:"" }}</td></tr>
	<tr><th>{% translate 'Restricted' %}</th><td>{{ page.is_restricted|yesno:"X,," }}</td></tr>

	
	<tr><th>{% translate 'Email' %}</th><td>{{ page.total_email_count|default:'' }}</td></tr>
	<tr><th>{% translate 'SMS' %}</th><td>{{ page.total_sms_count|default:''  }}</td></tr>

	<tr><th>{% translate 'Targets' %}</th>
		<td>
			{% for target in page.notified_targets %} {{ target }}{% if not forloop.last %}, {% endif %}{% endfor %}
		</td>
	</tr>

	<tr>
		<th>
			{% translate 'Recipients' %}  ({{ page.notified_username_count }})
		</th>
		<td>
			{{ page.notified_username|default:'' }}
		</td>
	</tr>

</table>

<!-- Close Confirmation Modal -->
<div class="modal fade" id="closeConfirmModal" tabindex="-1" aria-labelledby="closeConfirmLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title" id="closeConfirmLabel">{% translate 'Confirm Close' %}</h5>
				<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
			</div>
			<div class="modal-body">
				{% translate 'Are you sure you want to close this message?' %}
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% translate 'Cancel' %}</button>
				<form method="post" action="{% url 'app_sirene:close' page.id %}" class="cv-form-inline">
					{% csrf_token %}
					<button type="submit" class="btn btn-danger">{% translate 'Close Message' %}</button>
				</form>
			</div>
		</div>
	</div>
</div>

<!-- Reopen Confirmation Modal -->
<div class="modal fade" id="reopenConfirmModal" tabindex="-1" aria-labelledby="reopenConfirmLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title" id="reopenConfirmLabel">{% translate 'Confirm Reopen' %}</h5>
				<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
			</div>
			<div class="modal-body">
				{% translate 'Are you sure you want to reopen this message?' %}
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% translate 'Cancel' %}</button>
				<form method="post" action="{% url 'app_sirene:reopen' page.id %}" class="cv-form-inline">
					{% csrf_token %}
					<button type="submit" class="btn btn-danger">{% translate 'Reopen Message' %}</button>
				</form>
			</div>
		</div>
	</div>
</div>

{% endblock %}






