<?php
/**
 * Custom Functions.
 *
 * @package Cleaning Maintenance
 */

if( !function_exists( 'cleaning_maintenance_fonts_url' ) ) :

    //Google Fonts URL
    function cleaning_maintenance_fonts_url(){

        $cleaning_maintenance_font_families = array(
            'Plus+Jakarta+Sans:ital,wght@0,200..800;1,200..800',
            'Sonsie+One',
            'Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900',
        );

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

        return esc_url_raw($cleaning_maintenance_fonts_url);
    }

endif;

if ( ! function_exists( 'cleaning_maintenance_sub_menu_toggle_button' ) ) :

    function cleaning_maintenance_sub_menu_toggle_button( $cleaning_maintenance_args, $cleaning_maintenance_item, $depth ) {

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

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

                $cleaning_maintenance_toggle_target_string = '.menu-item.menu-item-' . $cleaning_maintenance_item->ID . ' > .sub-menu';

                // Add the sub menu toggle
                $cleaning_maintenance_args->after .= '<button type="button" class="theme-aria-button submenu-toggle" data-toggle-target="' . $cleaning_maintenance_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', 'cleaning-maintenance' ) . '</span>' . cleaning_maintenance_get_theme_svg( 'chevron-down' ) . '</span></button>';

            }

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

        }elseif( $cleaning_maintenance_args->theme_location == 'cleaning-maintenance-primary-menu' ) {

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

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

            } else {

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

            }

        }

        return $cleaning_maintenance_args;

    }

endif;

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

if ( ! function_exists( 'cleaning_maintenance_the_theme_svg' ) ):
    
    function cleaning_maintenance_the_theme_svg( $cleaning_maintenance_svg_name, $cleaning_maintenance_return = false ) {

        if( $cleaning_maintenance_return ){

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

        }else{

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

        }
    }

endif;

if ( ! function_exists( 'cleaning_maintenance_get_theme_svg' ) ):

    function cleaning_maintenance_get_theme_svg( $cleaning_maintenance_svg_name ) {

        // Make sure that only our allowed tags and attributes are included.
        $cleaning_maintenance_svg = wp_kses(
            Cleaning_Maintenance_SVG_Icons::get_svg( $cleaning_maintenance_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 ( ! $cleaning_maintenance_svg ) {
            return false;
        }
        return $cleaning_maintenance_svg;

    }

endif;

if( !function_exists( 'cleaning_maintenance_post_category_list' ) ) :

    // Post Category List.
    function cleaning_maintenance_post_category_list( $cleaning_maintenance_select_cat = true ){

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

        $cleaning_maintenance_post_cat_cat_array = array();
        if( $cleaning_maintenance_select_cat ){

            $cleaning_maintenance_post_cat_cat_array[''] = esc_html__( '-- Select Category --','cleaning-maintenance' );

        }

        foreach ( $cleaning_maintenance_post_cat_lists as $cleaning_maintenance_post_cat_list ) {

            $cleaning_maintenance_post_cat_cat_array[$cleaning_maintenance_post_cat_list->slug] = $cleaning_maintenance_post_cat_list->name;

        }

        return $cleaning_maintenance_post_cat_cat_array;
    }

endif;

if( !function_exists('cleaning_maintenance_single_post_navigation') ):

    function cleaning_maintenance_single_post_navigation(){

        $cleaning_maintenance_default = cleaning_maintenance_get_default_theme_options();
        $cleaning_maintenance_twp_navigation_type = esc_attr( get_post_meta( get_the_ID(), 'cleaning_maintenance_twp_disable_ajax_load_next_post', true ) );
        $cleaning_maintenance_current_id = '';
        $article_wrap_class = '';
        global $post;
        $cleaning_maintenance_current_id = $post->ID;
        if( $cleaning_maintenance_twp_navigation_type == '' || $cleaning_maintenance_twp_navigation_type == 'global-layout' ){
            $cleaning_maintenance_twp_navigation_type = get_theme_mod('cleaning_maintenance_twp_navigation_type', $cleaning_maintenance_default['cleaning_maintenance_twp_navigation_type']);
        }

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

            if( $cleaning_maintenance_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">' . cleaning_maintenance_the_theme_svg('arrow-left',$cleaning_maintenance_return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Previous post:', 'cleaning-maintenance') . '</span><span class="post-title">%title</span>',
                        'next_text' => '<span class="arrow" aria-hidden="true">' . cleaning_maintenance_the_theme_svg('arrow-right',$cleaning_maintenance_return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Next post:', 'cleaning-maintenance') . '</span><span class="post-title">%title</span>',
                    )); ?>
                </div>
                <?php

            }else{

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

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

                }
            }

        }

    }

