<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( ! bakery_confectionery_has_page_header() ) {
    return;
}

$bakery_confectionery_classes = array( 'page-header' );
$bakery_confectionery_style = bakery_confectionery_page_header_style();

if ( $bakery_confectionery_style ) {
    $bakery_confectionery_classes[] = $bakery_confectionery_style . '-page-header';
}

$bakery_confectionery_visibility = get_theme_mod( 'bakery_confectionery_page_header_visibility', 'all-devices' );

if ( 'hide-all-devices' === $bakery_confectionery_visibility ) {
    // Don't show the header at all
    return;
}

if ( 'hide-tablet' === $bakery_confectionery_visibility ) {
    $bakery_confectionery_classes[] = 'hide-on-tablet';
} elseif ( 'hide-mobile' === $bakery_confectionery_visibility ) {
    $bakery_confectionery_classes[] = 'hide-on-mobile';
} elseif ( 'hide-tablet-mobile' === $bakery_confectionery_visibility ) {
    $bakery_confectionery_classes[] = 'hide-on-tablet-mobile';
}

$bakery_confectionery_PAGE_TITLE_background_color = get_theme_mod('bakery_confectionery_page_title_background_color_setting', '');

// Get the toggle switch value
$bakery_confectionery_background_image_enabled = get_theme_mod('bakery_confectionery_page_header_style', true);

// Add background image to the header if enabled
$bakery_confectionery_background_image = get_theme_mod( 'bakery_confectionery_page_header_background_image', '' );
$bakery_confectionery_background_height = get_theme_mod( 'bakery_confectionery_page_header_image_height', '200' );
$bakery_confectionery_inline_style = '';

if ( $bakery_confectionery_background_image_enabled && ! empty( $bakery_confectionery_background_image ) ) {
    $bakery_confectionery_inline_style .= 'background-image: url(' . esc_url( $bakery_confectionery_background_image ) . '); ';
    $bakery_confectionery_inline_style .= 'height: ' . esc_attr( $bakery_confectionery_background_height ) . 'px; ';
    $bakery_confectionery_inline_style .= 'background-size: cover; ';
    $bakery_confectionery_inline_style .= 'background-position: center center; ';

    // Add the unique class if the background image is set
    $bakery_confectionery_classes[] = 'has-background-image';
}

$bakery_confectionery_classes = implode( ' ', $bakery_confectionery_classes );
$bakery_confectionery_heading = get_theme_mod( 'bakery_confectionery_page_header_heading_tag', 'h1' );
$bakery_confectionery_heading = apply_filters( 'bakery_confectionery_page_header_heading', $bakery_confectionery_heading );

?>

<?php do_action( 'bakery_confectionery_before_page_header' ); ?>

<header class="<?php echo esc_attr( $bakery_confectionery_classes ); ?>" style="<?php echo esc_attr( $bakery_confectionery_inline_style ); ?> background-color: <?php echo esc_attr($bakery_confectionery_PAGE_TITLE_background_color); ?>;">

    <?php do_action( 'bakery_confectionery_before_page_header_inner' ); ?>

    <div class="asterthemes-wrapper page-header-inner">

        <?php if ( bakery_confectionery_has_page_header() ) : ?>

            <<?php echo esc_attr( $bakery_confectionery_heading ); ?> class="page-header-title">
                <?php echo wp_kses_post( bakery_confectionery_get_page_title() ); ?>
            </<?php echo esc_attr( $bakery_confectionery_heading ); ?>>

        <?php endif; ?>

        <?php if ( function_exists( 'bakery_confectionery_breadcrumb' ) ) : ?>
            <?php bakery_confectionery_breadcrumb(); ?>
        <?php endif; ?>

    </div><!-- .page-header-inner -->

    <?php do_action( 'bakery_confectionery_after_page_header_inner' ); ?>

</header><!-- .page-header -->

<?php do_action( 'bakery_confectionery_after_page_header' ); ?>