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

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

add_action( 'florist_elementor_action_before', 'florist_elementor_skip_to_content', 15 );

// Middle Header

if ( ! function_exists( 'florist_elementor_site_branding' ) ) :

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

		$florist_elementor_header_text = florist_elementor_get_option( 'florist_elementor_header_text' );
		$florist_elementor_header_top_location = florist_elementor_get_option( 'florist_elementor_header_top_location');
		$florist_elementor_header_top_location_link = florist_elementor_get_option( 'florist_elementor_header_top_location_link' );
		$florist_elementor_header_top_email = florist_elementor_get_option( 'florist_elementor_header_top_email' );
		$florist_elementor_header_top_phone_number = florist_elementor_get_option( 'florist_elementor_header_top_phone_number' );

		$florist_elementor_header_social_facebook_link = florist_elementor_get_option( 'florist_elementor_header_social_facebook_link' );
		$florist_elementor_header_social_twitter_link = florist_elementor_get_option( 'florist_elementor_header_social_twitter_link' );
		$florist_elementor_header_social_instagram_link = florist_elementor_get_option( 'florist_elementor_header_social_instagram_link' );
		$florist_elementor_header_social_youtube_link = florist_elementor_get_option( 'florist_elementor_header_social_youtube_link' );

		$florist_elementor_header_top_text = florist_elementor_get_option( 'florist_elementor_header_top_text' );
		$florist_elementor_account_button = florist_elementor_get_option( 'florist_elementor_account_button' );
		$florist_elementor_data_sticky = florist_elementor_get_option( 'florist_elementor_show_data_sticky_setting' );
		?>

		<div class="top-header py-4">
			<div class="container">
				<?php if( !empty($florist_elementor_header_top_text)):?>
					<p class="mb-0 adver-text text-center"><?php echo esc_html($florist_elementor_header_top_text);?></p>
				<?php endif; ?>
			</div>
		</div>
		<div id="middle-header" class="py-2" data-sticky= "<?php echo esc_attr($florist_elementor_data_sticky); ?>">
			<div class="container">
				<div class="row">
					<div class="col-xl-2 col-lg-3 col-md-4 col-12 align-self-center">
						<div class="site-branding mb-3 mb-lg-0 text-md-start text-center">
							<?php florist_elementor_the_custom_logo(); ?>
							<?php $florist_elementor_show_title = florist_elementor_get_option( 'florist_elementor_show_title' ); ?>
							<?php $florist_elementor_show_tagline = florist_elementor_get_option( 'florist_elementor_show_tagline' ); ?>
							<?php if ( true === $florist_elementor_show_title || true === $florist_elementor_show_tagline ) :  ?>
								<div id="site-identity" class="text-center text-md-start text-lg-start">
									<?php if ( true === $florist_elementor_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 === $florist_elementor_show_tagline ) :  ?>
										<p class="site-description"><?php bloginfo( 'description' ); ?></p>
									<?php endif; ?>
								</div>
							<?php endif; ?>
						</div>
					</div>
					<div class="col-xl-8 col-lg-7 col-md-4 col-3 align-self-center text-center">
						<div class="top-menu">
							<div class="toggle-menu gb_menu">
								<button onclick="florist_elementor_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', 'florist-elementor' ); ?>">
									<?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 px-0">%3$s</ul>',
											'fallback_cb' => 'wp_page_menu',
										) );
									?>
									<a href="javascript:void(0)" class="closebtn gb_menu" onclick="florist_elementor_gb_Menu_close()">x<span class="screen-reader-text"><?php esc_html_e('Close Menu','florist-elementor'); ?></span></a>
								</nav>
							</div>
						</div>
					</div>
					<div class="col-xl-2 col-lg-2 col-md-4 col-9 align-self-center text-center d-flex justify-content-evenly">
						<?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','florist-elementor' ); ?>"><i class="fa-solid fa-cart-shopping"></i></a>
						<?php }?>
						<?php if (!empty($florist_elementor_account_button)): ?>
							<?php if(class_exists('woocommerce')){ ?>
								<?php if ( is_user_logged_in() ) { ?>
									<a class="my-account" href="<?php echo esc_url( get_permalink( get_option('woocommerce_myaccount_page_id') ) ); ?>" title="<?php esc_attr_e('My Account','florist-elementor'); ?>"><i class="fa-solid fa-user me-2"></i></span></a>
								<?php }
								else { ?>
									<a class="my-account" href="<?php echo esc_url( get_permalink( get_option('woocommerce_myaccount_page_id') ) ); ?>" title="<?php esc_attr_e('Login / Register','florist-elementor'); ?>"><i class="fa-solid fa-user me-2"></i></span></a>
								<?php } ?>
							<?php }?>
						<?php endif; ?>
						<div class="toggle-btn">
							<a class="sidebar-toggle" id="sidebar-pop" href="#"><i class="fas fa-bars"></i></a>
						</div>
					</div>
					<div class="header-sidebar">
						<div class="close-pop"><a href="#content"><i class="fas fa-window-close"></i></a></div>
						<div class="menu-drawer">
							<div class="logo-collapse">
								<div class="site-branding mb-3 mb-lg-0 text-md-start text-center">
									<?php florist_elementor_the_custom_logo(); ?>
									<?php $florist_elementor_show_title = florist_elementor_get_option( 'florist_elementor_show_title' ); ?>
									<?php $florist_elementor_show_tagline = florist_elementor_get_option( 'florist_elementor_show_tagline' ); ?>
									<?php if ( true === $florist_elementor_show_title || true === $florist_elementor_show_tagline ) :  ?>
										<div id="site-identity" class="text-center text-md-start text-lg-start">
											<?php if ( true === $florist_elementor_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 === $florist_elementor_show_tagline ) :  ?>
												<p class="site-description"><?php bloginfo( 'description' ); ?></p>
											<?php endif; ?>
										</div>
									<?php endif; ?>
								</div>
							</div>
							<div class="row">
								<?php if( !empty($florist_elementor_header_text)):?>
									<p class=""><?php echo esc_html($florist_elementor_header_text);?></p>
								<?php endif; ?>
							</div>
							<div class="row">
								<?php if( !empty($florist_elementor_header_top_location) ):?>
									<p class="topheader-location"><a href="<?php echo esc_url($florist_elementor_header_top_location_link);?>"><span class="dashicons dashicons-location me-2"></span><?php echo esc_html($florist_elementor_header_top_location);?></a></p>
								<?php endif; ?>
							</div>
							<div class="row">
								<?php if( !empty($florist_elementor_header_top_email) ):?>
									<p class="topheader-mail"><a href="mailto:<?php echo esc_attr($florist_elementor_header_top_email);?>"><span class="dashicons dashicons-email me-2"></span><?php echo esc_html($florist_elementor_header_top_email);?></a></p>
								<?php endif; ?>
							</div>
							<div class="row">
								<?php if( !empty($florist_elementor_header_top_phone_number) ):?>
									<p class="topheader-phone"><a href="tel:<?php echo esc_attr($florist_elementor_header_top_phone_number);?>"><span class="dashicons dashicons-phone me-2"></span><?php echo esc_html($florist_elementor_header_top_phone_number);?></a></p>
								<?php endif; ?>
							</div>
							<div class="row media-div">
								<?php if( !empty($florist_elementor_header_social_facebook_link) ):?>
									<a href="<?php echo esc_url($florist_elementor_header_social_facebook_link);?>" target="_blank" ><span class="dashicons dashicons-facebook-alt"></span></a>
								<?php endif; ?>
								<?php if( !empty($florist_elementor_header_social_twitter_link) ):?>
									<a href="<?php echo esc_url($florist_elementor_header_social_twitter_link);?>" target="_blank" ><span class="dashicons dashicons-twitter"></span></a>
								<?php endif; ?>
								<?php if( !empty($florist_elementor_header_social_instagram_link) ):?>
									<a href="<?php echo esc_url($florist_elementor_header_social_instagram_link);?>" target="_blank" ><span class="dashicons dashicons-instagram"></span></a>
								<?php endif; ?>
								<?php if( !empty($florist_elementor_header_social_youtube_link) ):?>
									<a href="<?php echo esc_url($florist_elementor_header_social_youtube_link);?>" target="_blank" ><span class="dashicons dashicons-youtube"></span></a>
								<?php endif; ?>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		
	    <?php
	}

