<?php
/**
 * Custom theme functions.
 *
 * This file contains hook functions attached to theme hooks.
 *
 * @package clothing_brand_store
 */

if ( ! function_exists( 'clothing_brand_store_skip_to_content' ) ) :
	/**
	 * Add Skip to content.
	 *
	 * @since 1.0.0
	 */
	function clothing_brand_store_skip_to_content() {
	?><a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'clothing-brand-store' ); ?></a><?php
	}
endif;

add_action( 'clothing_brand_store_action_before', 'clothing_brand_store_skip_to_content', 15 );

// Middle Header

if ( ! function_exists( 'clothing_brand_store_site_branding' ) ) :

	/**
	 * Site branding.
	 *
	 * @since 1.0.0
	 */
	function clothing_brand_store_site_branding() {

		$clothing_brand_store_header_top_button_text = clothing_brand_store_get_option( 'clothing_brand_store_header_top_button_text' );
		$clothing_brand_store_header_top_button_link = clothing_brand_store_get_option( 'clothing_brand_store_header_top_button_link' );
		
		$clothing_brand_store_show_social_icon = clothing_brand_store_get_option( 'clothing_brand_store_show_social_icon' );
		$clothing_brand_store_header_social_facebook_link = clothing_brand_store_get_option( 'clothing_brand_store_header_social_facebook_link' );
		$clothing_brand_store_header_social_twitter_link = clothing_brand_store_get_option( 'clothing_brand_store_header_social_twitter_link' );
		$clothing_brand_store_header_social_instagram_link = clothing_brand_store_get_option( 'clothing_brand_store_header_social_instagram_link' );
		$clothing_brand_store_header_social_youtube_link = clothing_brand_store_get_option( 'clothing_brand_store_header_social_youtube_link' );

		?>

		<div id="middle-header" class="py-3">
			<div class="container">
				<div class="row inner-middle">
					<div class="col-xl-2 col-lg-3 col-md-4 col-sm-4 col-8 align-self-center position-relative">
						<div class="site-branding text-sm-start">
							<?php clothing_brand_store_the_custom_logo(); ?>
							<?php $clothing_brand_store_show_title = clothing_brand_store_get_option( 'clothing_brand_store_show_title' ); ?>
							<?php $clothing_brand_store_show_tagline = clothing_brand_store_get_option( 'clothing_brand_store_show_tagline' ); ?>
							<?php if ( true === $clothing_brand_store_show_title || true === $clothing_brand_store_show_tagline ) :  ?>
								<div id="site-identity" class="text-sm-start">
									<?php if ( true === $clothing_brand_store_show_title ) :  ?>
										<?php if ( is_front_page() ) : ?>
											<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
										<?php else : ?>
											<p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
										<?php endif; ?>
									<?php endif; ?>
									<?php if ( true === $clothing_brand_store_show_tagline ) :  ?>
										<p class="site-description"><?php bloginfo( 'description' ); ?></p>
									<?php endif; ?>
								</div>
							<?php endif; ?>
						</div>
					</div>
					<div class="col-xl-7 col-lg-6 col-md-2 col-sm-2 col-4 align-self-center text-start">
						<div class="navigation_header">
							<div class="toggle-nav mobile-menu">
								<button onclick="clothing_brand_store_openNav()"><i class="fa-solid fa-bars"></i></button>
							</div>
							<div id="mySidenav" class="nav sidenav">
								<nav id="site-navigation" class="main-navigation navbar navbar-expand-xl" aria-label="<?php esc_attr_e( 'Top Menu', 'clothing-brand-store' ); ?>">
									<?php {
										wp_nav_menu(
											array(
												'theme_location' => 'primary',
												'menu_class'     => 'menu', 
												'items_wrap'     => '<ul id="%1$s" class="%2$s">%3$s</ul>',
												'fallback_cb' => 'wp_page_menu',
											)
										);
									} ?>
								</nav>
								<a href="javascript:void(0)" class="closebtn mobile-menu" onclick="clothing_brand_store_closeNav()"><i class="fas fa-times"></i></a>
							</div>
						</div>
					</div>
					<div class="col-xl-3 col-lg-3 col-md-6 col-sm-6 col-12 align-self-center d-flex justify-content-between">
						<div class="cart-wishlist d-flex justify-content-between w-25">
							<?php if ( class_exists( 'woocommerce' ) ) {?>
								<a class="cart-customlocation" href="<?php if(function_exists('wc_get_cart_url')){ echo esc_url(wc_get_cart_url()); } ?>" title="<?php esc_attr_e( 'View Shopping Cart','clothing-brand-store' ); ?>"><i class="fa-solid fa-cart-plus me-2"></i></a>
								<?php if(defined('YITH_WCWL')){ ?>
									<a class="wishlist_view" href="<?php echo YITH_WCWL()->get_wishlist_url(); ?>" title="<?php esc_attr_e('Wishlist','clothing-brand-store'); ?>"><i class="fa-solid fa-heart"></i></a>
								<?php }?>
							<?php }?>
						</div>
						<?php if ( true === $clothing_brand_store_show_social_icon ) : ?>
							<div class="header-social-icon">
								<?php if( !empty($clothing_brand_store_header_social_facebook_link) || !empty($clothing_brand_store_header_social_twitter_link) || !empty($clothing_brand_store_header_social_instagram_link) || !empty($clothing_brand_store_header_social_youtube_link) ):?>
									<?php if( !empty($clothing_brand_store_header_social_facebook_link) ):?>
										<a href="<?php echo esc_url($clothing_brand_store_header_social_facebook_link);?>" target="_blank" ><i class="fa-brands fa-facebook-f"></i></a>
									<?php endif; ?>
									<?php if( !empty($clothing_brand_store_header_social_twitter_link) ):?>
										<a href="<?php echo esc_url($clothing_brand_store_header_social_twitter_link);?>" target="_blank" ><i class="fa-brands fa-x-twitter"></i></a>
									<?php endif; ?>
									<?php if( !empty($clothing_brand_store_header_social_instagram_link) ):?>
										<a href="<?php echo esc_url($clothing_brand_store_header_social_instagram_link);?>" target="_blank" ><i class="fa-brands fa-instagram"></i></a>
									<?php endif; ?>
									<?php if( !empty($clothing_brand_store_header_social_youtube_link) ):?>
										<a href="<?php echo esc_url($clothing_brand_store_header_social_youtube_link);?>" target="_blank" ><i class="fa-brands fa-youtube"></i></a>
									<?php endif; ?>
								<?php endif;?>
							</div>
						<?php endif; ?>
					</div>
				</div>
			</div>
		</div>
	    <?php
	}

