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

if ( ! interior_services_has_page_header() ) {
    return;
}

$interior_services_classes = array( 'page-header' );
$interior_services_style = interior_services_page_header_style();

if ( $interior_services_style ) {
    $interior_services_classes[] = $interior_services_style . '-page-header';
}

$interior_services_visibility = get_theme_mod( 'interior_services_page_header_visibility', 'all-devices' );

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

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

$interior_services_PAGE_TITLE_background_color = get_theme_mod('interior_services_page_title_background_color_setting', '');

// Get the toggle switch value
$interior_services_background_image_enabled = get_theme_mod('interior_services_page_header_style', true);

// Add background image to the header if enabled
$interior_services_background_image = get_theme_mod( 'interior_services_page_header_background_image', '' );
$interior_services_background_height = get_theme_mod( 'interior_services_page_header_image_height', '200' );
$interior_services_inline_style = '';

if ( $interior_services_background_image_enabled && ! empty( $interior_services_background_image ) ) {
    $interior_services_inline_style .= 'background-image: url(' . esc_url( $interior_services_background_image ) . '); ';
    $interior_services_inline_style .= 'height: ' . esc_attr( $interior_services_background_height ) . 'px; ';
    $interior_services_inline_style .= 'background-size: cover; ';
    $interior_services_inline_style .= 'background-position: center center; ';

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

$interior_services_classes = implode( ' ', $interior_services_classes );
$interior_services_heading = get_theme_mod( 'interior_services_page_header_heading_tag', 'h1' );
$interior_services_heading = apply_filters( 'interior_services_page_header_heading', $interior_services_heading );

?>

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

<header class="<?php echo esc_attr( $interior_services_classes ); ?>" style="<?php echo esc_attr( $interior_services_inline_style ); ?> background-color: <?php echo esc_attr($interior_services_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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