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

if ( ! aster_vlogger_has_page_header() ) {
    return;
}

$aster_vlogger_classes = array( 'page-header' );
$aster_vlogger_style = aster_vlogger_page_header_style();

if ( $aster_vlogger_style ) {
    $aster_vlogger_classes[] = $aster_vlogger_style . '-page-header';
}

$aster_vlogger_visibility = get_theme_mod( 'aster_vlogger_page_header_visibility', 'all-devices' );

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

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

$aster_vlogger_PAGE_TITLE_background_color = get_theme_mod('aster_vlogger_page_title_background_color_setting', '');

// Get the toggle switch value
$aster_vlogger_background_image_enabled = get_theme_mod('aster_vlogger_page_header_style', true);

// Add background image to the header if enabled
$aster_vlogger_background_image = get_theme_mod( 'aster_vlogger_page_header_background_image', '' );
$aster_vlogger_background_height = get_theme_mod( 'aster_vlogger_page_header_image_height', '200' );
$aster_vlogger_inline_style = '';

if ( $aster_vlogger_background_image_enabled && ! empty( $aster_vlogger_background_image ) ) {
    $aster_vlogger_inline_style .= 'background-image: url(' . esc_url( $aster_vlogger_background_image ) . '); ';
    $aster_vlogger_inline_style .= 'height: ' . esc_attr( $aster_vlogger_background_height ) . 'px; ';
    $aster_vlogger_inline_style .= 'background-size: cover; ';
    $aster_vlogger_inline_style .= 'background-position: center center; ';

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

$aster_vlogger_classes = implode( ' ', $aster_vlogger_classes );
$aster_vlogger_heading = get_theme_mod( 'aster_vlogger_page_header_heading_tag', 'h1' );
$aster_vlogger_heading = apply_filters( 'aster_vlogger_page_header_heading', $aster_vlogger_heading );

?>

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

<header class="<?php echo esc_attr( $aster_vlogger_classes ); ?>" style="<?php echo esc_attr( $aster_vlogger_inline_style ); ?> background-color: <?php echo esc_attr($aster_vlogger_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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