<?php
/**
 * @package somalite
 */


/**
 * Soma Default Header Style
 */
if ( ! function_exists( 'somalite_header_default_style' ) ) :
function somalite_header_default_style() {
	?>
		<header class="style1">
			<a class="skip-link screen-reader-text" href="#main"><?php esc_html_e( 'Skip to content', 'somalite' ); ?></a>
	        <!-- logo & navigation -->
	        <div id="navigation" class="scroll-fix">
	            <div class="container">
	                <div class="row">
	                    <div class="logo">
	                        <?php
	                            if ( has_custom_logo() ) {
	                                somalite_the_custom_logo();
	                            }
	                        ?>
			        		<?php
				                $show_title   = ( true === get_theme_mod( 'soma_display_site_title_tagline', true ) );
								$header_class = $show_title ? 'site-title' : 'screen-reader-text';
								if(!empty(get_bloginfo( 'name' ))) {
									if ( is_front_page() ) {
								        ?>
				                			<h1 class="<?php echo esc_attr( $header_class ); ?>">
										        <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php esc_html(bloginfo( 'name' )); ?></a>
										    </h1>

										<?php

										if(true === get_theme_mod( 'soma_display_site_title_tagline', true )) {
											$description = esc_html(get_bloginfo( 'description', 'display' ));
									        if ( $description || is_customize_preview() ) { 
									            ?>
									                <p class="site-description"><?php echo $description; ?></p>
									            <?php 
									        }
										}
									}
									else {
										?>
											<p class="<?php echo esc_attr( $header_class ); ?>">
										        <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php esc_html(bloginfo( 'name' )); ?></a>
										    </p>
										<?php

										if(true === get_theme_mod( 'soma_display_site_title_tagline', true )) {
											$description = esc_html(get_bloginfo( 'description', 'display' ));
									        if ( $description || is_customize_preview() ) { 
									            ?>
									                <p class="site-description"><?php echo $description; ?></p>
									            <?php 
									        }
										}
									}
								}
			                ?>                     
	                    </div>
	                    <div class="top-menu navbar" id="top-menu-wrapper">
	                        <div class="soma-top-bar">
	                            <?php
	                            	$topbar_phone=esc_html(get_theme_mod( 'sm_topbar_phone'));
	                                if(!empty($topbar_phone)) {
	                                    ?>
	                                        <i class="fas fa-phone-alt"></i>
	                                        <span class="topbar-phone">
	                                            <?php esc_html_e('Call Us','somalite'); ?> : <?php echo esc_html(get_theme_mod( 'sm_topbar_phone'));  ?>
	                                        </span>
	                                    <?php
	                                }
	                            ?>
	                            <?php somalite_header_topbar(); ?>
	                        </div>
	                        <div class="navigation">
	                           	<nav class="soma-main-menu navbar" id="soma-main-menu-wrapper">
                                    <div class="navbar-header">
                                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-1" aria-expanded="false">
                                        	<span class="sr-only"><?php esc_html_e( 'Toggle navigation', 'somalite' ); ?></span>
                                            <span class="icon-bar"></span>
                                            <span class="icon-bar"></span>
                                            <span class="icon-bar"></span>
                                        </button>
                                    </div>
                                    <div class="collapse navbar-collapse" id="navbar-collapse-1">
	                                    <?php
	                                        wp_nav_menu( array(
	                                            'theme_location'    => 'primary',
	                                            'depth'             => 3,  // This displays menu level of depth 3 only
	                                            'container'         => 'ul',
	                                            'container_class'   => '',
	                                            'container_id'      => 'menu-primary',
	                                            'menu_class'        => 'nav',
	                                            'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
	                                            'walker'            => new wp_bootstrap_navwalker())
	                                        );
	                                    ?>
	                                </div>
	                            </nav>
	                        </div>
	                    </div>
	                </div>
	            </div>
	        </div>
	    </header>    	
	<?php	
}
endif;



/**
 * Soma Shop Header Style
 */
