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

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

add_action( 'solar_panel_distributor_action_before', 'solar_panel_distributor_skip_to_content', 15 );

// Middle Header

if ( ! function_exists( 'solar_panel_distributor_site_branding' ) ) :

	/**
	 * Site branding.
	 *
	 * @since 1.0.0
	 */
	function solar_panel_distributor_site_branding() {
		$solar_panel_distributor_header_top_text = solar_panel_distributor_get_option( 'solar_panel_distributor_header_top_text' );

		$solar_panel_distributor_header_top_location = solar_panel_distributor_get_option( 'solar_panel_distributor_header_top_location' );
		$solar_panel_distributor_header_top_email = solar_panel_distributor_get_option( 'solar_panel_distributor_header_top_email' );

		$solar_panel_distributor_header_top_button_text = solar_panel_distributor_get_option( 'solar_panel_distributor_header_top_button_text' );
		$solar_panel_distributor_header_top_button_link = solar_panel_distributor_get_option( 'solar_panel_distributor_header_top_button_link' );

		$solar_panel_distributor_header_social_facebook_link = solar_panel_distributor_get_option( 'solar_panel_distributor_header_social_facebook_link' );
		$solar_panel_distributor_header_social_twitter_link = solar_panel_distributor_get_option( 'solar_panel_distributor_header_social_twitter_link' );
		$solar_panel_distributor_header_social_instagram_link = solar_panel_distributor_get_option( 'solar_panel_distributor_header_social_instagram_link' );
		$solar_panel_distributor_header_social_youtube_link = solar_panel_distributor_get_option( 'solar_panel_distributor_header_social_youtube_link' );
		$solar_panel_distributor_header_social_pintrest_link = solar_panel_distributor_get_option( 'solar_panel_distributor_header_social_pintrest_link' );

		$solar_panel_distributor_header_top_phone_text = solar_panel_distributor_get_option( 'solar_panel_distributor_header_top_phone_text' );
		$solar_panel_distributor_header_top_phone_number = solar_panel_distributor_get_option( 'solar_panel_distributor_header_top_phone_number' );

		$solar_panel_distributor_data_sticky = solar_panel_distributor_get_option( 'solar_panel_distributor_show_data_sticky_setting' );
		?>

		<div class="topheader">
			<div class="container">
				<div class="row">
					<div class="col-lg-7 col-md-7 align-self-center">
						<?php if( !empty($solar_panel_distributor_header_top_text) ):?>
							<p class="mb-0"><?php echo esc_html($solar_panel_distributor_header_top_text);?></p>
						<?php endif; ?>
					</div>
					<div class="col-lg-5 col-md-5 align-self-center">
						<div class="topheader-box">
							<?php if( !empty($solar_panel_distributor_header_top_location) ):?>
								<p class="mb-0"><span class="dashicons dashicons-location me-2"></span><?php echo esc_html($solar_panel_distributor_header_top_location);?></p>
							<?php endif; ?>
							<?php if( !empty($solar_panel_distributor_header_top_email) ):?>
								<p class="mb-0" ><span class="dashicons dashicons-email me-2"></span><?php echo esc_html($solar_panel_distributor_header_top_email);?></p>
							<?php endif; ?>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div id="middle-header" data-sticky= "<?php echo esc_attr($solar_panel_distributor_data_sticky); ?>">
			<div class="container">
				<div class="row">
					<div class="col-lg-4 col-md-4 align-self-center  ">
					    <div class="site-branding mb-3 mb-lg-0 text-lg-start text-center">
							<?php solar_panel_distributor_the_custom_logo(); ?>
							<?php $solar_panel_distributor_show_title = solar_panel_distributor_get_option( 'solar_panel_distributor_show_title' ); ?>
							<?php $solar_panel_distributor_show_tagline = solar_panel_distributor_get_option( 'solar_panel_distributor_show_tagline' ); ?>
							<?php if ( true === $solar_panel_distributor_show_title || true === $solar_panel_distributor_show_tagline ) :  ?>
								<div id="site-identity" class="text-center text-md-center text-lg-start">
									<?php if ( true === $solar_panel_distributor_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 === $solar_panel_distributor_show_tagline ) :  ?>
										<p class="site-description"><?php bloginfo( 'description' ); ?></p>
									<?php endif; ?>
								</div>
							<?php endif; ?>
					    </div>
					</div>
					<div class="col-lg-3 col-md-3 align-self-center media-div text-md-start text-center">
						<?php if( !empty($solar_panel_distributor_header_social_facebook_link) ):?>
							<a href="<?php echo esc_url($solar_panel_distributor_header_social_facebook_link);?>"><span class="dashicons dashicons-facebook-alt"></span></a>
						<?php endif; ?>
						<?php if( !empty($solar_panel_distributor_header_social_twitter_link) ):?>
							<a href="<?php echo esc_url($solar_panel_distributor_header_social_twitter_link);?>"><span class="dashicons dashicons-twitter"></span></a>
						<?php endif; ?>
						<?php if( !empty($solar_panel_distributor_header_social_instagram_link) ):?>
							<a href="<?php echo esc_url($solar_panel_distributor_header_social_instagram_link);?>"><span class="dashicons dashicons-instagram"></span></a>
						<?php endif; ?>
						<?php if( !empty($solar_panel_distributor_header_social_youtube_link) ):?>
							<a href="<?php echo esc_url($solar_panel_distributor_header_social_youtube_link);?>"><span class="dashicons dashicons-youtube"></span></a>
						<?php endif; ?>
						<?php if( !empty($solar_panel_distributor_header_social_pintrest_link) ):?>
							<a href="<?php echo esc_url($solar_panel_distributor_header_social_pintrest_link);?>"><span class="dashicons dashicons-pinterest"></span></a>
						<?php endif; ?>
					</div>
					<div class="col-lg-3 col-md-3 align-self-center">
						<?php if( !empty($solar_panel_distributor_header_top_phone_text) || !empty($solar_panel_distributor_header_top_phone_number) ):?>
							<div class="row top-phone my-3 my-md-0 text-center text-md-start">
								<div class="col-lg-2 col-md-2 align-self-center">
									<span class="dashicons dashicons-phone"></span>
								</div>
								<div class="col-lg-10 col-md-10 align-self-center">
									<p class="mb-0"><?php echo esc_html($solar_panel_distributor_header_top_phone_text);?></p>
									<h5 class="mb-0"><?php echo esc_html($solar_panel_distributor_header_top_phone_number);?></h5>
								</div>
							</div>
						<?php endif; ?>
					</div>
					<div class="col-lg-2 col-md-2 align-self-center">
						<div class="top-btn text-md-end text-center">
							<?php if( !empty($solar_panel_distributor_header_top_button_text) || !empty($solar_panel_distributor_header_top_button_link) ):?>
								<a href="<?php echo esc_url($solar_panel_distributor_header_top_button_link);?>"><?php echo esc_html($solar_panel_distributor_header_top_button_text);?></a>
							<?php endif; ?>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div id="menu-header">
			<div class="container">
				<div class="center-header-box">
					<div class="toggle-menu gb_menu">
						<button onclick="solar_panel_distributor_gb_Menu_open()" class="gb_toggle"><?php esc_html_e('Menu','solar-panel-distributor'); ?></button>
					</div>
					<div id="gb_responsive" class="nav side_gb_nav">
						<nav id="top_gb_menu" class="gb_nav_menu" role="navigation" aria-label="<?php esc_attr_e( 'Menu', 'solar-panel-distributor' ); ?>">
							<?php 
							    wp_nav_menu( array( 
									'theme_location' => 'primary-menu',
									'container_class' => 'gb_navigation clearfix' ,
									'menu_class' => 'clearfix',
									'items_wrap' => '<ul id="%1$s" class="%2$s mobile_nav m-0 px-0">%3$s</ul>',
									'fallback_cb' => 'wp_page_menu',
							    ) ); 
							?>
							<a href="javascript:void(0)" class="closebtn gb_menu" onclick="solar_panel_distributor_gb_Menu_close()">x<span class="screen-reader-text"><?php esc_html_e('Close Menu','solar-panel-distributor'); ?></span></a>
						</nav>
					</div>
				</div>
			</div>
		</div>

	    <?php
	}

