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

if ( ! construction_engineer_has_page_header() ) {
    return;
}

$construction_engineer_classes = array( 'page-header' );
$construction_engineer_style = construction_engineer_page_header_style();

if ( $construction_engineer_style ) {
    $construction_engineer_classes[] = $construction_engineer_style . '-page-header';
}

$construction_engineer_visibility = get_theme_mod( 'construction_engineer_page_header_visibility', 'all-devices' );

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

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

$construction_engineer_PAGE_TITLE_background_color = get_theme_mod('construction_engineer_page_title_background_color_setting', '');

// Get the toggle switch value
$construction_engineer_background_image_enabled = get_theme_mod('construction_engineer_page_header_style', true);

// Add background image to the header if enabled
$construction_engineer_background_image = get_theme_mod( 'construction_engineer_page_header_background_image', '' );
$construction_engineer_background_height = get_theme_mod( 'construction_engineer_page_header_image_height', '200' );
$construction_engineer_inline_style = '';

if ( $construction_engineer_background_image_enabled && ! empty( $construction_engineer_background_image ) ) {
    $construction_engineer_inline_style .= 'background-image: url(' . esc_url( $construction_engineer_background_image ) . '); ';
    $construction_engineer_inline_style .= 'height: ' . esc_attr( $construction_engineer_background_height ) . 'px; ';
    $construction_engineer_inline_style .= 'background-size: cover; ';
    $construction_engineer_inline_style .= 'background-position: center center; ';

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

$construction_engineer_classes = implode( ' ', $construction_engineer_classes );
$construction_engineer_heading = get_theme_mod( 'construction_engineer_page_header_heading_tag', 'h1' );
$construction_engineer_heading = apply_filters( 'construction_engineer_page_header_heading', $construction_engineer_heading );

?>

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

<header class="<?php echo esc_attr( $construction_engineer_classes ); ?>" style="<?php echo esc_attr( $construction_engineer_inline_style ); ?> background-color: <?php echo esc_attr($construction_engineer_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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