{# LIBRARIES #}
{% extends "@molecules/tm-bs/card/card.twig" %}

{# VARIABLES #}
{% set alt = title ~ ' ' ~ body|striptags %}
{% set card_class = card_class|default("modern-card cbelianr") %}
{% set link_scope = link_scope|default('card') %}
{% set video_ratio = video_ratio|default('n') %}
{% set show_footer = show_footer|default(false) %}{# News overrides this #}
{% set show_header = show_header|default(true) %}{# News overrides this #}
{% if video_embed or video_src %}
  {% set card_class = 'modern-card video-card cbelianr' %}
  {% set link_scope = 'bottom' %}
{% endif %}
{% set card_class = card_class ~ ' vid-' ~ video_ratio %}

{# Add a state class when header has no content (no image/video/tag/etc.) #}
{% set _header_has_content =
  (video_embed or video_src or header_content or image or (img_alt and img_url) or header_tag_text)
%}
{% if (not show_header) or (not _header_has_content) %}
  {% set card_class = card_class ~ ' header-empty' %}
{% endif %}

{# BLOCK HEADER #}
{% block card_header %}

  {{ attach_library('ui_patterns/modern_card.modern_card_lib') }}

  {# Video embed code. This is usually an iFrame from JWPlayer #}
  {% if video_embed %}
    {{ video_embed }}
  {% endif %}

  {# Video file passed to template. Uses HTML5. #}
  {% if video_src %}
    {% include "@atoms/html5/video/video.twig" with {
      "src": video_src,
      "controls": video_controls
    } only %}
    <div class="play-pause">
      <i class="fas fa-play play-button display-5"></i>
    </div>
  {% endif %}

  {# Parent header from BS Card. In this case it's rendering the image. #}
  {{ parent() }}

  {# Header tag #}
  {% if header_tag_text %}
    <div class="header-tag {{ header_tag_colour }}">
      <h6 class="header-tag-text">{{ header_tag_text }}</h6>
    </div>
  {% endif %}

{% endblock %}

{# BLOCK BODY #}
{% block card_body %}
  {% if title %}
    <h3 class="card-title">
      {% if body is empty and card_link is not empty %}
        {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
          "text": title,
          "icon_right": global_icon_right|default('fas fa-chevron-right'),
          "tag_name": "span"
        } only %}
      {% else %}
        {{- title -}}
      {% endif %}
    </h3>
  {% endif %}
  {% if location %}
    <div class="card-location">
      {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
        "text": location,
        "icon_left": global_icon_nr_logo|default('fc fc-nr-logo'),
        "tag_name": "span",
        "class": "location"
      } only %}
    </div>
  {% endif %}
  {% if body %}
    {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
      "text": body,
      "icon_right": global_icon_right|default('fas fa-chevron-right'),
      "class": "subtitle",
    } only %}
  {% endif %}
  {% if date %}
    <span class="card-date">{{ date }}</span>
  {% endif %}
{% endblock %}