endif;

add_action( 'florist_elementor_action_header', 'florist_elementor_site_branding' );

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

if ( ! function_exists( 'florist_elementor_footer_copyright' ) ) :

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

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

		// Copyright content.
		$florist_elementor_copyright_text = florist_elementor_get_option( 'florist_elementor_copyright_text' );
		$florist_elementor_copyright_text = apply_filters( 'florist_elementor_filter_copyright_text', $florist_elementor_copyright_text );
		if ( ! empty( $florist_elementor_copyright_text ) ) {
			$florist_elementor_copyright_text = wp_kses_data( $florist_elementor_copyright_text );
		}

		// Powered by content.
		$florist_elementor_powered_by_text = sprintf( __( 'Florist Elementor by %s', 'florist-elementor' ), '<span>' . __( 'Mizan Themes', 'florist-elementor' ) . '</span>' );
		?>

		<div class="colophon-inner <?php echo esc_attr( get_theme_mod('florist_elementor_sticky_copyright_enable', false) ? 'sticky-copyright' : 'close-sticky' ); ?>">
		    <?php if ( ! empty( $florist_elementor_copyright_text ) ) : ?>
			    <div class="colophon-column">
			    	<div class="copyright">
					<a href="<?php echo esc_url('https://www.mizanthemes.com/products/free-bouquet-wordpress-theme','florist-elementor'); ?>"><?php echo $florist_elementor_copyright_text; ?></a>
			    	</div><!-- .copyright -->
			    </div><!-- .colophon-column -->
		    <?php endif; ?>

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

