<?php
$pageHeaderTitle = $attributes['pageHeaderTitle'] ?? null;
$pageHeaderDescription = $attributes['pageHeaderDescription'] ?? null;
$cta = $attributes['cta'] ?? null;
$pageIllustration = get_field('page_illustration');

$hasCustomImage = $attributes['hasCustomImage'] ?? null;
$customImageUrl = $attributes['imageUrl'] ?? null;
$customImageAlt = $attributes['imageAlt'] ?? null;

$customTitle = $attributes['blockCustomTitle'] ?? null;
$anchor = isset($attributes['anchor']) ? esc_html($attributes['anchor']) : null;
?>


<section id="<?php echo $anchor ?? "" ?>" <?php echo get_block_wrapper_attributes(['class' => 'block-content-page-header']) ?>>
	<div class="block-content-page-header__content">
		<div className="section_titling">
			<?php if (!$attributes['hasCustomTitle']) : ?>
				<h1 class="section_titling__title"><?php echo get_the_title() ?></h1>
			<?php endif; ?>
			<?php if ($attributes['hasCustomTitle'] && $customTitle) : ?>
				<h1 class="section_titling__title"><?php echo $customTitle ?></h1>
			<?php endif; ?>
			<h2 class="section_titling__subtitle"><?php echo $pageHeaderTitle ?> </h2>
		</div>
		<p><?php echo $pageHeaderDescription  ?> </p>
		<?php echo $content ?>
		<?php if ($cta && $cta['title'] && $cta['url']) : ?>
			<a class="block-content-page-header__cta-link" href="<?php echo $cta['url'] ?>"><?php echo $cta['title'] ?></a>
		<?php endif; ?>
	</div>

	<?php if ($pageIllustration && !$hasCustomImage) : ?>
		<img class="block-content-page-header__page-icon" src="<?php echo $pageIllustration['url'] ?>" alt="">
	<?php endif; ?>
	<?php if ($hasCustomImage && $customImageUrl) : ?>
		<img class="block-content-page-header__page-icon" src="<?php echo $customImageUrl ?>" alt="<?php echo $customImageAlt ?>">
	<?php endif; ?>

</section>