{% extends "layout.html" %}

{% block head %}
  <script type="text/javascript" src="/static/js/toggle.js"></script>
{% endblock %}

{% macro citationsMacro(citations) %}
  {% if citations | length == 0 %}
    <p>This item is never cited.
    <style type="text/css">span.toggle { display: none; }</style>
  {% elif citations | length == 1 %}
    <p>This item is referenced in 1 tag:
  {% elif citations | length > 1 %}
    <p>This item is referenced in {{ citations | length }} tags:
  {% endif %}

  {% if citations | length >= 1 %}
    <ul>
      {% for citation in citations %}
        <li>in {{ citation.tag.type | capitalize }} <a href="/tag/{{ citation.tag.tag }}" data-tag="{{ citation.tag.tag }}">{{ citation.tag.ref }}</a>{% if citation.tag.name %}: {{ citation.tag.name | safe }}{% endif %}{% if citation.note %}, which cites {{ citation.note }} of <span class="tag">{{ entry.key }}</span>{% endif %}
      {% endfor %}
    </ul>
  {% endif %}
{% endmacro %}

{% block title %}Bibliography entry{% endblock %}

{% block breadcrumb %}
  <li><a href="/bibliography">Bibliography</a>
  <li>{{ entry.fields["title"] | safe }}
{% endblock %}

{% block hamburger %}
  <div class="interaction">
    {{ neighboursMacro(neighbours) }}
  </div>
{% endblock %}

{% block sidebar %}
  <div class="interaction">
    {{ neighboursMacro(neighbours) }}
  </div>
{% endblock %}

{% macro neighboursMacro(neighbours) %}

<ul class="neighbours">
{% if neighbours[0] %}
  <li class="left"><a href="/bibliography/{{ neighbours[0].key }}">previous entry</a>
{% endif %}
{% if neighbours[1] %}
  <li class="right"><a href="/bibliography/{{ neighbours[1].key }}">next entry</a>
{% endif %}
</ul>
{% if neighbours[0] or neighbours[1] %}<br style="clear:both">{% endif %}

{% endmacro %}

{% block body %}
  <h2>Bibliography entry <span class="tag">{{ entry.key }}</span></h2>

  <nav class="nav nav-tabs nav-fill" role="tablist">
    <a class="nav-item nav-link active" data-toggle="tab" href="#entry-table" role="tab">entry</a>
    <a class="nav-item nav-link" data-toggle="tab" href="#entry-code" role="tab">code</a>
  </nav>

  <div class="tab-content" id="entry-content">
    <div class="tab-pane show active " id="entry-table" role="tabpanel">
      <dl class="entry">
        {% if "author" in entry.fields %}
          <dt>author</dt>
          <dd>{{ entry.fields["author"] | safe }}</dd>
        {% endif %}

        {% if "title" in entry.fields %}
          <dt>title</dt>
          <dd>{{ entry.fields["title"] | safe }}</dd>
        {% endif %}

        {% if "year" in entry.fields %}
          <dt>year</dt>
          <dd>{{ entry.fields["year"] }}</dd>
        {% endif %}

        {% if "journal" in entry.fields and not "fjournal" in entry.fields %}
          <dt>journal</dt>
          <dd>{{ entry.fields["journal"] | safe }}</dd>
        {% endif %}

        {% if "fjournal" in entry.fields %}
          <dt>journal</dt>
          <dd>{{ entry.fields["fjournal"] | safe }}</dd>
        {% endif %}

        {% if "publisher" in entry.fields %}
          <dt>publisher</dt>
          <dd>{{ entry.fields["publisher"] | safe }}</dd>
        {% endif %}

        {% if "series" in entry.fields %}
          <dt>series</dt>
          <dd>{{ entry.fields["series"] | safe }}</dd>
        {% endif %}

        {% if "volume" in entry.fields %}
          <dt>volume</dt>
          <dd>{{ entry.fields["volume"] }}</dd>
        {% endif %}

        {% if "number" in entry.fields %}
          <dt>number</dt>
          <dd>{{ entry.fields["number"] }}</dd>
        {% endif %}

        {% if "pages" in entry.fields %}
          <dt>pages</dt>
          <dd>{{ entry.fields["pages"] | replace("--", "&ndash;") | safe }}</dd>
        {% endif %}

        {% if "eprint" in entry.fields %}{# assume it's arXiv #}
          <dt>arXiv</dt>
          <dd><a href="https://arxiv.org/abs/{{ entry.fields["eprint"] }}">{{ entry.fields["eprint"] }}</a></dd>
        {% endif %}

        {% if "url" in entry.fields %}
          <dt>url</dt>
          <dd><a href="{{ entry.fields["url"] }}">{{ entry.fields["url"] }}</a></dd>
        {% endif %}

        {% if "mrnumber" in entry.fields %}
          <dt>MathSciNet
          <dd><a href="https://mathscinet.ams.org/mathscinet-getitem?mr={{ entry.fields["mrnumber"] }}">MR{{ entry.fields["mrnumber"] }}</a>
        {% endif %}

        {% if "doi" in entry.fields %}
          <dt><abbr title="Document Object Identifier">DOI</abbr>
          <dd><a href="https://doi.org/{{ entry.fields["doi"] }}"><code>doi:{{ entry.fields["mrnumber"] }}</code></a>
        {% endif %}
      </dl>
    </div>

    <div class="tab-pane" id="entry-code" role="tabpanel">
      <pre><code>
{{ entry.code }}
      </code></pre>
    </div>
  </div>

  <div id="citations-main">
    {{ citationsMacro(citations) }}
  </div>
{% endblock %}