endif;

add_action( 'clothing_brand_store_action_header', 'clothing_brand_store_site_branding' );

/////////////////////////////////// copyright start /////////////////////////////

if ( ! function_exists( 'clothing_brand_store_footer_copyright' ) ) :

	/**
	 * Footer copyright
	 *
	 * @since 1.0.0
	 */
	function clothing_brand_store_footer_copyright() {

		// Check if footer is disabled.
		$clothing_brand_store_footer_status = apply_filters( 'clothing_brand_store_filter_footer_status', true );
		if ( true !== $clothing_brand_store_footer_status ) {
			return;
		}

		// Copyright content.
		$clothing_brand_store_copyright_text = clothing_brand_store_get_option( 'clothing_brand_store_copyright_text' );
		$clothing_brand_store_copyright_text = apply_filters( 'clothing_brand_store_filter_copyright_text', $clothing_brand_store_copyright_text );
		if ( ! empty( $clothing_brand_store_copyright_text ) ) {
			$clothing_brand_store_copyright_text = wp_kses_data( $clothing_brand_store_copyright_text );
		}

		// Powered by content.
		$clothing_brand_store_powered_by_text = sprintf( __( 'Clothing Brand Store by %s', 'clothing-brand-store' ), '<span>' . __( 'Mizan Themes', 'clothing-brand-store' ) . '</span>' );
		?>

		<div class="colophon-inner <?php echo esc_attr( get_theme_mod('clothing_brand_store_sticky_copyright_enable', false) ? 'sticky-copyright' : 'close-sticky' ); ?>">
		    <?php if ( ! empty( $clothing_brand_store_copyright_text ) ) : ?>
			    <div class="colophon-column">
			    	<div class="copyright">
					<a href="<?php echo esc_url('https://www.mizanthemes.com/products/clothing-brand-store','clothing-brand-store'); ?>"><?php echo $clothing_brand_store_copyright_text; ?></a>
			    	</div><!-- .copyright -->
			    </div><!-- .colophon-column -->
		    <?php endif; ?>

		    <?php if ( ! empty( $clothing_brand_store_powered_by_text ) ) : ?>
			    <div class="colophon-column">
			    	<div class="site-info">
						<?php echo $clothing_brand_store_powered_by_text; ?>
			    	</div><!-- .site-info -->
			    </div><!-- .colophon-column -->
		    <?php endif; ?>
		</div><!-- .colophon-inner -->
		
	    <?php
	}