endif;

add_action( 'solar_panel_distributor_action_header', 'solar_panel_distributor_site_branding' );


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

if ( ! function_exists( 'solar_panel_distributor_footer_copyright' ) ) :

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

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

		// Copyright content.
		$solar_panel_distributor_copyright_text = solar_panel_distributor_get_option( 'solar_panel_distributor_copyright_text' );
		$solar_panel_distributor_copyright_text = apply_filters( 'solar_panel_distributor_filter_copyright_text', $solar_panel_distributor_copyright_text );
		if ( ! empty( $solar_panel_distributor_copyright_text ) ) {
			$solar_panel_distributor_copyright_text = wp_kses_data( $solar_panel_distributor_copyright_text );
		}

		// Powered by content.
		$solar_panel_distributor_powered_by_text = sprintf( __( 'Solar Panel Distributor by %s', 'solar-panel-distributor' ), '<span>' . __( 'Mizan Themes', 'solar-panel-distributor' ) . '</span>' );
		?>

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

		    <?php if ( ! empty( $solar_panel_distributor_powered_by_text ) ) : ?>
			    <div class="colophon-column">
			    	<div class="site-info">
					<a href="<?php echo esc_url('https://www.wpelemento.com/products/solar-panel-distributor/','solar-panel-distributor'); ?>"><?php echo $solar_panel_distributor_powered_by_text; ?></a>
			    	</div><!-- .site-info -->
			    </div><!-- .colophon-column -->
		    <?php endif; ?>
		</div><!-- colophon-inner -->
		
	    <?php
	}

