{% extends 'base.html' %}
{% block title %}
    Resource: {{ uid }}
{% endblock %}
{% block breadcrumbs %}
<nav aria-label="breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item">
            <a href="/ldp/">Root</a>
        </li>
        {% set frags = uid.strip('/').split('/') %}
        {% for frag in frags %}
            {% set href = '/' + '/'.join(frags[:loop.index]) %}
            {% if href == uid %}
            <li class="breadcrumb-item active" aria-current="page">{{frag}}
            {% else %}
            <li class="breadcrumb-item">
                <a href="/ldp{{ href }}">{{frag}}</a>
            {% endif %}
            </li>
        {% endfor %}
    </ol>
</nav>
{% endblock %}
{% block content %}
{% if gr[gr.identifier : nsc['rdf'].type : nsc['ldp'].NonRDFSource] %}
<div class="pull-right">
    <a href="{{ gr.identifier }}/fcr:content" class="btn btn-success btn-lg">
        <span class="glyphicon glyphicon-download" aria-hidden="true"></span>
        Download Content</a>
</div>
{% endif %}
{% set created_ts = arrow.get(
    gr.value(gr.identifier, nsc['fcrepo'].created)).to('local') %}
{% set updated_ts = arrow.get(
    gr.value(gr.identifier, nsc['fcrepo'].lastModified)).to('local') %}
<p><strong>Created on:</strong>&nbsp;{{ created_ts.format('YYYY-MM-DD HH:mm:ss ZZ') }}&nbsp;
({{created_ts.humanize() }})</p>
<p><strong>Last updated on:</strong>&nbsp;{{ updated_ts.format('YYYY-MM-DD HH:mm:ss ZZ') }}&nbsp;
({{updated_ts.humanize() }})</p>
<p><strong>Types:</strong>
{% for t in gr[gr.identifier : nsc['rdf'].type :] | sort %}
    <span class="label label-primary">{{ t.n3(namespace_manager=nsm) }}</span>
{% endfor %}
</p>
<h2>Properties</h2>
<table class="table table-striped">
    <thead>
        <tr>
            <!--
            <td>Subject</td>
            <td>Predicate</td>
            <td>Object</td>
            -->
        </tr>
    </thead>
    <tbody>
    {% for t in gr | sort %}
        {% if t[0] == uri and t[1] not in blacklist %}
        <tr>
            <!--
            <td>
                <a href="{{ t[0] }}">
                    {{ t[0].n3(namespace_manager=nsm) }}
                </a>
            </td>
            -->
            <td>
                <a href="{{ t[1] }}">
                    {{ t[1].n3(namespace_manager=nsm) }}
                </a>
            </td>
            <td>
            {% if 'Literal' in t[2].__class__.__name__ %}
            "{{ t[2] }}"
            {% if t[2].datatype %}
                <span class="label label-primary">
                    {{ t[2].datatype.n3(namespace_manager=nsm) }}
                </span>
            {% endif %}
            {% else %}
                <a href="{{ t[2] }}">
                    {{ t[2].n3(namespace_manager=nsm) }}
                </a>
            {% endif %}
            </td>
        </tr>
        {% endif %}
    {% endfor %}
    </tbody>
</table>

<h2>Other subjects</h2>
<table class="table table-striped">
    <thead>
        <tr>
            <td>Subject</td>
            <td>Predicate</td>
            <td>Object</td>
        </tr>
    </thead>
    <tbody>
    {% for t in gr | sort %}
        {% if t[0] != uri and t[1] not in blacklist %}
        <tr>
            <td>
                <a href="{{ t[0] }}">
                    {{ t[0].n3(namespace_manager=nsm) }}
                </a>
            </td>
            <td>
                <a href="{{ t[1] }}">
                    {{ t[1].n3(namespace_manager=nsm) }}
                </a>
            </td>
            <td>
            {% if 'Literal' in t[2].__class__.__name__ %}
            "{{ t[2] }}"
            {% if t[2].datatype %}
            <span class="label label-primary">{{ t[2].datatype.n3(namespace_manager=nsm) }}</span>
            {% endif %}
            {% else %}
                <a href="{{ t[2] }}">
                    {{ t[2].n3(namespace_manager=nsm) }}
                </a>
            {% endif %}
            </td>
        </tr>
        {% endif %}
    {% endfor %}
    </tbody>
</table>
{% block namespaces %}
            <h2>Namespaces</h2>
             <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#nslist" aria-expanded="false" aria-controls="nsList">
                Expand/Collapse
            </button>
            <div class="collapse" id="nslist">
                <div class="card card-body">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <td>Prefix</td>
                                <td>URI</td>
                            </tr>
                        </thead>
                        <tbody>
                        {% for ns in nsm.namespaces() | sort %}
                            <tr>
                                <td>{{ ns[0] }}</td>
                                <td>{{ ns[1] }}</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>

{% endblock %}
{% endblock %}