if ( ! function_exists( 'somalite_header_shop_style' ) ) :
function somalite_header_shop_style() {
	?>
		<header class="style2">
			<a class="skip-link screen-reader-text" href="#main"><?php esc_html_e( 'Skip to content', 'somalite' ); ?></a>
	        <!-- logo & navigation -->
	        <div id="navigation" class="scroll-fix">
	        	<div class="soma-top-header">
	        		<div class="container">
		                <div class="row">
		                	<?php somalite_header_topbar_shop(); ?>
		                </div>
		            </div>
	        	</div>
	        	<!-- Navigation -->
				<div id="navigation" class="scroll-fix">	        	
		            <div class="container">
		                <div class="row">	                	
		                    <div class="col-md-3 col-sm-3">
                                <div class="logo">
                                    <?php
			                            if ( has_custom_logo() ) {
			                                somalite_the_custom_logo();
			                            }
			                        ?> 
			                        <?php
						                $show_title   = ( true === get_theme_mod( 'soma_display_site_title_tagline', true ) );
										$header_class = $show_title ? 'site-title' : 'screen-reader-text';
										if(!empty(get_bloginfo( 'name' ))) {
											if ( is_front_page() ) {
										        ?>
						                			<h1 class="<?php echo esc_attr( $header_class ); ?>">
												        <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php esc_html(bloginfo( 'name' )); ?></a>
												    </h1>

												<?php

												if(true === get_theme_mod( 'soma_display_site_title_tagline', true )) {
													$description = esc_html(get_bloginfo( 'description', 'display' ));
											        if ( $description || is_customize_preview() ) { 
											            ?>
											                <p class="site-description"><?php echo $description; ?></p>
											            <?php 
											        }
												}
											}
											else {
												?>
													<p class="<?php echo esc_attr( $header_class ); ?>">
												        <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php esc_html(bloginfo( 'name' )); ?></a>
												    </p>
												<?php

												if(true === get_theme_mod( 'soma_display_site_title_tagline', true )) {
													$description = esc_html(get_bloginfo( 'description', 'display' ));
											        if ( $description || is_customize_preview() ) { 
											            ?>
											                <p class="site-description"><?php echo $description; ?></p>
											            <?php 
											        }
												}
											}
										}
					                ?>                              
                                </div>                
		                    </div>
		                    <div class="col-md-9 col-sm-9">
		                    	<div class="products-search">
		                    		<?php 
		                    			if ( somalite_is_woocommerce_activated() ) {
		                    				get_template_part( 'template-parts/product-search' ); 
		                    			}
		                    			else{
		                    				?>
		                    					<div class="soma-blog-search">
		                    						<?php
		                    							get_search_form();
		                    						?>
		                    					</div>
		                    				<?php
		                    			}
		                    		?>
		                    	</div>
		                    </div>
		                </div>
		            </div>
		        </div>
	            <div id="shop-nav" >
		        	<div class="container">
		        		<div class="row">
		        			<div class="col-md-12">
		        				<div class="navigation">
		                           	<nav class="soma-main-menu navbar" id="soma-main-menu-wrapper">
	                                    <div class="navbar-header">
	                                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-1" aria-expanded="false">
	                                        	<span class="sr-only"><?php esc_html_e( 'Toggle navigation', 'somalite' ); ?></span>
	                                            <span class="icon-bar"></span>
	                                            <span class="icon-bar"></span>
	                                            <span class="icon-bar"></span>
	                                        </button>
	                                    </div>
	                                    <div class="collapse navbar-collapse" id="navbar-collapse-1">
		                                    <?php
		                                        wp_nav_menu( array(
		                                            'theme_location'    => 'primary',
		                                            'depth'             => 3,  // This displays menu level of depth 3 only
		                                            'container'         => 'ul',
		                                            'container_class'   => '',
		                                            'container_id'      => 'menu-primary',
		                                            'menu_class'        => 'nav',
		                                            'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
		                                            'walker'            => new wp_bootstrap_navwalker())
		                                        );
		                                    ?>
		                                </div>
		                            </nav>
		                        </div>
		                    </div>
		                </div>
		            </div>
		    	</div>
	        </div>
	    </header>
	<?php		

}
endif;


