{% extends "spider_base/uc_base.html" %}
{% load i18n static spider_base spider_paging spider_rdf %}
{% block title %}{% if uc.public %}{% blocktrans trimmed %}
  Content of:
{% endblocktrans %} {{uc}} ({{uc.username}}){% else %}{% blocktrans trimmed %}
  Content List
{% endblocktrans %}{% endif %}{% endblock %}

{% block public_meta %}
  {{block.super}}
  <meta name="description" content="{{uc.description|escape}}" />
{% endblock %}

{% block extrahead %}
{{block.super}}
<script src="{% static 'node_modules/qrcode/build/qrcode.min.js' %}"></script>
<link rel="stylesheet" href="{% static 'node_modules/select2/dist/css/select2.min.css' %}">
{% if DEBUG %}
  <script src="{% static 'node_modules/jquery/dist/jquery.js' %}"></script>
  <script src="{% static 'node_modules/select2/dist/js/select2.js' %}"></script>
{% else %}
  <script src="{% static 'node_modules/jquery/dist/jquery.min.js' %}"></script>
  <script src="{% static 'node_modules/select2/dist/js/select2.min.js' %}"></script>
{% endif %}
{% endblock %}

{% block content %}
<div>
  <data hidden="hidden" property="spkc:action:view" datatype="xsd:anyURI">{% action_view %}</data>
  <div class="w3-padding">
    <span class="w3-left">
      {% if request.user == uc.user %}
        <a class="w3-block" style="margin-bottom:5px" href="{% if request.is_owner %}{% url 'spider_base:ucomponent-list' %}{% else %}{% url 'spider_base:ucomponent-list' %}{% endif %}">
          <i class="fas fa-arrow-up" style="margin-right:10px" aria-hidden="true"></i>{% trans 'Own' %}
        </a>
      {% endif %}
      <a class="w3-block" style="margin-bottom:5px" href="{% url 'spider_base:ucomponent-listpublic' %}">
        <i class="fas {% if request.user == uc.user or request.is_staff %}fa-angle-double-up{% else %}fa-arrow-up{% endif %}" style="margin-right:10px" aria-hidden="true"></i>{% trans 'Public' %}
      </a>
    </span>
    <span class="w3-right w3-left-align">
      {% if request.user == uc.user %}
        <a class="w3-block" style="margin-bottom:5px" href="{% url 'spider_base:ucomponent-update' token=uc.token %}">
          <i class="fas fa-edit" style="margin-right:10px" aria-hidden="true"></i>{% trans 'Update' %}
        </a>
      {% endif %}
      {% if request.is_staff and uc.user != request.user %}
        <a class="w3-block" style="margin-bottom:5px" href="{% if request.is_owner %}{% url 'spider_base:ucomponent-list' %}{% else %}{% url 'spider_base:ucomponent-list' user=uc.user %}{% endif %}">
          <i class="fas fa-arrow-up" style="margin-right:10px" aria-hidden="true"></i>{% trans 'User' %}
        </a>
      {% endif %}
      <a class="w3-block" style="margin-bottom:5px" onclick="if(document.readyState === 'complete'){open_qrmodal();}; return false;" href="#">
        <i class="fas fa-file-export" style="margin-right:10px" aria-hidden="true"></i>{% trans 'Link/Export' %}
      </a>
      <div>
        <i class="fas fa-lock" style="margin-right:10px" aria-hidden="true"></i>{% trans "Strength:" %} <data property="spkc:strength" datatype="xsd:integer">{{uc.strength}}</data>
      </div>
    </span>
    <h1 class="w3-center">
      {% if request.is_special_user or uc.public %}
        {% blocktrans trimmed %}
          Content of:
        {% endblocktrans %} <b>{{uc}}</b> <em>({{uc.user}})</em>
        <data hidden="hidden" rel="spkc:properties">
          <data hidden="hidden" typeof="spkc:Property">
            <data hidden="hidden" property="spkc:name" datatype="xsd:string">name</data>
            <data hidden="hidden" property="spkc:value" datatype="xsd:string">{{uc.name}}</data>
          </data>
          <data hidden="hidden" typeof="spkc:Property">
            <data hidden="hidden" property="spkc:name" datatype="xsd:string">user</data>
            <data hidden="hidden" property="spkc:value" datatype="xsd:string">{{uc.username}}</data>
          </data>
        </data>
      {% else %}
        {% blocktrans trimmed %}
          Content:
        {% endblocktrans %}
      {% endif %}
    </h1>
    {% for f in active_features %}
      {% for action in f.feature_urls %}
        <data hidden="hidden" typeof="spkc:action:feature" resource="{{hostpart}}{{action.url}}">
          <data hidden="hidden" property="spkc:feature:name" datatype="xsd:string">{{action.name}}</data>
        </data>
      {% endfor %}
    {% endfor %}
    <data hidden="hidden" rel="spkc:properties">
      <data hidden="hidden" typeof="spkc:Property">
        <data hidden="hidden" property="spkc:name" datatype="xsd:string">description</data>
        <data hidden="hidden" property="spkc:value" datatype="xsd:string">{{uc.description}}</data>
        <data hidden="hidden" property="spkc:hashable" datatype="xsd:boolean">false</data>
      </data>

      {% if uc.primary_anchor %}
      <data hidden="hidden" typeof="spkc:Property">
        <data hidden="hidden" property="spkc:name" datatype="xsd:string">primary_anchor</data>
        <data hidden="hidden" property="spkc:hashable" datatype="xsd:boolean">false</data>
        <data hidden="hidden" property="spkc:value" datatype="xsd:anyURI">{{hostpart}}{{uc.primary_anchor.get_absolute_url}}</data>
      </data>
      {% endif %}
      <data hidden="hidden" typeof="spkc:Property">
        <data hidden="hidden" property="spkc:name" datatype="xsd:string">features</data>
        <data hidden="hidden" property="spkc:hashable" datatype="xsd:boolean">false</data>
        {% for f in active_features %}
          <data hidden="hidden" datatype="xsd:string" property="spkc:value">{{f.name}}</data>
        {% empty %}
          <data hidden="hidden" rel="spkc:value" resource="rdf:nil"></data>
        {% endfor %}
      </data>
      <data hidden="hidden" typeof="spkc:Property">
        <data hidden="hidden" property="spkc:name" datatype="xsd:string">intentions</data>
        <data hidden="hidden" property="spkc:hashable" datatype="xsd:boolean">false</data>
        {% for i in intentions %}
          <data hidden="hidden" property="spkc:value" datatype="xsd:string">{{i}}</data>
        {% empty %}
          <data hidden="hidden" rel="spkc:value" resource="rdf:nil"></data>
        {% endfor %}
      </data>
    </data>
    {% if uc.description %}
      <div class="w3-white w3-center">
        {{uc.description|linebreaks}}
      </div>
    {% endif %}
    {% if request.token_expires %}
    <div>
      {% include 'spider_base/partials/token_lifetime.html' with rtime=request.token_expires %}
    </div>
    {% endif %}
  </div>
  {% list_parameters "search" as cur_search %}
  {% if request.is_owner and not cur_search %}
    <div class="w3-padding" style="margin-bottom:30px">
      <details {% if object_list|length < 2 %}open="open"{% endif %}>
        <summary class="w3-button w3-hover-dark-grey w3-black">
          <i class="fas fa-plus" style="margin-right:10px" aria-hidden="true"></i>
          {% trans 'Add new content' %}
          <i class="fas fa-caret-down" style="margin-left:5px" aria-hidden="true"></i>
        </summary>
        <div class="w3-white w3-border">
          {% include "spider_base/partials/content_variants_box.html" %}
        </div>
      </details>
    </div>
  {% endif %}

  {% if active_features.exists %}
  <div class="w3-padding">
    <div class="w3-white w3-padding">
      <h4>{% trans 'Active Component Features' %}:</h4>
      <div>
        {% for f in active_features %}
          <span class="" style="display:inline-block;white-space:nowrap;">{{f}}{% if not forloop.last %}, {% endif %}</span>
        {% endfor %}
      </div>
    </div>
  </div>
  {% endif %}
  <div class="w3-margin">
    <table class="w3-table w3-bordered" rel="spkc:contents">
      <thead>
      <tbody>
      {% for content in object_list %}
        <tr class="w3-light-grey" resource="{% url 'spider_base:ucontent-access' token=content.token access='view' %}" typeof="spkc:Content">
          <td class="" style="min-height:48px;display:inline-block;word-break: break-all;" rel="spkc:properties">
            <span>{{ content.name }}<span class="w3-small" style="margin-left: 5px">({{ content.ctype }})</span></span>
            <data hidden="hidden" typeof="spkc:Property">
              <data hidden="hidden" property="spkc:name" datatype="xsd:string">info</data>
              <data hidden="hidden" property="spkc:value" datatype="xsd:string">{{content.info}}</data>
            </data>
            <data hidden="hidden" typeof="spkc:Property">
              <data hidden="hidden" property="spkc:name" datatype="xsd:string">id</data>
              <data hidden="hidden" property="spkc:value" datatype="xsd:integer">{{content.id}}</data>
            </data>
            <data hidden="hidden" typeof="spkc:Property">
              <data hidden="hidden" property="spkc:name" datatype="xsd:string">name</data>
              <data hidden="hidden" property="spkc:value" datatype="xsd:string">{{content.name|escape}}</data>
            </data>
            <data hidden="hidden" typeof="spkc:Property">
              <data hidden="hidden" property="spkc:name" datatype="xsd:string">description</data>
              <data hidden="hidden" property="spkc:value" datatype="xsd:string">{{content.description|escape}}</data>
            </data>
          </td>
          <td>
            {% if uc.public or request.is_special_user %}
              {% blocktrans trimmed with time=content.modified|timesince %}
              Modified: {{time}} ago
              {% endblocktrans %}
            {% endif %}
          </td>
          <td style="display:inline-block">
            <data hidden="hidden" property="spkc:type" datatype="xsd:string">Content</data>
            <div class="w3-bar w3-round-large w3-tiny w3-blue">
              <a style="{% if request.is_special_user  %}width:34%{% else %}width:100%{% endif %}" class="w3-hover-black w3-button w3-bar-item w3-tooltip w3-mobile" href="{% url 'spider_base:ucontent-access' token=content.token access='view' %}?{{spider_GET.urlencode}}">
                <div class="spkc-entity-button"><i class="fas fa-eye" alt="{% trans 'View' %}" aria-label="{% trans 'View' %}"></i></div>
                <div aria-hidden="true" class="w3-text w3-black spkc-entity-button-text"><div class="w3-animate-opacity">{% trans "View" %}</div></div>
              </a>
              {% if request.is_special_user  %}
              <a style="width:33%" rel="nofollow" class="w3-hover-black w3-button w3-bar-item w3-tooltip w3-mobile" href="{% url 'spider_base:ucontent-access' token=content.token access='update' %}?{{spider_GET.urlencode}}" property="spkc:action:update">
                <div class="spkc-entity-button"><i class="fas fa-edit" alt="{% trans 'Edit' %}" aria-label="{% trans 'Edit' %}"></i></div>
                <div aria-hidden="true" class="w3-text w3-black spkc-entity-button-text"><div class="w3-animate-opacity">{% trans "Edit" %}</div></div>
              </a>
              <a style="width:33%" rel="nofollow" class="w3-hover-black w3-button w3-bar-item w3-tooltip w3-mobile" href="{% url 'spider_base:ucontent-delete' token=content.token %}" property="spkc:action:delete">
                <div class="spkc-entity-button"><i class="fas fa-trash" alt="{% trans 'Delete' %}" aria-label="{% trans 'Delete' %}"></i></div>
                <div aria-hidden="true" class="w3-text w3-black spkc-entity-button-text"><div class="w3-animate-opacity">{% trans "Del" %}</div></div>
              </a>
              {% endif %}
            </div>
          </td>
        </tr>
        <tr><td colspan="3" style="padding:0">
          <div class="w3-white w3-padding w3-border-bottom" style="{% if not forloop.last %}margin-bottom:20px{% endif %}">
            {% with content.localized_description as description %}
              {% if not description|is_not_or_space %}
                {{description|escape|linebreaksbr}}
              {% else %}
                <span class="w3-text-gray">{% trans 'No description' %}</span>
              {% endif %}
            {% endwith %}
          </div>
        </td></tr>
      {% empty %}
        <tr class="w3-light-grey"><td colspan="3">{% trans 'No User Content available.' %}</td></tr>
      {% endfor %}
      </tbody>
    </table>
  </div>
  <div class="page-manipulation w3-padding" style="margin-top:40px">
    {% list_parameters "search" as cur_search %}
    {% if request.is_special_user and has_unlisted and "_unlisted" not in cur_search %}
      {% blocktrans trimmed %}
        This Component contains unlisted content, use "_unlisted" in search to see and edit them
      {% endblocktrans %}
    {% endif %}
    {% include 'spider_base/partials/list_footer.html' %}
  </div>
</div>
{% endblock %}

{% block outercontent %}
{% if request.is_owner %}
{% url 'spider_base:ucontent-export' token=uc.token as exportlink %}
{% with exportlink=exportlink|add:"?"|add:spider_GET.urlencode %}
{% include "spider_base/partials/modalpresenter.html" %}
{% endwith %}
{% else %}
{% include "spider_base/partials/modalpresenter.html" %}
{% endif %}
{% endblock %}