endif;

add_action( 'solar_panel_distributor_action_footer', 'solar_panel_distributor_footer_copyright', 10 );

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


if ( ! function_exists( 'solar_panel_distributor_add_sidebar' ) ) :

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

		global $post;

		$solar_panel_distributor_global_layout = solar_panel_distributor_get_option( 'solar_panel_distributor_global_layout' );
		$solar_panel_distributor_global_layout = apply_filters( 'solar_panel_distributor_filter_theme_global_layout', $solar_panel_distributor_global_layout );

		// Check if single.
		if ( $post && is_singular() ) {
			$solar_panel_distributor_post_options = get_post_meta( $post->ID, 'solar_panel_distributor_theme_settings', true );
			if ( isset( $solar_panel_distributor_post_options['post_layout'] ) && ! empty( $solar_panel_distributor_post_options['solar_panel_distributor_post_layout'] ) ) {
				$solar_panel_distributor_global_layout = $solar_panel_distributor_post_options['solar_panel_distributor_post_layout'];
			}
		}

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

			default:
			break;
		}

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

			default:
			break;
		}

	}

endif;

add_action( 'solar_panel_distributor_action_sidebar', 'solar_panel_distributor_add_sidebar' );

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


if ( ! function_exists( 'solar_panel_distributor_add_image_in_single_display' ) ) :

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

		global $post;

		if ( has_post_thumbnail() ) {

			$values = get_post_meta( $post->ID, 'solar_panel_distributor_theme_settings', true );
			$solar_panel_distributor_theme_settings_single_image = isset( $values['solar_panel_distributor_single_image'] ) ? esc_attr( $values['solar_panel_distributor_single_image'] ) : '';

			if ( ! $solar_panel_distributor_theme_settings_single_image ) {
				$solar_panel_distributor_theme_settings_single_image = solar_panel_distributor_get_option( 'solar_panel_distributor_single_image' );
			}

			if ( 'disable' !== $solar_panel_distributor_theme_settings_single_image ) {
				$args = array(
					'class' => 'aligncenter blog-post-img',
				);
				the_post_thumbnail( esc_attr( $solar_panel_distributor_theme_settings_single_image ), $args );
			}
		}

	}

endif;

add_action( 'solar_panel_distributor_single_image', 'solar_panel_distributor_add_image_in_single_display' );

if ( ! function_exists( 'solar_panel_distributor_footer_goto_top' ) ) :

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

		$solar_panel_distributor_show_progress_bar =
		solar_panel_distributor_get_option( 'solar_panel_distributor_progress_bar' );

		if ( true === $solar_panel_distributor_show_progress_bar ) :
			echo '<div id="elemento-progress-bar" class="theme-progress-bar top"></div>';
		endif;
        
        $solar_panel_distributor_show_scroll_to_top = solar_panel_distributor_get_option( 'solar_panel_distributor_show_scroll_to_top' );
        if ( true === $solar_panel_distributor_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( 'solar_panel_distributor_action_after', 'solar_panel_distributor_footer_goto_top', 20 );