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

if ( ! auto_mechanic_has_page_header() ) {
    return;
}

$auto_mechanic_classes = array( 'page-header' );
$auto_mechanic_style = auto_mechanic_page_header_style();

if ( $auto_mechanic_style ) {
    $auto_mechanic_classes[] = $auto_mechanic_style . '-page-header';
}

$auto_mechanic_visibility = get_theme_mod( 'auto_mechanic_page_header_visibility', 'all-devices' );

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

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

$auto_mechanic_PAGE_TITLE_background_color = get_theme_mod('auto_mechanic_page_title_background_color_setting', '');

// Get the toggle switch value
$auto_mechanic_background_image_enabled = get_theme_mod('auto_mechanic_page_header_style', true);

// Add background image to the header if enabled
$auto_mechanic_background_image = get_theme_mod( 'auto_mechanic_page_header_background_image', '' );
$auto_mechanic_background_height = get_theme_mod( 'auto_mechanic_page_header_image_height', '200' );
$auto_mechanic_inline_style = '';

if ( $auto_mechanic_background_image_enabled && ! empty( $auto_mechanic_background_image ) ) {
    $auto_mechanic_inline_style .= 'background-image: url(' . esc_url( $auto_mechanic_background_image ) . '); ';
    $auto_mechanic_inline_style .= 'height: ' . esc_attr( $auto_mechanic_background_height ) . 'px; ';
    $auto_mechanic_inline_style .= 'background-size: cover; ';
    $auto_mechanic_inline_style .= 'background-position: center center; ';

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

$auto_mechanic_classes = implode( ' ', $auto_mechanic_classes );
$auto_mechanic_heading = get_theme_mod( 'auto_mechanic_page_header_heading_tag', 'h1' );
$auto_mechanic_heading = apply_filters( 'auto_mechanic_page_header_heading', $auto_mechanic_heading );

?>

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

<header class="<?php echo esc_attr( $auto_mechanic_classes ); ?>" style="<?php echo esc_attr( $auto_mechanic_inline_style ); ?> background-color: <?php echo esc_attr($auto_mechanic_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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