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

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

add_action( 'unique_fun_center_action_before', 'unique_fun_center_skip_to_content', 15 );

// Middle Header

if ( ! function_exists( 'unique_fun_center_site_branding' ) ) :

	/**
	 * Site branding.
	 *
	 * @since 1.0.0
	 */
	function unique_fun_center_site_branding() {
		$unique_fun_center_header_top_button = unique_fun_center_get_option( 'unique_fun_center_header_top_button' );
		$unique_fun_center_header_top_buttonlink = unique_fun_center_get_option( 'unique_fun_center_header_top_buttonlink' );

		$unique_fun_center_header_opening_time = unique_fun_center_get_option( 'unique_fun_center_header_opening_time' );
		$unique_fun_center_header_location = unique_fun_center_get_option( 'unique_fun_center_header_location' );
		$unique_fun_center_header_email_address = unique_fun_center_get_option( 'unique_fun_center_header_email_address' );

		$unique_fun_center_header_facebook_link = unique_fun_center_get_option( 'unique_fun_center_header_facebook_link' );
		$unique_fun_center_header_twitter_link = unique_fun_center_get_option( 'unique_fun_center_header_twitter_link' );
		$unique_fun_center_header_instagram_link = unique_fun_center_get_option( 'unique_fun_center_header_instagram_link');
		$unique_fun_center_header_youtube_link = unique_fun_center_get_option( 'unique_fun_center_header_youtube_link' );
		$unique_fun_center_data_sticky = unique_fun_center_get_option( 'unique_fun_center_show_data_sticky_setting' );

		?>
        <?php $unique_fun_center_show_header_top = unique_fun_center_get_option( 'unique_fun_center_show_header_top' ); ?>
		<?php if ( true === $unique_fun_center_show_header_top ) :  ?>
		<div id="top-header" class="text-center">
			<div class="container">
				<div class="row">
					<div class="col-xl-2 col-lg-3 col-md-3 text-md-start">
						<?php if( !empty($unique_fun_center_header_location) ):?>
						    <p class="mb-0"><span class="dashicons dashicons-location me-2"></span><?php echo esc_html($unique_fun_center_header_location);?></p>
						<?php endif;?>
					</div>
					<div class="col-xl-3 col-lg-3 col-md-3 text-center">
						<?php if( !empty($unique_fun_center_header_email_address) ):?>
						    <p class="mb-0"><span class="dashicons dashicons-email me-2"></span><a href="mailto:<?php echo esc_html($unique_fun_center_header_email_address);?>"><?php echo esc_html($unique_fun_center_header_email_address);?></a></p>
						<?php endif;?>
					</div>
					<div class="col-xl-4 col-lg-4 col-md-4 text-center">
						<?php if( !empty($unique_fun_center_header_opening_time) ):?>
						    <p class="mb-0"><span class="dashicons dashicons-clock me-2"></span> <?php echo esc_html($unique_fun_center_header_opening_time);?></p>
						<?php endif;?>
					</div>
					<?php $unique_fun_center_show_social_icon = unique_fun_center_get_option( 'unique_fun_center_show_social_icon' ); ?>
					<?php if ( true === $unique_fun_center_show_social_icon ) :  ?>
						<div class="col-xl-3 col-lg-2 col-md-2 text-md-end">
							<?php if( !empty($unique_fun_center_header_facebook_link) || !empty($unique_fun_center_header_twitter_link) || !empty($unique_fun_center_header_instagram_link) || !empty($unique_fun_center_header_youtube_link) ):?>
								<span class="follow-us"><?php esc_html_e('Follow Us :','unique-fun-center'); ?></span>
								<?php if( !empty($unique_fun_center_header_facebook_link) ):?>
								    <a href="<?php echo esc_url($unique_fun_center_header_facebook_link);?> " class="mb-0" target='_blank'><span class="dashicons dashicons-facebook-alt"></span></a>
								<?php endif;?>
								<?php if( !empty($unique_fun_center_header_twitter_link) ):?>
								    <a href="<?php echo esc_url($unique_fun_center_header_twitter_link);?>" class="mb-0" target='_blank'><span class="dashicons dashicons-twitter"></span></a>
								<?php endif;?>
								<?php if( !empty($unique_fun_center_header_instagram_link) ):?>
								    <a href="<?php echo esc_url($unique_fun_center_header_instagram_link);?>" class="mb-0" target='_blank'><span class="dashicons dashicons-instagram"></span></a>
								<?php endif;?>
								<?php if( !empty($unique_fun_center_header_youtube_link) ):?>
								    <a href="<?php echo esc_url($unique_fun_center_header_youtube_link);?>" class="mb-0" target='_blank'><span class="dashicons dashicons-youtube"></span></a>
								<?php endif;?>
							<?php endif;?>
						</div>
					<?php endif;?>
				</div>
			</div>
		</div>
		<?php endif; ?>

		<div id="middle-header" data-sticky= "<?php echo esc_attr($unique_fun_center_data_sticky); ?>">
			<div class="container">
				<div class="row">
				    <div class="col-lg-3 col-md-4 col-sm-4 align-self-center text-center text-lg-start">
						<div class="site-branding mb-3 mb-lg-0">
							<?php unique_fun_center_the_custom_logo(); ?>
							<?php $unique_fun_center_show_title = unique_fun_center_get_option( 'unique_fun_center_show_title' ); ?>
							<?php $unique_fun_center_show_tagline = unique_fun_center_get_option( 'unique_fun_center_show_tagline' ); ?>
							<?php if ( true === $unique_fun_center_show_title || true === $unique_fun_center_show_tagline ) :  ?>
								<div id="site-identity" class="text-center text-md-start">
									<?php if ( true === $unique_fun_center_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 === $unique_fun_center_show_tagline ) :  ?>
										<p class="site-description"><?php bloginfo( 'description' ); ?></p>
									<?php endif; ?>
								</div>
							<?php endif; ?>
						</div>
					</div>
					<div class="col-lg-6 col-md-4 col-sm-4 col-4 align-self-center">
						<div class="toggle-menu gb_menu text-md-center my-2 text-start">
							<button onclick="unique_fun_center_gb_Menu_open()" class="gb_toggle"><span class="dashicons dashicons-menu-alt"></span></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', 'unique-fun-center' ); ?>">
								<?php
									wp_nav_menu( array( 
										'theme_location' => 'primary-menu',
										'container_class' => 'gb_navigation clearfix' ,
										'menu_class' => 'gb_navigation 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="unique_fun_center_gb_Menu_close()">x<span class="screen-reader-text"><?php esc_html_e('Close Menu','unique-fun-center'); ?></span></a>
							</nav>
						</div>
					</div>
					<div class="col-lg-3 col-md-4 col-sm-4 col-8 align-self-center text-end">
						<?php if( !empty($unique_fun_center_header_top_button) || !empty($unique_fun_center_header_top_buttonlink) ):?>
						    <p class="header-button mb-0">
						    	<a href="<?php echo esc_url($unique_fun_center_header_top_buttonlink);?>" target='_blank'><?php echo esc_html($unique_fun_center_header_top_button);?> <span class="dashicons dashicons-arrow-right-alt"></span></a>
						   	</p>
						<?php endif;?>
					</div>
				</div>
			</div>
		</div>

	    <?php
	}

endif;

add_action( 'unique_fun_center_action_header', 'unique_fun_center_site_branding' );


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

if ( ! function_exists( 'unique_fun_center_footer_copyright' ) ) :

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

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

		// Copyright content.
		$unique_fun_center_copyright_text = unique_fun_center_get_option( 'unique_fun_center_copyright_text' );
		$unique_fun_center_copyright_text = apply_filters( 'unique_fun_center_filter_copyright_text', $unique_fun_center_copyright_text );
		if ( ! empty( $unique_fun_center_copyright_text ) ) {
			$unique_fun_center_copyright_text = wp_kses_data( $unique_fun_center_copyright_text );
		}

		// Powered by content.
		$unique_fun_center_powered_by_text = sprintf( __( 'Unique Fun Center by %s', 'unique-fun-center' ), '<span>' . __( 'Mizan Themes', 'unique-fun-center' ) . '</span>' );
		?>

		<div class="colophon-inner <?php echo esc_attr( get_theme_mod('unique_fun_center_sticky_copyright_enable', false) ? 'sticky-copyright' : 'close-sticky' ); ?>">
		    <?php if ( ! empty( $unique_fun_center_copyright_text ) ) : ?>
			    <div class="colophon-column">
			    	<div class="copyright">
						<a href="<?php echo esc_url('https://www.wpelemento.com/products/unique-fun-center/','unique-fun-center'); ?>"><?php echo $unique_fun_center_copyright_text; ?></a>
			    	</div><!-- .copyright -->
			    </div><!-- .colophon-column -->
		    <?php endif; ?>

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

endif;

add_action( 'unique_fun_center_action_footer', 'unique_fun_center_footer_copyright', 10 );

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

if ( ! function_exists( 'unique_fun_center_add_sidebar' ) ) :

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

		global $post;

		$unique_fun_center_global_layout = unique_fun_center_get_option( 'unique_fun_center_global_layout' );
		$unique_fun_center_global_layout = apply_filters( 'unique_fun_center_filter_theme_global_layout', $unique_fun_center_global_layout );

		// Check if single.
		if ( $post && is_singular() ) {
			$unique_fun_center_post_options = get_post_meta( $post->ID, 'unique_fun_center_theme_settings', true );
			if ( isset( $unique_fun_center_post_options['post_layout'] ) && ! empty( $unique_fun_center_post_options['unique_fun_center_post_layout'] ) ) {
				$unique_fun_center_global_layout = $unique_fun_center_post_options['unique_fun_center_post_layout'];
			}
		}

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

			default:
			break;
		}

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

			default:
			break;
		}

	}

