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

if ( ! cat_groomer_has_page_header() ) {
    return;
}

$cat_groomer_classes = array( 'page-header' );
$cat_groomer_style = cat_groomer_page_header_style();

if ( $cat_groomer_style ) {
    $cat_groomer_classes[] = $cat_groomer_style . '-page-header';
}

$cat_groomer_visibility = get_theme_mod( 'cat_groomer_page_header_visibility', 'all-devices' );

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

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

$cat_groomer_PAGE_TITLE_background_color = get_theme_mod('cat_groomer_page_title_background_color_setting', '');

// Get the toggle switch value
$cat_groomer_background_image_enabled = get_theme_mod('cat_groomer_page_header_style', true);

// Add background image to the header if enabled
$cat_groomer_background_image = get_theme_mod( 'cat_groomer_page_header_background_image', '' );
$cat_groomer_background_height = get_theme_mod( 'cat_groomer_page_header_image_height', '200' );
$cat_groomer_inline_style = '';

if ( $cat_groomer_background_image_enabled && ! empty( $cat_groomer_background_image ) ) {
    $cat_groomer_inline_style .= 'background-image: url(' . esc_url( $cat_groomer_background_image ) . '); ';
    $cat_groomer_inline_style .= 'height: ' . esc_attr( $cat_groomer_background_height ) . 'px; ';
    $cat_groomer_inline_style .= 'background-size: cover; ';
    $cat_groomer_inline_style .= 'background-position: center center; ';

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

$cat_groomer_classes = implode( ' ', $cat_groomer_classes );
$cat_groomer_heading = get_theme_mod( 'cat_groomer_page_header_heading_tag', 'h1' );
$cat_groomer_heading = apply_filters( 'cat_groomer_page_header_heading', $cat_groomer_heading );

?>

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

<header class="<?php echo esc_attr( $cat_groomer_classes ); ?>" style="<?php echo esc_attr( $cat_groomer_inline_style ); ?> background-color: <?php echo esc_attr($cat_groomer_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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