<?php
/**
 * Custom Functions.
 *
 * @package Solar Energy Engine
 */

if( !function_exists( 'solar_energy_engine_fonts_url' ) ) :

    //Google Fonts URL
    function solar_energy_engine_fonts_url(){

        $solar_energy_engine_font_families = array(
            'Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
        );

        $solar_energy_engine_fonts_url = add_query_arg( array(
            'family' => implode( '&family=', $solar_energy_engine_font_families ),
            'display' => 'swap',
        ), 'https://fonts.googleapis.com/css2' );

        return esc_url_raw($solar_energy_engine_fonts_url);

    }

endif;

if ( ! function_exists( 'solar_energy_engine_sub_menu_toggle_button' ) ) :

    function solar_energy_engine_sub_menu_toggle_button( $solar_energy_engine_args, $solar_energy_engine_item, $depth ) {

        // Add sub menu toggles to the main menu with toggles
        if ( $solar_energy_engine_args->theme_location == 'solar-energy-engine-primary-menu' && isset( $solar_energy_engine_args->show_toggles ) ) {
            
            // Wrap the menu item link contents in a div, used for positioning
            $solar_energy_engine_args->before = '<div class="submenu-wrapper">';
            $solar_energy_engine_args->after  = '';

            // Add a toggle to items with children
            if ( in_array( 'menu-item-has-children', $solar_energy_engine_item->classes ) ) {

                $solar_energy_engine_toggle_target_string = '.menu-item.menu-item-' . $solar_energy_engine_item->ID . ' > .sub-menu';

                // Add the sub menu toggle
                $solar_energy_engine_args->after .= '<button type="button" class="theme-aria-button submenu-toggle" data-toggle-target="' . $solar_energy_engine_toggle_target_string . '" data-toggle-type="slidetoggle" data-toggle-duration="250" aria-expanded="false"><span class="btn__content" tabindex="-1"><span class="screen-reader-text">' . esc_html__( 'Show sub menu', 'solar-energy-engine' ) . '</span>' . solar_energy_engine_get_theme_svg( 'chevron-down' ) . '</span></button>';

            }

            // Close the wrapper
            $solar_energy_engine_args->after .= '</div><!-- .submenu-wrapper -->';
            // Add sub menu icons to the main menu without toggles (the fallback menu)

        }elseif( $solar_energy_engine_args->theme_location == 'solar-energy-engine-primary-menu' ) {

            if ( in_array( 'menu-item-has-children', $solar_energy_engine_item->classes ) ) {

                $solar_energy_engine_args->before = '<div class="link-icon-wrapper">';
                $solar_energy_engine_args->after  = solar_energy_engine_get_theme_svg( 'chevron-down' ) . '</div>';

            } else {

                $solar_energy_engine_args->before = '';
                $solar_energy_engine_args->after  = '';

            }

        }

        return $solar_energy_engine_args;

    }

endif;

add_filter( 'nav_menu_item_args', 'solar_energy_engine_sub_menu_toggle_button', 10, 3 );

if ( ! function_exists( 'solar_energy_engine_the_theme_svg' ) ):
    
    function solar_energy_engine_the_theme_svg( $solar_energy_engine_svg_name, $solar_energy_engine_return = false ) {

        if( $solar_energy_engine_return ){

            return solar_energy_engine_get_theme_svg( $solar_energy_engine_svg_name ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in solar_energy_engine_get_theme_svg();.

        }else{

            echo solar_energy_engine_get_theme_svg( $solar_energy_engine_svg_name ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in solar_energy_engine_get_theme_svg();.

        }
    }

endif;

if ( ! function_exists( 'solar_energy_engine_get_theme_svg' ) ):

    function solar_energy_engine_get_theme_svg( $solar_energy_engine_svg_name ) {

        // Make sure that only our allowed tags and attributes are included.
        $solar_energy_engine_svg = wp_kses(
            solar_energy_engine_SVG_Icons::get_svg( $solar_energy_engine_svg_name ),
            array(
                'svg'     => array(
                    'class'       => true,
                    'xmlns'       => true,
                    'width'       => true,
                    'height'      => true,
                    'viewbox'     => true,
                    'aria-hidden' => true,
                    'role'        => true,
                    'focusable'   => true,
                ),
                'path'    => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'd'         => true,
                    'transform' => true,
                ),
                'polygon' => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'points'    => true,
                    'transform' => true,
                    'focusable' => true,
                ),
                'polyline' => array(
                    'fill'      => true,
                    'points'    => true,
                ),
                'line' => array(
                    'fill'      => true,
                    'x1'      => true,
                    'x2' => true,
                    'y1'    => true,
                    'y2' => true,
                ),
            )
        );
        if ( ! $solar_energy_engine_svg ) {
            return false;
        }
        return $solar_energy_engine_svg;

    }

