<?php
	function electromix_track_link() {
		$page = get_page_by_path( 'order-tracking' );

		if ( $page ) {
			echo '<aside class="widget widget_nav_menu d-md-block d-none"><span class="order-tracking  mx-3"><a href="' . esc_url( get_permalink( $page ) ) . '">' . esc_html__( 'Track Order', 'electromix' ) .'</a></span></aside>';
		}
		else
		{ echo '<span class="order-tracking mx-3">Tracking Page Not Exist.</span>'; }
	}
	
	
/**
 * Electromix Above Header First
 */
if ( ! function_exists( 'electromix_abv_hdr_group_1' ) ) {
	function electromix_abv_hdr_group_1() {
		//above_header_first	
		$electromix_enbale_tracking = get_theme_mod('enbale_tracking_first');		
			
			//widget
			electromix_get_sidebars('electromix-header-above-first');
			 			
			if($electromix_enbale_tracking == '1') { electromix_track_link(); }
	}
}
add_action( 'electromix_abv_hdr_group_1', 'electromix_abv_hdr_group_1' );

/**
 * Electromix Above Header Second
 */
if ( ! function_exists( 'electromix_abv_hdr_group_2' ) ) {
	function electromix_abv_hdr_group_2() {
		//above_header_second		
		$electromix_enbale_tracking = get_theme_mod('enbale_tracking_second');
		if($electromix_enbale_tracking == '1') { electromix_track_link(); }		
		
		//widget
		electromix_get_sidebars('electromix-header-above-second'); 
		 
	}
}
add_action( 'electromix_abv_hdr_group_2', 'electromix_abv_hdr_group_2' );

/**
 * Electromix Above Header Third
 */
if ( ! function_exists( 'electromix_abv_hdr_group_3' ) ) {
	function electromix_abv_hdr_group_3() {
		//above_header_third
		$electromix_enbale_tracking = get_theme_mod('enbale_tracking_third');
		if($electromix_enbale_tracking == '1') { electromix_track_link(); }
		
		//widget
		 electromix_get_sidebars('electromix-header-above-third');
	}
}
add_action( 'electromix_abv_hdr_group_3', 'electromix_abv_hdr_group_3' );


if ( ! function_exists( 'electromix_hdr_slides' ) ) {
	function electromix_hdr_slides() {
		$electromix_hdr_slider = get_theme_mod('hdr_info_slides', get_default_hdr_slider() );
		$electromix_hdr_slider_hs = get_theme_mod('hide_show_hdr_info_slider', '1' );
		
		if($electromix_hdr_slider_hs == '1'):
		echo '<div class="benefit-slider owl-carousel" style="width: 68%;">';
			if ( ! empty( $electromix_hdr_slider ) ) {
				$electromix_hdr_slider = json_decode( $electromix_hdr_slider );
				foreach ( $electromix_hdr_slider as $electromix_slide_item ) {
					$electromix_icon = ! empty( $electromix_slide_item->icon_value ) ? apply_filters( 'electromix_translate_single_string', $electromix_slide_item->icon_value, 'Header slider section' ) : '';
					$electromix_title = ! empty( $electromix_slide_item->title ) ? apply_filters( 'electromix_translate_single_string', $electromix_slide_item->title, 'Header slider section' ) : '';
					$electromix_text = ! empty( $electromix_slide_item->text ) ? apply_filters( 'electromix_translate_single_string', $electromix_slide_item->text, 'Header slider section' ) : '';
					$electromix_link = ! empty( $electromix_slide_item->link ) ? apply_filters( 'electromix_translate_single_string', $electromix_slide_item->link, 'Header slider section' ) : '';
					
			echo '<aside class="benefit-item">
					<div class="benefit-area">
						<div class="benefit-icon">
							<i class="fa '.esc_attr($electromix_icon).'"></i>
						</div>
						<div class="benefit-info">
							<p>'.esc_html( $electromix_title ).'</p>
							<a href="'.esc_url($electromix_link).'">
								<span class="title">'.esc_html($electromix_text).'</span>
							</a>
						</div>
					</div>
				</aside>';
			}}    
			echo '</div>';
		endif;
	}
}
add_action( 'electromix_hdr_slides', 'electromix_hdr_slides' );


