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

if ( ! dog_pet_house_has_page_header() ) {
    return;
}

$dog_pet_house_classes = array( 'page-header' );
$dog_pet_house_style = dog_pet_house_page_header_style();

if ( $dog_pet_house_style ) {
    $dog_pet_house_classes[] = $dog_pet_house_style . '-page-header';
}

$dog_pet_house_visibility = get_theme_mod( 'dog_pet_house_page_header_visibility', 'all-devices' );

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

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

$dog_pet_house_PAGE_TITLE_background_color = get_theme_mod('dog_pet_house_page_title_background_color_setting', '');

// Get the toggle switch value
$dog_pet_house_background_image_enabled = get_theme_mod('dog_pet_house_page_header_style', true);

// Add background image to the header if enabled
$dog_pet_house_background_image = get_theme_mod( 'dog_pet_house_page_header_background_image', '' );
$dog_pet_house_background_height = get_theme_mod( 'dog_pet_house_page_header_image_height', '200' );
$dog_pet_house_inline_style = '';

if ( $dog_pet_house_background_image_enabled && ! empty( $dog_pet_house_background_image ) ) {
    $dog_pet_house_inline_style .= 'background-image: url(' . esc_url( $dog_pet_house_background_image ) . '); ';
    $dog_pet_house_inline_style .= 'height: ' . esc_attr( $dog_pet_house_background_height ) . 'px; ';
    $dog_pet_house_inline_style .= 'background-size: cover; ';
    $dog_pet_house_inline_style .= 'background-position: center center; ';

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

$dog_pet_house_classes = implode( ' ', $dog_pet_house_classes );
$dog_pet_house_heading = get_theme_mod( 'dog_pet_house_page_header_heading_tag', 'h1' );
$dog_pet_house_heading = apply_filters( 'dog_pet_house_page_header_heading', $dog_pet_house_heading );

?>

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

<header class="<?php echo esc_attr( $dog_pet_house_classes ); ?>" style="<?php echo esc_attr( $dog_pet_house_inline_style ); ?> background-color: <?php echo esc_attr($dog_pet_house_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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