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

if ( ! burger_joint_has_page_header() ) {
    return;
}

$burger_joint_classes = array( 'page-header' );
$burger_joint_style = burger_joint_page_header_style();

if ( $burger_joint_style ) {
    $burger_joint_classes[] = $burger_joint_style . '-page-header';
}

$burger_joint_visibility = get_theme_mod( 'burger_joint_page_header_visibility', 'all-devices' );

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

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

$burger_joint_PAGE_TITLE_background_color = get_theme_mod('burger_joint_page_title_background_color_setting', '');

// Get the toggle switch value
$burger_joint_background_image_enabled = get_theme_mod('burger_joint_page_header_style', true);

// Add background image to the header if enabled
$burger_joint_background_image = get_theme_mod( 'burger_joint_page_header_background_image', '' );
$burger_joint_background_height = get_theme_mod( 'burger_joint_page_header_image_height', '200' );
$burger_joint_inline_style = '';

if ( $burger_joint_background_image_enabled && ! empty( $burger_joint_background_image ) ) {
    $burger_joint_inline_style .= 'background-image: url(' . esc_url( $burger_joint_background_image ) . '); ';
    $burger_joint_inline_style .= 'height: ' . esc_attr( $burger_joint_background_height ) . 'px; ';
    $burger_joint_inline_style .= 'background-size: cover; ';
    $burger_joint_inline_style .= 'background-position: center center; ';

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

$burger_joint_classes = implode( ' ', $burger_joint_classes );
$burger_joint_heading = get_theme_mod( 'burger_joint_page_header_heading_tag', 'h1' );
$burger_joint_heading = apply_filters( 'burger_joint_page_header_heading', $burger_joint_heading );

?>

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

<header class="<?php echo esc_attr( $burger_joint_classes ); ?>" style="<?php echo esc_attr( $burger_joint_inline_style ); ?> background-color: <?php echo esc_attr($burger_joint_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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