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

if ( ! events_and_celebrations_has_page_header() ) {
    return;
}

$events_and_celebrations_classes = array( 'page-header' );
$events_and_celebrations_style = events_and_celebrations_page_header_style();

if ( $events_and_celebrations_style ) {
    $events_and_celebrations_classes[] = $events_and_celebrations_style . '-page-header';
}

$events_and_celebrations_visibility = get_theme_mod( 'events_and_celebrations_page_header_visibility', 'all-devices' );

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

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

$events_and_celebrations_PAGE_TITLE_background_color = get_theme_mod('events_and_celebrations_page_title_background_color_setting', '');

// Get the toggle switch value
$events_and_celebrations_background_image_enabled = get_theme_mod('events_and_celebrations_page_header_style', true);

// Add background image to the header if enabled
$events_and_celebrations_background_image = get_theme_mod( 'events_and_celebrations_page_header_background_image', '' );
$events_and_celebrations_background_height = get_theme_mod( 'events_and_celebrations_page_header_image_height', '200' );
$events_and_celebrations_inline_style = '';

if ( $events_and_celebrations_background_image_enabled && ! empty( $events_and_celebrations_background_image ) ) {
    $events_and_celebrations_inline_style .= 'background-image: url(' . esc_url( $events_and_celebrations_background_image ) . '); ';
    $events_and_celebrations_inline_style .= 'height: ' . esc_attr( $events_and_celebrations_background_height ) . 'px; ';
    $events_and_celebrations_inline_style .= 'background-size: cover; ';
    $events_and_celebrations_inline_style .= 'background-position: center center; ';

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

$events_and_celebrations_classes = implode( ' ', $events_and_celebrations_classes );
$events_and_celebrations_heading = get_theme_mod( 'events_and_celebrations_page_header_heading_tag', 'h2' );
$events_and_celebrations_heading = apply_filters( 'events_and_celebrations_page_header_heading', $events_and_celebrations_heading );

?>

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

<header class="<?php echo esc_attr( $events_and_celebrations_classes ); ?>" style="<?php echo esc_attr( $events_and_celebrations_inline_style ); ?> background-color: <?php echo esc_attr($events_and_celebrations_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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