endif;


if( !function_exists( 'solar_energy_engine_post_category_list' ) ) :

    // Post Category List.
    function solar_energy_engine_post_category_list( $solar_energy_engine_select_cat = true ){

        $solar_energy_engine_post_cat_lists = get_categories(
            array(
                'hide_empty' => '0',
                'exclude' => '1',
            )
        );

        $solar_energy_engine_post_cat_cat_array = array();
        if( $solar_energy_engine_select_cat ){

            $solar_energy_engine_post_cat_cat_array[''] = esc_html__( '-- Select Category --','solar-energy-engine' );

        }

        foreach ( $solar_energy_engine_post_cat_lists as $solar_energy_engine_post_cat_list ) {

            $solar_energy_engine_post_cat_cat_array[$solar_energy_engine_post_cat_list->slug] = $solar_energy_engine_post_cat_list->name;

        }

        return $solar_energy_engine_post_cat_cat_array;
    }

endif;

if( !function_exists('solar_energy_engine_single_post_navigation') ):

    function solar_energy_engine_single_post_navigation(){

        $solar_energy_engine_default = solar_energy_engine_get_default_theme_options();
        $solar_energy_engine_twp_navigation_type = esc_attr( get_post_meta( get_the_ID(), 'twp_disable_ajax_load_next_post', true ) );
        $solar_energy_engine_current_id = '';
        $article_wrap_class = '';
        global $post;
        $solar_energy_engine_current_id = $post->ID;
        if( $solar_energy_engine_twp_navigation_type == '' || $solar_energy_engine_twp_navigation_type == 'global-layout' ){
            $solar_energy_engine_twp_navigation_type = get_theme_mod('solar_energy_engine_twp_navigation_type', $solar_energy_engine_default['solar_energy_engine_twp_navigation_type']);
        }

        if( $solar_energy_engine_twp_navigation_type != 'no-navigation' && 'post' === get_post_type() ){

            if( $solar_energy_engine_twp_navigation_type == 'theme-normal-navigation' ){ ?>

                <div class="navigation-wrapper">
                    <?php
                    // Previous/next post navigation.
                    the_post_navigation(array(
                        'prev_text' => '<span class="arrow" aria-hidden="true">' . solar_energy_engine_the_theme_svg('arrow-left',$solar_energy_engine_return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Previous post:', 'solar-energy-engine') . '</span><span class="post-title">%title</span>',
                        'next_text' => '<span class="arrow" aria-hidden="true">' . solar_energy_engine_the_theme_svg('arrow-right',$solar_energy_engine_return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Next post:', 'solar-energy-engine') . '</span><span class="post-title">%title</span>',
                    )); ?>
                </div>
                <?php

            }else{

                $solar_energy_engine_next_post = get_next_post();
                if( isset( $solar_energy_engine_next_post->ID ) ){

                    $solar_energy_engine_next_post_id = $solar_energy_engine_next_post->ID;
                    echo '<div loop-count="1" next-post="' . absint( $solar_energy_engine_next_post_id ) . '" class="twp-single-infinity"></div>';

                }
            }

        }

    }

endif;

add_action( 'solar_energy_engine_navigation_action','solar_energy_engine_single_post_navigation',30 );

if( !function_exists('solar_energy_engine_content_offcanvas') ):

    // Offcanvas Contents
    function solar_energy_engine_content_offcanvas(){ ?>

        <div id="offcanvas-menu">
            <div class="offcanvas-wraper">
                <div class="close-offcanvas-menu">
                    <div class="offcanvas-close">
                        <a href="javascript:void(0)" class="skip-link-menu-start"></a>
                        <button type="button" class="button-offcanvas-close">
                            <span class="offcanvas-close-label">
                                <?php echo esc_html__('Close', 'solar-energy-engine'); ?>
                            </span>
                        </button>
                    </div>
                </div>
                <div id="primary-nav-offcanvas" class="offcanvas-item offcanvas-main-navigation">
                    <nav class="primary-menu-wrapper" aria-label="<?php esc_attr_e('Horizontal', 'solar-energy-engine'); ?>" role="navigation">
                        <ul class="primary-menu theme-menu">
                            <?php
                            if (has_nav_menu('solar-energy-engine-primary-menu')) {
                                wp_nav_menu(
                                    array(
                                        'container' => '',
                                        'items_wrap' => '%3$s',
                                        'theme_location' => 'solar-energy-engine-primary-menu',
                                        'show_toggles' => true,
                                    )
                                );
                            }else{

                                wp_list_pages(
                                    array(
                                        'match_menu_classes' => true,
                                        'show_sub_menu_icons' => true,
                                        'title_li' => false,
                                        'show_toggles' => true,
                                        'walker' => new solar_energy_engine_Walker_Page(),
                                    )
                                );
                            }
                            ?>
                        </ul>
                    </nav><!-- .primary-menu-wrapper -->
                </div>
                <a href="javascript:void(0)" class="skip-link-menu-end"></a>
            </div>
        </div>

    <?php
    }

endif;

add_action( 'solar_energy_engine_before_footer_content_action','solar_energy_engine_content_offcanvas',30 );

if( !function_exists('solar_energy_engine_footer_content_widget') ):

    function solar_energy_engine_footer_content_widget(){
        
        $solar_energy_engine_default = solar_energy_engine_get_default_theme_options();
        
        $solar_energy_engine_footer_column_layout = absint(get_theme_mod('solar_energy_engine_footer_column_layout', $solar_energy_engine_default['solar_energy_engine_footer_column_layout']));
        $solar_energy_engine_footer_sidebar_class = 12;
        
        if($solar_energy_engine_footer_column_layout == 2) {
            $solar_energy_engine_footer_sidebar_class = 6;
        }
        
        if($solar_energy_engine_footer_column_layout == 3) {
            $solar_energy_engine_footer_sidebar_class = 4;
        }
        ?>
        
        <?php if ( get_theme_mod('solar_energy_engine_display_footer', true) == true ) : ?>
            <div class="footer-widgetarea">
                <div class="wrapper">
                    <div class="column-row">
                    
                        <?php for ($i = 0; $i < $solar_energy_engine_footer_column_layout; $i++) : ?>
                            
                            <div class="column <?php echo 'column-' . absint($solar_energy_engine_footer_sidebar_class); ?> column-sm-12">
                                
                                <?php 
                                // If no widgets are assigned, display default widgets
                                if ( ! is_active_sidebar( 'solar-energy-engine-footer-widget-' . $i ) ) : 

                                    if ($i === 0) : ?>
                                        <div id="media_image-3" class="widget widget_media_image">
                                            <img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/logo.png'); ?>" alt="<?php echo esc_attr__( 'Footer Image', 'solar-energy-engine' ); ?>" style="max-width: 100%; height: auto;">
                                        </div>
                                        <div id="text-3" class="widget widget_text">
                                            <div class="textwidget">
                                                <p class="widget_text">
                                                    <?php esc_html_e('Solar Energy Engine is a powerful and versatile WordPress theme designed specifically for websites related to solar energy, renewable energy, and sustainability. It provides a comprehensive set of features and functionalities to create stunning websites that promote and educate about solar energy solutions, solar energy, renewable energy, solar power...', 'solar-energy-engine'); ?>
                                                </p>
                                            </div>
                                        </div>

                                    <?php elseif ($i === 1) : ?>
                                        <div id="pages-2" class="widget widget_pages">
                                            <h2 class="widget-title"><?php esc_html_e('Calendar', 'solar-energy-engine'); ?></h2>
                                            <?php get_calendar(); ?>
                                        </div>

                                    <?php elseif ($i === 2) : ?>
                                        <div id="search-2" class="widget widget_search">
                                            <h2 class="widget-title"><?php esc_html_e('Enter Keywords Here', 'solar-energy-engine'); ?></h2>
                                            <?php get_search_form(); ?>
                                        </div>
                                    <?php endif; 
                                    
                                else :
                                    // Display dynamic sidebar widget if assigned
                                    dynamic_sidebar('solar-energy-engine-footer-widget-' . $i);
                                endif;
                                ?>
                                
                            </div>
                            
                        <?php endfor; ?>

                    </div>
                </div>
            </div>
        <?php endif; ?> 

    <?php
    }

endif;

add_action( 'solar_energy_engine_footer_content_action', 'solar_energy_engine_footer_content_widget', 10 );

if( !function_exists('solar_energy_engine_footer_content_info') ):

    /**
     * Footer Copyright Area
    **/
    function solar_energy_engine_footer_content_info(){

        $solar_energy_engine_default = solar_energy_engine_get_default_theme_options(); ?>
        <div class="site-info">
            <div class="wrapper">
                <div class="column-row">
                    <div class="column column-9">
                        <div class="footer-credits">
                            <div class="footer-copyright">
                                <?php
                                $solar_energy_engine_solar_energy_engine_footer_copyright_text = wp_kses_post( get_theme_mod( 'solar_energy_engine_footer_copyright_text', $solar_energy_engine_default['solar_energy_engine_footer_copyright_text'] ) );
                                echo esc_html__('Copyright ', 'solar-energy-engine') . '&copy ' . absint(date('Y')) . ' <a href="' . esc_url(home_url('/')) . '" title="' . esc_attr(get_bloginfo('name', 'display')) . '" ><span>' . esc_html( get_bloginfo( 'name', 'display' ) ) . '. </span></a> ' . esc_html( $solar_energy_engine_solar_energy_engine_footer_copyright_text );
                                    echo '<br>';
                                    echo esc_html__('Theme: ', 'solar-energy-engine') . '<a href="' . esc_url('https://www.omegathemes.com/products/free-solar-wordpress-theme') . ' " title=" ' . esc_attr__('Solar Energy Engine', 'solar-energy-engine') . '" target="_blank"><span>' . esc_html__('Solar Energy Engine', 'solar-energy-engine') . '</span></a>' . esc_html__(' By ', 'solar-energy-engine') . '  <span>' . esc_html__('OMEGA ', 'solar-energy-engine') . '</span>';
                                    echo esc_html__('Powered by ', 'solar-energy-engine') . '<a href="' . esc_url('https://wordpress.org') . '" title="' . esc_attr__('WordPress', 'solar-energy-engine') . '" target="_blank"><span>' . esc_html__('WordPress.', 'solar-energy-engine') . '</span></a>';
                                 ?>
                            </div>
                        </div>
                    </div>
                    <div class="column column-3 align-text-right">
                        <a class="to-the-top" href="#site-header">
                            <span class="to-the-top-long">
                                <?php if ( get_theme_mod('solar_energy_engine_enable_to_the_top', true) == true ) : ?>
                                    <?php
                                    $solar_energy_engine_to_the_top_text = get_theme_mod( 'solar_energy_engine_to_the_top_text', __( 'To the Top', 'solar-energy-engine' ) );
                                    printf( 
                                        wp_kses( 
                                            /* translators: %s is the arrow icon markup */
                                            '%s %s', 
                                            array( 'span' => array( 'class' => array(), 'aria-hidden' => array() ) ) 
                                        ), 
                                        esc_html( $solar_energy_engine_to_the_top_text ),
                                        '<span class="arrow" aria-hidden="true">&uarr;</span>' 
                                    );
                                    ?>
                                <?php endif; ?>
                            </span>
                        </a>
                    </div>
                </div>
            </div>
        </div>

    <?php
    }

endif;

add_action( 'solar_energy_engine_footer_content_action','solar_energy_engine_footer_content_info',20 );


if( !function_exists( 'solar_energy_engine_main_slider' ) ) :

    function solar_energy_engine_main_slider(){

        $solar_energy_engine_default = solar_energy_engine_get_default_theme_options();
        $solar_energy_engine_header_banner = get_theme_mod( 'solar_energy_engine_header_banner', $solar_energy_engine_default['solar_energy_engine_header_banner'] );
        $solar_energy_engine_header_banner_cat = get_theme_mod( 'solar_energy_engine_header_banner_cat' );

        if( $solar_energy_engine_header_banner ){

            $solar_energy_engine_rtl = '';
            if( is_rtl() ){
                $solar_energy_engine_rtl = 'dir="rtl"';
            }

          $solar_energy_engine_banner_query = new WP_Query( array('post_type' => 'post', 'posts_per_page' => 4,'post__not_in' => get_option("sticky_posts"), 'category_name' => esc_html( $solar_energy_engine_header_banner_cat ) ) );

          if( $solar_energy_engine_banner_query->have_posts() ): ?>

            <div class="theme-custom-block theme-banner-block">
                <div class="swiper-container theme-main-carousel swiper-container" <?php echo $solar_energy_engine_rtl; ?>>

                    <div class="swiper-wrapper">

                      <?php
                      while( $solar_energy_engine_banner_query->have_posts() ):
                        $solar_energy_engine_banner_query->the_post();
                        $solar_energy_engine_featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
                        $solar_energy_engine_default_image = get_template_directory_uri() . '/assets/images/slider1.png'; // Replace with the actual path to your default image  
                        $solar_energy_engine_featured_image = isset( $solar_energy_engine_featured_image[0] ) ? $solar_energy_engine_featured_image[0] : $solar_energy_engine_default_image;?>

                          <div class="swiper-slide main-carousel-item">
                             
                                  <div class="theme-article-post">
                                  <div class="entry-thumbnail">
                                      <div class="data-bg data-bg-large" data-background="<?php echo esc_url($solar_energy_engine_featured_image); ?>">
                                          <a href="<?php the_permalink(); ?>" class="theme-image-responsive" tabindex="0"></a>
                                      </div>
                                      <?php solar_energy_engine_post_format_icon(); ?>
                                  </div>
                            
                                  <div class="main-carousel-caption">
                                      <div class="post-content ">
                                          <header class="entry-header">
                                                <h2 class="entry-title entry-title-big">
                                                    <a href="<?php the_permalink(); ?>" rel="bookmark"><span><?php the_title(); ?></span></a>
                                                </h2>
                                          </header>
                                          <div class="entry-content">
                                              <?php
                                              if (has_excerpt()) {
                                                  the_excerpt();
                                              } else {
                                                  echo esc_html(wp_trim_words(get_the_content(), 25, '...'));
                                              } ?>
                                          </div>
                                          <a href="<?php the_permalink(); ?>" class="btn-fancy btn-fancy-primary" tabindex="0">
                                              <?php echo esc_html__('Request A Quote', 'solar-energy-engine'); ?>
                                          </a>
                                            <?php if( get_theme_mod( 'solar_energy_engine_video_button_link','https://www.youtube.com/watch?v=9xwazD5SyVg&pp=ygULZHVtbXkgdmlkZW8%3D' ) != '') { ?>
                                                <div class="slider-video">
                                                    <a target="_blank" href="<?php echo esc_url( get_theme_mod( 'solar_energy_engine_video_button_link','https://www.youtube.com/watch?v=9xwazD5SyVg&pp=ygULZHVtbXkgdmlkZW8%3D' ) ); ?>"><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512"><path d="M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"/></svg></a><span class="watch-text"><?php esc_html_e('Connect the inverter to Consumer Unit','solar-energy-engine'); ?></span>
                                                </div>
                                          <?php } ?>
                                      </div>

                                  </div>

                                  </div>
                                  <?php if( get_theme_mod( 'solar_energy_engine_installation_text','254+ Solar Installed' ) != '') { ?>
                                      <div class="installation-box">
                                          <div class="install-icon">
                                            <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 640 512"><path d="M432 448l-48 .1V416h-128v32.2l-48 .1c-8.8 0-16 7.2-16 16l-.1 31.7c0 8.9 7.2 16 16 16l224-.3c8.8 0 16-7.2 16-16l0-31.7c0-8.9-7.2-16-16-16zM585.2 26.7C582.6 11.3 569 0 553.1 0H86.9C71 0 57.4 11.3 54.8 26.7-3.3 369.2 0 348.1 0 352c0 17.3 14.3 32 32.6 32h574.7c18.2 0 32.5-14.6 32.6-31.8 0-4.1 3.4 17-54.8-325.5zM259.8 64h120.3l9.8 96H250.1l9.8-96zm-75.2 256H71.1L90.1 208h106l-11.4 112zm16.3-160H98.2l16.3-96h96.2l-9.8 96zm32.8 160l11.4-112h149.7l11.4 112H233.8zm195.5-256h96.2l16.3 96H439l-9.8-96zm26.1 256l-11.4-112H549.9l19 112H455.3z"/></svg>
                                            </div>
                                          <h6><?php echo esc_html( get_theme_mod( 'solar_energy_engine_installation_text','254+ Solar Installed' ) ); ?></h6>
                                      </div>
                                  <?php } ?>
                          </div>
                      <?php endwhile; ?>
                    </div>
                    <div class="swiper-pagination"></div>
                    <div class="swiper-control swiper-control_center">
                            <div class="theme-carousel-control">
                            <div class="swiper-button-prev">
                            <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="45.0282" height="9" viewBox="0 0 45.0282 9.0371"><polyline points="4.825 0.354 0.707 4.471 4.92 8.684"></polyline><line x1="0.9028" y1="4.513" x2="45.0278" y2="4.5405"></line></svg>
                            </div>
                            
                            <div class="swiper-button-next">
                            <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="45.0277" height="9" viewBox="0 0 45.0277 9.0373"><polyline points="40.108 8.684 44.321 4.471 40.203 0.354"></polyline><line x1="0.0003" y1="4.5409" x2="44.1253" y2="4.5134"></line></svg>
                            </div>
                            </div>
                    </div>

                </div>
            </div>

          <?php
          wp_reset_postdata();
          endif;

        }

    }

endif;

if (!function_exists('solar_energy_engine_post_format_icon')):

    // Post Format Icon.
    function solar_energy_engine_post_format_icon() {

        $solar_energy_engine_format = get_post_format(get_the_ID()) ?: 'standard';
        $solar_energy_engine_icon = '';
        $solar_energy_engine_title = '';
        if( $solar_energy_engine_format == 'video' ){
            $solar_energy_engine_icon = solar_energy_engine_get_theme_svg( 'video' );
            $solar_energy_engine_title = esc_html__('Video','solar-energy-engine');
        }elseif( $solar_energy_engine_format == 'audio' ){
            $solar_energy_engine_icon = solar_energy_engine_get_theme_svg( 'audio' );
            $solar_energy_engine_title = esc_html__('Audio','solar-energy-engine');
        }elseif( $solar_energy_engine_format == 'gallery' ){
            $solar_energy_engine_icon = solar_energy_engine_get_theme_svg( 'gallery' );
            $solar_energy_engine_title = esc_html__('Gallery','solar-energy-engine');
        }elseif( $solar_energy_engine_format == 'quote' ){
            $solar_energy_engine_icon = solar_energy_engine_get_theme_svg( 'quote' );
            $solar_energy_engine_title = esc_html__('Quote','solar-energy-engine');
        }elseif( $solar_energy_engine_format == 'image' ){
            $solar_energy_engine_icon = solar_energy_engine_get_theme_svg( 'image' );
            $solar_energy_engine_title = esc_html__('Image','solar-energy-engine');
        } elseif( $solar_energy_engine_format == 'link' ){
            $solar_energy_engine_icon = solar_energy_engine_get_theme_svg( 'link' );
            $solar_energy_engine_title = esc_html__('Link','solar-energy-engine');
        } elseif( $solar_energy_engine_format == 'status' ){
            $solar_energy_engine_icon = solar_energy_engine_get_theme_svg( 'status' );
            $solar_energy_engine_title = esc_html__('Status','solar-energy-engine');
        } elseif( $solar_energy_engine_format == 'aside' ){
            $solar_energy_engine_icon = solar_energy_engine_get_theme_svg( 'aside' );
            $solar_energy_engine_title = esc_html__('Aside','solar-energy-engine');
        } elseif( $solar_energy_engine_format == 'chat' ){
            $solar_energy_engine_icon = solar_energy_engine_get_theme_svg( 'chat' );
            $solar_energy_engine_title = esc_html__('Chat','solar-energy-engine');
        }
        
        if (!empty($solar_energy_engine_icon)) { ?>
            <div class="theme-post-format">
                <span class="post-format-icom"><?php echo solar_energy_engine_svg_escape($solar_energy_engine_icon); ?></span>
                <?php if( $solar_energy_engine_title ){ echo '<span class="post-format-label">'.esc_html( $solar_energy_engine_title ).'</span>'; } ?>
            </div>
        <?php }
    }

endif;

if ( ! function_exists( 'solar_energy_engine_svg_escape' ) ):

    /**
     * Get information about the SVG icon.
     *
     * @param string $solar_energy_engine_svg_name The name of the icon.
     * @param string $group The group the icon belongs to.
     * @param string $color Color code.
     */
    function solar_energy_engine_svg_escape( $solar_energy_engine_input ) {

        // Make sure that only our allowed tags and attributes are included.
        $solar_energy_engine_svg = wp_kses(
            $solar_energy_engine_input,
            array(
                'svg'     => array(
                    'class'       => true,
                    'xmlns'       => true,
                    'width'       => true,
                    'height'      => true,
                    'viewbox'     => true,
                    'aria-hidden' => true,
                    'role'        => true,
                    'focusable'   => true,
                ),
                'path'    => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'd'         => true,
                    'transform' => true,
                ),
                'polygon' => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'points'    => true,
                    'transform' => true,
                    'focusable' => true,
                ),
            )
        );

        if ( ! $solar_energy_engine_svg ) {
            return false;
        }

        return $solar_energy_engine_svg;

    }