endif;

add_action( 'unique_fun_center_action_sidebar', 'unique_fun_center_add_sidebar' );

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


if ( ! function_exists( 'unique_fun_center_add_image_in_single_display' ) ) :

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

		global $post;

		if ( has_post_thumbnail() ) {

			$values = get_post_meta( $post->ID, 'unique_fun_center_theme_settings', true );
			$unique_fun_center_theme_settings_single_image = isset( $values['unique_fun_center_single_image'] ) ? esc_attr( $values['unique_fun_center_single_image'] ) : '';

			if ( ! $unique_fun_center_theme_settings_single_image ) {
				$unique_fun_center_theme_settings_single_image = unique_fun_center_get_option( 'unique_fun_center_single_image' );
			}

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

	}

endif;

add_action( 'unique_fun_center_single_image', 'unique_fun_center_add_image_in_single_display' );

if ( ! function_exists( 'unique_fun_center_footer_goto_top' ) ) :

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

		$unique_fun_center_show_progress_bar =
		unique_fun_center_get_option( 'unique_fun_center_progress_bar' );

		if ( true === $unique_fun_center_show_progress_bar ) :
			echo '<div id="elemento-progress-bar" class="theme-progress-bar top"></div>';
		endif;
        
        $unique_fun_center_show_scroll_to_top = unique_fun_center_get_option( 'unique_fun_center_show_scroll_to_top' );
        if ( true === $unique_fun_center_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( 'unique_fun_center_action_after', 'unique_fun_center_footer_goto_top', 20 );