{% include_template "_books" %}
{%- assign post = model.posts | first -%}
<div class="content">
  <article class="item">
    <h1 class="item-heading">{{ post.title }}</h1>
    {%- if logged_on %}<p class="item-meta"><a href="{{ post | edit_post_link }}">Edit Post</a></p>{% endif %}
    {% assign media = post.metadata | value: "episode_media_file" %}
    {%- unless media == "-- episode_media_file not found --" %}
      <aside class="podcast">
        <p class="text-center"><strong>Listen While<br>You Read</strong></p>
        <audio controls onplaying="awftw.countPlay('{{ media }}')">
          <source src="https://files.bitbadger.solutions/devotions/{{ media }}">
        </audio>
        <p class="text-center">
          <a class="dl" href="https://pdcst.click/c/awftw/files.bitbadger.solutions/devotions/{{ media }}" download>
            <i class="fa fa-download" title="Download Audio"></i>
          </a>
        </p>
      </aside>
    {%- endunless %}
    {{ post.text }}
  </article>
  <nav aria-label="pagination">
    <div class="nav-previous">
      {% if model.newer_link %}
        <span class="post-nav">Previous Post</span><br>
        <a class="post-nav-title" href="{{ model.newer_link.value | relative_link }}">{{ model.newer_name.value }}</a>
      {% endif %}
    </div>
    <div class="nav-next">
      {% if model.older_link %}
        <span class="post-nav">Next Post</span> <br>
        <a class="post-nav-title" href="{{ model.older_link.value | relative_link }}">{{ model.older_name.value }}</a>
      {% endif %}
    </div>
  </nav>
</div>
<div class="sidebar post-sidebar">
  <div class="item">
    <h4 class="item-heading">Date</h4>
    <div class="date-posted">
      <i class="fa fa-calendar" title="Date" aria-hidden="true"></i>
      {{ post.published_on | date: "dddd, MMMM d, yyyy" }}
    </div>
  </div>
  {%- assign has_ot = false -%}
  {%- for ot_id in ot_books -%}
    {%- if post.category_ids contains ot_id %}{% assign has_ot = true %}{% endif -%}
  {%- endfor -%}
  {%- assign has_nt = false -%}
  {%- for nt_id in nt_books -%}
    {%- if post.category_ids contains nt_id %}{% assign has_nt = true %}{% endif -%}
  {%- endfor -%}
  {%- if has_ot or has_nt %}
    <div class="item">
      <h4 class="item-heading">Scripture</h4>
      {%- if has_ot %}
        <ul>
          <li>
            {%- assign cat_id = ot_books | first -%}
            {%- assign cat = categories | where: "id", cat_id | first -%}
            <i class="fa fa-book" title="Book" aria-hidden="true"></i>
            <a href="{{ cat | category_link }}"
               {%- if cat.description %} title="{{ cat.description.value | escape_once }}"{% endif %}>
              {{ cat.name }}
            </a>
            <ul>
              {%- assign first_time = true -%}
              {%- for cat_id in ot_books %}
                {%- if first_time %}
                  {%- assign first_time = false -%}
                {%- elsif post.category_ids contains cat_id %}
                  {% assign cat = categories | where: "id", cat_id | first %}
                  <li>
                    <i class="fa fa-book" title="Book" aria-hidden="true"></i>
                    <a href="{{ cat | category_link }}"
                       {%- if cat.description %} title="{{ cat.description.value | escape_once }}"{% endif %}>
                      {{ cat.name }}
                    </a>
                  </li>
                {%- endif %}
              {%- endfor %}
            </ul>
          </li>
        </ul>
      {%- endif %}
      {%- if has_nt %}
        <ul>
          <li>
            {%- assign cat_id = nt_books | first -%}
            {%- assign cat = categories | where: "id", cat_id | first -%}
            <i class="fa fa-book" title="Book" aria-hidden="true"></i>
            <a href="{{ cat | category_link }}"
               {%- if cat.description %} title="{{ cat.description.value | escape_once }}"{% endif %}>
              {{ cat.name }}
            </a>
            <ul>
              {%- assign first_time = true -%}
              {%- for cat_id in nt_books %}
                {%- if first_time %}
                  {%- assign first_time = false -%}
                {%- elsif post.category_ids contains cat_id %}
                  {% assign cat = categories | where: "id", cat_id | first %}
                  <li>
                    <i class="fa fa-book" title="Book" aria-hidden="true"></i>
                    <a href="{{ cat | category_link }}"
                       {%- if cat.description %} title="{{ cat.description.value | escape_once }}"{% endif %}>
                      {{ cat.name }}
                    </a>
                  </li>
                {%- endif %}
              {%- endfor %}
            </ul>
          </li>
        </ul>
      {%- endif %}
    </div>
  {%- endif %}
  {%- assign in_series = false -%}
  {%- for series_id in series_ids %}
    {%- if post.category_ids contains series_id -%}
      {%- assign in_series = true -%}
      {%- assign series_cat = categories | where: "id", series_id | first -%}
    {%- endif -%}
  {%- endfor -%}
  {%- if in_series %}
    <div class="item text-center">
      <h4 class="item-heading">Series</h4>
      <a href="{{ series_cat | category_link }}"
         {% if series_cat.description %} title="{{ series_cat.description.value | escape_once }}"{% endif %}>
        {{ series_cat.name }}
      </a>
    </div>
  {%- endif %}
  {%- assign has_topics = false -%}
  {% for cat_id in post.category_ids -%}
    {%- unless ot_books contains cat_id or nt_books contains cat_id or series_ids contains cat_id -%}
      {% assign has_topics = true -%}
    {%- endunless -%}
  {% endfor %}
  {%- if has_topics %}
    <div class="item">
      <h4 class="item-heading">Topics</h4>
      <ul>
        {%- for cat_id in post.category_ids %}
          {% unless ot_books contains cat_id or nt_books contains cat_id or series_ids contains cat_id %}
            {%- assign cat = categories | where: "id", cat_id | first -%}
            <li>
              <i class="fa fa-folder-open-o" title="Category" aria-hidden="true"></i>
              <a href="{{ cat | category_link }}" rel="tag" title="Categorized under {{ cat.name | escape }}">
                {{ cat.name }}
              </a>
            </li>
          {% endunless %}
        {%- endfor %}
      </ul>
    </div>
  {%- endif %}
  {%- assign tag_count = post.tags | size -%}
  {%- if tag_count > 0 %}
    <div class="item">
      <h4 class="item-heading">Tags</h4>
      <ul>
        {%- for tag in post.tags %}
          <li>
            <a href="{{ tag | tag_link }}" title="Tagged &ldquo;{{ tag }}&rdquo;">
              <i class="fa fa-tag" aria-hidden="true"></i> {{ tag }}
            </a>
        {%- endfor %}
      </ul>
    </div>
  {%- endif %}
</div>
