{% load i18n %}
{% load rules %}
{% load accounts_tags %}

{% has_perm 'projects.add_integration_object' request.user project as can_add_integration %}
{% has_perm 'projects.change_integration_object' request.user project as can_change_integration %}
{% has_perm 'projects.delete_integration_object' request.user project as can_delete_integration %}

{% if integrations %}

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

    {% include 'projects/project_detail_integrations_help.html' %}

    <table class="table">
        <thead>
            <th style="width: 10%">{% trans 'Provider' %}</th>
            <th style="width: 50%">{% trans 'Description' %}</th>
            <th style="width: 30%">{% trans 'Options' %}</th>
            <th style="width: 10%"></th>
        </thead>
        <tbody>
            {% for integration in integrations %}
            {% if integration.provider %}
            <tr>
                <td>
                    {{ integration.provider.label }}
                </td>
                <td>
                    {{ integration.provider.description }}
                </td>
                <td>
                    {% for option in integration.options.all %}
                    {% if not option.secret %}
                    {{ option.key.title }}: {{ option.value }}<br />
                    {% endif %}
                    {% endfor %}

                    {% if integration.project != project %}
                    ({% trans 'from' %} <a href="{% url 'project' integration.project.id %}">{{ integration.project.title }}</a>)
                    {% endif %}
                </td>
                <td class="text-right">
                    {% if integration.project == project %}

                    {% if can_change_integration %}
                    <a href="{% url 'integration_update' project.pk integration.pk %}" class="fa fa-pencil"
                        title="{% trans 'Update integration' %}">
                    </a>
                    {% endif %}
                    {% if can_delete_integration %}
                    <a href="{% url 'integration_delete' project.pk integration.pk %}" class="fa fa-remove"
                        title="{% trans 'Delete integration' %}">
                    </a>
                    {% endif %}

                    {% endif %}
                </td>
            </tr>
            {% endif %}
            {% endfor %}
        </tbody>
    </table>

{% endif %}
