<?php
/**
 * Managed the theme's dynamic styles.
 *
 * @package Blogbuster
 *
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/*---------------------- Custom CSS ----------------------------*/
    
    if ( ! function_exists( 'blogbuster_custom_css' ) ) :

        /**
         * Handles the `blogbuster_head_css` filter, where all CSS-related functions are hooked.
         *
         * @since 1.0.0
         */
        function blogbuster_custom_css( $output_css = NULL ) {

            // Add filter blogbuster_head_css for adding custom css via other functions.
            $output_css = apply_filters( 'blogbuster_head_css', $output_css );

            if ( ! empty( $output_css ) ) {
                $output_css = wp_strip_all_tags( blogbuster_minify_css( $output_css ) );
                echo "<!--Blogbuster CSS -->\n<style type=\"text/css\">\n". $output_css ."\n</style>";
            }
        }

    endif;

    add_action( 'wp_head', 'blogbuster_custom_css', 999 );

/*---------------------- General CSS ---------------------------*/

    if ( ! function_exists( 'blogbuster_general_css' ) ) :

        /**
         * Handles the general CSS.
         * 
         * @since 1.0.0
         */
        function blogbuster_general_css( $output_css ) {
            $blogbuster_primary_theme_color    = blogbuster_get_customizer_option_value( 'blogbuster_primary_theme_color' );
            $primary_darker_color              = blogbuster_darker_color( $blogbuster_primary_theme_color, '-20' );
            $blogbuster_text_color             = blogbuster_get_customizer_option_value( 'blogbuster_text_color' );
            $blogbuster_link_color             = blogbuster_get_customizer_option_value( 'blogbuster_link_color' );
            $blogbuster_link_hover_color       = blogbuster_get_customizer_option_value( 'blogbuster_link_hover_color' );
            
            $get_categories = get_categories( array( 'hide_empty' => 1 ) );

            //define variable for custom css
            $custom_css = '';


            // Background Color
            $custom_css .= "
            .trending-posts-wrapper .post-cat-item a, .latest-posts-wrapper .post-cat-item a, .bttn:hover,button,input[type='button']:hover,input[type='reset']:hover,input[type='submit']:hover,.reply .comment-reply-link,.widget_search .search-submit,.widget_search .search-submit:hover,.widget_tag_cloud .tagcloud a:hover,.widget.widget_tag_cloud a:hover,.read-more-button:hover a,.edit-link a,#site-navigation ul.sub-menu, #site-navigation ul.children,.wp-block-search__button,.responsive-menu-icon-wrapper #site-navigation .primary-menu-wrap,#site-navigation ul li a.mt-sub-menu-toggle:hover,  .single .post-cat-item a,
            #site-navigation ul li a.mt-sub-menu-toggle:focus,.header-search-wrapper .mt-search-icon a i ,.site-footer, .header-search-wrapper .search-form-wrap .search-submit, #mt-scrollup ,.mt-front-sticky-post-wrapper .post-cat-item a,.trending-posts .post-thumbnail-wrap .post-count,.entry-title a::after,.mt-wave .mt-rect,.mt-three-bounce .mt-child,.mt-folding-cube .mt-cube:before {background-color: ". esc_attr( $blogbuster_primary_theme_color ) ."}\n";

            // Color
           $custom_css .= ".nav-content:hover,a:hover,a:focus,a:active,.entry-cat .cat-links a:hover,.entry-cat a:hover,.byline a:hover,.posted-on a:hover,.entry-footer a:hover,.comment-author .fn .url:hover,.commentmetadata .comment-edit-link,#cancel-comment-reply-link,#cancel-comment-reply-link:before,.logged-in-as a,.widget a:hover,.widget a:hover::before,.widget li:hover::before,.post-cat-item a:hover, .featured-info-wrap:hover a,.featured-info-wrap:hover span, .published.updated:hover,.published:hover, .author:hover,.entry-meta span:hover::before,.entry-meta span:hover::before,.site-info .sep,.author-website a ,#secondary .widget .widget-title, .wp-block-heading, .mt-related-post-title,.wp-block-search__label,#site-navigation ul li a.mt-sub-menu-toggle,span.tags-links:hover, .mt-front-sticky-post-wrapper .post-cat-item a:hover,.mt-front-sticky-post-wrapper .tags-links a:hover,.widget-title,.mt-menu-toggle:hover{color: ". esc_attr( $blogbuster_primary_theme_color ) ."}\n";

            // Border Color
            $custom_css .= ".navigation .nav-links a:hover{border-color: ". esc_attr( $blogbuster_primary_theme_color ) ."}\n";

            // Border Left Color
            $custom_css .= ".page-header .page-title{border-left-color: ". esc_attr( $blogbuster_primary_theme_color ) ."}\n";

            // RTL Border Right Color
            $custom_css .= ".rtl .page-header .page-title,{border-right-color: ". esc_attr( $blogbuster_primary_theme_color ) ."}\n";

            // Border Top Color
            $custom_css .= "#site-navigation .menu-item-description::after,.search-form-wrap{border-top-color: ". esc_attr( $blogbuster_primary_theme_color ) ."}\n";

            // Woocommerce Dynamic color

            $custom_css .= ".woocommerce ul.products li.product .price,.woocommerce div.product p.price, .woocommerce div.product span.price,.woocommerce .product_meta a:hover,.woocommerce-error:before, .woocommerce-info:before, .woocommerce-message:before{color: ". esc_attr( $blogbuster_primary_theme_color ) ."}\n";

            $custom_css .= ".woocommerce div.product .woocommerce-tabs ul.tabs{border-bottom-color: ". esc_attr( $blogbuster_primary_theme_color ) ."}\n";

            $custom_css .= ".woocommerce-error, .woocommerce-info, .woocommerce-message{border-top-color: ". esc_attr( $blogbuster_primary_theme_color ) ."}\n";

            // Primary Hover Color
            $custom_css .= "#site-navigation ul li:hover > a, #site-navigation ul li.current-menu-item > a, #site-navigation ul li.current_page_item > a, #site-navigation ul li.current-menu-ancestor > a, #site-navigation ul li.focus > a{color: ". esc_attr( $primary_darker_color ) ."}\n";

            // Text Color
            $custom_css .= "body {color: ". esc_attr( $blogbuster_text_color ) ."}\n";

            // Link Color
            $custom_css .= ".page-content a, .entry-content a, .entry-summary a{color: ". esc_attr( $blogbuster_link_color ) ."}\n";

            // Link Hover Color
            $custom_css .= ".page-content a:hover, .entry-content a:hover, .entry-summary a:, .entry-title a:hover{color: ". esc_attr( $blogbuster_link_hover_color ) ."}\n";

            // different categories color
            foreach ( $get_categories as $category ) {
                $get_term_id = $category->term_id;
                $get_cat_color = get_theme_mod( 'category_color_'.strtolower( $get_term_id ), '#ffeed6', '25' );      

                // category Color
                $custom_css .= ".mt-single-featured-wrapper.featured-cat-".esc_attr( $get_term_id ).", .blogbuster-related-posts-wrapper article.post-cat-".esc_attr( $get_term_id ).", .archive-content-wrapper article.post-cat-".esc_attr( $get_term_id )."{background-color: ". esc_attr( $get_cat_color ) ."}\n";
                        


                }
            
            if ( ! empty( $custom_css ) ) {
                $output_css .= $custom_css;
            }


            return $output_css;
        }



    endif;

    add_filter( 'blogbuster_head_css', 'blogbuster_general_css' );

