{% set layout = layout|default('split') %}
{% set level = heading_level|default(2) %}
{% set tag = 'h' ~ level %}

{# ── Shared button fragment ──────────────────────────────────────── #}
{% set has_buttons = primary_button_label or secondary_button_label %}
{% set text_color = textcolor|default('dark') %}

<div
	class="section-intro section-intro--{{ layout }} section-intro--text-{{ text_color }} custom-container">

	{# ================================================================
										     SPLIT layout
										     ================================================================ #}
	{% if layout == 'split' %}

		{# Left column: tagline + heading #}
		<div class="section-intro__col section-intro__col--primary">
			{% if tagline %}
				<div class="section-intro__tagline-wrap">
					<p class="section-intro__tagline">{{ tagline }}</p>
				</div>
			{% endif %}
			{% if heading %}
				<{{tag}} class="section-intro__heading section-intro__heading--{{ tag }}">
					{{- heading -}}
				</{{tag}}>
			{% endif %}
		</div>

		{# Right column: description + buttons #}
		<div class="section-intro__col section-intro__col--secondary">
			{% if description %}
				<p class="section-intro__description">{{ description }}</p>
			{% endif %}
			{% if has_buttons %}
				<div class="section-intro__actions">
					{% if primary_button_label %}
						{% set primary_btn_props = {
							variant: primary_button_variant|default('primary'),
							label: primary_button_label,
							href: primary_button_url|default(''),
							size: primary_button_size|default('medium')
						} %}
						{% if primary_button_icon and primary_button_icon != 'none' %}
							{% set primary_btn_props = primary_btn_props|merge({icon: primary_button_icon}) %}
						{% elseif primary_button_variant|default('primary') == 'link' and primary_button_icon is null %}
							{% set primary_btn_props = primary_btn_props|merge({icon: 'caret-right'}) %}
						{% endif %}
						{{ include('caresphere_theme:button', primary_btn_props) }}
					{% endif %}
					{% if secondary_button_label %}
						{% set secondary_btn_props = {
							variant: secondary_button_variant|default('link'),
							label: secondary_button_label,
							href: secondary_button_url|default(''),
							size: secondary_button_size|default('medium')
						} %}
						{% if secondary_button_icon and secondary_button_icon != 'none' %}
							{% set secondary_btn_props = secondary_btn_props|merge({icon: secondary_button_icon}) %}
						{% elseif secondary_button_variant|default('link') == 'link' and secondary_button_icon is null %}
							{% set secondary_btn_props = secondary_btn_props|merge({icon: 'caret-right'}) %}
						{% endif %}
						{{ include('caresphere_theme:button', secondary_btn_props) }}
					{% endif %}
				</div>
			{% endif %}
		</div>

		{# ================================================================
																				     CENTERED layout
																				     ================================================================ #}
	{% else %}

		<div class="section-intro__content">
			{% if tagline %}
				<div class="section-intro__tagline-wrap">
					<p class="section-intro__tagline">{{ tagline }}</p>
				</div>
			{% endif %}
			{% if heading %}
				<{{tag}} class="section-intro__heading section-intro__heading--{{ tag }}">
					{{- heading -}}
				</{{tag}}>
			{% endif %}
			{% if description %}
				<p class="section-intro__description">{{ description }}</p>
			{% endif %}
		</div>

		{% if has_buttons %}
			<div class="section-intro__actions">
				{% if primary_button_label %}
					{% set primary_btn_props = {
						variant: primary_button_variant|default('primary'),
						label: primary_button_label,
						href: primary_button_url|default(''),
						size: primary_button_size|default('medium')
					} %}
					{% if primary_button_icon and primary_button_icon != 'none' %}
						{% set primary_btn_props = primary_btn_props|merge({icon: primary_button_icon}) %}
					{% elseif primary_button_variant|default('primary') == 'link' and primary_button_icon is null %}
						{% set primary_btn_props = primary_btn_props|merge({icon: 'caret-right'}) %}
					{% endif %}
					{{ include('caresphere_theme:button', primary_btn_props) }}
				{% endif %}
				{% if secondary_button_label %}
					{% set secondary_btn_props = {
						variant: secondary_button_variant|default('link'),
						label: secondary_button_label,
						href: secondary_button_url|default(''),
						size: secondary_button_size|default('medium')
					} %}
					{% if secondary_button_icon and secondary_button_icon != 'none' %}
						{% set secondary_btn_props = secondary_btn_props|merge({icon: secondary_button_icon}) %}
					{% elseif secondary_button_variant|default('link') == 'link' and secondary_button_icon is null %}
						{% set secondary_btn_props = secondary_btn_props|merge({icon: 'caret-right'}) %}
					{% endif %}
					{{ include('caresphere_theme:button', secondary_btn_props) }}
				{% endif %}
			</div>
		{% endif %}

	{% endif %}

</div>
