{% 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 'admin/css/vendor/select2/select2.css' %}">
{% if DEBUG %}
  <script src="{% static 'admin/js/vendor/jquery/jquery.js' %}"></script>
  <script src="{% static 'admin/js/vendor/select2/select2.full.js' %}"></script>
{% else %}
  <script src="{% static 'admin/js/vendor/jquery/jquery.min.js' %}"></script>
  <script src="{% static 'admin/js/vendor/select2/select2.full.min.js' %}"></script>
{% endif %}
{% endblock %}

{% block content %}
<div>
  <div class="w3-padding">
    {% if request.user == uc.user %}
      <a class="w3-left" href="{% url 'spider_base:ucomponent-list' %}">{% trans 'Up (Owned)' %}</a>
    {% else %}
      <a class="w3-left" href="{% url 'spider_base:ucomponent-listpublic' %}">{% trans 'up (Public)' %}</a>
    {% endif %}
    <span class="w3-right">
      {% if request.user == uc.user %}
      <div style="margin-bottom:5px" class="actionbar_user">
        <a class="" href="{% url 'spider_base:ucomponent-update' name=uc.name nonce=uc.nonce %}">{% trans 'Update' %}</a>
      </div>
      {% endif %}
      <div style="margin-bottom:5px">
        <a class="" onclick="if(document.readyState === 'complete'){open_qrmodal();}; return false;" href="#">{% trans 'Link/Export' %}</a>
      </div>
      <div>
        {% trans "Strength:" %} <data property="spkc:strength">{{uc.strength}}</data>
      </div>
    </span>
    <h1 class="w3-center">
      {% if request.is_owner or uc.public %}
        {% blocktrans trimmed %}
          Content of:
        {% endblocktrans %} <b>{{uc}}</b> <em>({{uc.user}})</em>
        <data hidden="hidden" rel="spkc:properties" typeof="spkc:Property">
          <data hidden="hidden" property="spkc:name">name</data>
          <data hidden="hidden" property="spkc:value">{{uc.name}}</data>
        </data>
        <data hidden="hidden" rel="spkc:properties" typeof="spkc:Property">
          <data hidden="hidden" property="spkc:name">user</data>
          <data hidden="hidden" property="spkc:value">{{uc.username}}</data>
        </data>
      {% else %}
        {% blocktrans trimmed %}
          Content:
        {% endblocktrans %}
      {% endif %}
    </h1>
    <data hidden="hidden" rel="spkc:properties">
      <data hidden="hidden" typeof="spkc:Property">
        <data hidden="hidden" property="spkc:name">description</data>
        <data hidden="hidden" property="spkc:value">{{uc.description}}</data>
      </data>
    </data>
    {% if uc.description %}
      <div class="w3-white w3-center">
        {{uc.description|linebreaks}}
      </div>
    {% endif %}
    {% if request.token_expires %}
    <div>
      {% include 'spider_base/token_lifetime.html' with rtime=request.token_expires %}
    </div>
    {% endif %}
  </div>
  {% list_parameters "search" as cur_search %}
  {% list_parameters "info" as cur_info %}
  {% if uc.user == request.user and not cur_search and not cur_info %}
    <details class="w3-margin" style="margin-bottom:30px" {% if object_list|length < 2 %}open="open"{% endif %}>
      <summary class="w3-button w3-hover-dark-grey w3-black">
        <i class="fa fa-plus" style="margin-right:10px" aria-hidden="true"></i>
        {% trans 'Add new content' %}
        <i class="fa fa-caret-down" style="margin-left:5px" aria-hidden="true"></i>
      </summary>
      <div class="w3-padding w3-border">
        <div class="w3-row">
          {% for variant in content_variants %}
            {% if uc.strength < variant.strength %}
            <div class="w3-padding w3-left-align w3-col s12 m4 l3 w3-red w3-tooltip">
              <b style="margin-right:5px" aria-hidden="true">X</b>{{variant}}
              <div aria-hidden="true" title="{{variant}}" class="w3-text spkc-variant-errcolor spkc-variant-text"><div class="w3-padding"><b style="margin-right:5px" aria-hidden="true">X</b><span class="w3-tiny">{% blocktrans trimmed with required_strength=variant.strength %}
                Requires Strength: {{required_strength}}
              {% endblocktrans %}</span></div></div>
            </div>
            {% else %}
            <a class="w3-button w3-left-align w3-col s12 m4 l3 w3-pale-green" href="{% url 'spider_base:ucontent-add' name=uc.name type=variant.name %}" >
              <b style="margin-right:5px" aria-hidden="true">+</b>{{variant}}
            </a>
            {% endif %}
          {% empty %}
              {% trans 'No Content Variants available.' %}
          {% endfor %}
        </div>
      </div>
    </details>
  {% endif %}
  <div class="w3-margin">
    <table class="w3-table w3-striped w3-bordered w3-hoverable w3-white" rel="spkc:contents">
      {% for content in object_list %}
        <tr resource="{% url 'spider_base:ucontent-access' id=content.id nonce=content.nonce access='view' %}" typeof="spkc:Content">
          <td class="" style="width:20%; min-height:48px" rel="spkc:properties">
            <data hidden="hidden" property="spkc:type">Content</data>
            <span>
              <span>{{ content.content|truncatechars:50 }}</span>
            </span>
            <data hidden="hidden" typeof="spkc:Property">
              <data hidden="hidden" property="spkc:name">item</data>
              <data hidden="hidden" property="spkc:value">{{ content.info}}</data>
            </data>
          </td>
          <td>
            {% if uc.public or request.user == uc.user %}
              {% blocktrans trimmed with time=content.modified|timesince %}
              Modified: {{time}} ago
              {% endblocktrans %}
            {% endif %}
          </td>
          <td class="w3-show-inline-block">
            <div class="w3-bar w3-round-large w3-tiny w3-blue">
              <a class="w3-hover-black w3-button w3-bar-item w3-tooltip w3-mobile" href="{% url 'spider_base:ucontent-access' id=content.id nonce=content.nonce access='view' %}?{{spider_GET.urlencode}}" property="spkc:action:view">
                <div class="spkc-entity-button"><i class="fa 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 uc.user == request.user  %}
              <a class="w3-hover-black w3-button w3-bar-item w3-tooltip w3-mobile" href="{% url 'spider_base:ucontent-access' id=content.id nonce=content.nonce access='update' %}" property="spkc:action:update">
                <div class="spkc-entity-button"><i class="fa 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 class="w3-hover-black w3-button w3-bar-item w3-tooltip w3-mobile" href="{% url 'spider_base:ucontent-remove' user=content.usercomponent.username name=content.usercomponent.name id=content.id  nonce=content.nonce %}" property="spkc:action:delete">
                <div class="spkc-entity-button"><i class="fa 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>
      {% empty %}
        <tr><td>{% trans 'No User Content available.' %}</td></tr>
      {% endfor %}
    </table>
  </div>
  <div class="page-manipulation w3-padding" style="margin-top:40px">
    {% include 'spider_base/list_footer.html' %}
  </div>
</div>
{% endblock %}

{% block outercontent %}
{% if request.user == uc.user %}
{% url 'spider_base:ucontent-export' id=uc.id nonce=uc.nonce as exportlink %}
{% endif %}
{% include "spider_base/modalpresenter.html" %}
{% endblock %}
