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

if ( ! charitable_funds_has_page_header() ) {
    return;
}

$charitable_funds_classes = array( 'page-header' );
$charitable_funds_style = charitable_funds_page_header_style();

if ( $charitable_funds_style ) {
    $charitable_funds_classes[] = $charitable_funds_style . '-page-header';
}

$charitable_funds_visibility = get_theme_mod( 'charitable_funds_page_header_visibility', 'all-devices' );

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

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

$charitable_funds_PAGE_TITLE_background_color = get_theme_mod('charitable_funds_page_title_background_color_setting', '');

// Get the toggle switch value
$charitable_funds_background_image_enabled = get_theme_mod('charitable_funds_page_header_style', true);

// Add background image to the header if enabled
$charitable_funds_background_image = get_theme_mod( 'charitable_funds_page_header_background_image', '' );
$charitable_funds_background_height = get_theme_mod( 'charitable_funds_page_header_image_height', '200' );
$charitable_funds_inline_style = '';

if ( $charitable_funds_background_image_enabled && ! empty( $charitable_funds_background_image ) ) {
    $charitable_funds_inline_style .= 'background-image: url(' . esc_url( $charitable_funds_background_image ) . '); ';
    $charitable_funds_inline_style .= 'height: ' . esc_attr( $charitable_funds_background_height ) . 'px; ';
    $charitable_funds_inline_style .= 'background-size: cover; ';
    $charitable_funds_inline_style .= 'background-position: center center; ';

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

$charitable_funds_classes = implode( ' ', $charitable_funds_classes );
$charitable_funds_heading = get_theme_mod( 'charitable_funds_page_header_heading_tag', 'h1' );
$charitable_funds_heading = apply_filters( 'charitable_funds_page_header_heading', $charitable_funds_heading );

?>

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

<header class="<?php echo esc_attr( $charitable_funds_classes ); ?>" style="<?php echo esc_attr( $charitable_funds_inline_style ); ?> background-color: <?php echo esc_attr($charitable_funds_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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