<?php
/**
 * Inner page banner with breadcrumbs.
 * @package Pr Agency
 */

$pr_agency_banner_bg    = get_theme_mod( 'pr_agency_banner_bg', '' );
$pr_agency_banner_title = get_theme_mod( 'pr_agency_banner_title_toggle', true );
$pr_agency_banner_bread = get_theme_mod( 'pr_agency_breadcrumb_show', true );

$pr_agency_banner_style = '';
if ( $pr_agency_banner_bg ) {
	$pr_agency_banner_style = 'background-image: url(' . esc_url( $pr_agency_banner_bg ) . ');';
}
?>
<div class="pr-agency-page-banner"<?php if ( $pr_agency_banner_style ) : ?> style="<?php echo esc_attr( $pr_agency_banner_style ); ?>"<?php endif; ?>>
	<div class="page-banner-overlay"></div>
	<div class="container">
		<div class="page-banner-inner">
			<?php if ( $pr_agency_banner_title ) : ?>
				<h1 class="page-banner-title">
					<?php
					if ( is_front_page() && is_page() ) {
						echo esc_html( get_bloginfo( 'name' ) );
					} elseif ( is_home() ) {
						esc_html_e( 'Blog', 'pr-agency' );
					} elseif ( is_single() ) {
						echo esc_html( get_the_title() );
					} elseif ( is_page() ) {
						echo esc_html( get_the_title() );
					} elseif ( is_archive() ) {
						echo esc_html( wp_strip_all_tags( get_the_archive_title() ) );
					} elseif ( is_search() ) {
						/* translators: %s: search query */
						printf( esc_html__( 'Results for: %s', 'pr-agency' ), esc_html( get_search_query() ) );
					} elseif ( is_404() ) {
						esc_html_e( 'Page Not Found', 'pr-agency' );
					} else {
						echo esc_html( get_the_title() );
					}
					?>
				</h1>
			<?php endif; ?>

			<?php if ( $pr_agency_banner_bread ) : ?>
				<nav class="pr-agency-breadcrumb" aria-label="<?php esc_attr_e( 'Breadcrumb', 'pr-agency' ); ?>">
					<ol class="breadcrumb-list">
						<?php
						$pr_agency_sep = get_theme_mod( 'pr_agency_breadcrumb_separator', '/' );
					$pr_agency_sep_html = wp_kses_post( '<span class="breadcrumb-sep">' . esc_html( $pr_agency_sep ) . '</span>' );

					echo wp_kses_post( '<li class="breadcrumb-item"><a href="' . esc_url( home_url( '/' ) ) . '"><i class="fas fa-home"></i> ' . esc_html( get_theme_mod( 'pr_agency_breadcrumb_home_text', __( 'Home', 'pr-agency' ) ) ) . '</a></li>' );
						if ( is_home() && ! is_front_page() ) {
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">' . esc_html( get_the_title( get_option( 'page_for_posts' ) ) ) . '</li>';

						} elseif ( function_exists( 'is_product' ) && is_product() ) {
							$pr_agency_shop_id = function_exists( 'wc_get_page_id' ) ? wc_get_page_id( 'shop' ) : 0;
							if ( $pr_agency_shop_id ) {
								echo $pr_agency_sep_html;
								echo '<li class="breadcrumb-item"><a href="' . esc_url( get_permalink( $pr_agency_shop_id ) ) . '">' . esc_html( get_the_title( $pr_agency_shop_id ) ) . '</a></li>';
							}
							$pr_agency_product_cats = wc_get_product_term_ids( get_the_ID(), 'product_cat' );
							if ( $pr_agency_product_cats ) {
								$pr_agency_product_cat = get_term( $pr_agency_product_cats[0], 'product_cat' );
								if ( $pr_agency_product_cat && ! is_wp_error( $pr_agency_product_cat ) ) {
									echo $pr_agency_sep_html;
									echo '<li class="breadcrumb-item"><a href="' . esc_url( get_term_link( $pr_agency_product_cat ) ) . '">' . esc_html( $pr_agency_product_cat->name ) . '</a></li>';
								}
							}
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">' . esc_html( get_the_title() ) . '</li>';

						} elseif ( is_single() ) {
							$pr_agency_cat = get_the_category();
							if ( $pr_agency_cat ) {
								echo $pr_agency_sep_html;
								echo '<li class="breadcrumb-item"><a href="' . esc_url( get_category_link( $pr_agency_cat[0]->term_id ) ) . '">' . esc_html( $pr_agency_cat[0]->name ) . '</a></li>';
							}
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">' . esc_html( get_the_title() ) . '</li>';

						} elseif ( is_page() && ! is_front_page() ) {
							$pr_agency_ancestors = get_post_ancestors( get_the_ID() );
							$pr_agency_ancestors = array_reverse( $pr_agency_ancestors );
							foreach ( $pr_agency_ancestors as $pr_agency_anc ) {
								echo $pr_agency_sep_html;
								echo '<li class="breadcrumb-item"><a href="' . esc_url( get_permalink( $pr_agency_anc ) ) . '">' . esc_html( get_the_title( $pr_agency_anc ) ) . '</a></li>';
							}
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">' . esc_html( get_the_title() ) . '</li>';

						} elseif ( is_category() ) {
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">' . esc_html( single_cat_title( '', false ) ) . '</li>';

						} elseif ( is_tag() ) {
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">' . esc_html( single_tag_title( '', false ) ) . '</li>';

						} elseif ( is_author() ) {
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">' . esc_html( get_the_author() ) . '</li>';

						} elseif ( is_year() ) {
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">' . esc_html( get_the_date( 'Y' ) ) . '</li>';

						} elseif ( is_month() ) {
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">' . esc_html( get_the_date( 'F Y' ) ) . '</li>';

						} elseif ( is_day() ) {
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">' . esc_html( get_the_date() ) . '</li>';

						} elseif ( is_search() ) {
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">' . esc_html__( 'Search Results', 'pr-agency' ) . '</li>';

						} elseif ( is_404() ) {
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">404</li>';

						} elseif ( is_tax() ) {
							$pr_agency_term = get_queried_object();
							if ( $pr_agency_term ) {
								echo $pr_agency_sep_html;
								echo '<li class="breadcrumb-item active">' . esc_html( $pr_agency_term->name ) . '</li>';
							}

						} elseif ( is_post_type_archive() ) {
							echo $pr_agency_sep_html;
							echo '<li class="breadcrumb-item active">' . esc_html( post_type_archive_title( '', false ) ) . '</li>';

						} elseif ( is_archive() ) {
							echo $pr_agency_sep_html;
								echo '<li class="breadcrumb-item active">' . esc_html( wp_strip_all_tags( get_the_archive_title() ) ) . '</li>';
						}
						?>
					</ol>
				</nav>
			<?php endif; ?>
		</div>
	</div>
</div>
