{#
/**
 * @file
 * Template for a Bootstrap 5 Paragraph component.
 *
 * Available variables:
 * - attributes: HTML attributes for the wrapper element.
 * - text: The paragraph text content. Required. Accepts HTML.
 * - text_color: Bootstrap text color utility class.
 * - margin_*/padding_* props: Bootstrap spacing classes.
 * - custom_class: Additional CSS classes.
 *
 * Note: If the text content contains block-level HTML elements (p, div, ul,
 * ol, blockquote), the wrapper renders as a <div> to avoid invalid nesting.
 *
 * @ingroup themeable
 */
#}

{% set text_rendered = text is iterable ? text|render : text|default('') %}
{% set text_markup = text_rendered|lower %}
{% set has_block_tags = text_markup matches '/<\\s*(p|div|ul|ol|blockquote)\\b/' %}
{% set wrapper_tag = has_block_tags ? 'div' : 'p' %}

{% set classes = [
  'paragraph',
  text_color and text_color != 'none' ? text_color : '',
  margin_all,
  margin_top,
  margin_bottom,
  margin_start,
  margin_end,
  margin_x,
  margin_y,
  padding_all,
  padding_top,
  padding_bottom,
  padding_start,
  padding_end,
  padding_x,
  padding_y,
  custom_class|default(''),
]|filter(v => v) %}

<{{ wrapper_tag }}{{ attributes.addClass(classes) }}>
  {{ text_rendered }}
</{{ wrapper_tag }}>
