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

if ( ! resort_motel_has_page_header() ) {
    return;
}

$resort_motel_classes = array( 'page-header' );
$resort_motel_style = resort_motel_page_header_style();

if ( $resort_motel_style ) {
    $resort_motel_classes[] = $resort_motel_style . '-page-header';
}

$resort_motel_visibility = get_theme_mod( 'resort_motel_page_header_visibility', 'all-devices' );

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

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

$resort_motel_PAGE_TITLE_background_color = get_theme_mod('resort_motel_page_title_background_color_setting', '');

// Get the toggle switch value
$resort_motel_background_image_enabled = get_theme_mod('resort_motel_page_header_style', true);

// Add background image to the header if enabled
$resort_motel_background_image = get_theme_mod( 'resort_motel_page_header_background_image', '' );
$resort_motel_background_height = get_theme_mod( 'resort_motel_page_header_image_height', '200' );
$resort_motel_inline_style = '';

if ( $resort_motel_background_image_enabled && ! empty( $resort_motel_background_image ) ) {
    $resort_motel_inline_style .= 'background-image: url(' . esc_url( $resort_motel_background_image ) . '); ';
    $resort_motel_inline_style .= 'height: ' . esc_attr( $resort_motel_background_height ) . 'px; ';
    $resort_motel_inline_style .= 'background-size: cover; ';
    $resort_motel_inline_style .= 'background-position: center center; ';

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

$resort_motel_classes = implode( ' ', $resort_motel_classes );
$resort_motel_heading = get_theme_mod( 'resort_motel_page_header_heading_tag', 'h1' );
$resort_motel_heading = apply_filters( 'resort_motel_page_header_heading', $resort_motel_heading );

?>

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

<header class="<?php echo esc_attr( $resort_motel_classes ); ?>" style="<?php echo esc_attr( $resort_motel_inline_style ); ?> background-color: <?php echo esc_attr($resort_motel_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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