endif;

add_action( 'clothing_brand_store_action_footer', 'clothing_brand_store_footer_copyright', 10 );

// /////////////////////////////////sidebar//////////////////

if ( ! function_exists( 'clothing_brand_store_add_sidebar' ) ) :

	/**
	 * Add sidebar.
	 *
	 * @since 1.0.0
	 */
	function clothing_brand_store_add_sidebar() {

		global $post;

		$clothing_brand_store_global_layout = clothing_brand_store_get_option( 'clothing_brand_store_global_layout' );
		$clothing_brand_store_global_layout = apply_filters( 'clothing_brand_store_filter_theme_global_layout', $clothing_brand_store_global_layout );

		// Check if single.
		if ( $post && is_singular() ) {
			$clothing_brand_store_post_options = get_post_meta( $post->ID, 'clothing_brand_store_theme_settings', true );
			if ( isset( $clothing_brand_store_post_options['post_layout'] ) && ! empty( $clothing_brand_store_post_options['clothing_brand_store_post_layout'] ) ) {
				$clothing_brand_store_global_layout = $clothing_brand_store_post_options['clothing_brand_store_post_layout'];
			}
		}

		// Include primary sidebar.
		if ( 'no-sidebar' !== $clothing_brand_store_global_layout ) {
			get_sidebar();
		}
		// Include Secondary sidebar.
		switch ( $clothing_brand_store_global_layout ) {
			case 'three-columns':
			get_sidebar( 'secondary' );
			break;

			default:
			break;
		}

		// Include Secondary sidebar 1.
		switch ( $clothing_brand_store_global_layout ) {
			case 'four-columns':
			get_sidebar( 'secondary' );
			break;

			default:
			break;
		}

	}

endif;

add_action( 'clothing_brand_store_action_sidebar', 'clothing_brand_store_add_sidebar' );

//////////////////////////////////////// single page


if ( ! function_exists( 'clothing_brand_store_add_image_in_single_display' ) ) :

	/**
	 * Add image in single post.
	 *
	 * @since 1.0.0
	 */
	function clothing_brand_store_add_image_in_single_display() {

		global $post;

		if ( has_post_thumbnail() ) {

			$values = get_post_meta( $post->ID, 'clothing_brand_store_theme_settings', true );
			$clothing_brand_store_theme_settings_single_image = isset( $values['clothing_brand_store_single_image'] ) ? esc_attr( $values['clothing_brand_store_single_image'] ) : '';

			if ( ! $clothing_brand_store_theme_settings_single_image ) {
				$clothing_brand_store_theme_settings_single_image = clothing_brand_store_get_option( 'clothing_brand_store_single_image' );
			}

			if ( 'disable' !== $clothing_brand_store_theme_settings_single_image ) {
				$args = array(
					'class' => 'alignleft',
				);
				the_post_thumbnail( esc_attr( $clothing_brand_store_theme_settings_single_image ), $args );
			}
		}

	}

endif;

add_action( 'clothing_brand_store_single_image', 'clothing_brand_store_add_image_in_single_display' );

if ( ! function_exists( 'clothing_brand_store_footer_goto_top' ) ) :

	/**
	 * Go to top.
	 *
	 * @since 1.0.0
	 */
	function clothing_brand_store_footer_goto_top() {

		$clothing_brand_store_show_progress_bar =
		clothing_brand_store_get_option( 'clothing_brand_store_progress_bar' );

		if ( true === $clothing_brand_store_show_progress_bar ) :
			echo '<div id="elemento-progress-bar" class="theme-progress-bar top"></div>';
		endif;
        
        $clothing_brand_store_show_scroll_to_top = clothing_brand_store_get_option( 'clothing_brand_store_show_scroll_to_top' );
        if ( true === $clothing_brand_store_show_scroll_to_top ) :
		echo '<a id="scrollToTopBtn" href="#page">
				<svg id="progressCircle" width="50" height="50" aria-hidden="true">
					<circle cx="25" cy="25" r="22" stroke-width="4" fill="none"/>
				</svg>
				<i class="fa-solid fa-arrow-up"></i>
				</a>';
		endif;

	}

endif;

add_action( 'clothing_brand_store_action_after', 'clothing_brand_store_footer_goto_top', 20 );