{% extends "item_base.html" %}
{% load static %}
{% load i18n %}
{% load l10n %}
{% load humanize %}
{% load mastodon %}
{% load strip_scheme %}
{% load thumb %}
{% block head %}
  {% if item.author %}
    <meta property="og:book:author"
          content="{% for author in item.author %}{{ author }}{% if not forloop.last %},{% endif %}{% endfor %}">
  {% endif %}
  {% if item.isbn %}<meta property="og:book:isbn" content="{{ item.isbn }}">{% endif %}
{% endblock %}
{% block details %}
  <div>
    {% if item.isbn %}
      {% trans 'ISBN' %}: {{ item.isbn }}
    {% endif %}
  </div>
  <div>{% include '_people.html' with people=item.author role='author' max=5 %}</div>
  <div>{% include '_people.html' with people=item.translator role='translator' max=5 %}</div>
  <div>
    <div>
      {% if item.format %}
        {% trans 'book format' %}: {{ item.get_format_display }}
      {% endif %}
    </div>
  </div>
  <div>
    {% if item.pub_house %}
      {% trans 'publishing house' %}: {{ item.pub_house }}
    {% endif %}
  </div>
  <div>
    {% if item.imprint %}
      {% trans 'imprint' %}: {{ item.imprint }}
    {% endif %}
  </div>
  <div>
    {% if item.pub_year %}
      {% trans 'publication date' %}: {{ item.pub_year }}
      {% if item.pub_month %}-{{ item.pub_month }}{% endif %}
    {% endif %}
  </div>
  <div>
    {% if item.series %}
      {% trans 'series' %}: {{ item.series }}
    {% endif %}
  </div>
  <div>{% include '_people.html' with people=item.language role='language' max=10 %}</div>
  <div>
    {% if item.binding %}
      {% trans 'binding' %}: {{ item.binding }}
    {% endif %}
  </div>
  <div>
    {% if item.price %}
      {% trans 'price' %}: {{ item.price }}
    {% endif %}
  </div>
  <div>
    {% if item.pages %}
      {% trans 'number of pages' %}: {{ item.pages }}
    {% endif %}
  </div>
  {% if item.other_info %}
    {% for k, v in item.other_info.items %}<div>{{ k }}: {{ v|urlizetrunc:24 }}</div>{% endfor %}
  {% endif %}
{% endblock %}
{% block content %}
  {% if item.contents %}
    <h5>contents</h5>
    <p class="tldr" _="on click toggle .tldr on me">{{ item.contents | linebreaksbr }}</p>
  {% endif %}
{% endblock %}
{% block left_sidebar %}
  <script>
  $(function () {
    function _sidebar_auto_collapse(mm){
      if (mm.matches) {
        $('.auto-collapse').removeAttr('open')
      } else {
        $('.auto-collapse').attr('open', '')
      }
    }
    var mm = window.matchMedia("(max-width: 768px)")
    mm.addListener(_sidebar_auto_collapse);
    _sidebar_auto_collapse(mm);
  });
  </script>
  {% with related_books=item.sibling_items %}
    {% if related_books.count > 0 %}
      <section>
        <details class="auto-collapse" open>
          <summary>{% trans 'other editions' %}</summary>
          {% for b in related_books %}
            <div>
              <a href="{{ b.url }}">{{ b.display_title }}</a>
              <small class="title_deco">{{ b.title_deco }}</small>
              {% comment %} {% for res in b.external_resources.all %}
              <a href="{{ res.url }}">
                <span class="source-label source-label__{{ res.site_name }}">{{ res.site_name.label }}</span>
              </a>
              {% endfor %} {% endcomment %}
            </div>
          {% endfor %}
        </details>
      </section>
    {% endif %}
  {% endwith %}
  {% if item.isbn %}
    <section>
      <details class="auto-collapse" open>
        <summary>{% trans 'Borrow or Buy' %}</summary>
        <div>
          <div>
            <a target="_blank"
               rel="noopener"
               href="https://www.worldcat.org/isbn/{{ item.isbn }}">WorldCat</a>
          </div>
          <div>
            <a target="_blank"
               rel="noopener"
               href="https://openlibrary.org/search?isbn={{ item.isbn }}">Open Library</a>
          </div>
          <div>
            <a target="_blank"
               rel="noopener"
               href="https://library.oapen.org/discover?filtertype_1=isbn&amp;filter_relational_operator_1=equals&amp;filter_1={{ item.isbn }}">
            OAPEN</a>
          </div>
          <div>
            <a target="_blank"
               rel="noopener"
               href="https://bookshop.org/search?keywords={{ item.isbn }}">Bookshop.org</a>
          </div>
          <div>
            <a target="_blank"
               rel="noopener"
               href="https://www.amazon.com/s?k={{ item.isbn }}">Amazon</a>
            <a target="_blank"
               rel="noopener"
               href="https://www.amazon.de/s?k={{ item.isbn }}">DE</a>
            <a target="_blank"
               rel="noopener"
               href="https://www.amazon.co.jp/s?k={{ item.isbn }}">JP</a>
            <a target="_blank"
               rel="noopener"
               href="https://www.amazon.co.uk/s?k={{ item.isbn }}">UK</a>
          </div>
          <div>
            <a target="_blank"
               rel="noopener"
               href="https://www.kobo.com/search?query={{ item.isbn }}">Kobo</a>
            <a target="_blank"
               rel="noopener"
               href="https://www.kobo.com/jp/en/search?query={{ item.isbn }}">JP</a>
            <a target="_blank"
               rel="noopener"
               href="https://www.kobo.com/tw/zh/search?query={{ item.isbn }}">TW</a>
            <a target="_blank"
               rel="noopener"
               href="https://www.kobo.com/us/en/search?query={{ item.isbn }}">US</a>
          </div>
          <div>
            <a target="_blank"
               rel="noopener"
               href="https://www.duozhuayu.com/search/book/{{ item.isbn }}">多抓鱼</a>
            <a target="_blank"
               rel="noopener"
               href="https://search.kongfz.com/product_result/?key={{ item.isbn }}">孔夫子旧书</a>
          </div>
          <div>
            <a target="_blank"
               rel="noopener"
               href="https://search.books.com.tw/search/query/key/{{ item.isbn }}/cat/all">博客来</a>
            <a target="_blank"
               rel="noopener"
               href="https://readmoo.com/search/keyword?q={{ item.isbn }}">Readmoo 讀墨</a>
          </div>
        </div>
      </details>
    </section>
  {% endif %}
{% endblock %}
