{% set title = post.post_title %}
{% set content = post.post_content %}
{% set date = fn.get_the_date('d M') %}

{% set tax = fn.get_post_taxonomies(post) %}
{% set terms = fn.get_the_terms(post.ID, tax[0]) %}

{% set linkPage = fn.get_permalink() %}

{% set post_day = post.start_date | date('d') %}
{% set post_month = post.start_date | date('M') %}

{% set thumb = fn.get_post_thumbnail_id(post.ID) %}

{% set street = post.street_number ? post.street_number : '' %}
{% set zip = street and post.zip ? ", " ~ post.zip ~ " " : post.zip %}
{% set city = street and not zip and post.city ? ", " ~ post.city : post.city %}
{% set country = street or zip or post.city ? " - " ~ post.country : '' %}
{% set address = street ~ zip ~ city ~ country %}
{# og #}
{% set og_title = title %}
{% set og_desc = post.post_excerpt %}
{% set og_thumb = fn.get_the_post_thumbnail_url(post.ID, 'thumbnail') %}
{% set og_url = fn.get_the_permalink(post.ID) %}
{% if not og_desc %}{% set og_desc = post.post_excerpt
    ? post.post_excerpt
    : post.post_content | slice(0, 180) %}
{% endif %}


{% extends 'm_layout/base.twig' %}

{% block main %}

<article class="article {% if related %}article--hasRelated{% endif %} article-event" m-pack="single">
  <div class="grid--lg">
    <section class="article__header">
      {% if date or title %}
        {% if date %}
          <time class="article__date" datetime="{{post.start_date|date('Y-m-d')}}"><span class="day">{{ post_day }}</span>{{ post_month }}</time>
        {% endif %}
        {% if title %}
          <h1 class="h2">{{title}}</h1>
        {% endif %}
      {% endif %}
      <div class="article__bundle">
        <div class="article__bundle-info">
          {% if address %}
            <address>{{address}}</address>
          {% endif %}
          <strong>
            {% if terms %}
                {% if address %}<span class="separate">|</span>{% endif %}
                {% for term in terms %}
                  <a href="{{fn.get_term_link(term.term_id) }}">{{term.name}}</a>{% if loop.index < terms|length %}, {% endif %}
                {% endfor %}
            {% endif %}
          </strong>

        </div>

        {% include 'm_pages/components/sharing.twig' with {url: linkPage} only %}

      </div>

    </section>
    {% if thumb %}
      <section class="article__hero">
        {% include 'm_components/widgets/picture.twig' with {image: thumb, title: title} only %}
      </section>
    {% endif %}

    {% if content %}
      <section class="article__content m_content ">
        {{ fn.apply_filters('the_content', content)|raw }}
      </section>
    {% endif %}

    <section class="article__share">
      <h3 class="h4">Share</h3>
      {% include 'm_pages/components/sharing.twig' with {url: linkPage} only %}
    </section>
  </div>


</article>

{% if related %}
  <aside class="m_panel article-related">
    <div class="grid--lg">
      <div class="m_headline">
        <h2 class="m_headline__title">{{post.post_type}} linked with the same category</h2>
      </div>
      <div class="grid">
        {% for item in related %}

          {% set related_title = item.post_title %}

          {% set related_content = item.post_excerpt
            ? item.post_excerpt
            : fn.wp_trim_words(item.post_content, 18, '...') %}

          {% set image = fn.get_post_thumbnail_id(item.ID) %}

          <a href="{{fn.get_the_permalink(item.ID)}}" class="m_panel__block">
            <div class="m_panel__image">
              {% include 'm_components/widgets/picture.twig' with {image: image, title: title} only %}
              <time class="m_panel__date"><span class="day"> {{ item.start_date|date('d') }}</span>{{ item.start_date|date('M') }}</time>
            </div>
            <div class="m_panel__content">
              <h2 class="h4">{{ item.post_title }}</h2>
              {% if related_content %}
                <p>{{related_content|striptags}}</p>
              {% endif %}
              <span class="btn__arrow btn__arrow--right">Read more</span>
            </div>
          </a>

        {% endfor %}
      </div>
    </div>

  </aside>
{% endif %}

{% endblock %}