endif;

if( !function_exists( 'solar_energy_engine_sanitize_sidebar_option_meta' ) ) :

    // Sidebar Option Sanitize.
    function solar_energy_engine_sanitize_sidebar_option_meta( $solar_energy_engine_input ){

        $solar_energy_engine_metabox_options = array( 'global-sidebar','left-sidebar','right-sidebar','no-sidebar' );
        if( in_array( $solar_energy_engine_input,$solar_energy_engine_metabox_options ) ){

            return $solar_energy_engine_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'solar_energy_engine_sanitize_pagination_meta' ) ) :

    // Sidebar Option Sanitize.
    function solar_energy_engine_sanitize_pagination_meta( $solar_energy_engine_input ){

        $solar_energy_engine_metabox_options = array( 'Center','Right','Left');
        if( in_array( $solar_energy_engine_input,$solar_energy_engine_metabox_options ) ){

            return $solar_energy_engine_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists('solar_energy_engine_category_carousel') ):

    // Single Posts Related Posts.
    function solar_energy_engine_category_carousel(){

        $solar_energy_engine_default = solar_energy_engine_get_default_theme_options();
        $solar_energy_engine_category_section = absint( get_theme_mod( 'solar_energy_engine_category_section',$solar_energy_engine_default['solar_energy_engine_category_section'] ) );

        if( $solar_energy_engine_category_section ){
            $solar_energy_engine_rtl = '';
            if( is_rtl() ){
                $solar_energy_engine_rtl = 'dir="rtl"';
            } ?>

            <div class="theme-custom-block featured-categories-block">

                <div class="wrapper">
                    <div class="featureheading-1">
                       <?php $solar_energy_engine_cat_short_title = esc_html( get_theme_mod( 'solar_energy_engine_cat_short_title',$solar_energy_engine_default['solar_energy_engine_cat_short_title'] ) );
                        if( $solar_energy_engine_cat_short_title ){ ?>
                        <h6 class="entry-title"><?php echo esc_html( $solar_energy_engine_cat_short_title ); ?></h6>
                    <?php } ?>
                    <?php $solar_energy_engine_cat_main_title = esc_html( get_theme_mod( 'solar_energy_engine_cat_main_title',$solar_energy_engine_default['solar_energy_engine_cat_main_title'] ) );
                        if( $solar_energy_engine_cat_main_title ){ ?>
                        <h2 class="entry-title"><?php echo esc_html( $solar_energy_engine_cat_main_title ); ?></h2>
                    <?php } ?>  
                    </div>
                   <div class="featureheading-2">
                       
                   </div>

                    <div class="swiper-container theme-main-carousel theme-categories-carousel" <?php echo $solar_energy_engine_rtl; ?>>
                        <div class="swiper-wrapper">

                            <?php
                            for ($solar_energy_engine_x = 1; $solar_energy_engine_x <= 10; $solar_energy_engine_x++) {

                                
                                $solar_energy_engine_c_category = get_theme_mod('solar_energy_engine_category_cat_' . $solar_energy_engine_x,'uncategorized');

                                if ($solar_energy_engine_c_category) {
                                    $solar_energy_engine_cat_obj = get_category_by_slug($solar_energy_engine_c_category);
                                    $solar_energy_engine_cat_name = isset($solar_energy_engine_cat_obj->name) ? $solar_energy_engine_cat_obj->name : '';
                                    $solar_energy_engine_cat_id = isset($solar_energy_engine_cat_obj->term_id) ? $solar_energy_engine_cat_obj->term_id : '';
                                    $solar_energy_engine_cat_link = get_category_link($solar_energy_engine_cat_id);
                                    $solar_energy_engine_term_image_url = get_term_meta($solar_energy_engine_cat_id, 'term_image', true);
                                
                                    // Define your default image URL
                                    $solar_energy_engine_default_image_url = get_template_directory_uri() . '/assets/images/abt.png';
                                
                                    // Use the default image if no term image is found
                                    if (empty($solar_energy_engine_term_image_url)) {
                                        $solar_energy_engine_term_image_url = $solar_energy_engine_default_image_url;
                                    }
                                    ?>
                                
                                    <div class="swiper-slide be-category-item">
                                        <div class="theme-article-post theme-transform-zoom">
                                            <div class="post-thumb-categories">
                                                <div class="data-bg data-bg-medium" data-background="<?php echo esc_url($solar_energy_engine_term_image_url); ?>">
                                                    <a class="theme-image-responsive" href="<?php echo esc_url($solar_energy_engine_cat_link); ?>" tabindex="0"></a>
                                                </div>
                                            </div>
                                
                                            <div class="article-content">
                                                <?php
                                                if ($solar_energy_engine_cat_name) { ?>
                                                    <h3 class="category-title">
                                                        <a href="<?php echo esc_url($solar_energy_engine_cat_link); ?>" tabindex="0">
                                                            <?php echo esc_html($solar_energy_engine_cat_name); ?>
                                                        </a>
                                                    </h3>
                                                <?php } ?>
                                            </div>
                                        </div>
                                    </div>
                                
                                    <?php
                                }
                                

                            } ?>

                        </div>

                        <div class="swiper-control swiper-control_center">
                            <div class="theme-carousel-control">
                            <div class="swiper-button-prev">
                            <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="45.0282" height="9" viewBox="0 0 45.0282 9.0371"><polyline points="4.825 0.354 0.707 4.471 4.92 8.684"></polyline><line x1="0.9028" y1="4.513" x2="45.0278" y2="4.5405"></line></svg>
                            </div>
                            
                            <div class="swiper-button-next">
                            <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="45.0277" height="9" viewBox="0 0 45.0277 9.0373"><polyline points="40.108 8.684 44.321 4.471 40.203 0.354"></polyline><line x1="0.0003" y1="4.5409" x2="44.1253" y2="4.5134"></line></svg>
                            </div>
                            </div>
                        </div>                        
                    </div>
                </div>
            </div>
        <?php
        }

    }

endif;

if( !function_exists( 'solar_energy_engine_sanitize_menu_transform' ) ) :

    // Sidebar Option Sanitize.
    function solar_energy_engine_sanitize_menu_transform( $solar_energy_engine_input ){

        $solar_energy_engine_metabox_options = array( 'capitalize','uppercase','lowercase');
        if( in_array( $solar_energy_engine_input,$solar_energy_engine_metabox_options ) ){

            return $solar_energy_engine_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'solar_energy_engine_sanitize_page_content_alignment' ) ) :

    // Sidebar Option Sanitize.
    function solar_energy_engine_sanitize_page_content_alignment( $solar_energy_engine_input ){

        $solar_energy_engine_metabox_options = array( 'left','center','right');
        if( in_array( $solar_energy_engine_input,$solar_energy_engine_metabox_options ) ){

            return $solar_energy_engine_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'solar_energy_engine_sanitize_footer_widget_title_alignment' ) ) :

    // Footer Option Sanitize.
    function solar_energy_engine_sanitize_footer_widget_title_alignment( $solar_energy_engine_input ){

        $solar_energy_engine_metabox_options = array( 'left','center','right');
        if( in_array( $solar_energy_engine_input,$solar_energy_engine_metabox_options ) ){

            return $solar_energy_engine_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'solar_energy_engine_sanitize_pagination_type' ) ) :

    /**
     * Sanitize the pagination type setting.
     *
     * @param string $solar_energy_engine_input The input value from the Customizer.
     * @return string The sanitized value.
     */
    function solar_energy_engine_sanitize_pagination_type( $solar_energy_engine_input ) {
        // Define valid options for the pagination type.
        $solar_energy_engine_valid_options = array( 'numeric', 'newer_older' ); // Update valid options to include 'newer_older'

        // If the input is one of the valid options, return it. Otherwise, return the default option ('numeric').
        if ( in_array( $solar_energy_engine_input, $solar_energy_engine_valid_options, true ) ) {
            return $solar_energy_engine_input;
        } else {
            // Return 'numeric' as the fallback if the input is invalid.
            return 'numeric';
        }
    }

endif;

// Sanitize the enable/disable setting for pagination
if( !function_exists('solar_energy_engine_sanitize_enable_pagination') ) :
    function solar_energy_engine_sanitize_enable_pagination( $solar_energy_engine_input ) {
        return (bool) $solar_energy_engine_input;
    }
endif;

if( !function_exists( 'solar_energy_engine_sanitize_copyright_alignment_meta' ) ) :

    // Sidebar Option Sanitize.
    function solar_energy_engine_sanitize_copyright_alignment_meta( $solar_energy_engine_input ){

        $solar_energy_engine_metabox_options = array( 'Default','Reverse','Center');
        if( in_array( $solar_energy_engine_input,$solar_energy_engine_metabox_options ) ){

            return $solar_energy_engine_input;

        }else{

            return '';

        }
    }

endif;

/**
 * Sidebar Layout Function
 */
function solar_energy_engine_get_final_sidebar_layout() {
	$solar_energy_engine_defaults       = solar_energy_engine_get_default_theme_options();
	$solar_energy_engine_global_layout  = get_theme_mod('solar_energy_engine_global_sidebar_layout', $solar_energy_engine_defaults['solar_energy_engine_global_sidebar_layout']);
	$solar_energy_engine_page_layout    = get_theme_mod('solar_energy_engine_page_sidebar_layout', $solar_energy_engine_global_layout);
	$solar_energy_engine_post_layout    = get_theme_mod('solar_energy_engine_post_sidebar_layout', $solar_energy_engine_global_layout);
	$solar_energy_engine_meta_layout    = get_post_meta(get_the_ID(), 'solar_energy_engine_post_sidebar_option', true);

	if (!empty($solar_energy_engine_meta_layout) && $solar_energy_engine_meta_layout !== 'default') {
		return $solar_energy_engine_meta_layout;
	}
	if (is_page() || (function_exists('is_shop') && is_shop())) {
		return $solar_energy_engine_page_layout;
	}
	if (is_single()) {
		return $solar_energy_engine_post_layout;
	}
	return $solar_energy_engine_global_layout;
}