<?php
/**
 * The header for our theme
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package wheel_alignment_service
 */
$wheel_alignment_service_menu_text_transform = get_theme_mod( 'wheel_alignment_service_menu_text_transform', 'uppercase' );
$wheel_alignment_service_menu_text_transform_css = 'text-transform: ' . esc_attr( $wheel_alignment_service_menu_text_transform ) . ';';
$wheel_alignment_service_menu_text_color = get_theme_mod('wheel_alignment_service_menu_text_color', ''); 
$wheel_alignment_service_sub_menu_text_color = get_theme_mod('wheel_alignment_service_sub_menu_text_color', ''); 
?>
<!doctype html>
<html <?php language_attributes(); ?>>

<head>
	<meta charset="<?php bloginfo( 'charset' ); ?>">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="profile" href="https://gmpg.org/xfn/11">
	<?php wp_head(); ?>
</head>

<body <?php body_class(get_theme_mod('wheel_alignment_service_website_layout', false) ? 'site-boxed--layout' : ''); ?>>
<?php wp_body_open(); ?>
<div id="page" class="site asterthemes-site-wrapper">
<a class="skip-link screen-reader-text" href="#primary"><?php esc_html_e( 'Skip to content', 'wheel-alignment-service' ); ?></a>
    <?php if (get_theme_mod('wheel_alignment_service_enable_preloader', false)) : ?>
        <div id="loader" class="<?php echo esc_attr(get_theme_mod('wheel_alignment_service_preloader_style', 'style1')); ?>">
            <div class="loader-container">
                <div id="preloader">
                    <?php 
                    $wheel_alignment_service_preloader_style = get_theme_mod('wheel_alignment_service_preloader_style', 'style1');
                    if ($wheel_alignment_service_preloader_style === 'style1') : ?>
                        <!-- STYLE 1 -->
                        <img src="<?php echo esc_url(get_template_directory_uri() . '/resource/loader.gif'); ?>" alt="<?php esc_attr_e('Loading...', 'wheel-alignment-service'); ?>">
                    <?php elseif ($wheel_alignment_service_preloader_style === 'style2') : ?>
                        <!-- STYLE 2 -->
                        <div class="dot"></div>
                    <?php elseif ($wheel_alignment_service_preloader_style === 'style3') : ?>
                        <!-- STYLE 3 -->
                        <div class="bars">
                            <div class="bar"></div>
                            <div class="bar"></div>
                            <div class="bar"></div>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    <?php endif; ?>
