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

if ( ! bike_workshop_has_page_header() ) {
    return;
}

$bike_workshop_classes = array( 'page-header' );
$bike_workshop_style = bike_workshop_page_header_style();

if ( $bike_workshop_style ) {
    $bike_workshop_classes[] = $bike_workshop_style . '-page-header';
}

$bike_workshop_visibility = get_theme_mod( 'bike_workshop_page_header_visibility', 'all-devices' );

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

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

$bike_workshop_PAGE_TITLE_background_color = get_theme_mod('bike_workshop_page_title_background_color_setting', '');

// Get the toggle switch value
$bike_workshop_background_image_enabled = get_theme_mod('bike_workshop_page_header_style', true);

// Add background image to the header if enabled
$bike_workshop_background_image = get_theme_mod( 'bike_workshop_page_header_background_image', '' );
$bike_workshop_background_height = get_theme_mod( 'bike_workshop_page_header_image_height', '200' );
$bike_workshop_inline_style = '';

if ( $bike_workshop_background_image_enabled && ! empty( $bike_workshop_background_image ) ) {
    $bike_workshop_inline_style .= 'background-image: url(' . esc_url( $bike_workshop_background_image ) . '); ';
    $bike_workshop_inline_style .= 'height: ' . esc_attr( $bike_workshop_background_height ) . 'px; ';
    $bike_workshop_inline_style .= 'background-size: cover; ';
    $bike_workshop_inline_style .= 'background-position: center center; ';

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

$bike_workshop_classes = implode( ' ', $bike_workshop_classes );
$bike_workshop_heading = get_theme_mod( 'bike_workshop_page_header_heading_tag', 'h1' );
$bike_workshop_heading = apply_filters( 'bike_workshop_page_header_heading', $bike_workshop_heading );

?>

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

<header class="<?php echo esc_attr( $bike_workshop_classes ); ?>" style="<?php echo esc_attr( $bike_workshop_inline_style ); ?> background-color: <?php echo esc_attr($bike_workshop_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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