{% load i18n static cosinnus_tags widget_tweaks %}

{% captureas cosinnus_app_list_url %}cosinnus:{{ COSINNUS_CURRENT_APP }}:list{% endcaptureas %}

{% if current_folder and current_folder.path != '/' %}
    {% if current_folder.container and current_folder.container.path != '/' %}
        {% captureas href %}{% group_url cosinnus_app_list_url group=group slug=current_folder.container.slug %}{% add_current_params %}{% endcaptureas %}
        {% captureas label %}{% trans "Back to" %} {{ current_folder.container.title }}{% endcaptureas %}
        {% include "cosinnus/leftnav_button.html" with extra_classes="regular-space" icon="fa-reply" label=label href=href  %}
    {% else %}
	    {% captureas href %}{% group_url cosinnus_app_list_url group=group %}{% add_current_params %}{% endcaptureas %}
	    {% captureas label %}{% trans "Back to" %} {% trans COSINNUS_CURRENT_APP context "the_app" %}{% endcaptureas %}
	    {% include "cosinnus/leftnav_button.html" with extra_classes="regular-space" icon="fa-reply" label=label href=href  %}
    {% endif %}
{% endif %}

{% for folder in folders %}
    {% captureas href %}{% group_url cosinnus_app_list_url group=group slug=folder.container_object.slug %}{% add_current_params %}{% endcaptureas %}
    {% captureas label %}{% if folder.container_object.special_type %}{% trans folder.container_object.title context "special_folder_type" %}{% else %}{{ folder.container_object.title }}{% endif %}{% endcaptureas %}
    {% captureas button_class %}{% if forloop.last or folder.container_object.special_type %}regular-space{% else %}fine-space{% endif %}{% endcaptureas %}
    {% if not is_deep_hierarchy or is_deep_hierarchy == False %}
        {% captureas folder_size %}{{ folder.objects|length }}{% endcaptureas %}
    {% endif %}
    {% captureas active %}{% if current_folder and folder.name == current_folder.slug %}True{% endif %}{% endcaptureas %}
    {% captureas button_template %}{% if user|can_create_objects_in:folder.container_object.group and not folder.container_object.special_type %}cosinnus/leftnav_button_editable_folder.html{% else %}cosinnus/leftnav_button.html{% endif %}{% endcaptureas %}
    
    {% include button_template with active=active extra_classes=button_class icon="fa-folder" icon_content=folder_size label=label href=href folder=folder.container_object %}
{% endfor %}

{% if user|can_create_objects_in:group %}
	<form action="" name="container_form" method="post"class="form-horizontal" autocomplete="off">{% csrf_token %}
	    <div type="button" class="btn btn-default w100">
	        <ul class="media-list">
	            <li class="media">
	                <a class="pull-left" href="#">
	                    <i class="fa fa-plus"></i>
	                </a>
	                <div class="media-body media-body-form-control">
	                    {{ container_form.title.errors }}
	                    <!-- use spaces for centering. CSS padding does not work here. -->
	                    {% captureas placeholder %}{% trans "New folder name" %}{% endcaptureas %}
	                    {% render_field container_form.title class+="form-control next-button-is-for-sending" placeholder=placeholder %}
	                    <!-- next-button-is-for-sending -->
	                </div>
	            </li>
	        </ul>
	    </div>
	    <button type="submit"  name="create_container" class="btn btn-emphasized large-space" style="display: none;">
	        <ul class="media-list">
	            <li class="media">
	                <a class="pull-left" href="#">
	                    <i class="fa fa-pencil"></i>
	                </a>
	                <div class="media-body">
	                    {% trans "Create folder" %}
	                </div>
	            </li>
	        </ul>
	    </button>
	</form>
{% endif %}
	