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

if ( ! design_studio_has_page_header() ) {
    return;
}

$design_studio_classes = array( 'page-header' );
$design_studio_style = design_studio_page_header_style();

if ( $design_studio_style ) {
    $design_studio_classes[] = $design_studio_style . '-page-header';
}

$design_studio_visibility = get_theme_mod( 'design_studio_page_header_visibility', 'all-devices' );

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

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

$design_studio_PAGE_TITLE_background_color = get_theme_mod('design_studio_page_title_background_color_setting', '');

// Get the toggle switch value
$design_studio_background_image_enabled = get_theme_mod('design_studio_page_header_style', true);

// Add background image to the header if enabled
$design_studio_background_image = get_theme_mod( 'design_studio_page_header_background_image', '' );
$design_studio_background_height = get_theme_mod( 'design_studio_page_header_image_height', '200' );
$design_studio_inline_style = '';

if ( $design_studio_background_image_enabled && ! empty( $design_studio_background_image ) ) {
    $design_studio_inline_style .= 'background-image: url(' . esc_url( $design_studio_background_image ) . '); ';
    $design_studio_inline_style .= 'height: ' . esc_attr( $design_studio_background_height ) . 'px; ';
    $design_studio_inline_style .= 'background-size: cover; ';
    $design_studio_inline_style .= 'background-position: center center; ';

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

$design_studio_classes = implode( ' ', $design_studio_classes );
$design_studio_heading = get_theme_mod( 'design_studio_page_header_heading_tag', 'h2' );
$design_studio_heading = apply_filters( 'design_studio_page_header_heading', $design_studio_heading );

?>

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

<header class="<?php echo esc_attr( $design_studio_classes ); ?>" style="<?php echo esc_attr( $design_studio_inline_style ); ?> background-color: <?php echo esc_attr($design_studio_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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