{% extends "webpage/base.html" %}
{% load mptt_tags %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
    <div class="card">
        <div class="card-header">
        <h2><a href="{{ object.scheme.get_absolute_url }}">{{object.scheme}}</a>
        {% if user.is_authenticated %}
            <a class ="btn btn-outline-secondary"  href="{% url 'vocabs:skosconcept_create' %}?scheme={{object.scheme.id}}&collection={{object.id}}">
            Add Concept
            </a>
            <a class ="btn btn-outline-secondary"  href="{% url 'vocabs:skoscollection_create' %}?scheme={{object.scheme.id}}">
            Add Collection
            </a>
        {% endif %}
        </h2>
        </div>
    <div class="card-body">
        <!-- Hierarchy location -->
        {% if object.has_members.all %}
        <strong>Concepts in this Collection ({{ object.has_members.all|length }})</strong>

        {% for concept,structure in object.has_members.all|tree_info %}
        {% if structure.new_level %}<ul><li>{% else %}</li><li>{% endif %}
        <a href="{{ concept.get_absolute_url }}">
        {% if concept.needs_review == True %}
        {{ concept.pref_label }} <b style="color:red;" title="Needs review"> !</b>
        {% else %}
        {{ concept.pref_label }}
        {% endif %}
        </a>
        {% for level in structure.closed_levels %}</li></ul>{% endfor %}
        {% endfor %}

        {% else %}

        <strong>No concepts in this Collection</strong>

        {% endif %}
        <!-- Hierarchy END -->
    </div>
    </div>
</div>
<div class="col-md-8">
    <div class="card">
        <div class="card-header">
            <h2 style="text-align: center;">
                <small>skos:Collection</small> {{ object }}
                {% if user.is_authenticated %}
                    <small>
                        <a href="{% url 'vocabs:skoscollection_update' pk=object.id %}">
                            <i data-feather="edit"></i>
                        </a>
                    </small>
                    |
                    <small>
                        <a href="{% url 'vocabs:skoscollection_delete' pk=object.id %}">
                            <i data-feather="delete"></i>
                        </a>
                    </small>
                {% endif %}
            </h2>
        </div>
        <table class="table">
        {% if object.name %}
        <tr>
            <th class="w-25">skos:prefLabel {% if object.label_lang %}@{{object.label_lang}}{% endif %}</th>
            <td>
           {{ object.name }}
            </td>
        </tr>
        {% endif %}

        <!--for inline added abels-->
        {% if object.has_labels %}
        {% for label in object.has_labels.all %}
        <tr>
            <th>skos:{{label.label_type}} @{{label.language}}</th>
            <td>{{label.name}}</td>
        </tr>
        {% endfor %}
        {% endif %}
        <!--end-->

        {% if object.scheme %}
         <tr>
            <th>skos:ConceptScheme</th>
            <td>
            <a href="{{ object.scheme.get_absolute_url }}">
            {{object.scheme}}
            </a>
            </td>
        </tr>
        {% endif %}
        {% if object.legacy_id %}
         <tr>
            <th>legacy id</th>
            <td>{{object.legacy_id}}</td>
        </tr>
        {% endif %}
        {% if object.creator %}
         <tr>
            <th class="w-25">dc:creator</th>
            <td>
            {% for creator in object.creator_as_list %}
            <li>{{ creator }}</li>
            {% endfor %}
            </td>
        </tr>
        {% endif %}
        {% if object.contributor %}
         <tr>
            <th class="w-25">dc:contributor</th>
            <td>
            {% for contributor in object.contributor_as_list %}
            <li>{{ contributor }}</li>
            {% endfor %}
            </td>
        </tr>
        {% endif %}

        <!--for inline added notes-->
        {% if object.has_notes %}
        {% for note in object.has_notes.all %}
        <tr>
            <th>skos:{{note.note_type}} @{{note.language}}</th>
            <td>{{note.name}}</td>
        </tr>
        {% endfor %}
        {% endif %}
        <!--end-->

        <!--for inline added sources-->
        {% if object.has_sources %}
        {% for source in object.has_sources.all %}
        <tr>
            <th>dc:source @{{source.language}}</th>
            <td>{{source.name}}</td>
        </tr>
        {% endfor %}
        {% endif %}
        <!--end-->

        {% if object.date_created %}
         <tr>
            <th class="w-25">dct:created</th>
            <td>{{object.date_created}}</td>
        </tr>
        {% endif %}

        {% if object.date_modified %}
         <tr>
            <th class="w-25">dct:modified</th>
            <td>{{object.date_modified}}</td>
        </tr>
        {% endif %}

        {% if user.is_authenticated %}
        {% if object.created_by %}
         <tr>
            <th class="w-25">created by</th>
            <td>{{object.created_by}}</td>
        </tr>
        {% endif %}
        {% endif %}

        {% if object.has_members.all %}
        <tr>
            <th>download this collection</th>
            <td>
                <li><a href="{% url 'vocabs:vocabs-download' %}?collection={{object.id}}">RDF/XML</a></li>
                <li><a href="{% url 'vocabs:vocabs-download' %}?format=turtle&collection={{object.id}}">Turtle</a></li>
            </td>
        </tr>
        {% endif %}

        </table>
        <!--change history collapse button-->
        {% if user.is_authenticated %}
        {% if history %}
        <div class="col-md-12" style="margin-bottom: 20px;">
        <button class="btn btn-outline-info" type="button" data-toggle="collapse" data-target="#changeHistory" aria-expanded="false" aria-controls="changeHistory" style="margin-bottom: 20px;">
        Change history
        </button>
        <div class="collapse" id="changeHistory">
           {% for x in history %}
            <li>
            {% if forloop.last %}
            {{ x.revision.date_created }} created by {{ x.revision.user }}
            {% else %}
            {{ x.revision.date_created }} changed by {{ x.revision.user }}
            {% endif %}
           </li>
           {% endfor %}
        </div>
        </div>
        {% endif %}
        {% endif %}
        <!--change history ends here-->
    </div>
</div><!-- col-8 ends -->
</div><!-- row ends -->
</div>
{% endblock %}
