{% load i18n %}
{% load rules %}
{% load core_tags %}

{% has_perm 'projects.change_project_object' request.user project as can_change_project %}
{% has_perm 'projects.delete_project_object' request.user project as can_delete_project %}
{% has_perm 'projects.leave_project_object' request.user project as can_leave_project %}

{% has_perm 'projects.change_value_object' request.user project as can_change_value %}

<h2>{% trans 'Options' %}</h2>

<ul class="list-unstyled">
    <li id="project-questions">
        <strong>
            {% if can_change_value %}
            <a href="{% url 'project_questions' project.pk %}">{% trans 'Answer questions' %}</a>
            {% else %}
            <a href="{% url 'project_questions' project.pk %}">{% trans 'View questions' %}</a>
            {% endif %}
        </strong>
    </li>
</ul>

<ul class="list-unstyled">
    <li>
        <strong>
            <a href="{% url 'project_answers' project.pk %}">{% trans 'View answers' %}</a>
        </strong>
    </li>
</ul>

{% if can_leave_project and membership and not membership.is_last_owner %}
<ul class="list-unstyled">
    <li>
        <a href="{% url 'project_leave' project.pk %}">{% trans 'Leave project' %}</a>
    </li>
</ul>
{% endif %}

{% if can_change_project or can_delete_project %}
<ul class="list-unstyled">
    {% if can_change_project %}
    <li>
        <a href="{% url 'project_update_information' project.pk %}">{% trans 'Update project information' %}</a>
    </li>
    <li>
        <a href="{% url 'project_update_catalog' project.pk %}">{% trans 'Update project catalog' %}</a>
    </li>
    {% if settings.NESTED_PROJECTS %}
    <li>
        <a href="{% url 'project_update_parent' project.pk %}">{% trans 'Update parent project' %}</a>
    </li>
    {% endif %}
    {% if settings.PROJECT_ISSUES %}
    <li>
        <a href="{% url 'project_update_tasks' project.pk %}">{% trans 'Update project tasks' %}</a>
    </li>
    {% endif %}
    {% if settings.PROJECT_VIEWS %}
    <li>
        <a href="{% url 'project_update_views' project.pk %}">{% trans 'Update project views' %}</a>
    </li>
    {% endif %}
    {% endif %}
    {% if can_delete_project %}
    <li>
        <a href="{% url 'project_delete' project.pk %}">{% trans 'Delete project' %}</a>
    </li>
    {% endif %}
</ul>
{% endif %}

{% has_perm 'projects.add_membership_object' request.user project as can_add_membership %}
{% if can_add_membership %}
<ul class="list-unstyled">
    <li>
        <a href="{% url 'membership_create' project.pk %}">{% trans 'Add member' %}</a>
    </li>
</ul>
{% endif %}

{% has_perm 'projects.add_snapshot_object' request.user project as can_add_snapshot %}
{% if can_add_snapshot %}
<ul class="list-unstyled">
    <li>
        <a href="{% url 'snapshot_create' project.pk %}">{% trans 'Create snapshot' %}</a>
    </li>
</ul>
{% endif %}

{% has_perm 'projects.add_integration_object' request.user project as can_add_integration %}
{% if providers and can_add_integration %}
<ul class="list-unstyled">
    {% for provider_key, provider in providers.items %}
    <li>
        <a href="{% url 'integration_create' project.pk provider_key %}">{{ provider.add_label }}</a>
    </li>
    {% endfor %}
</ul>
{% endif %}

<ul class="list-unstyled">
    <li>
        <a href="{% url 'projects' %}">{% trans 'Back to projects overview' %}</a>
    </li>
</ul>

{% has_perm 'projects.export_project_object' request.user project as can_export_project %}
{% if settings.PROJECT_EXPORTS and can_export_project %}
<h2 id="export-project">{% trans 'Export' %}</h2>

<ul class="list-unstyled">
    {% for key, label, class in settings.PROJECT_EXPORTS %}
    <li>
        <a href="{% url 'project_export' project.pk key %}" target="_blank">
            {{ label }}
        </a>
    </li>
    {% endfor %}
</ul>
{% endif %}

{% has_perm 'projects.import_project_object' request.user project as can_import_project %}
{% if settings.PROJECT_IMPORTS and can_import_project %}
<h2 id="import-project">{% trans 'Import values' %}</h2>

<ul class="list-unstyled">
    <li>
        <p>
            <strong>{% trans 'Import from file' %}</strong>
        </p>
        {% url 'project_update_import' project.id as upload_url %}
        {% include 'core/upload_form.html' with upload_url=upload_url label=True %}
    </li>
    {% if settings.NESTED_PROJECTS and project.get_ancestors %}
    <li>
        <p>
            <strong>{% trans 'Import from parent project' %}</strong>
        </p>
        {% include 'projects/project_detail_sidebar_parent_import.html' %}
    </li>
    {% endif %}
</ul>
{% endif %}
