{% load guardian_tags %}
{% load widget_tweaks %}
{% load url_link %}
{% load humansize %}
{% load is_publisher %}
{% load crispy_forms_tags %}
{% load has_access_url %}

{% block content %}

{% if investigation_linked == True or assay_linked == True %}
<a class="add-link btn btn-primary"
    href="{% url 'core:choose_tool_project' project.id investigation.id data_type item.id %}">Add
    Link</a>

{% else %}
<div class="disabled-button-wrapper" data-toggle="popover" data-trigger="hover" data-placement="right"
    title="Action not available" data-container="body" data-html="true"
    data-content="Please link at least one <br/> <strong>investigation</strong> or one <strong>assay</strong> first.">
    <button class="add-link btn btn-primary" type="button" disabled>Add Link</button>
</div>
{% endif %}
</div>
</div>
</br>
<section>

    <table id="table" class="table table-striped table-bordered table-hover">

        <thead>
            <tr>
                <th>Name</th>
                <th>Tool</th>
                <th>Size</th>
                <th>Actions</th>
            </tr>
        </thead>

        <tbody>
            {% for mapping in mappings %}
            {% if not mapping.0.tool_id|is_publisher %}

            <tr>
                <td><i class="fa fa-database fa-1x image ic-w mx-1 "></i><a href="{{mapping.0.link_url}}"
                        target="_blank">{{mapping.0.name}}</a></td>
                <td>{{mapping.0.link_tool}}</td>
                <td>{{mapping.0.size|humansize}}</td>
                <td>
                    <div class="btn-group">
                        <div class="btn-group">
                            {% if mapping.0.tool_id|has_access_url %}
                            <a type="button" style="margin-right:0; margin-left: 10px;"
                                class="btn-sm btn rounded btn-secondary" role=button href="{{mapping.0.link_url}}"
                                target="_blank">View on {{mapping.0.link_tool}}</a>
                            {% endif %}
                        </div>

                        <a type="button" style="margin-right:0; margin-left: 10px;"
                            class="btn-sm btn rounded btn-danger" role=button
                            href='{% url 'core:delete-mapping' project_id=project.id investigation_id=investigation.id data_type="dataset" pk=mapping.0.id  %}'><i
                                class="fa fa-trash-alt fa-1x"></i></a>
                </td>
                </div>
            </tr>
            {% endif %}
            {% endfor %}
        </tbody>
    </table>
</section>
<br><br>
<div class="row">
    <div class="col-sm-6">
        <span class="badge badge-pill badge-secondary">{{ nb_publisher }}</span>
        <span class="texte-badge"> publication found</span>
    </div>
</div>
<section>

    <table id="table" class="table table-striped table-bordered table-hover">

        <thead>
            <tr>
                <th>Name</th>
                <th>DOI</th>
                <th>Tool</th>
                <th>Actions</th>
            </tr>
        </thead>

        <tbody>
            {% for mapping in mappings %}
            {% if mapping.0.tool_id|is_publisher %}
            <tr>
                <td><i class="fa fa-database fa-1x image ic-w mx-1 "></i><a href="{{mapping.0.link_url}}"
                        target="_blank">{{mapping.0.name}}</a></td>
                <td>{{mapping.0.link_tool}}</td>
                <td>{{mapping.0.size|humansize}}</td>
                <td>
                    <div class="btn-group">
                        <div class="btn-group">
                            <a type="button" style="margin-right:0; margin-left: 10px;"
                                class="btn-sm btn rounded btn-secondary" role=button href="{{mapping.0.link_url}}"
                                target="_blank">View on {{mapping.0.link_tool}}</a>
                        </div>

                        <a type="button" style="margin-right:0; margin-left: 10px;"
                            class="btn-sm btn rounded btn-danger" role=button
                            href='{% url 'core:delete-mapping' project_id=project.id investigation_id=investigation.id data_type="dataset" pk=mapping.0.id  %}'><i
                                class="fa fa-trash-alt fa-1x"></i></a>
                </td>
                </div>
            </tr>
            {% endif %}
            {% endfor %}
        </tbody>
    </table>

</section>
<button type="button" class="btn btn-secondary"><a href="{% url 'core:projects-details' project.id %}"> Back
    </a></button>



{% endblock %}