{% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link, link_news_logo %}
{% from "com/macros.jinja" import news_moderation_alert %}

{% block title %}
  {% trans %}News{% endtrans %} - {{ object.title }}
{% endblock %}

{% block description %}{{ news.summary }}{% endblock %}

{% block metatags %}
  <meta property="og:url" content="{{ news.get_full_url() }}" />
  <meta property="og:type" content="article" />
  <meta property="article:section" content="{% trans %}News{% endtrans %}" />
  <meta property="og:title" content="{{ news.title }}" />
  <meta property="og:description" content="{{ news.summary }}" />
  <meta property="og:image" content="{{ request.build_absolute_uri(link_news_logo(news)) }}" />
{% endblock %}


{% block additional_css %}
  <link rel="stylesheet" href="{{ static('com/css/news-detail.scss') }}">
{% endblock %}

{% block additional_js %}
  <script type="module" src={{ static("bundled/com/moderation-alert-index.ts") }}></script>
{% endblock %}

{% block content %}
  <p><a href="{{ url('com:news_list') }}">{% trans %}Back to news{% endtrans %}</a></p>
  <div x-data="{newsState: AlertState.PENDING}">

    {% if not news.is_published %}
      {{ news_moderation_alert(news, user, "newsState") }}
    {% endif %}
    <article id="news_details" x-show="newsState !== AlertState.DELETED">
      <div class="club_logo">
        <img src="{{ link_news_logo(news)}}" alt="{{ news.club }}" />
        <a href="{{ news.club.get_absolute_url() }}">{{ news.club }}</a>
      </div>
      <h4>{{ news.title }}</h4>
      <p class="date">
        <time datetime="{{ date.start_date.isoformat(timespec="seconds") }}">{{ date.start_date|localtime|date(DATETIME_FORMAT) }}
          {{ date.start_date|localtime|time(DATETIME_FORMAT) }}</time> -
        <time datetime="{{ date.end_date.isoformat(timespec="seconds") }}">{{ date.end_date|localtime|date(DATETIME_FORMAT) }}
          {{ date.end_date|localtime|time(DATETIME_FORMAT) }}</time>
      </p>
      <div class="news_content">
        <div><em>{{ news.summary|markdown }}</em></div>
        <br/>
        <div>{{ news.content|markdown }}</div>
        <a
          rel="nofollow"
          target="#"
          class="share_button facebook"
          href="https://www.facebook.com/sharer/sharer.php?u={{ news.get_full_url() }}"
        >
          {% trans %}Share on Facebook{% endtrans %}
        </a>
        <div class="news_meta">
          <p>{% trans %}Author: {% endtrans %}{{ user_profile_link(news.author) }}</p>
          {% if news.moderator %}
            <p>{% trans %}Moderator: {% endtrans %}{{ user_profile_link(news.moderator) }}</p>
          {% elif user.is_com_admin %}
            <p> <a href="{{ url('com:news_moderate', news_id=news.id) }}">{% trans %}Publish{% endtrans %}</a></p>
          {% endif %}
          {% if user.can_edit(news) %}
            <p> <a href="{{ url('com:news_edit', news_id=news.id) }}">{% trans %}Edit (will be moderated again){% endtrans %}</a></p>
          {% endif %}
        </div>
      </div>
    </article>
  </div>
{% endblock %}



