{% load i18n cosinnus_tags widget_tweaks %}

{% if not no_imports %}
{{ form.forms.media_tag.media }}
{% endif %}


<script type="text/javascript">
    function display_media_tags() {
        $('.media_tag_initial_hidden').fadeIn();
        $('.media_tag_initial_visible').hide();
        {% if form.forms.obj.attached_objects %}
        $('#s2id_{{ form.forms.obj.attached_objects.id_for_label }} input').css('width', '');
        {% endif %}
    }
</script>


{% if not media_tags_label %}{% trans "Additional options" as media_tags_label %}{% endif %}
{% if not media_tags_legend %}{% trans "Attach files, add a location, mark topics and adjust visibility settings" as media_tags_legend %}{% endif %}
<div {% if not show_all and not all_errors %}class="media_tag_initial_hidden" style="display: none;"{% endif %}>
    {% include 'cosinnus/fields/default_field.html' with legend=media_tags_legend label=media_tags_label %}
</div>


{% if not disable_persons %}
	<div class="media_tag_initial_hidden" {% if not show_persons == True and not show_all == True and not form.forms.media_tag.persons.errors %}style="display: none;"{% endif %}>
		{% if not persons_label %}{% trans "Tag persons" as persons_label %}{% endif %}
        {% trans "Tag persons" as persons_placeholder %}
		{% include 'cosinnus/fields/media_tag_field.html' with field=form.forms.media_tag.persons label=persons_label icon="fa-user" placeholder=persons_placeholder %}
	</div>
{% endif %}


{% if not disable_tags %}
    <div class="media_tag_initial_hidden" {% if not show_tags == True and not show_all == True and not form.forms.media_tag.tags.errors %}style="display: none;"{% endif %}>
        {% if not tags_label %}{% trans "Select tags" as tags_label %}{% endif %}
        {% trans "Select tags" as tags_placeholder %}
        {% include 'cosinnus/fields/media_tag_field.html' with field=form.forms.media_tag.tags label=tags_label icon="fa-tags" placeholder=tags_placeholder %}
    </div>
{% endif %}


{% if not disable_location %}
    {% captureas loc_html %}
        {% trans "Place or adress" as loc_placeholder %}
        {% render_field form.forms.media_tag.location placeholder=loc_placeholder class+="font14px" %}
        {{ form.forms.media_tag.location_lat }}
        {{ form.forms.media_tag.location_lon }}
        <div id="id_media_tag-location-map"></div>
    {% endcaptureas %}

    <div class="media_tag_initial_hidden" {% if not show_location == True and not show_all == True and not form.forms.media_tag.location.errors %}style="display: none;"{% endif %}>
        {% if not loc_label %}{% trans "Location" as loc_label %}{% endif %}
        {% include 'cosinnus/fields/media_tag_field.html' with field_html=loc_html label=loc_label legend=loc_legend icon="fa-map-marker" %}
    </div>
{% endif %}


{% if form.forms.obj.attached_objects and not disable_files %}
    <div class="media_tag_initial_hidden" {% if not show_files == True and not show_all == True and not form.forms.obj.attached_objects.errors %}style="display: none;"{% endif %}>
        {% if not files_label %}{% trans "Upload a file or image or attach an existing one" as files_label %}{% endif %}
        {% captureas files_html %}
            {% include 'cosinnus/attached/attached_objects_widget.html' with form=form.forms.obj %}
        {% endcaptureas %}
        {% include 'cosinnus/fields/media_tag_field.html' with field_html=files_html label=files_label legend=files_legend icon="fa-paperclip" %}
    </div>
{% endif %}


{% if not disable_topics %}
    <div class="media_tag_initial_hidden" {% if not show_topics == True and not show_all == True and not form.forms.media_tag.topics.errors %}style="display: none;"{% endif %}>
        {% if not topics_label %}{% trans "Select topic" as topics_label %}{% endif %}
        {% trans "Select topic" as topics_placeholder %}
        {% include 'cosinnus/fields/media_tag_field.html' with field=form.forms.media_tag.topics label=topics_label icon="fa-lightbulb-o" placeholder=topics_placeholder %}
    </div>
{% endif %}


{% if not disable_visibility %}
    <div class="media_tag_initial_hidden" {% if not form.forms.media_tag.initial.visibility == 2 and not show_visibility == True and not show_all == True and not form.forms.media_tag.visibility.errors %}style="display: none;"{% endif %}>
        {% if not visibility_label %}{% trans "Visibility" as visibility_label %}{% endif %}
        {% trans "Visibility" as visibility_placeholder %}
        {% include 'cosinnus/fields/media_tag_field.html' with field=form.forms.media_tag.visibility label=visibility_label icon="fa-globe" placeholder=visibility_placeholder help_popup="helptext_51_objectprivacy" %}
    </div>
	<ol class="group-public-warning-area" {% if form.forms.media_tag.initial.visibility != 2 %}style="display: none;"{% endif %} id="visibility-warning">
	    <li class="w100">
	        <i class="fa fa-fw fa-globe"></i>
	        {% trans "This item will be posted as publicly visible! This means that anyone on the internet can access and see it, and it may potentially be included in search engine results." %}
	        {% trans "If you do not wish this, you can change this item's visibility setting below." %}
	    </li>
	</ol>

	<script type="text/javascript">
		{# show or hide a visibility warning #}
		$('#{{ form.forms.media_tag.visibility.auto_id }}').on('change', function(){
			if ($(this).val() == "2") {
				$('#visibility-warning').show();
			} else {
				$('#visibility-warning').hide();
			} 
		});
	</script>
{% endif %}


{% if SETTINGS.COSINNUS_FACEBOOK_INTEGRATION_ENABLED and do_include_facebook_button %}
	<div class="">
        {% if not fb_label %}{% trans "Facebook-Integration" as fb_label %}{% endif %}
        {% captureas fb_html %}
			    {% include 'cosinnus/utils/facebook_integration.html' %}
        {% endcaptureas %}
        {% include 'cosinnus/fields/media_tag_field.html' with field_html=fb_html label=fb_label icon="fa-facebook-square" %}
    </div>
{% endif %}

{% if not show_all %}
	<div class="media_tag_initial_visible">
	    {% include 'cosinnus/fields/default_field.html' with legend=media_tags_legend label=media_tags_label %}
	    <div class="btn btn-emphasized btn-small btn-no-float regular-space w100" onclick="display_media_tags();">
	        <ul class="media-list">
	            <li class="media">
	                <a class="pull-left" href="#">
	                    <i class="fa fa-caret-down"></i>
	                </a>
	                <div class="media-body">
	                    {% trans "Show more options..." %}
	                </div>
	            </li>
	        </ul>
	    </div>
	</div>
{% endif %}
