<?php
/**
* Body Classes.
*
* @package Vintuna
*/
 
 if (!function_exists('vintuna_body_classes')) :

    function vintuna_body_classes($classes) {

        $vintuna_default = vintuna_get_default_theme_options();
        global $post;

        // Adds a class of hfeed to non-singular pages.
        if ( !is_singular() ) {
            $classes[] = 'hfeed';
        }

        // Adds a class of no-sidebar when there is no sidebar present.
        if ( !is_active_sidebar( 'sidebar-1' ) ) {
            $classes[] = 'no-sidebar';
        }
        
        if ( is_active_sidebar( 'sidebar-1' ) ) {

            $global_sidebar_layout = esc_html( get_theme_mod( 'global_sidebar_layout',$vintuna_default['global_sidebar_layout'] ) );

            if( is_single() || is_page() ){

                $vintuna_post_sidebar = esc_html( get_post_meta( $post->ID, 'vintuna_post_sidebar_option', true ) );

                if( $vintuna_post_sidebar == 'global-sidebar' || empty( $vintuna_post_sidebar ) ){

                    if( class_exists('WooCommerce') && ( is_cart() || is_checkout() ) ){
                        
                        $classes[] = 'no-sidebar';

                    }else{

                        $classes[] = esc_attr( $global_sidebar_layout );

                    }

                }else{

                    if( class_exists('WooCommerce') && ( is_cart() || is_checkout() ) ){
                        
                        $classes[] = 'no-sidebar';

                    }else{

                        $classes[] = esc_attr( $vintuna_post_sidebar );

                    }
                }
                
            }elseif( is_404() ){

                $classes[] = 'no-sidebar';

            }else{
                
                $classes[] = esc_attr( $global_sidebar_layout );
            }

        }
        if (is_active_sidebar('vintuna-offcanvas-widget')){
            $classes[] = 'offcanvas-on';
        }
        if( is_page() ){

            $vintuna_header_trending_page = get_theme_mod( 'vintuna_header_trending_page' );
            $vintuna_header_popular_page = get_theme_mod( 'vintuna_header_popular_page' );

            if( $vintuna_header_trending_page == $post->ID || $vintuna_header_popular_page == $post->ID ){

                $vintuna_archive_layout = get_theme_mod( 'vintuna_archive_layout',$vintuna_default['vintuna_archive_layout'] );
                $ed_image_content_inverse = get_theme_mod( 'ed_image_content_inverse',$vintuna_default['ed_image_content_inverse'] );
                if( $vintuna_archive_layout == 'default' && $ed_image_content_inverse ){

                    $classes[] = 'wpi-archive-alternative';

                }

                $classes[] = 'wpi-archive-'.esc_attr( $vintuna_archive_layout );
                
            }

        }

        if( is_singular('post') ){

            $vintuna_post_layout = esc_html( get_post_meta( $post->ID, 'vintuna_post_layout', true ) );

            if( $vintuna_post_layout == '' || $vintuna_post_layout == 'global-layout' ){
                
                $vintuna_post_layout = get_theme_mod( 'vintuna_single_post_layout',$vintuna_default['vintuna_archive_layout'] );

            }

            $classes[] = 'wpi-single-'.esc_attr( $vintuna_post_layout );

            if( $vintuna_post_layout == 'layout-2' ){
                
                $vintuna_header_overlay = esc_html( get_post_meta( $post->ID, 'vintuna_header_overlay', true ) );

                if( $vintuna_header_overlay == '' || $vintuna_header_overlay == 'global-layout' ){

                    $vintuna_post_layout2 = get_theme_mod( 'vintuna_single_post_layout',$vintuna_default['vintuna_archive_layout'] );

                    if( $vintuna_post_layout2 == 'layout-2' ){

                        $ed_header_overlay = esc_html( get_post_meta( $post->ID, 'ed_header_overlay', true ) );
                        if( $ed_header_overlay == '' || $ed_header_overlay == 'global-layout' ){
                            
                            $ed_header_overlay = get_theme_mod( 'ed_header_overlay',$vintuna_default['ed_header_overlay'] );
                        }

                    }else{

                        $ed_header_overlay = false;

                    }

                }else{

                    $ed_header_overlay = true;

                }
                if( $ed_header_overlay ){

                    $classes[] = 'wpi-single-header-overlay';

                }

            }

        }

        if( is_singular('page') ){

            $vintuna_page_layout = get_post_meta( $post->ID, 'vintuna_page_layout', true );

            if( $vintuna_page_layout == ''  ){
                
                $vintuna_page_layout = 'layout-1';

            }

            $classes[] = 'theme-single-'.esc_attr( $vintuna_page_layout );

            if( $vintuna_page_layout == 'layout-2' ){
                
                $vintuna_ed_header_overlay = get_post_meta( $post->ID, 'vintuna_ed_header_overlay', true );
                if( $vintuna_ed_header_overlay ){
                    $classes[] = 'theme-single-header-overlay';
                }

            }

        }

        if( is_archive() || is_home() || is_search() ){

            $vintuna_archive_layout = get_theme_mod( 'vintuna_archive_layout',$vintuna_default['vintuna_archive_layout'] );
            $ed_image_content_inverse = get_theme_mod( 'ed_image_content_inverse',$vintuna_default['ed_image_content_inverse'] );
            if( $vintuna_archive_layout == 'default' && $ed_image_content_inverse ){

                $classes[] = 'wpi-archive-alternative';

            }

            $classes[] = 'wpi-archive-'.esc_attr( $vintuna_archive_layout );
            
        }

        if( is_singular('post') ){

            $vintuna_ed_post_reaction = esc_html( get_post_meta( $post->ID, 'vintuna_ed_post_reaction', true ) );
            if( $vintuna_ed_post_reaction ){
                $classes[] = 'hide-comment-rating';
            }

        }

        return $classes;
    }

endif;

add_filter('body_class', 'vintuna_body_classes');