if ( ! function_exists( 'somalite_action_header_hook' ) ) :
function somalite_action_header_hook() {
	if("style1" === esc_html(get_theme_mod( 'sm_header_styles','style1'))) {
	    add_action( 'somalite_action_header', 'somalite_header_default_style' );
	}
	else{
	    add_action( 'somalite_action_header', 'somalite_header_shop_style' );
	}
}
endif;
add_action( 'wp', 'somalite_action_header_hook' );



/**
 * Soma Shop Topbar
 */
if ( ! function_exists( 'somalite_header_topbar_shop' ) ) :
function somalite_header_topbar_shop() {
	?>
		<div class="col-md-12">
            <div class="soma-top-menu">
                <?php
                	$topbar_phone=esc_html(get_theme_mod( 'sm_topbar_phone' ));
                    if(!empty($topbar_phone)) {
                        ?>
                            <i class="fas fa-phone-alt"></i>
                            <span class="topbar-phone">
                                <?php esc_html_e('Call Us','somalite'); ?> : <?php echo esc_html(get_theme_mod( 'sm_topbar_phone'));  ?>
                            </span>
                        <?php
                    }
                ?>                                                             
                <?php
                	if(somalite_is_woocommerce_activated()) {
                		?>
                			<span class="top-menu-links">
                				<?php
                					if(is_user_logged_in()){
                						?>
                							<a href="<?php echo esc_url(get_permalink( get_option('woocommerce_myaccount_page_id'))); ?>"><i class="fas fa-lock"></i><?php esc_html_e('My Account','somalite'); ?></a>           			
                						<?php		                            						
                					}
                					else{
                						?>
                							<a href="<?php echo esc_url(get_permalink( get_option('woocommerce_myaccount_page_id'))); ?>"><i class="fas fa-lock"></i><?php esc_html_e('Login','somalite'); ?></a> |         			
                							<a href="<?php echo esc_url(get_permalink( get_option('woocommerce_myaccount_page_id'))); ?>"><i class="fas fa-user"></i><?php esc_html_e('Register','somalite'); ?></a>        			
                						<?php		                            							
                					}
                				?>
                            </span>
                		<?php
                	}
                ?>
                <span class="top-social">
                	<?php 
						for ($i = 1; $i <= 3; $i++) {
						    // Get the icon class and URL for the current index
						    $icon = get_theme_mod('sm_topbar_icon' . $i);
						    $icon_url = get_theme_mod('sm_topbar_icon' . $i . '_url');
						    // Check if the icon is 'fa-twitter'
						    if ($icon === "fa-twitter") {
						        // Output the SVG for 'fa-twitter'
						        echo '<a href="' . esc_url($icon_url) . '" target="_blank">
						                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="12" height="12">
						                    <path d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z"/>
						                </svg>
						              </a>';
						    } else if (!empty($icon)) {
						        // Output the normal Font Awesome icon for all other cases
						        echo '<a href="' . esc_url($icon_url) . '" target="_blank"><i class="fab ' . esc_attr($icon) . '"></i></a>';
						    }
						}
					?>
                </span>		                            
            </div>
        </div>	
	<?php
}
endif;


/**
 * Soma Header Topbar
 */
if ( ! function_exists( 'somalite_header_topbar' ) ) :
function somalite_header_topbar() {
	?>
		<span class="top-social">
        	<?php
				for ($i = 1; $i <= 3; $i++) {
				    // Get the icon class and URL for the current index
				    $icon = get_theme_mod('sm_topbar_icon' . $i);
				    $icon_url = get_theme_mod('sm_topbar_icon' . $i . '_url');
				    // Check if the icon is 'fa-twitter'
				    if ($icon === "fa-twitter") {
				        // Output the SVG for 'fa-twitter'
				        echo '<a href="' . esc_url($icon_url) . '" target="_blank">
				                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="12" height="12">
				                    <path d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z"/>
				                </svg>
				              </a>';
				    } else if (!empty($icon)) {
				        // Output the normal Font Awesome icon for all other cases
				        echo '<a href="' . esc_url($icon_url) . '" target="_blank"><i class="fab ' . esc_attr($icon) . '"></i></a>';
				    }
				}
        	?>                               
        </span>
	<?php
}
endif;