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

if ( ! electrical_services_has_page_header() ) {
    return;
}

$electrical_services_classes = array( 'page-header' );
$electrical_services_style = electrical_services_page_header_style();

if ( $electrical_services_style ) {
    $electrical_services_classes[] = $electrical_services_style . '-page-header';
}

$electrical_services_visibility = get_theme_mod( 'electrical_services_page_header_visibility', 'all-devices' );

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

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

$electrical_services_PAGE_TITLE_background_color = get_theme_mod('electrical_services_page_title_background_color_setting', '');

// Get the toggle switch value
$electrical_services_background_image_enabled = get_theme_mod('electrical_services_page_header_style', true);

// Add background image to the header if enabled
$electrical_services_background_image = get_theme_mod( 'electrical_services_page_header_background_image', '' );
$electrical_services_background_height = get_theme_mod( 'electrical_services_page_header_image_height', '200' );
$electrical_services_inline_style = '';

if ( $electrical_services_background_image_enabled && ! empty( $electrical_services_background_image ) ) {
    $electrical_services_inline_style .= 'background-image: url(' . esc_url( $electrical_services_background_image ) . '); ';
    $electrical_services_inline_style .= 'height: ' . esc_attr( $electrical_services_background_height ) . 'px; ';
    $electrical_services_inline_style .= 'background-size: cover; ';
    $electrical_services_inline_style .= 'background-position: center center; ';

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

$electrical_services_classes = implode( ' ', $electrical_services_classes );
$electrical_services_heading = get_theme_mod( 'electrical_services_page_header_heading_tag', 'h2' );
$electrical_services_heading = apply_filters( 'electrical_services_page_header_heading', $electrical_services_heading );

?>

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

<header class="<?php echo esc_attr( $electrical_services_classes ); ?>" style="<?php echo esc_attr( $electrical_services_inline_style ); ?> background-color: <?php echo esc_attr($electrical_services_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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