endif;

add_action( 'florist_elementor_action_footer', 'florist_elementor_footer_copyright', 10 );

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

if ( ! function_exists( 'florist_elementor_add_sidebar' ) ) :

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

		global $post;

		$florist_elementor_global_layout = florist_elementor_get_option( 'florist_elementor_global_layout' );
		$florist_elementor_global_layout = apply_filters( 'florist_elementor_filter_theme_global_layout', $florist_elementor_global_layout );

		// Check if single.
		if ( $post && is_singular() ) {
			$florist_elementor_post_options = get_post_meta( $post->ID, 'florist_elementor_theme_settings', true );
			if ( isset( $florist_elementor_post_options['post_layout'] ) && ! empty( $florist_elementor_post_options['florist_elementor_post_layout'] ) ) {
				$florist_elementor_global_layout = $florist_elementor_post_options['florist_elementor_post_layout'];
			}
		}

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

			default:
			break;
		}

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

			default:
			break;
		}

	}

endif;

add_action( 'florist_elementor_action_sidebar', 'florist_elementor_add_sidebar' );

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


if ( ! function_exists( 'florist_elementor_add_image_in_single_display' ) ) :

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

		global $post;

		if ( has_post_thumbnail() ) {

			$values = get_post_meta( $post->ID, 'florist_elementor_theme_settings', true );
			$florist_elementor_theme_settings_single_image = isset( $values['florist_elementor_single_image'] ) ? esc_attr( $values['florist_elementor_single_image'] ) : '';

			if ( ! $florist_elementor_theme_settings_single_image ) {
				$florist_elementor_theme_settings_single_image = florist_elementor_get_option( 'florist_elementor_single_image' );
			}

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

	}

endif;

add_action( 'florist_elementor_single_image', 'florist_elementor_add_image_in_single_display' );

if ( ! function_exists( 'florist_elementor_footer_goto_top' ) ) :

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

		$florist_elementor_show_progress_bar =
		florist_elementor_get_option( 'florist_elementor_progress_bar' );

		if ( true === $florist_elementor_show_progress_bar ) :
			echo '<div id="elemento-progress-bar" class="theme-progress-bar top"></div>';
		endif;
        
        $florist_elementor_show_scroll_to_top = florist_elementor_get_option( 'florist_elementor_show_scroll_to_top' );
        if ( true === $florist_elementor_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( 'florist_elementor_action_after', 'florist_elementor_footer_goto_top', 20 );