{#
/**
 * @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-banner') }}

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

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

{# Banner content classes #}
{% set content_classes = (content.field_banner_content|render and content.field_banner_image|render) ?
  'col-12 col-lg-6' : ((content.field_banner_content|render or content.field_banner_image|render) ?
  'col-12' : 'col-12 main-content' ) %}

{# Banner logo URL #}
{% if content.field_banner_logo|render %}
  {% set logoUrl = content.field_banner_logo|render|striptags|trim %}
{% endif %}

{# BG Color #}
{% if content.field_background_color|render %}
  {% set bgColor = content.field_background_color|render|striptags|trim %}
{% endif %}

{# Banner image position #}
{% set bannerImgPosition = content.field_banner_img_position|render|striptags|trim %}

{# Banner image position class #}
{% if bannerImgPosition == 'left' %}
  {% set bannerImgPositionClass = 'd-flex flex-row-reverse' %}
{% else %}
  {% set bannerImgPositionClass = 'd-flex flex-row' %}
{% endif %}

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

{# Banner container width unit #}
{% if content.field_banner_content_width_units|render %}
  {% set containerWidthUnit = content.field_banner_content_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) }}>
      {# Banner Logo SP #}
      {% if content.field_banner_logo|render %}
      <div class="container d-block d-md-none mb-3 clearfix">
        <img src="{{ logoUrl }}" alt="{{ paragraph.field_banner_logo.alt }}" class="img-fluid" />
      </div>
      {% endif %}

      <section class="section-banner-content mb-5" 
        {# BG Color #}
        {% if bgColor is not empty %} style="background-color:{{ bgColor }}"{% endif %}
      >
        {# 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-md-block clearfix" style="background-image: url('{{ pcImgUrl }}')">
              {# Banner Details #}
              <div class="container pc-banner-container clearfix">
                {# Banner Logo #}
                {% if content.field_banner_logo|render %}
                <div class="banner-logo d-none d-md-block mb-3">
                  <img src="{{ logoUrl }}" alt="{{ paragraph.field_banner_logo.alt }}" class="img-fluid" />
                </div>
                {% endif %}

                {# Content and Image #}
                <div class="row {{ bannerImgPositionClass }}">
                  {# Banner content #}
                  {% if content.field_banner_content|render %}
                  <div class="banner-content {{ content_classes }}">
                    {{ content.field_banner_content }}
                  </div>
                  {% endif %}

                  {# Banner image #}
                  {% if content.field_banner_image|render %}
                  <div class="banner-image {{ content_classes }}">
                    {{ content.field_banner_image }}
                  </div>
                  {% endif %}
                </div>
              </div>
            </div>
          {% endif %}

          {# SP image #}
          {% if spImgUrl is not empty %}
            <div class="banner-bg d-block d-md-none clearfix" style="background-image: url('{{ spImgUrl }}')">
          {% else %}
            <div class="banner-bg d-block d-md-none clearfix" style="background-image: url('{{ pcImgUrl }}')">
          {% endif %}
            {# Banner Details #}
            <div class="container pc-banner-container ">
              {# Content and Image #}
              <div class="row {{ bannerImgPositionClass }}">
                {# Banner content #}
                {% if content.field_banner_content|render %}
                <div class="banner-content {{ content_classes }}">
                  {{ content.field_banner_content }}
                </div>
                {% endif %}

                {# Banner image #}
                {% if content.field_banner_image|render %}
                <div class="banner-image {{ content_classes }}">
                  {{ content.field_banner_image }}
                </div>
                {% endif %}
              </div>
            </div>
          </div>
        {% else %}
          {# Banner Details #}
          <div class="container pc-banner-container clearfix">

            {# Content and Image #}
            <div class="row {{ bannerImgPositionClass }}">
              {# Banner content #}
              {% if content.field_banner_content|render %}
              <div class="banner-content {{ content_classes }}">
                {{ content.field_banner_content }}
              </div>
              {% endif %}

              {# Banner image #}
              {% if content.field_banner_image|render %}
              <div class="banner-image {{ content_classes }}">
                {{ content.field_banner_image }}
              </div>
              {% endif %}
            </div>
          </div>
        {% endif %}
      </section>
    </section>
  {% endblock %}
{% endblock paragraph %}
