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

if ( ! clothing_marketplace_has_page_header() ) {
    return;
}

$clothing_marketplace_classes = array( 'page-header' );
$clothing_marketplace_style = clothing_marketplace_page_header_style();

if ( $clothing_marketplace_style ) {
    $clothing_marketplace_classes[] = $clothing_marketplace_style . '-page-header';
}

$clothing_marketplace_visibility = get_theme_mod( 'clothing_marketplace_page_header_visibility', 'all-devices' );

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

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

$clothing_marketplace_PAGE_TITLE_background_color = get_theme_mod('clothing_marketplace_page_title_background_color_setting', '');

// Get the toggle switch value
$clothing_marketplace_background_image_enabled = get_theme_mod('clothing_marketplace_page_header_style', true);

// Add background image to the header if enabled
$clothing_marketplace_background_image = get_theme_mod( 'clothing_marketplace_page_header_background_image', '' );
$clothing_marketplace_background_height = get_theme_mod( 'clothing_marketplace_page_header_image_height', '200' );
$clothing_marketplace_inline_style = '';

if ( $clothing_marketplace_background_image_enabled && ! empty( $clothing_marketplace_background_image ) ) {
    $clothing_marketplace_inline_style .= 'background-image: url(' . esc_url( $clothing_marketplace_background_image ) . '); ';
    $clothing_marketplace_inline_style .= 'height: ' . esc_attr( $clothing_marketplace_background_height ) . 'px; ';
    $clothing_marketplace_inline_style .= 'background-size: cover; ';
    $clothing_marketplace_inline_style .= 'background-position: center center; ';

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

$clothing_marketplace_classes = implode( ' ', $clothing_marketplace_classes );
$clothing_marketplace_heading = get_theme_mod( 'clothing_marketplace_page_header_heading_tag', 'h2' );
$clothing_marketplace_heading = apply_filters( 'clothing_marketplace_page_header_heading', $clothing_marketplace_heading );

?>

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

<header class="<?php echo esc_attr( $clothing_marketplace_classes ); ?>" style="<?php echo esc_attr( $clothing_marketplace_inline_style ); ?> background-color: <?php echo esc_attr($clothing_marketplace_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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