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

if ( ! wheel_alignment_service_has_page_header() ) {
    return;
}

$wheel_alignment_service_classes = array( 'page-header' );
$wheel_alignment_service_style = wheel_alignment_service_page_header_style();

if ( $wheel_alignment_service_style ) {
    $wheel_alignment_service_classes[] = $wheel_alignment_service_style . '-page-header';
}

$wheel_alignment_service_visibility = get_theme_mod( 'wheel_alignment_service_page_header_visibility', 'all-devices' );

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

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

$wheel_alignment_service_PAGE_TITLE_background_color = get_theme_mod('wheel_alignment_service_page_title_background_color_setting', '');

// Get the toggle switch value
$wheel_alignment_service_background_image_enabled = get_theme_mod('wheel_alignment_service_page_header_style', true);

// Add background image to the header if enabled
$wheel_alignment_service_background_image = get_theme_mod( 'wheel_alignment_service_page_header_background_image', '' );
$wheel_alignment_service_background_height = get_theme_mod( 'wheel_alignment_service_page_header_image_height', '200' );
$wheel_alignment_service_inline_style = '';

if ( $wheel_alignment_service_background_image_enabled && ! empty( $wheel_alignment_service_background_image ) ) {
    $wheel_alignment_service_inline_style .= 'background-image: url(' . esc_url( $wheel_alignment_service_background_image ) . '); ';
    $wheel_alignment_service_inline_style .= 'height: ' . esc_attr( $wheel_alignment_service_background_height ) . 'px; ';
    $wheel_alignment_service_inline_style .= 'background-size: cover; ';
    $wheel_alignment_service_inline_style .= 'background-position: center center; ';

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

$wheel_alignment_service_classes = implode( ' ', $wheel_alignment_service_classes );
$wheel_alignment_service_heading = get_theme_mod( 'wheel_alignment_service_page_header_heading_tag', 'h1' );
$wheel_alignment_service_heading = apply_filters( 'wheel_alignment_service_page_header_heading', $wheel_alignment_service_heading );

?>

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

<header class="<?php echo esc_attr( $wheel_alignment_service_classes ); ?>" style="<?php echo esc_attr( $wheel_alignment_service_inline_style ); ?> background-color: <?php echo esc_attr($wheel_alignment_service_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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