{#
/**
 * @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
 */
#}
{{  attach_library('kamihaya_cms_paragraph_type/border-box-css') }}

{% set v_margin = paragraph.field_vertical_margin.0.value %}

{%
  set classes = [
    'paragraph',
    'paragraph--type--' ~ paragraph.bundle|clean_class,
    view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class,
    not paragraph.isPublished() ? 'paragraph--unpublished',
    'border-box',
    v_margin ? v_margin,
  ]
%}
{% block paragraph %}
  {% block content %}
    <div{{attributes.addClass(classes)}}>
      {% set width = paragraph.field_width.0.value %}
      {% set width_unit = paragraph.field_width_unit.0.value %}
      {% set bg_color = content.field_bg_color|render|striptags|trim|lower %}
      {% set bg_gd_end_color = content.field_bg_color_gd_end|render|striptags|trim|lower %}
      {% set gd_dir = content.field_gradation_direction|render|striptags|trim|lower %}
      {% set bd_style = content.field_border_style|render|striptags|trim|lower %}
      {% set bd_top_color = content.field_border_top_color|render|striptags|trim|lower %}
      {% set bd_bottom_color = content.field_border_bottom_color|render|striptags|trim|lower %}
      {% set bd_left_color = content.field_border_left_color|render|striptags|trim|lower %}
      {% set bd_right_color = content.field_border_right_color|render|striptags|trim|lower %}
      {% set bd_top_width = content.field_border_top_width|render|striptags|trim|lower %}
      {% set bd_bottom_width = content.field_border_bottom_width|render|striptags|trim|lower %}
      {% set bd_left_width = content.field_border_left_width|render|striptags|trim|lower %}
      {% set bd_right_width = content.field_border_right_width|render|striptags|trim|lower %}
      {% set bd_radius_type = content.field_radius_type|render|striptags|trim|lower %}
      {% set bd_radius_size = content.field_radius_size|render|striptags|trim|lower %}
      {% set padding = content.field_padding|render|striptags|trim|lower %}
      {% set align = content.field_align|render|striptags|trim|lower %}
      {# Component ID #}
      {% if content.field_component_id|render %}
        {% set component_id = content.field_component_id|render|striptags|trim %}
      {% endif %}
      {# CSS Class #}
      {% if content.field_css_class|render %}
        {% set css_class = content.field_css_class|render|striptags|trim %}
      {% endif %}
      {% if bg_gd_end_color %}
        {% set gd_style = 'linear-gradient(' ~ bg_color ~ ', ' ~ bg_gd_end_color ~ ');'%}
        {% if gd_dir == 'horizontal' %}
          {% set gd_style = 'linear-gradient(to right, ' ~ bg_color ~ ', ' ~ bg_gd_end_color ~ ');' %}
        {% elseif gd_dir == 'vertical' %}
          {% set gd_style = 'linear-gradient(to bottom, ' ~ bg_color ~ ', ' ~ bg_gd_end_color ~ ');' %}
        {% elseif gd_dir == 'right_down' %}
          {% set gd_style = 'linear-gradient(to bottom right, ' ~ bg_color ~ ', ' ~ bg_gd_end_color ~ ');' %}
        {% elseif gd_dir == 'right_up' %}
          {% set gd_style = 'linear-gradient(to top right, ' ~ bg_color ~ ', ' ~ bg_gd_end_color ~ ');' %}
        {% elseif gd_dir == 'radial' %}
          {% set gd_style = 'radial-gradient(' ~ bg_color ~ ', ' ~ bg_gd_end_color ~ ');' %}
        {% endif %}
      {% endif %}
      {%
        set style = [
          width ? (width_unit == 'px' ? ('width: 100%; max-width: ' ~ width ~ width_unit ~ ';') : ('width: ' ~ width ~ (width_unit ? width_unit ~ ';' : 'px;'))) : 'width: 100%;',
          gd_style ? 'background: ' ~ gd_style : (bg_color ? 'background-color: ' ~ bg_color ~ ';'),
          bd_top_color ? 'border-top-color: ' ~ bd_top_color  ~ ';',
          bd_bottom_color ? 'border-bottom-color: ' ~ bd_bottom_color  ~ ';',
          bd_left_color ? 'border-left-color: ' ~ bd_left_color  ~ ';',
          bd_right_color ? 'border-right-color: ' ~ bd_right_color  ~ ';',
        ]
      %}
      {% if width_unit == 'vw' %}
        {%
          set style = style|merge([
            'margin-left: calc(-50vw + 50%);',
            'max-width: none;',
          ])
        %}
      {% endif %}

      {% set box_attribute = create_attribute() %}
      {%
        set box_classes = [
          bd_style ? 'border-' ~ bd_style,
          bd_top_width ? 'border-top-' ~ bd_top_width,
          bd_bottom_width ? 'border-bottom-' ~ bd_bottom_width,
          bd_left_width ? 'border-left-' ~ bd_left_width,
          bd_right_width ? 'border-right-' ~ bd_right_width,
          bd_radius_type ? 'rounded-' ~ bd_radius_type,
          bd_radius_size ? 'rounded-' ~ bd_radius_size,
          align ? 'align-' ~ align,
          css_class ? css_class,
        ]
      %}

      <div{{box_attribute.addClass(box_classes).setAttribute('style', style|join(' '))}}{% if component_id %} id="{{ component_id }}"{% endif %}>
        <div class="border-box-item {{ padding ? padding }}">
          {{ content.field_border_box_item }}
        </div>
      </div>
    </div>
  {% endblock %}
{% endblock paragraph %}
