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

if ( ! dark_fitness_has_page_header() ) {
    return;
}

$dark_fitness_classes = array( 'page-header' );
$dark_fitness_style = dark_fitness_page_header_style();

if ( $dark_fitness_style ) {
    $dark_fitness_classes[] = $dark_fitness_style . '-page-header';
}

$dark_fitness_visibility = get_theme_mod( 'dark_fitness_page_header_visibility', 'all-devices' );

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

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

$dark_fitness_PAGE_TITLE_background_color = get_theme_mod('dark_fitness_page_title_background_color_setting', '');

// Get the toggle switch value
$dark_fitness_background_image_enabled = get_theme_mod('dark_fitness_page_header_style', true);

// Add background image to the header if enabled
$dark_fitness_background_image = get_theme_mod( 'dark_fitness_page_header_background_image', '' );
$dark_fitness_background_height = get_theme_mod( 'dark_fitness_page_header_image_height', '200' );
$dark_fitness_inline_style = '';

if ( $dark_fitness_background_image_enabled && ! empty( $dark_fitness_background_image ) ) {
    $dark_fitness_inline_style .= 'background-image: url(' . esc_url( $dark_fitness_background_image ) . '); ';
    $dark_fitness_inline_style .= 'height: ' . esc_attr( $dark_fitness_background_height ) . 'px; ';
    $dark_fitness_inline_style .= 'background-size: cover; ';
    $dark_fitness_inline_style .= 'background-position: center center; ';

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

$dark_fitness_classes = implode( ' ', $dark_fitness_classes );
$dark_fitness_heading = get_theme_mod( 'dark_fitness_page_header_heading_tag', 'h1' );
$dark_fitness_heading = apply_filters( 'dark_fitness_page_header_heading', $dark_fitness_heading );

?>

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

<header class="<?php echo esc_attr( $dark_fitness_classes ); ?>" style="<?php echo esc_attr( $dark_fitness_inline_style ); ?> background-color: <?php echo esc_attr($dark_fitness_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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