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

if ( ! handmade_craft_has_page_header() ) {
    return;
}

$handmade_craft_classes = array( 'page-header' );
$handmade_craft_style = handmade_craft_page_header_style();

if ( $handmade_craft_style ) {
    $handmade_craft_classes[] = $handmade_craft_style . '-page-header';
}

$handmade_craft_visibility = get_theme_mod( 'handmade_craft_page_header_visibility', 'all-devices' );

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

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

$handmade_craft_PAGE_TITLE_background_color = get_theme_mod('handmade_craft_page_title_background_color_setting', '');

// Get the toggle switch value
$handmade_craft_background_image_enabled = get_theme_mod('handmade_craft_page_header_style', true);

// Add background image to the header if enabled
$handmade_craft_background_image = get_theme_mod( 'handmade_craft_page_header_background_image', '' );
$handmade_craft_background_height = get_theme_mod( 'handmade_craft_page_header_image_height', '200' );
$handmade_craft_inline_style = '';

if ( $handmade_craft_background_image_enabled && ! empty( $handmade_craft_background_image ) ) {
    $handmade_craft_inline_style .= 'background-image: url(' . esc_url( $handmade_craft_background_image ) . '); ';
    $handmade_craft_inline_style .= 'height: ' . esc_attr( $handmade_craft_background_height ) . 'px; ';
    $handmade_craft_inline_style .= 'background-size: cover; ';
    $handmade_craft_inline_style .= 'background-position: center center; ';

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

$handmade_craft_classes = implode( ' ', $handmade_craft_classes );
$handmade_craft_heading = get_theme_mod( 'handmade_craft_page_header_heading_tag', 'h1' );
$handmade_craft_heading = apply_filters( 'handmade_craft_page_header_heading', $handmade_craft_heading );

?>

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

<header class="<?php echo esc_attr( $handmade_craft_classes ); ?>" style="<?php echo esc_attr( $handmade_craft_inline_style ); ?> background-color: <?php echo esc_attr($handmade_craft_PAGE_TITLE_background_color); ?>;">

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

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

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

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

        <?php endif; ?>

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

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

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

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

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