/**
 * Electromix Header My Account
 */
if ( ! function_exists( 'electromix_hdr_account' ) ) {
	function electromix_hdr_account() {
		$electromix_hide_show_account = get_theme_mod( 'hide_show_account','1');
		$electromix_hide_show_account_title = get_theme_mod( 'hide_show_account_title','0');
		if($electromix_hide_show_account=='1'  && class_exists( 'woocommerce' )): ?>
			<li class="myaccount">
				<?php if(is_user_logged_in()): ?>
					<a href="<?php echo esc_url(wp_logout_url( home_url())); ?>" class="myaccount-btn" aria-label="<?php esc_attr_e('Logout Button','electromix'); ?>">
						<i class="fa fa-sign-out"></i>
					</a>
				<?php else: ?>
					<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" class="myaccount-btn" aria-label="<?php esc_attr_e('Login Button','electromix'); ?>">
						<i class="far fa-user"></i>
					</a>
				<?php endif; ?>
			</li>
		<?php endif;
	}
}
add_action( 'electromix_hdr_account', 'electromix_hdr_account' );

/**
 * Electromix Header My Account
 */
if ( ! function_exists( 'electromix_hdr_account2' ) ) {
	function electromix_hdr_account2() {
		$electromix_hide_show_account 			= get_theme_mod( 'hide_show_account','1');
		$electromix_hdr_account_ttl 			= get_theme_mod( 'hdr_account_ttl2');
		$electromix_hdr_account_subttl 		= get_theme_mod( 'hdr_account_subttl2');
		$electromix_hide_show_account_title 	= get_theme_mod( 'hide_show_account_title','1');
		if($electromix_hide_show_account =='1'  && class_exists( 'woocommerce' )): 
				if(is_user_logged_in()):
					$electromix_hdr_account_href = esc_url(wp_logout_url( home_url())); 
				else:
					$electromix_hdr_account_href = get_permalink( get_option('woocommerce_myaccount_page_id') );
				endif;
			?>
			<li class="myaccount d-flex align-items-center gap-2">
				<a href="<?php echo $electromix_hdr_account_href; ?>" class="myaccount-btn"><i class="far fa-user"></i></a>
				<div>
					<p class="text-white mb-0"><?php echo esc_html($electromix_hdr_account_ttl); ?></p>
					<a href="<?php echo $electromix_hdr_account_href; ?>"><strong class="color-primary"><?php echo esc_html($electromix_hdr_account_subttl); ?></strong></a>
				</div>
			</li>
		<?php endif;
	}
}
add_action( 'electromix_hdr_account2', 'electromix_hdr_account2' );

function cart_product_count() {	
	if ( class_exists( 'woocommerce' ) ) {
		$electromix_count = WC()->cart->cart_contents_count;
		$electromix_cart_url = wc_get_cart_url();
		
		if ( $electromix_count > 0 ) {
		?>
			 <span class="cart-counts count"><?php echo esc_html( $electromix_count ); ?></span>
		<?php 
		}
		else {
			?>
			<span class="cart-counts count">0</span>
			<?php 
		}
	}
}

function cart_slide_docker() { 
	$electromix_hdr_cart_ttl = get_theme_mod( 'hdr_cart_ttl');
	?>
	<div class="docker-widget-popup docker-right" id="cart-popup">
		<div class="docker-overlay-layer"></div>
			<div class="docker-div">
				<div class="docker-anim">
					<div class="docker-cart">													
						<div class="cart-container">
							<div class="cart-header">
								<div class="cart-top">
									<span class="cart-icon"><i class="fa fa-shopping-cart"></i><?php cart_product_count(); ?></span>
									<span class="cart-text"><?php echo wp_kses_post($electromix_hdr_cart_ttl); ?></span>
									<span>
										<a href="#" class="cart-close clear-cart"><?php esc_html_e('Clear All','electromix'); ?></a>
										<a href="javascript:void(0);" class="cart-close docker-widget-close"><i class="fa fa-times"></i></a>
									</span>
								</div>
							</div>
							<div class="cart-data">
							<?php get_template_part('woocommerce/cart/mini','cart'); ?>
						</div></div>
					</div>
				</div>
			</div>
		</div>
<?php }

