{% extends "webpage/base.html" %}
{% load mptt_tags %}
{% block Title %}{{ object }}{% endblock %}
{% 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}}">
            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 -->
    {% if object.scheme %}

            {% for concept,structure in object.scheme.has_concepts.all|tree_info %}
            {% if structure.new_level %}<ul><li>{% else %}</li><li>{% endif %}

            {% if concept.id == object.id and concept.needs_review == False %}
            <strong>{{ concept.pref_label }}</strong>
            {% elif concept.id == object.id and concept.needs_review == True %}
            <strong>
            {{ concept.pref_label }} <b style="color:red;" title="Needs review"> !</b>
            </strong>
            {% elif concept.id == object.id %}
            <strong>{{ concept.pref_label }}</strong>
            {% elif concept.id != object.id and concept.needs_review == True %}
            <a href="{{ concept.get_absolute_url }}">
            {{ concept.pref_label }} <b style="color:red;" title="Needs review"> !</b>
            </a>
            {% else %}
            <a href="{{ concept.get_absolute_url }}">{{ concept.pref_label }}</a>
            {% endif %}

            {% for level in structure.closed_levels %}</li></ul>{% endfor %}
            {% endfor %}

    {% 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:Concept</small> {{ object }}
            {% if user.is_authenticated %}
                <small>
                    <a href="{% url 'vocabs:skosconcept_update' pk=object.id %}">
                        <i data-feather="edit"></i>
                    </a>
                </small>
              
                <small>
                    <a href="{% url 'vocabs:skosconcept_delete' pk=object.id %}">
                        <i data-feather="delete"></i>
                    </a>
                </small>
            {% endif %}
        </h2>
    </div>
    <table class="table">
        {% if object.pref_label %}
        <tr>
            <th class="w-25">
            skos:prefLabel{% if object.pref_label_lang %} @{{object.pref_label_lang}}{% endif %}
            </th>
            <td>{{ object.pref_label }}</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.notation %}
        <tr>
        <th>skos:notation</th>
        <td>{{object.notation}}</td>
        </tr>
        {% endif %}

        {% if object.scheme %}
        <tr>
        <th>skos:inScheme</th>
        <td>
            <a href="{{ object.scheme.get_absolute_url }}">{{object.scheme}}</a>
        </td>
        </tr>
        {% endif %}
         {% if object.collection.all %}
        <tr>
        <th>member of skos:Collection</th>
        <td>
            {% for x in object.collection.all %}
            <a href="{{ x.get_absolute_url }}">{{x}}</a><br>
            {% endfor %}
        </td>
        </tr>
        {% endif %}
        {% if object.legacy_id %}
        <tr>
        <th>legacy id</th>
        <td>{{object.legacy_id}}</td>
        </tr>
        {% endif %}
        {% if object.creator %}
        <tr>
        <th>dc:creator</th>
        <td>
        {% for creator in object.creator_as_list %}
        <li>{{creator}}</li>
        {% endfor %}
        </td>
        </tr>
        {% endif %}

        {% if object.contributor %}
        <tr>
        <th>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-->
<!-- Mapping relationships -->
        {% if object.broader_concept %}
        <tr>
        <th>skos:broader</th>
        <td>
        <a href="{{ object.broader_concept.get_absolute_url }}">
        {{object.broader_concept}}
        </a>
        </td>
        </tr>
        {% endif %}
        {% if object.narrower_concepts.all %}
        <tr>
        <th>skos:narrower</th>
        <td>
            {% for x in object.narrower_concepts.all %}
            <a href="{{ x.get_absolute_url }}">{{x}}</a><br>
            {% endfor %}
        </td>
        </tr>
        {% endif %}
<!-- external macthes via AC -->
        {% if object.related %}
        <tr>
            <th>skos:related</th>
            <td>
            {% for x in object.related_as_list %}
            <li>{{x|urlize}}</li>
            {% endfor %}
            </td>
        </tr>
        {% endif %}
        {% if object.broad_match %}
        <tr>
            <th>skos:broadMatch</th>
            <td>
            {% for x in object.broad_match_as_list %}
            <li>{{x|urlize}}</li>
            {% endfor %}
            </td>
        </tr>
        {% endif %}
        {% if object.narrow_match %}
        <tr>
            <th>skos:narrowMatch</th>
            <td>
            {% for x in object.narrow_match_as_list %}
            <li>{{x|urlize}}</li>
            {% endfor %}
            </td>
        </tr>
        {% endif %}
        {% if object.exact_match %}
        <tr>
            <th>skos:exactMatch</th>
            <td>
            {% for x in object.exact_match_as_list %}
            <li>{{x|urlize}}</li>
            {% endfor %}
            </td>
        </tr>
        {% endif %}
        {% if object.related_match %}
        <tr>
            <th>skos:relatedMatch</th>
            <td>
            {% for x in object.related_match_as_list %}
            <li>{{x|urlize}}</li>
            {% endfor %}
            </td>
        </tr>
        {% endif %}
        {% if object.close_match %}
        <tr>
            <th>skos:closeMatch</th>
            <td>
            {% for x in object.close_match_as_list %}
            <li>{{x|urlize}}</li>
            {% endfor %}
            </td>
        </tr>
        {% endif %}
<!--  -->
        {% if object.date_created %}
         <tr>
            <th>dct:created</th>
            <td>{{object.date_created}}</td>
        </tr>
        {% endif %}
        {% if object.date_modified %}
         <tr>
            <th>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 %}
        {% if object.needs_review == True %}
         <tr>
            <th class="w-25"></th>
            <td style="color:red;"><b>Needs review</b></td>
        </tr>
        {% endif %}
        {% endif %}
        <tr>
            <th>download this concept</th>
            <td>
                <li><a href="{% url 'vocabs:vocabs-download' %}?pref_label={{object.id}}">RDF/XML</a></li>
                <li><a href="{% url 'vocabs:vocabs-download' %}?format=turtle&pref_label={{object.id}}">Turtle</a></li>
            </td>
        </tr>
        </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 content %}