<header id="masthead" class="site-header">
    <div class="header-main-wrapper">
        <div class="bottom-header-outer-wrapper">
            <div class="bottom-header-part">
                <div class="asterthemes-wrapper">
                    <div class="bottom-header-part-wrapper hello <?php echo esc_attr( get_theme_mod( 'wheel_alignment_service_enable_sticky_header', false ) ? 'sticky-header' : '' ); ?>">
                        <div class="bottom-header-left-part">
                            <div class="site-branding">
                                <?php
                                // Check if the 'Enable Site Logo' setting is true.
                                if ( get_theme_mod( 'wheel_alignment_service_enable_site_logo', true ) ) {
                                    if ( has_custom_logo() ) { ?>
                                        <div class="site-logo">
                                            <?php the_custom_logo(); ?>
                                        </div>
                                    <?php } else { ?>
                                        <div class="site-logo">
                                            <!-- Fallback logo if no custom logo is set -->
                                            <a href="<?php echo esc_url(home_url('/')); ?>" rel="home">
                                                <img src="<?php echo esc_url(get_template_directory_uri() . '/resource/img/Logo.png'); ?>" alt="<?php bloginfo('name'); ?>">
                                            </a>
                                        </div>
                                    <?php }
                                } ?>
                                <div class="site-identity">
                                    <?php
                                    $wheel_alignment_service_site_title_size = get_theme_mod('wheel_alignment_service_site_title_size', 20);
                                    $wheel_alignment_service_site_title = get_bloginfo('name');
                                    $wheel_alignment_service_site_title_words = explode(' ', $wheel_alignment_service_site_title);
                                    $wheel_alignment_service_first_word = array_shift($wheel_alignment_service_site_title_words);
                                    $wheel_alignment_service_remaining_title = implode(' ', $wheel_alignment_service_site_title_words);

                                    // Check if it's a single word or multiple words
                                    if (count($wheel_alignment_service_site_title_words) > 1) {
                                        // Multiple words: split first word from the rest
                                        $wheel_alignment_service_first_part = array_shift($wheel_alignment_service_site_title_words);
                                        $wheel_alignment_service_remaining_part = implode(' ', $wheel_alignment_service_site_title_words);
                                    } else {
                                        // Single word: split first 5 letters
                                        $wheel_alignment_service_first_part = mb_substr($wheel_alignment_service_site_title, 0, 5);
                                        $wheel_alignment_service_remaining_part = mb_substr($wheel_alignment_service_site_title, 5);
                                    }

                                    if (get_theme_mod('wheel_alignment_service_enable_site_title_setting', false)) {
                                        if (is_front_page() && is_home()) : ?>
                                            <h1 class="site-title" style="font-size: <?php echo esc_attr($wheel_alignment_service_site_title_size); ?>px;">
                                                <a href="<?php echo esc_url(home_url('/')); ?>" rel="home">
                                                    <span class="first-part"><?php echo esc_html($wheel_alignment_service_first_part); ?></span><?php echo esc_html($wheel_alignment_service_remaining_part); ?>
                                                </a>
                                            </h1>
                                        <?php else : ?>
                                            <p class="site-title" style="font-size: <?php echo esc_attr($wheel_alignment_service_site_title_size); ?>px;">
                                                <a href="<?php echo esc_url(home_url('/')); ?>" rel="home">
                                                    <span class="first-part"><?php echo esc_html($wheel_alignment_service_first_part); ?></span><?php echo esc_html($wheel_alignment_service_remaining_part); ?>
                                                </a>
                                            </p>
                                        <?php endif;
                                    }

                                    if (get_theme_mod('wheel_alignment_service_enable_tagline_setting', false)) :
                                        $wheel_alignment_service_description = get_bloginfo('description', 'display');
                                        if ($wheel_alignment_service_description || is_customize_preview()) : ?>
                                            <p class="site-description"><?php echo esc_html($wheel_alignment_service_description); ?></p>
                                        <?php endif;
                                    endif;
                                    ?>
                                </div>
                            </div>
                        </div>
                        <div class="bottom-header-middle-part">
                        <?php if ( get_theme_mod( 'wheel_alignment_service_post_hide_header_sidebar', false ) ) : ?>
                            <div class="toggle-btn">
                                <a href="#" id="sidebar-pop">
                                    <i class="fas fa-bars"></i>
                                </a>
                            </div>
                        <?php endif; ?>
                            <div class="header-sidebar px-3">
                                <div class="close-pop"><a href="#maincontent"><i class="fas fa-window-close"></i></a></div>
                                <div class="sidebar-content">
                                    <!-- Search Form -->
                                    <div class="sidebar-search">
                                        <h2 class="widget-title"><span><?php esc_html_e( 'Search', 'wheel-alignment-service' ); ?></span></h2>
                                        <?php get_search_form(); ?>
                                    </div>

                                    <!-- Sidebar Widgets -->
                                    <?php if ( is_active_sidebar( 'sidebar-2' ) ) : ?>
                                        <?php dynamic_sidebar( 'sidebar-2' ); ?>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div> 
                        
                        <div class="navigation-menus">
                            <div class="asterthemes-wrapper">
                                <div class="navigation-part">
                                    <nav id="site-navigation" class="main-navigation">
                                    <?php
                                    $wheel_alignment_service_hide_sidebar = get_theme_mod( 'wheel_alignment_service_post_hide_header_sidebar', false );
                                    $wheel_alignment_service_menu_toggle_margin = $wheel_alignment_service_hide_sidebar ? '10px 0' : '10px auto';
                                    ?>
                                        <button class="menu-toggle"  style="margin: <?php echo esc_attr( $wheel_alignment_service_menu_toggle_margin ); ?>;" aria-controls="primary-menu" aria-expanded="false">
                                            <span></span>
                                            <span></span>
                                            <span></span>
                                        </button>
                                        <div class="main-navigation-links" style="<?php echo esc_attr( $wheel_alignment_service_menu_text_transform_css ); ?>">
                                            <?php
                                                wp_nav_menu(
                                                    array(
                                                        'theme_location' => 'primary',
                                                    )
                                                );
                                            ?>
                                        </div>
                                        <style>
                                            /* Main Menu Links */
                                            .main-navigation ul li a, .menu a {
                                                color: <?php echo esc_attr($wheel_alignment_service_menu_text_color); ?>;
                                            }

                                            /* Submenu Links */
                                            .main-navigation ul.children a, 
                                            .home .main-navigation ul.children a, 
                                            .main-navigation ul.menu li .sub-menu a, 
                                            .home .main-navigation ul ul a {
                                                color: <?php echo esc_attr($wheel_alignment_service_sub_menu_text_color); ?>;
                                            }
                                        </style>
                                    </nav>
                                </div>
                            </div>
                        </div>                      
                    </div>
                </div>
            </div>
        </div>
    </div>
</header>
<?php
    if ( ! is_front_page() || is_home() ) {
	if ( is_front_page() ) {
		require get_template_directory() . '/sections/sections.php';
		wheel_alignment_service_homepage_sections();
	}
	?>
    <?php
        if (!is_front_page() || is_home()) {
            get_template_part('page-header');
        }
    ?>
	<div id="content" class="site-content">
		<div class="asterthemes-wrapper">
			<div class="asterthemes-page">
			<?php } ?>