endif;

add_action( 'cleaning_maintenance_navigation_action','cleaning_maintenance_single_post_navigation',30 );

if( !function_exists('cleaning_maintenance_content_offcanvas') ):

    // Offcanvas Contents
    function cleaning_maintenance_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', 'cleaning-maintenance'); ?>
                            </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', 'cleaning-maintenance'); ?>" role="navigation">
                        <ul class="primary-menu theme-menu">
                            <?php
                            if (has_nav_menu('cleaning-maintenance-primary-menu')) {
                                wp_nav_menu(
                                    array(
                                        'container' => '',
                                        'items_wrap' => '%3$s',
                                        'theme_location' => 'cleaning-maintenance-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 Cleaning_Maintenance_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( 'cleaning_maintenance_before_footer_content_action','cleaning_maintenance_content_offcanvas',30 );

if( !function_exists('cleaning_maintenance_footer_content_widget') ):

    function cleaning_maintenance_footer_content_widget(){
        
        $cleaning_maintenance_default = cleaning_maintenance_get_default_theme_options();
        
        $cleaning_maintenance_footer_column_layout = absint(get_theme_mod('cleaning_maintenance_footer_column_layout', $cleaning_maintenance_default['cleaning_maintenance_footer_column_layout']));
        $cleaning_maintenance_footer_sidebar_class = 12;
        
        if($cleaning_maintenance_footer_column_layout == 2) {
            $cleaning_maintenance_footer_sidebar_class = 6;
        }
        
        if($cleaning_maintenance_footer_column_layout == 3) {
            $cleaning_maintenance_footer_sidebar_class = 4;
        }
        ?>
        
        <?php if ( get_theme_mod('cleaning_maintenance_display_footer', true) == true ) : ?>
            <div class="footer-widgetarea">
                <div class="wrapper">
                    <div class="column-row">
                    
                        <?php for ($i = 0; $i < $cleaning_maintenance_footer_column_layout; $i++) : ?>
                            
                            <div class="column <?php echo 'column-' . absint($cleaning_maintenance_footer_sidebar_class); ?> column-sm-12">
                                
                                <?php 
                                // If no widgets are assigned, display default widgets
                                if ( ! is_active_sidebar( 'cleaning-maintenance-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', 'cleaning-maintenance' ); ?>" 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('Cleaning Maintenance is a dynamic and versatile WordPress theme designed to meet the specific needs of janitorial services, commercial cleaning, residential cleaning, office cleaning, carpet cleaning, window cleaning, floor maintenance, deep cleaning, sanitation services, janitorial supplies, cleaning contractors, building maintenance, facility management, housekeeping services, industrial cleaning, cleaning service providers, etc...', 'cleaning-maintenance'); ?>
                                                </p>
                                            </div>
                                        </div>

                                    <?php elseif ($i === 1) : ?>
                                        <div id="pages-2" class="widget widget_pages">
                                            <h2 class="widget-title"><?php esc_html_e('Calendar', 'cleaning-maintenance'); ?></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', 'cleaning-maintenance'); ?></h2>
                                            <?php get_search_form(); ?>
                                        </div>
                                    <?php endif; 
                                    
                                else :
                                    // Display dynamic sidebar widget if assigned
                                    dynamic_sidebar('cleaning-maintenance-footer-widget-' . $i);
                                endif;
                                ?>
                                
                            </div>
                            
                        <?php endfor; ?>

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

    <?php
    }

endif;

add_action( 'cleaning_maintenance_footer_content_action', 'cleaning_maintenance_footer_content_widget', 10 );

if( !function_exists('cleaning_maintenance_footer_content_info') ):

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

        $cleaning_maintenance_default = cleaning_maintenance_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
                                $cleaning_maintenance_footer_copyright_text = wp_kses_post( get_theme_mod( 'cleaning_maintenance_footer_copyright_text', $cleaning_maintenance_default['cleaning_maintenance_footer_copyright_text'] ) );
                                    echo esc_html( $cleaning_maintenance_footer_copyright_text );
                                    echo '<br>';
                                    echo esc_html__('Theme: ', 'cleaning-maintenance') . '<a href="' . esc_url('https://www.omegathemes.com/products/free-maintenance-wordpress-theme') . '" title="' . esc_attr__('Cleaning Maintenance', 'cleaning-maintenance') . '" target="_blank"><span>' . esc_html__('Cleaning Maintenance', 'cleaning-maintenance') . '</span></a>' . esc_html__(' By ', 'cleaning-maintenance') . '  <span>' . esc_html__('OMEGA ', 'cleaning-maintenance') . '</span>';
                                    echo esc_html__('Powered by ', 'cleaning-maintenance') . '<a href="' . esc_url('https://wordpress.org') . '" title="' . esc_attr__('WordPress', 'cleaning-maintenance') . '" target="_blank"><span>' . esc_html__('WordPress.', 'cleaning-maintenance') . '</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('cleaning_maintenance_enable_to_the_top', true) == true ) : ?>
                                    <?php
                                    $cleaning_maintenance_to_the_top_text = get_theme_mod( 'cleaning_maintenance_to_the_top_text', __( 'To the Top', 'cleaning-maintenance' ) );
                                    printf( 
                                        wp_kses( 
                                            /* translators: %s is the arrow icon markup */
                                            '%s %s', 
                                            array( 'span' => array( 'class' => array(), 'aria-hidden' => array() ) ) 
                                        ), 
                                        esc_html( $cleaning_maintenance_to_the_top_text ),
                                        '<span class="arrow" aria-hidden="true">&uarr;</span>' 
                                    );
                                    ?>
                                <?php endif; ?>
                            </span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    <?php
    }

endif;

add_action( 'cleaning_maintenance_footer_content_action','cleaning_maintenance_footer_content_info',20 );


if( !function_exists( 'cleaning_maintenance_main_slider' ) ) :

    function cleaning_maintenance_main_slider(){

        $cleaning_maintenance_defaults = cleaning_maintenance_get_default_theme_options();
        $cleaning_maintenance_header_slider = get_theme_mod( 'cleaning_maintenance_header_slider', $cleaning_maintenance_defaults['cleaning_maintenance_header_slider'] );
        $cleaning_maintenance_header_slider_cat = get_theme_mod( 'cleaning_maintenance_header_slider_cat','uncategorized');
        $cleaning_maintenance_banner_left_image = get_theme_mod( 'cleaning_maintenance_banner_left_image', $cleaning_maintenance_defaults['cleaning_maintenance_banner_left_image'] );
        $cleaning_maintenance_banner_right_image = get_theme_mod( 'cleaning_maintenance_banner_right_image', $cleaning_maintenance_defaults['cleaning_maintenance_banner_right_image'] );

        $cleaning_maintenance_slider_section_guarantee_title = esc_html( get_theme_mod( 'cleaning_maintenance_slider_section_guarantee_title',
        $cleaning_maintenance_defaults['cleaning_maintenance_slider_section_guarantee_title'] ) );

        $cleaning_maintenance_slider_section_availablity_title = esc_html( get_theme_mod( 'cleaning_maintenance_slider_section_availablity_title',
        $cleaning_maintenance_defaults['cleaning_maintenance_slider_section_availablity_title'] ) );

        $cleaning_maintenance_slider_section_location_title = esc_html( get_theme_mod( 'cleaning_maintenance_slider_section_location_title',
        $cleaning_maintenance_defaults['cleaning_maintenance_slider_section_location_title'] ) );

        $cleaning_maintenance_slider_section_appoinment_title = esc_html( get_theme_mod( 'cleaning_maintenance_slider_section_appoinment_title',
        $cleaning_maintenance_defaults['cleaning_maintenance_slider_section_appoinment_title'] ) );

        if( $cleaning_maintenance_header_slider ){
            if( $cleaning_maintenance_header_slider_cat ){ ?>
                <div class="slider-box">
                    <div class="wrapper">
                        <div class="slider-main">
                            <div class="right-box">
                                <div class="entry-thumbnail">
                                    <?php if( $cleaning_maintenance_banner_left_image ){ ?>
                                        <img src="<?php echo esc_url( $cleaning_maintenance_banner_left_image ); ?>" alt="Banner Left Image">
                                    <?php } ?>
                                </div>
                                <div class="slide-center">
                                    <?php
                                    $cleaning_maintenance_rtl = '';
                                    if( is_rtl() ){
                                        $cleaning_maintenance_rtl = 'dir="rtl"';
                                    }
                                    $cleaning_maintenance_banner_query = new WP_Query( array('post_type' => 'post', 'posts_per_page' => 4,'post__not_in' => get_option("sticky_posts"), 'category_name' => esc_html( $cleaning_maintenance_header_slider_cat ) ) );
                                    if( $cleaning_maintenance_banner_query->have_posts() ): ?>
                                        <div class="theme-custom-block theme-banner-block">
                                            <div class="swiper-container theme-main-carousel swiper-container" <?php echo esc_attr($cleaning_maintenance_rtl);  ?>>
                                                <div class="swiper-wrapper">
                                                    <?php
                                                    while( $cleaning_maintenance_banner_query->have_posts() ):
                                                    $cleaning_maintenance_banner_query->the_post();?>
                                                        <div class="swiper-slide main-carousel-item">                                    
                                                            <div class="main-carousel-caption">
                                                                <header class="entry-header">
                                                                    <div class="entry-author">
                                                                        <span class="slide-cat"><?php the_category(); ?></span>
                                                                    </div>
                                                                    <h2 class="entry-title">
                                                                        <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
                                                                    </h2>
                                                                    <a href="<?php the_permalink(); ?>" class="btn-fancy btn-fancy-primary" tabindex="0">
                                                                        <?php echo esc_html('Call Us Now', 'cleaning-maintenance'); ?><span><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><path d="M497.4 361.8l-112-48a24 24 0 0 0 -28 6.9l-49.6 60.6A370.7 370.7 0 0 1 130.6 204.1l60.6-49.6a23.9 23.9 0 0 0 6.9-28l-48-112A24.2 24.2 0 0 0 122.6 .6l-104 24A24 24 0 0 0 0 48c0 256.5 207.9 464 464 464a24 24 0 0 0 23.4-18.6l24-104a24.3 24.3 0 0 0 -14-27.6z"/></svg></span>
                                                                    </a>
                                                                </header>
                                                                
                                                            </div>
                                                        </div>
                                                    <?php endwhile; ?>
                                                </div>
                                                <div class="swiper-pagination"></div>
                                            </div>
                                        </div>
                                    <?php
                                        wp_reset_postdata();
                                        endif; ?>
                                </div>
                                <div class="entry-thumbnail">
                                    <?php if( $cleaning_maintenance_banner_right_image ){ ?>
                                        <img src="<?php echo esc_url( $cleaning_maintenance_banner_right_image ); ?>" alt="Banner Left Image">
                                    <?php } ?>
                                </div>
                                <?php }?>
                            </div>
                        </div>
                        <section id="info-header">
                            <div class="header-wrapper">
                                <div class="theme-header-areas header-areas-left">
                                    <span class="service-icon"><svg xmlns="http://www.w3.org/2000/svg" height="1.5em" viewBox="0 0 448 512"><path d="M400 480H48c-26.5 0-48-21.5-48-48V80c0-26.5 21.5-48 48-48h352c26.5 0 48 21.5 48 48v352c0 26.5-21.5 48-48 48zm-204.7-98.1l184-184c6.2-6.2 6.2-16.4 0-22.6l-22.6-22.6c-6.2-6.2-16.4-6.2-22.6 0L184 302.7l-70.1-70.1c-6.2-6.2-16.4-6.2-22.6 0l-22.6 22.6c-6.2 6.2-6.2 16.4 0 22.6l104 104c6.2 6.3 16.4 6.3 22.6 0z"/></svg></span>
                                    <div class="header-areas-box">
                                        <?php if( $cleaning_maintenance_slider_section_guarantee_title ){ ?>
                                            <h6><?php echo esc_html( $cleaning_maintenance_slider_section_guarantee_title ); ?></h6>
                                        <?php } ?>
                                    </div>
                                </div>
                                <div class="theme-header-areas header-areas-left">
                                    <span class="service-icon"><svg xmlns="http://www.w3.org/2000/svg" height="1.5em" viewBox="0 0 512 512"><path d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200zm61.8-104.4l-84.9-61.7c-3.1-2.3-4.9-5.9-4.9-9.7V116c0-6.6 5.4-12 12-12h32c6.6 0 12 5.4 12 12v141.7l66.8 48.6c5.4 3.9 6.5 11.4 2.6 16.8L334.6 349c-3.9 5.3-11.4 6.5-16.8 2.6z"/></svg></span>
                                    <div class="header-areas-box">
                                        <?php if( $cleaning_maintenance_slider_section_availablity_title ){ ?>
                                            <h6><?php echo esc_html( $cleaning_maintenance_slider_section_availablity_title ); ?></h6>
                                        <?php } ?>
                                    </div>
                                </div>
                                <div class="theme-header-areas header-areas-right">
                                    <span class="service-icon"><svg xmlns="http://www.w3.org/2000/svg" height="1.5em" viewBox="0 0 384 512"><path d="M172.3 501.7C27 291 0 269.4 0 192 0 86 86 0 192 0s192 86 192 192c0 77.4-27 99-172.3 309.7-9.5 13.8-29.9 13.8-39.5 0zM192 272c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80z"/></svg></span>
                                    <div class="header-areas-box">
                                        <?php if( $cleaning_maintenance_slider_section_location_title ){ ?>
                                            <h6><?php echo esc_html( $cleaning_maintenance_slider_section_location_title ); ?></h6>
                                        <?php } ?>
                                    </div>
                                </div>
                                <div class="theme-header-areas header-areas-right">
                                    <span class="service-icon"><svg xmlns="http://www.w3.org/2000/svg" height="1.5em" viewBox="0 0 448 512"><path d="M436 160H12c-6.6 0-12-5.4-12-12v-36c0-26.5 21.5-48 48-48h48V12c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v52h128V12c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v52h48c26.5 0 48 21.5 48 48v36c0 6.6-5.4 12-12 12zM12 192h424c6.6 0 12 5.4 12 12v260c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V204c0-6.6 5.4-12 12-12zm333.3 95.9l-28.2-28.4c-4.7-4.7-12.3-4.7-17-.1L194.1 364.7l-46-46.4c-4.7-4.7-12.3-4.7-17-.1l-28.4 28.2c-4.7 4.7-4.7 12.3-.1 17l82.6 83.3c4.7 4.7 12.3 4.7 17 .1l143-141.8c4.7-4.7 4.7-12.3 .1-17z"/></svg></span>
                                    <div class="header-areas-box">
                                        <?php if( $cleaning_maintenance_slider_section_appoinment_title ){ ?>
                                            <h6><?php echo esc_html( $cleaning_maintenance_slider_section_appoinment_title ); ?></h6>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
        <?php }
    }

endif;

if( !function_exists( 'cleaning_maintenance_about_us_section' ) ) :

    function cleaning_maintenance_about_us_section(){ 

        $cleaning_maintenance_deafult = cleaning_maintenance_get_default_theme_options();

        $cleaning_maintenance_header_about_us = get_theme_mod( 'cleaning_maintenance_header_about_us', 
        $cleaning_maintenance_deafult['cleaning_maintenance_header_about_us'] );

        $cleaning_maintenance_about_us_section_title = esc_html( get_theme_mod( 'cleaning_maintenance_about_us_section_title',
        $cleaning_maintenance_deafult['cleaning_maintenance_about_us_section_title'] ) );

        $cleaning_maintenance_about_us_section_sub_title = esc_html( get_theme_mod( 'cleaning_maintenance_about_us_section_sub_title',
        $cleaning_maintenance_deafult['cleaning_maintenance_about_us_section_sub_title'] ) );

        $cleaning_maintenance_about_us_section_content = esc_html( get_theme_mod( 'cleaning_maintenance_about_us_section_content',
        $cleaning_maintenance_deafult['cleaning_maintenance_about_us_section_content'] ) );

        $cleaning_maintenance_about_us_section_content_1 = esc_html( get_theme_mod( 'cleaning_maintenance_about_us_section_content_1',
        $cleaning_maintenance_deafult['cleaning_maintenance_about_us_section_content_1'] ) );

        $cleaning_maintenance_about_us_section_image_title = esc_html( get_theme_mod( 'cleaning_maintenance_about_us_section_image_title',
        $cleaning_maintenance_deafult['cleaning_maintenance_about_us_section_image_title'] ) );

        $cleaning_maintenance_about_us_left_image = esc_html( get_theme_mod( 'cleaning_maintenance_about_us_left_image',
        $cleaning_maintenance_deafult['cleaning_maintenance_about_us_left_image'] ) );

        $cleaning_maintenance_about_us_exprience_title = esc_html( get_theme_mod( 'cleaning_maintenance_about_us_exprience_title',
        $cleaning_maintenance_deafult['cleaning_maintenance_about_us_exprience_title'] ) );

        $cleaning_maintenance_about_us_work_title = esc_html( get_theme_mod( 'cleaning_maintenance_about_us_work_title',
        $cleaning_maintenance_deafult['cleaning_maintenance_about_us_work_title'] ) );

        $cleaning_maintenance_about_us_service_title = esc_html( get_theme_mod( 'cleaning_maintenance_about_us_service_title',
        $cleaning_maintenance_deafult['cleaning_maintenance_about_us_service_title'] ) );
        
        if( $cleaning_maintenance_header_about_us ){ ?>
            <div class="most-read">
                <div class="wrapper">
                    <div class="most-read-div">
                        <div class="most-sidebar-box">
                            <?php if( $cleaning_maintenance_about_us_left_image ){ ?>
                                <img src="<?php echo esc_url( $cleaning_maintenance_about_us_left_image ); ?>" alt="About Us Left Image">
                                <?php if( $cleaning_maintenance_about_us_section_image_title ){ ?>
                                    <h4 class="list-title">
                                        <?php echo esc_html($cleaning_maintenance_about_us_section_image_title) ?>
                                    </h4>
                                <?php } ?>
                            <?php } ?>
                        </div>
                        <div class="blog-main-box">
                            <div class="list-heading-main">
                                <h4 class="list-title">
                                    <?php if( $cleaning_maintenance_about_us_section_title ){ ?>
                                        <?php echo esc_html($cleaning_maintenance_about_us_section_title) ?>
                                    <?php } ?>
                                </h4>
                                <h3 class="list-sub-title">
                                    <?php if( $cleaning_maintenance_about_us_section_sub_title ){ ?>
                                        <?php echo esc_html($cleaning_maintenance_about_us_section_sub_title) ?>
                                    <?php } ?>
                                </h3>
                                <p class="list-content">
                                    <?php if( $cleaning_maintenance_about_us_section_content ){ ?>
                                        <?php echo esc_html($cleaning_maintenance_about_us_section_content) ?>
                                    <?php } ?>
                                </p>
                                <p class="list-content1">
                                    <?php if( $cleaning_maintenance_about_us_section_content_1 ){ ?>
                                        <?php echo esc_html($cleaning_maintenance_about_us_section_content_1) ?>
                                    <?php } ?>
                                </p>
                            </div>
                            <div class="header-wrapper about-box">
                                <div class="theme-header-areas header-areas-left about-single-box">

                                    <span class="about-icon"><svg xmlns="http://www.w3.org/2000/svg" height="1.2em" viewBox="0 0 512 512"><path d="M320 336c0 8.8-7.2 16-16 16h-96c-8.8 0-16-7.2-16-16v-48H0v144c0 25.6 22.4 48 48 48h416c25.6 0 48-22.4 48-48V288H320v48zm144-208h-80V80c0-25.6-22.4-48-48-48H176c-25.6 0-48 22.4-48 48v48H48c-25.6 0-48 22.4-48 48v80h512v-80c0-25.6-22.4-48-48-48zm-144 0H192V96h128v32z"/></svg></span>
                                    <div class="header-areas-box">
                                        <?php if( $cleaning_maintenance_about_us_exprience_title ){ ?>
                                            <h6><?php echo esc_html( $cleaning_maintenance_about_us_exprience_title ); ?></h6>
                                        <?php } ?>
                                    </div>
                                </div>
                                <div class="theme-header-areas header-areas-left about-single-box">
                                    <span class="about-icon"><svg xmlns="http://www.w3.org/2000/svg" height="1.2em" viewBox="0 0 576 512"><path d="M552 64H88c-13.3 0-24 10.7-24 24v8H24c-13.3 0-24 10.7-24 24v272c0 30.9 25.1 56 56 56h472c26.5 0 48-21.5 48-48V88c0-13.3-10.7-24-24-24zM56 400a8 8 0 0 1 -8-8V144h16v248a8 8 0 0 1 -8 8zm236-16H140c-6.6 0-12-5.4-12-12v-8c0-6.6 5.4-12 12-12h152c6.6 0 12 5.4 12 12v8c0 6.6-5.4 12-12 12zm208 0H348c-6.6 0-12-5.4-12-12v-8c0-6.6 5.4-12 12-12h152c6.6 0 12 5.4 12 12v8c0 6.6-5.4 12-12 12zm-208-96H140c-6.6 0-12-5.4-12-12v-8c0-6.6 5.4-12 12-12h152c6.6 0 12 5.4 12 12v8c0 6.6-5.4 12-12 12zm208 0H348c-6.6 0-12-5.4-12-12v-8c0-6.6 5.4-12 12-12h152c6.6 0 12 5.4 12 12v8c0 6.6-5.4 12-12 12zm0-96H140c-6.6 0-12-5.4-12-12v-40c0-6.6 5.4-12 12-12h360c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12z"/></svg></span>
                                    <div class="header-areas-box">
                                        <?php if( $cleaning_maintenance_about_us_work_title ){ ?>
                                            <h6><?php echo esc_html( $cleaning_maintenance_about_us_work_title ); ?></h6>
                                        <?php } ?>
                                    </div>
                                </div>
                                <div class="theme-header-areas header-areas-left about-single-box">
                                    <span class="about-icon"><svg xmlns="http://www.w3.org/2000/svg" height="1.2em" viewBox="0 0 576 512"><path d="M280.4 148.3L96 300.1V464a16 16 0 0 0 16 16l112.1-.3a16 16 0 0 0 15.9-16V368a16 16 0 0 1 16-16h64a16 16 0 0 1 16 16v95.6a16 16 0 0 0 16 16.1L464 480a16 16 0 0 0 16-16V300L295.7 148.3a12.2 12.2 0 0 0 -15.3 0zM571.6 251.5L488 182.6V44.1a12 12 0 0 0 -12-12h-56a12 12 0 0 0 -12 12v72.6L318.5 43a48 48 0 0 0 -61 0L4.3 251.5a12 12 0 0 0 -1.6 16.9l25.5 31A12 12 0 0 0 45.2 301l235.2-193.7a12.2 12.2 0 0 1 15.3 0L530.9 301a12 12 0 0 0 16.9-1.6l25.5-31a12 12 0 0 0 -1.7-16.9z"/></svg></span>
                                    <div class="header-areas-box">
                                        <?php if( $cleaning_maintenance_about_us_service_title ){ ?>
                                            <h6><?php echo esc_html( $cleaning_maintenance_about_us_service_title ); ?></h6>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        <?php } ?>
    <?php }

endif;

if (!function_exists('cleaning_maintenance_post_format_icon')):

    // Post Format Icon.
    function cleaning_maintenance_post_format_icon() {

        $cleaning_maintenance_format = get_post_format(get_the_ID()) ?: 'standard';
        $cleaning_maintenance_icon = '';
        $cleaning_maintenance_title = '';
        if( $cleaning_maintenance_format == 'video' ){
            $cleaning_maintenance_icon = cleaning_maintenance_get_theme_svg( 'video' );
            $cleaning_maintenance_title = esc_html__('Video','cleaning-maintenance');
        }elseif( $cleaning_maintenance_format == 'audio' ){
            $cleaning_maintenance_icon = cleaning_maintenance_get_theme_svg( 'audio' );
            $cleaning_maintenance_title = esc_html__('Audio','cleaning-maintenance');
        }elseif( $cleaning_maintenance_format == 'gallery' ){
            $cleaning_maintenance_icon = cleaning_maintenance_get_theme_svg( 'gallery' );
            $cleaning_maintenance_title = esc_html__('Gallery','cleaning-maintenance');
        }elseif( $cleaning_maintenance_format == 'quote' ){
            $cleaning_maintenance_icon = cleaning_maintenance_get_theme_svg( 'quote' );
            $cleaning_maintenance_title = esc_html__('Quote','cleaning-maintenance');
        }elseif( $cleaning_maintenance_format == 'image' ){
            $cleaning_maintenance_icon = cleaning_maintenance_get_theme_svg( 'image' );
            $cleaning_maintenance_title = esc_html__('Image','cleaning-maintenance');
        } elseif( $cleaning_maintenance_format == 'link' ){
            $cleaning_maintenance_icon = cleaning_maintenance_get_theme_svg( 'link' );
            $cleaning_maintenance_title = esc_html__('Link','cleaning-maintenance');
        } elseif( $cleaning_maintenance_format == 'status' ){
            $cleaning_maintenance_icon = cleaning_maintenance_get_theme_svg( 'status' );
            $cleaning_maintenance_title = esc_html__('Status','cleaning-maintenance');
        } elseif( $cleaning_maintenance_format == 'aside' ){
            $cleaning_maintenance_icon = cleaning_maintenance_get_theme_svg( 'aside' );
            $cleaning_maintenance_title = esc_html__('Aside','cleaning-maintenance');
        } elseif( $cleaning_maintenance_format == 'chat' ){
            $cleaning_maintenance_icon = cleaning_maintenance_get_theme_svg( 'chat' );
            $cleaning_maintenance_title = esc_html__('Chat','cleaning-maintenance');
        }
        
        if (!empty($cleaning_maintenance_icon)) { ?>
            <div class="theme-post-format">
                <span class="post-format-icom"><?php echo cleaning_maintenance_svg_escape($cleaning_maintenance_icon); ?></span>
                <?php if( $cleaning_maintenance_title ){ echo '<span class="post-format-label">'.esc_html( $cleaning_maintenance_title ).'</span>'; } ?>
            </div>
        <?php }
    }

endif;

if ( ! function_exists( 'cleaning_maintenance_svg_escape' ) ):

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

        // Make sure that only our allowed tags and attributes are included.
        $cleaning_maintenance_svg = wp_kses(
            $cleaning_maintenance_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 ( ! $cleaning_maintenance_svg ) {
            return false;
        }

        return $cleaning_maintenance_svg;

    }

endif;

if( !function_exists( 'cleaning_maintenance_sanitize_sidebar_option_meta' ) ) :

    // Sidebar Option Sanitize.
    function cleaning_maintenance_sanitize_sidebar_option_meta( $cleaning_maintenance_input ){

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

            return $cleaning_maintenance_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'cleaning_maintenance_sanitize_pagination_meta' ) ) :

    // Sidebar Option Sanitize.
    function cleaning_maintenance_sanitize_pagination_meta( $cleaning_maintenance_input ){

        $cleaning_maintenance_metabox_options = array( 'Center','Right','Left');
        if( in_array( $cleaning_maintenance_input,$cleaning_maintenance_metabox_options ) ){

            return $cleaning_maintenance_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'cleaning_maintenance_sanitize_menu_transform' ) ) :

    // Sidebar Option Sanitize.
    function cleaning_maintenance_sanitize_menu_transform( $cleaning_maintenance_input ){

        $cleaning_maintenance_metabox_options = array( 'capitalize','uppercase','lowercase');
        if( in_array( $cleaning_maintenance_input,$cleaning_maintenance_metabox_options ) ){

            return $cleaning_maintenance_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'cleaning_maintenance_sanitize_page_content_alignment' ) ) :

    // Sidebar Option Sanitize.
    function cleaning_maintenance_sanitize_page_content_alignment( $cleaning_maintenance_input ){

        $cleaning_maintenance_metabox_options = array( 'left','center','right');
        if( in_array( $cleaning_maintenance_input,$cleaning_maintenance_metabox_options ) ){

            return $cleaning_maintenance_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'cleaning_maintenance_sanitize_copyright_alignment_meta' ) ) :

    // Sidebar Option Sanitize.
    function cleaning_maintenance_sanitize_copyright_alignment_meta( $cleaning_maintenance_input ){

        $cleaning_maintenance_metabox_options = array( 'Default','Reverse','Center');
        if( in_array( $cleaning_maintenance_input,$cleaning_maintenance_metabox_options ) ){

            return $cleaning_maintenance_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'cleaning_maintenance_sanitize_footer_widget_title_alignment' ) ) :

    // Footer Option Sanitize.
    function cleaning_maintenance_sanitize_footer_widget_title_alignment( $cleaning_maintenance_input ){

        $cleaning_maintenance_metabox_options = array( 'left','center','right');
        if( in_array( $cleaning_maintenance_input,$cleaning_maintenance_metabox_options ) ){

            return $cleaning_maintenance_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'cleaning_maintenance_sanitize_pagination_type' ) ) :

    /**
     * Sanitize the pagination type setting.
     *
     * @param string $cleaning_maintenance_input The input value from the Customizer.
     * @return string The sanitized value.
     */
    function cleaning_maintenance_sanitize_pagination_type( $cleaning_maintenance_input ) {
        // Define valid options for the pagination type.
        $cleaning_maintenance_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( $cleaning_maintenance_input, $cleaning_maintenance_valid_options, true ) ) {
            return $cleaning_maintenance_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('cleaning_maintenance_sanitize_enable_pagination') ) :
    function cleaning_maintenance_sanitize_enable_pagination( $cleaning_maintenance_input ) {
        return (bool) $cleaning_maintenance_input;
    }
endif;

/**
 * Sidebar Layout Function
 */
function cleaning_maintenance_get_final_sidebar_layout() {
	$cleaning_maintenance_defaults       = cleaning_maintenance_get_default_theme_options();
	$cleaning_maintenance_global_layout  = get_theme_mod('cleaning_maintenance_global_sidebar_layout', $cleaning_maintenance_defaults['cleaning_maintenance_global_sidebar_layout']);
	$cleaning_maintenance_page_layout    = get_theme_mod('cleaning_maintenance_page_sidebar_layout', $cleaning_maintenance_global_layout);
	$cleaning_maintenance_post_layout    = get_theme_mod('cleaning_maintenance_post_sidebar_layout', $cleaning_maintenance_global_layout);
	$cleaning_maintenance_meta_layout    = get_post_meta(get_the_ID(), 'cleaning_maintenance_post_sidebar_option', true);

	if (!empty($cleaning_maintenance_meta_layout) && $cleaning_maintenance_meta_layout !== 'default') {
		return $cleaning_maintenance_meta_layout;
	}
	if (is_page() || (function_exists('is_shop') && is_shop())) {
		return $cleaning_maintenance_page_layout;
	}
	if (is_single()) {
		return $cleaning_maintenance_post_layout;
	}
	return $cleaning_maintenance_global_layout;
}