<?php
/**
* Css Classes Functions
*
* @package GridFeel WordPress Theme
* @copyright Copyright (C) 2025 ThemesDNA
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
* @author ThemesDNA <themesdna@gmail.com>
*/

// Category ids in post class
function gridfeel_category_id_class($classes) {
    global $post;
    foreach((get_the_category($post->ID)) as $category) {
        $classes[] = 'wpcat-' . $category->cat_ID . '-id';
    }
    return apply_filters( 'gridfeel_category_id_class', $classes );
}
add_filter('post_class', 'gridfeel_category_id_class');


// Adds custom classes to the array of body classes.
function gridfeel_body_classes( $classes ) {
    // Adds a class of group-blog to blogs with more than 1 published author.
    if ( is_multi_author() ) {
        $classes[] = 'gridfeel-group-blog';
    }

    if ( !(gridfeel_get_option('disable_loading_animation')) ) {
        $classes[] = 'gridfeel-animated gridfeel-fadein';
    }

    $classes[] = 'gridfeel-theme-is-active';

    if ( get_header_image() ) {
        $classes[] = 'gridfeel-header-image-active';
    }

    if ( gridfeel_get_option('header_image_cover') ) {
        $classes[] = 'gridfeel-header-image-cover';
    }

    if ( has_custom_logo() ) {
        $classes[] = 'gridfeel-custom-logo-active';
    }

    $classes[] = 'gridfeel-layout-type-full';

    $classes[] = 'gridfeel-masonry-inactive';

    if ( is_singular() ) {
        if( is_single() ) {
            if ( gridfeel_get_option('featured_media_under_post_title') ) {
                $classes[] = 'gridfeel-single-media-under-title';
            }
        }
        if( is_page() ) {
            if ( gridfeel_get_option('featured_media_under_page_title') ) {
                $classes[] = 'gridfeel-single-media-under-title';
            }
        }
        if ( is_page_template() ) {
            if ( is_page_template( array( 'template-full-width-page.php', 'template-full-width-page-sidebar.php', 'template-full-width-post.php', 'template-full-width-post-sidebar.php' ) ) ) {
               $classes[] = 'gridfeel-layout-full-width';
            } else {
                $classes[] = 'gridfeel-layout-s1-c-s2';
            }
        } else {
            $classes[] = 'gridfeel-layout-s1-c-s2';
        }
    } else {
        if ( is_404() ) {
            $classes[] = 'gridfeel-layout-full-width';
        } else {
            $classes[] = 'gridfeel-layout-s1-c-s2';
        }
    }

    $classes[] = 'gridfeel-header-banner-active';

    if ( gridfeel_get_option('hide_tagline') ) {
        $classes[] = 'gridfeel-tagline-inactive';
    }

    if ( 'beside-title' === gridfeel_get_option('logo_location') ) {
        $classes[] = 'gridfeel-logo-beside-title';
    } elseif ( 'above-title' === gridfeel_get_option('logo_location') ) {
        $classes[] = 'gridfeel-logo-above-title';
    } else {
        $classes[] = 'gridfeel-logo-above-title';
    }

    if ( gridfeel_is_primary_menu_active() ) {
        $classes[] = 'gridfeel-primary-menu-active';
    } else {
        $classes[] = 'gridfeel-primary-menu-inactive';
    }
    $classes[] = 'gridfeel-primary-mobile-menu-active';
    if ( gridfeel_get_option('center_primary_menu') ) {
        $classes[] = 'gridfeel-primary-menu-centered';
    }

    if ( gridfeel_is_secondary_menu_active() ) {
        $classes[] = 'gridfeel-secondary-menu-active';
    } else {
        $classes[] = 'gridfeel-secondary-menu-inactive';
    }
    $classes[] = 'gridfeel-secondary-mobile-menu-active';
    if ( gridfeel_get_option('center_secondary_menu') ) {
        $classes[] = 'gridfeel-secondary-menu-centered';
    }

    $classes[] = 'gridfeel-secondary-menu-before-header';

    if ( 'top' === gridfeel_grid_thumb_position() ) {
        $classes[] = 'gridfeel-grid-post-thumbnail-position-top';
    } elseif ( 'bottom' === gridfeel_grid_thumb_position() ) {
        $classes[] = 'gridfeel-grid-post-thumbnail-position-bottom';
    } elseif ( 'left' === gridfeel_grid_thumb_position() ) {
        $classes[] = 'gridfeel-grid-post-thumbnail-position-left';
    } elseif ( 'right' === gridfeel_grid_thumb_position() ) {
        $classes[] = 'gridfeel-grid-post-thumbnail-position-right';
    } elseif ( 'center' === gridfeel_grid_thumb_position() ) {
        $classes[] = 'gridfeel-grid-post-thumbnail-position-center';
    } elseif ( 'initial' === gridfeel_grid_thumb_position() ) {
        $classes[] = 'gridfeel-grid-post-thumbnail-position-initial';
    } else {
        $classes[] = 'gridfeel-grid-post-thumbnail-position-top';
    }

    $classes[] = 'gridfeel-table-css-active';

    if ( gridfeel_get_option('activate_responsive_grid_data') ) {
        $classes[] = 'gridfeel-responsive-grid-data';
    } else {
        $classes[] = 'gridfeel-unresponsive-grid-data';
    }

    if ( gridfeel_get_option('auto_width_thumbnail') ) {
        $classes[] = 'gridfeel-auto-width-thumbnail';
    } else {
        $classes[] = 'gridfeel-full-width-thumbnail';
    }

    if ( gridfeel_get_option('no_underline_content_links') ) {
        $classes[] = 'gridfeel-nouc-links';
    } else {
        $classes[] = 'gridfeel-uc-links';
    }

    return apply_filters( 'gridfeel_body_classes', $classes );
}
add_filter( 'body_class', 'gridfeel_body_classes' );