<?php
/*--------------------------------------------------------------
 Breadcrumb Title
--------------------------------------------------------------*/
function saint_get_page_title()
{
    if (is_front_page() && is_home()) {
        return get_bloginfo('name');
    }

    if (is_front_page()) {
        return get_bloginfo('name');
    }

    if (is_home()) {
        $posts_page_id = (int) get_option('page_for_posts');
        return $posts_page_id ? get_the_title($posts_page_id) : esc_html__('المدونة', 'saint');
    }

    if (is_singular()) {
        return get_the_title();
    }

    if (is_category() || is_tax() || is_tag()) {
        return single_term_title('', false);
    }

    if (is_post_type_archive()) {
        return post_type_archive_title('', false);
    }

    if (is_search()) {
        return sprintf(
            esc_html__('نتائج البحث عن: %s', 'saint'),
            '<span class="search-query">' . esc_html(get_search_query()) . '</span>'
        );
    }

    if (is_404()) {
        return esc_html__('الصفحة غير موجودة', 'saint');
    }

    if (is_archive()) {
        return get_the_archive_title();
    }

    return get_bloginfo('name');
}
?>

<?php
/*--------------------------------------------------------------
 Breadcrumb Area
--------------------------------------------------------------*/
$title = saint_get_page_title();
$icon    = get_field('serv_icon');
?>

<?php if ($title || function_exists('bcn_display')) : ?>
	<div class="breadcrumb-area">
		<div class="container">
			<div class="row align-items-center justify-content-between">

				<div class="col-12">
					<?php
                        if (is_singular('services')) :?>
						<div class="hold_serv_tit d-flex justify-content-center">
							<?php if ($icon) : ?>
								<div class="service-icon mb-0">
									<img src="<?php echo esc_url($icon['url']); ?>" style="filter: brightness(0) saturate(100%) invert(100%) sepia(100%) saturate(1%) hue-rotate(31deg) brightness(109%) contrast(101%); margin-inline-end: 10px;"
																alt="<?php echo esc_attr($icon['alt'] ?: get_the_title()); ?>">
								</div>
							<?php endif; ?>
							<h1 class="page-tit text-center"><?php echo wp_kses_post($title); ?></h1>
							</div>
								<?php else: ?>
									<h1 class="page-tit text-center"><?php echo wp_kses_post($title); ?></h1>
						<?php endif; 
					?>
				</div>

				<?php if (function_exists('bcn_display')) : ?>
					<div class="col-12">
						<nav class="breadcrumb-links" aria-label="<?php esc_attr_e('مسار التنقل', 'saint'); ?>">
							<?php bcn_display(); ?>
						</nav>
					</div>
				<?php endif; ?>

			</div>
		</div>
	</div>
<?php endif; ?>
