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

if ( ! property_dealer_has_page_header() ) {
    return;
}

$property_dealer_classes = array( 'page-header' );
$property_dealer_style = property_dealer_page_header_style();

if ( $property_dealer_style ) {
    $property_dealer_classes[] = $property_dealer_style . '-page-header';
}

$property_dealer_visibility = get_theme_mod( 'property_dealer_page_header_visibility', 'all-devices' );

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

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

$property_dealer_PAGE_TITLE_background_color = get_theme_mod('property_dealer_page_title_background_color_setting', '');

// Get the toggle switch value
$property_dealer_background_image_enabled = get_theme_mod('property_dealer_page_header_style', true);

// Add background image to the header if enabled
$property_dealer_background_image = get_theme_mod( 'property_dealer_page_header_background_image', '' );
$property_dealer_background_height = get_theme_mod( 'property_dealer_page_header_image_height', '200' );
$property_dealer_inline_style = '';

if ( $property_dealer_background_image_enabled && ! empty( $property_dealer_background_image ) ) {
    $property_dealer_inline_style .= 'background-image: url(' . esc_url( $property_dealer_background_image ) . '); ';
    $property_dealer_inline_style .= 'height: ' . esc_attr( $property_dealer_background_height ) . 'px; ';
    $property_dealer_inline_style .= 'background-size: cover; ';
    $property_dealer_inline_style .= 'background-position: center center; ';

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

$property_dealer_classes = implode( ' ', $property_dealer_classes );
$property_dealer_heading = get_theme_mod( 'property_dealer_page_header_heading_tag', 'h1' );
$property_dealer_heading = apply_filters( 'property_dealer_page_header_heading', $property_dealer_heading );

?>

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

<header class="<?php echo esc_attr( $property_dealer_classes ); ?>" style="<?php echo esc_attr( $property_dealer_inline_style ); ?> background-color: <?php echo esc_attr($property_dealer_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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