{% extends 'template_content/template_content_base.html' %}
{% load i18n imagekit static localcosmos_tags %}

{% block extra_style %}
	<link href="{% static 'template_content/template_content.css' %}" rel="stylesheet">
{% endblock %}

{% block content %}
	<div class="container-fluid mt-3">
		<div class="row">
			<div class="col-12">
				<h3>
					{% if localized_template_content %}
						{{ localized_template_content.draft_title }} <img src="{% static 'localcosmos_server/images/countries/' %}{{ localized_template_content.language }}.gif" />
						
						<small><span class="badge badge-info">version {{ localized_template_content.draft_version }}</span></small>

						{% if localized_template_content.published_version == localized_template_content.draft_version %}
							<small><span class="badge badge-success">{% trans 'published' %}</span></small>
						{% else %}
							{% if localized_template_content.published_version %}
								<small><span class="badge badge-warning">{% trans 'unpublished changes' %}</span></small>
							{% else %}
								<small><span class="badge badge-warning">{% trans 'not published' %}</span></small>
							{% endif %}
						{% endif %}
					{% endif %}
					<!--
					{% if app.secondary_languages %}
						{% if localized_template_content.published_version == localized_template_content.draft_version %}
						{% else %}
							{% if localized_template_content.translation_ready %}
								<small><span class="badge badge-info">{% trans 'ready for translation' %}</span></small>
							{% else %}
								<small><span class="badge badge-warning">{% trans 'not ready for translation' %}</span></small>
							{% endif %}
						{% endif %}
					{% endif %}
					-->
				</h3>

				{% if saved %}
					<div class="row">
						<div class="col-12">
							<div class="alert alert-success">
								{% trans 'Successfully saved your content.' %}
							</div>
						</div>
					</div>
				{% endif %}

			</div>
		</div>

		<div class="row">
			<div class="col-12 col-md-6">
				
				{% block taxonomic_restriction %}
				<div class="row">
					<div class="col-12">
					
						<div class="card">
							<div class="card-body">
								{% render_taxonomic_restriction app localized_template_content.template_content %}
							</div>
						</div>
					</div>
				</div>
				
				<hr>

				{% endblock %}
				
				<h4>{% trans 'Components' %}</h4>
				<form id="contentform" action="{% block form_action %}{% url 'manage_localized_template_content' app.uid localized_template_content.id %}{% endblock %}" method="POST">{% csrf_token %}

					{% block form %}
						{% include 'template_content/ajax/localized_template_content_form.html' %}
					{% endblock %}

					<hr>
					<p>
						<button type="submit" class="btn btn-outline-primary">
							{% block save_button_text %}{% trans 'save content' %}{% endblock %}
						</button>
					</p>
				</form>
			</div>
			<div class="col-12 col-md-6">
				<h4>{% trans 'Preview' %} <small><a href="{{ preview_url }}" target="_blank">{% trans 'Show in separate window' %}</a></small></h4>
				<object id="contentPreview" type="text/html" data="{{ preview_url }}"></object>
			</div>
		</div>
	</div>
{% endblock %}
{% block extra_script %}
	{% include 'template_content/ajax/manage_template_content_extra_scripts.html' %}

	<script>

		function reloadPreview(){
			$("#contentPreview").attr("data", "{{ preview_url }}");
		}

	</script>
{% endblock %}