/*---------------------- Typography CSS-------------------------*/
    
    if ( ! function_exists( 'blogbuster_typography_css' ) ) :

        /**
         * Handles the typography CSS output.
         *
         * @since 1.0.0
         */
        function blogbuster_typography_css( $output_css ) {

            $custom_css = '';

            /**
             * Body typography
             */
            $blogbuster_body_font_family       = blogbuster_get_customizer_option_value( 'blogbuster_body_font_family' );
            $blogbuster_body_font_weight       = blogbuster_get_customizer_option_value( 'blogbuster_body_font_weight' );
            $blogbuster_body_font_style        = blogbuster_get_customizer_option_value( 'blogbuster_body_font_style' );
            $blogbuster_body_font_transform    = blogbuster_get_customizer_option_value( 'blogbuster_body_font_transform' );
            $blogbuster_body_font_decoration   = blogbuster_get_customizer_option_value( 'blogbuster_body_font_decoration' );

            $custom_css .= "body{
                font-family:        $blogbuster_body_font_family;
                font-style:         $blogbuster_body_font_style;
                font-weight:        $blogbuster_body_font_weight;
                text-decoration:    $blogbuster_body_font_decoration;
                text-transform:     $blogbuster_body_font_transform;
            }\n";

            /**
             * H1 to H6 typography
             */
            $blogbuster_heading_font_family       = blogbuster_get_customizer_option_value( 'blogbuster_heading_font_family' );
            $blogbuster_heading_font_weight       = blogbuster_get_customizer_option_value( 'blogbuster_heading_font_weight' );
            $blogbuster_heading_font_style        = blogbuster_get_customizer_option_value( 'blogbuster_heading_font_style' );
            $blogbuster_heading_font_transform    = blogbuster_get_customizer_option_value( 'blogbuster_heading_font_transform' );
            $blogbuster_heading_font_decoration   = blogbuster_get_customizer_option_value( 'blogbuster_heading_font_decoration' );

            $custom_css .= "h1, h2, h3, h4, h5, h6,.site-title{
                font-family:        $blogbuster_heading_font_family;
                font-style:         $blogbuster_heading_font_style;
                font-weight:        $blogbuster_heading_font_weight;
                text-decoration:    $blogbuster_heading_font_decoration;
                text-transform:     $blogbuster_heading_font_transform;
            }\n";

            if ( ! empty( $custom_css ) ) {
                $output_css .= '/*/ Typography CSS /*/'. $custom_css;
            }

            return $output_css;
        }

    endif;

    add_filter( 'blogbuster_head_css', 'blogbuster_typography_css' );