{% extends "package/base.html" %}

{% block subtitle %}{{ pkg.title or pkg.name }}{% endblock %}

{% block links -%}
    {{ super() }}
    <link rel="alternate" type="application/rdf+xml" href="{{ h.url_for(controller='package', action='read', id=pkg.id, format='rdf', qualified=True) }}"/>
{% endblock -%}

{% block head_extras -%}
  {{ super() }}
  {% set description = h.markdown_extract(pkg.notes, extract_length=200)|forceescape %}
  <meta property="og:title" content="{{ h.dataset_display_name(pkg) }} - {{ g.site_title }}">
  <meta property="og:description" content="{{ description|forceescape }}">
{% endblock -%}

{% block content_action %}
  {% if h.check_access('package_update', {'id':pkg.id }) %}
    {% link_for _('Edit'), controller='package', action='edit', id=pkg.name, class_='btn', icon='wrench' %}
  {% endif %}
{% endblock %}

{% block content_primary_nav %}
  {{ h.build_nav_icon('dataset_read', _('Dataset'), id=pkg.name) }}
  {{ h.build_nav_icon('dataset_activity', _('Activity Stream'), id=pkg.name) }}
  {{ h.build_nav_icon('related_list', _('Related'), id=pkg.name) }}
{% endblock %}

{% block primary_content_inner %}
    {% block package_revision_info %}
      {% if c.pkg_revision_id %}
        <div class="module info alert alert-info">
          <p class="module-content">
            {% set timestamp = h.render_datetime(c.pkg_revision_timestamp, with_hours=True) %}
            {% set url = h.url(controller='package', action='read', id=pkg.name) %}

            {% if c.pkg_revision_not_latest %}
              {% trans timestamp=timestamp, url=url %}This is an old revision of this dataset, as edited at {{ timestamp }}. It may differ significantly from the <a href="{{ url }}">current revision</a>.{% endtrans %}
            {% else %}
              {% trans timestamp=timestamp %}This is the current revision of this dataset, as edited at {{ timestamp }}.{% endtrans %}
            {% endif %}
          </p>
        </div>
      {% endif %}
    {% endblock %}
{% endblock %}

{% block secondary_content %}

  {% block secondary_help_content %}{% endblock %}

  {% block package_info %}
    <div class="module context-info">
      <div class="module-content">
        <h1 class="heading">{{ pkg.title or pkg.name }}</h1>
        <div class="nums">
          <dl>
            <dt>{{ _('Followers') }}</dt>
            <dd>{{ h.SI_number_span(h.get_action('dataset_follower_count', {'id': pkg.id})) }}</dd>
          </dl>
        </div>
        <div class="follow_button">
          {{ h.follow_button('dataset', pkg.name) }}
        </div>
      </div>
    </div>
  {% endblock %}

  {% block package_organization %}
    {% if pkg.organization %}
      {% snippet "snippets/organization.html", organization=pkg.organization, has_context_title=true %}
    {% endif %}
  {% endblock %}

  {% block package_groups %}
    {% if pkg.groups %}
      <div class="module module-narrow">
        <h2 class="module-heading"><i class="icon-folder-open"></i> {{ _('Groups') }}</h2>
        <ul class="nav nav-simple">
          {% for group in pkg.groups %}
            <li class="nav-item">
              <a href="{{ h.url_for(controller='group', action='read', id=group.name) }}">
                {{ group.title or group.name }}
              </a>
            </li>
          {% endfor %}
        </ul>
      </div>
    {% endif %}
  {% endblock %}

  {% block package_social %}
    {% snippet "snippets/social.html" %}
  {% endblock %}

  {% block package_license %}
    {% snippet "snippets/license.html", pkg_dict=pkg %}
  {% endblock %}

{% endblock %}