/**
 * Electromix Header Cart
 */
if ( ! function_exists( 'electromix_hdr_cart' ) ) {
	function electromix_hdr_cart() {
		$electromix_hide_show_cart = get_theme_mod( 'hide_show_cart','1');
		$electromix_hide_show_cart_ttl = get_theme_mod( 'hide_show_cart_ttl','1');
		$electromix_hdr_cart_style = get_theme_mod( 'hdr_cart_style','1');
		$electromix_hdr_cart_ttl = get_theme_mod( 'hdr_cart_ttl');
		if($electromix_hide_show_cart=='1' && class_exists( 'woocommerce' )): ?>
			<li class="cart-wrapper">
				<div class="cart-main">
					<button type="button" class="cart-icon-wrap header-cart cart-toggle" data-target="#cart-popup">						
						 <i class="fa fa-basket-shopping"></i> <?php if($electromix_hide_show_cart_ttl == '1'){	?>
							<?php echo wp_kses_post($electromix_hdr_cart_ttl); ?>
						<?php }
						cart_product_count();
						?>						
					</button>
					
					<?php cart_slide_docker(); ?>
				</li>
				<?php endif;
	}
}
add_action( 'electromix_hdr_cart', 'electromix_hdr_cart' );

/**
 * Electromix Header Cart
 */
if ( ! function_exists( 'electromix_hdr_cart2' ) ) {
	function electromix_hdr_cart2() {
		$electromix_hide_show_cart = get_theme_mod( 'hide_show_cart','1');
		$electromix_hide_show_cart_ttl = get_theme_mod( 'hide_show_cart_ttl','1');
		$electromix_hdr_cart_ttl = get_theme_mod( 'hdr_cart_ttl');
		if($electromix_hide_show_cart == '1' && class_exists( 'woocommerce' )): 
		
		$electromix_cart_total = WC()->cart->get_cart_total(); ?>
				
		<li class="cart-wrapper">
			<div class="cart-main d-flex align-items-center gap-2">
				<button type="button" class="cart-icon-wrap header-cart cart-toggle" data-target="#cart-popup">					
					<i class="fa fa-shopping-bag"></i>
					<?php cart_product_count(); ?>
				</button>
				<div>
				<?php if($electromix_hide_show_cart_ttl == '1'){	?>
					<p class="text-white mb-0"><?php echo wp_kses_post($electromix_hdr_cart_ttl); ?></p>
				<?php } ?>
					<strong class="color-primary"><?php echo $electromix_cart_total; ?></strong>
				</div>
				<?php cart_slide_docker(); ?>
			</div>
		</li>
		<?php endif;
	}
}
add_action( 'electromix_hdr_cart2', 'electromix_hdr_cart2' );

function hdr_contact_widget() { 
	$electromix_hide_show_hdr_contact 		= 	get_theme_mod('hide_show_hdr_contact','1');
	$electromix_hdr_contact_icon 			= 	get_theme_mod('hdr_contact_icon','fa-mobile');
	$electromix_hdr_contact_ttl 			= 	get_theme_mod('hdr_contact_ttl');
	$electromix_hdr_contact_subttl 		= 	get_theme_mod('hdr_contact_subttl');
	
	if($electromix_hide_show_hdr_contact == '1') {
	echo '<aside class="widget widget-contact">
			<div class="contact-area">
				<div class="contact-icon ring-effect">
					<i class="fa '.esc_attr($electromix_hdr_contact_icon).'"></i>
				</div>
				<div class="contact-info">
					<p>'.esc_html( $electromix_hdr_contact_ttl ).'</p>
					<a href="tel:'.esc_attr($electromix_hdr_contact_subttl).'" class="contact-info">
						<span class="title">'.esc_html( $electromix_hdr_contact_subttl ).'</span>
					</a>
				</div>
			</div>
		</aside>';
	}
}