{#
/**
 * @file
 * Default theme implementation to display a paragraph.
 *
 * Available variables:
 * - paragraph: Full paragraph entity.
 *   Only method names starting with "get", "has", or "is" and a few common
 *   methods such as "id", "label", and "bundle" are available. For example:
 *   - paragraph.getCreatedTime() will return the paragraph creation timestamp.
 *   - paragraph.id(): The paragraph ID.
 *   - paragraph.bundle(): The type of the paragraph, for example, "image" or "text".
 *   - paragraph.getOwnerId(): The user ID of the paragraph author.
 *   See Drupal\paragraphs\Entity\Paragraph for a full list of public properties
 *   and methods for the paragraph object.
 * - content: All paragraph items. Use {{ content }} to print them all,
 *   or print a subset such as {{ content.field_example }}. Use
 *   {{ content|without('field_example') }} to temporarily suppress the printing
 *   of a given child element.
 * - attributes: HTML attributes for the containing element.
 *   The attributes.class element may contain one or more of the following
 *   classes:
 *   - paragraphs: The current template type (also known as a "theming hook").
 *   - paragraphs--type-[type]: The current paragraphs type. For example, if the paragraph is an
 *     "Image" it would result in "paragraphs--type--image". Note that the machine
 *     name will often be in a short form of the human readable label.
 *   - paragraphs--view-mode--[view_mode]: The View Mode of the paragraph; for example, a
 *     preview would result in: "paragraphs--view-mode--preview", and
 *     default: "paragraphs--view-mode--default".
 * - view_mode: View mode; for example, "preview" or "full".
 * - logged_in: Flag for authenticated user status. Will be true when the
 *   current user is a logged-in member.
 * - is_admin: Flag for admin user status. Will be true when the current user
 *   is an administrator.
 *
 * @see template_preprocess_paragraph()
 *
 * @ingroup themeable
 */
#}
{%
  set classes = [
    'paragraph',
    'paragraph--type--' ~ paragraph.bundle|clean_class,
    view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class,
    not paragraph.isPublished() ? 'paragraph--unpublished',
    'paragraph-banner clearfix'
  ]
%}

{{ attach_library('kamihaya_digitalagency/paragraph-hero-banner') }}

{# PC Image #}
{% if content.field_hero_pc_bg_image|render %}
  {% set pcImgUrl = content.field_hero_pc_bg_image|render|striptags|trim %}
{% endif %}

{# SP Image #}
{% if content.field_hero_sp_bg_image|render %}
  {% set spImgUrl = content.field_hero_sp_bg_image|render|striptags|trim %}
{% endif %}

{# Colors #}
{% set color = content.field_hero_title_color|render|striptags|trim|lower %}
{% set desc_color = content.field_hero_description_color|render|striptags|trim|lower %}
{% set link_color = content.field_hero_link_color|render|striptags|trim|lower %}
{% set link_text_color = content.field_hero_link_text_color|render|striptags|trim|lower %}
{% set small_text_color = content.field_hero_small_text_color|render|striptags|trim|lower %}

{# Link #}
{% set link = content.field_hero_link.0['#url'] %}
{% set link_text = content.field_hero_link.0['#title'] %}
{% set style = [
  link_text_color ? 'color: ' ~ link_text_color ~ ';',
  link_color ? 'background-color: ' ~ link_color ~ ';',
] %}

{# Banner container class #}
{% set bannerContainerClass = '' %}

{# Banner container width #}
{% if content.field_hero_container_width|render %}
  {% set containerWidth = content.field_hero_container_width %}
{% else %}
  {% set containerWidth = '1200' %}
{% endif %}

{# Banner container width unit #}
{% if content.field_hero_width_units|render %}
  {% set containerWidthUnit = content.field_hero_width_units.0 %}
{% else %}
  {% set containerWidthUnit = 'px' %}
{% endif %}

{% if containerWidth is not empty and containerWidthUnit is not empty %}
  {% set bannerContainerClass = containerWidth|render|striptags|trim~containerWidthUnit|render|striptags|trim %}
{% endif %}

<style type="text/css">
  .pc-banner-container {
    max-width: {{ bannerContainerClass }};
    margin: 0 auto;
  }
  @media (max-width: 991px) {
    .pc-banner-container {
      max-width: 100%;
    }
  }
</style>

{# Banner content #}
{% block paragraph %}
  {% block content %}
    <section{{ attributes.addClass(classes) }}>

        {# PC/SP BG image #}
        {% if pcImgUrl is not empty or spImgUrl is not empty %}
          {# PC image #}
          {% if pcImgUrl is not empty %}
            <div class="banner-bg d-none d-lg-block clearfix" style="background-image: url('{{ pcImgUrl }}')">
              <div class="container pc-banner-container clearfix">
                <div class="hero-contents">
                  {# Title #}
                  {% if content.field_hero_title|render %}
                    <div class="hero-title">
                      <h1{% if color is not empty %} style="color: {{ color }};"{% endif %}>{{ paragraph.field_hero_title.0.value|striptags('<br>')|raw }}</h1>
                    </div>
                  {% endif %}

                  {# Description #}
                  {% if content.field_hero_description|render %}
                    <div class="hero-description"{% if desc_color is not empty %} style="color: {{ desc_color }};"{% endif %}>
                    {{ content.field_hero_description }}
                    </div>
                  {% endif %}

                  {# Link #}
                  {% if content.field_hero_link|render %}
                    <div class="hero-link">
                      <a href="{{ link }}"{% if style %} style="{{ style|join(' ') }}"{% endif %}>{{ link_text }}</a>
                    </div>
                  {% endif %}

                  {# small text #}
                  {% if content.field_hero_small_text|render %}
                    <div class="hero-small-text"{% if small_text_color is not empty %} style="color: {{ small_text_color }};"{% endif %}>
                    {{ content.field_hero_small_text }}
                    </div>
                  {% endif %}
                </div>
              </div>
            </div>
          {% endif %}

          {# SP image #}
          {% if spImgUrl is not empty %}
            <div class="banner-bg d-block d-lg-none clearfix" style="background-image: url('{{ spImgUrl }}')">
          {% else %}
            <div class="banner-bg d-block d-lg-none clearfix" style="background-image: url('{{ pcImgUrl }}')">
          {% endif %}
            <div class="container pc-banner-container clearfix">
              <div class="hero-contents">
                {# Title #}
                {% if content.field_hero_title|render %}
                  <div class="hero-title">
                    <h1{% if color is not empty %} style="color: {{ color }};"{% endif %}>{{ paragraph.field_hero_title.0.value|striptags('<br>')|raw }}</h1>
                  </div>
                {% endif %}

                {# Description #}
                {% if content.field_hero_description|render %}
                  <div class="hero-description"{% if desc_color is not empty %} style="color: {{ desc_color }};"{% endif %}>
                  {{ content.field_hero_description }}
                  </div>
                {% endif %}

                {# Link #}
                {% if content.field_hero_link|render %}
                  <div class="hero-link">
                      <a href="{{ link }}"{% if style %} style="{{ style|join(' ') }}"{% endif %}>{{ link_text }}</a>
                  </div>
                {% endif %}

                {# small text #}
                {% if content.field_hero_small_text|render %}
                  <div class="hero-small-text"{% if small_text_color is not empty %} style="color: {{ small_text_color }};"{% endif %}>
                  {{ content.field_hero_small_text }}
                  </div>
                {% endif %}
              </div>
            </div>
          </div>
        {% endif %}
      </section>
    </section>
  {% endblock %}
{% endblock paragraph %}
