{# -*- coding: utf-8 -*-

  This file is part of Invenio.
  Copyright (C) 2016-2020 CERN.

  Invenio is free software; you can redistribute it and/or modify it
  under the terms of the MIT License; see LICENSE file for more details.
#}

{# TODO: Use url_for instead #}

{%- from "invenio_theme/macros/truncate.html" import truncate_text %}

<div class="ui container fluid page-subheader-outer with-submenu rel-pt-2">
  <div class="ui container relaxed grid page-subheader">
    <div class="row">
      <div class="two wide column">
        {% if logo %}
        <div class="ui rounded image medium community-image">
          <img src="{{logo.links.self}}" alt="No image found"/>
        </div>
        {% else %}
        <div class="ui rounded image">
          <img src="/static/images/square-placeholder.png" alt="No image found"/>
        </div>
        {% endif %}
      </div>
      <div class="ten wide column">
          <h2 class="ui header">{{ community.metadata.title }}</h2>
          {{ truncate_text(community.metadata.description) }}
          {% if community.metadata.website %}
            <a href="{{community.metadata.website}}"> <i class="linkify icon"></i>
              {{community.metadata.website}}
            </a>
          {% endif %}
          {% if community.metadata.type is defined %}
            <i class="tag icon community-tags"></i>
            <div class="ui label small grey type-label">
              {{ community.metadata.type.title.en }}
            </div>
          {% endif %}
          {% if community.metadata.organizations %}
            <i class="building outline icon community-tags"></i>
            <span class="label label-keyword">{{ community.metadata.organizations| map(attribute='name') | join(', ') }}</span>
          {% endif %}
      </div>

      <div id="community-upload-button"
           class="four wide right aligned column">
        <a href="/uploads/new?community={{ community.id }}"
           class="ui positive button labeled icon">
          <i class="plus icon"></i>

          {{ _("New upload") }}
        </a>
      </div>
      {# TODO: Add proper statistics #}
      <!-- <div class="two wide floated right column">
        <div class="ui mini statistic">
          <div class="value">
            5,550
          </div>
          <div class="label">
            Views
          </div>
        </div>
      </div>
      <div class="two wide floated right column">
        <div class="ui mini statistic">
          <div class=" value">
            4,200
          </div>
          <div class="label">
            Downloads
          </div>
        </div>
      </div> -->
    </div>
    <!--TODO: Delete this menu to avoid using invenio_app_rdm-->
    <div class="ui container secondary pointing menu page-subheader pl-0">
      {% for item in current_menu.submenu('communities').children if item.permissions == True or permissions[item.permissions]  %}
        <a class="item {{ 'active' if active_header_menu_item == item.name }} {{ 'disabled' if not item.url }}" href="{{ item.url }}"><i aria-hidden="true" class="{{item.icon}} icon"></i>{{ item.text }}</a>
      {% endfor %}
    </div>
  </div>
</div>
