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

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

/*---------------------- Custom CSS ----------------------------*/

    if ( ! function_exists( 'purenote_custom_css' ) ) :

        /**
         * function to handle purenote_head_css filter where all the css relation functions are hooked.
         *
         * @since 1.0.0
         */
        function purenote_custom_css( $output_css = NULL ) {

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

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

    endif;

    add_action( 'wp_head', 'purenote_custom_css', 9999 );

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

    if ( ! function_exists( 'purenote_general_css' ) ) :

        /**
         * function to handle the genral css for all sections.
         * 
         * @since 1.0.0
         */
        function purenote_general_css( $output_css ) {
            $purenote_primary_theme_color    = purenote_get_customizer_option_value( 'purenote_primary_theme_color' );
            $purenote_text_color             = purenote_get_customizer_option_value( 'purenote_text_color' );
            $purenote_link_color             = purenote_get_customizer_option_value( 'purenote_link_color' );
            $purenote_link_hover_color       = purenote_get_customizer_option_value( 'purenote_link_hover_color' );
            
            $get_categories = get_categories( array( 'hide_empty' => 1 ) );

            $purenote_main_container_width   = purenote_get_customizer_option_value( 'purenote_main_container_width' );
            $purenote_boxed_container_width  = purenote_get_customizer_option_value( 'purenote_boxed_container_width' );

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

            // top header bg color
        $header_top_bg_color = purenote_get_customizer_option_value( 'purenote_header_main_bg_color' );
        $custom_css .= "#top-header {background-color: ". esc_attr( $header_top_bg_color ) ."}\n";
        
            // Background Color
            $custom_css .= "#purenote-scrollup, .news-ticker-label, #site-navigation .menu-item-description , #site-navigation ul.sub-menu,
            #site-navigation ul.children, .header-search-wrapper .search-form-wrap .search-submit, .custom-button-wrap.purenote-icon-elements a, .site-footer, #purenote-scrollup, .purenote-banner-wrapper .lSAction>a,.purenote-wave .purenote-rect ,.purenote-three-bounce .purenote-child,.purenote-folding-cube .purenote-cube:before, #site-navigation .primary-menu-wrap.isActive , button.wp-block-search__button{background-color: ". esc_attr( $purenote_primary_theme_color ) ."}\n";

            // Color
           $custom_css .= " a:hover,a:focus,a:active,#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,#site-navigation .menu-item-description::after, .post-cat-item a:hover, .purenote-web-stories .content-wrap .cat-item a:hover, .navigation .nav-links .page-numbers ,.purenote-banner-wrapper .slide-title a:hover,button.wp-block-search__button:hover, .read-more-button a:hover, .sticky-sidebar-close, .form-submit .submit:hover,.post-meta-wrap span>a:hover,.highlight-slider-wrapper .post-title a:hover, .posted-on:hover,.trending-posts-wrapper .entry-title a:hover, .latest-posts-wrapper .entry-title a:hover,.highlight-slider-wrapper .post-meta:hover i,.header-news-ticker-wrapper .news-ticker-posts-wrapper .post-title a:hover,.published.updated:hover, .byline:hover, .byline:hover span{color: ". esc_attr( $purenote_primary_theme_color ) ."}\n";

            // Border 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 {border-color:". esc_attr( $purenote_primary_theme_color ) ."}\n";

            // Border-top Color
           $custom_css .= ".search-form-wrap {border-top-color: ". esc_attr( $purenote_primary_theme_color ) ."}\n";

            // Woocommerce Dynamic color

            $custom_css .= " ". esc_attr( $purenote_primary_theme_color ) ."}\n";

            $custom_css .= " ". esc_attr( $purenote_primary_theme_color ) ."}\n";

            $custom_css .= " ". esc_attr( $purenote_primary_theme_color ) ."}\n";

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

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

            // Link Hover Color
            $custom_css .= " .header-news-ticker-wrapper .news-ticker-posts-wrapper .post-title a:hover,.banner-tabbed-wrapper ul.banner-tabs li a:hover,.entry-cat .cat-links a:hover, .entry-cat a:hover,.byline a:hover, .posted-on a:hover,.entry-meta span:hover::before, .byline:hover:before,.posted-on:hover:before,.edit-link a,.widget a:hover, .widget a:hover::before,.widget li:hover::before,.site-info .widget a:hover, .frontpage-block .entry-title a:hover, .slide-title a:hover, .trending-posts .entry-title a:hover, .latest-posts-wrapper .posts-column-wrapper .entry-title a:hover, .header-news-ticker-wrapper .post-title a:hover, .entry-title a:hover, .page-content a:hover,.entry-content a:hover, .entry-summary a:hover, .social-icons-wrapper a:hover{color: ". esc_attr( $purenote_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 ), '#3b2d1b' );


                $custom_css .= ".post-cats-list li.cat-".absint( $get_term_id ) ." a,.purenote-web-stories .content-wrap .cat-".absint( $get_term_id ) ." a, .highlight-slider-wrapper .post-categories li.cat-".absint( $get_term_id ) ." a  { background-color: ". esc_attr( $get_cat_color ) ."}\n";

                $custom_css .= ".post-cats-list li.cat-".absint( $get_term_id ) ." a,.purenote-web-stories .content-wrap .cat-".absint( $get_term_id ) ." a,.highlight-slider-wrapper .post-categories li.cat-".absint( $get_term_id ) ." a { border-color: ". esc_attr( $get_cat_color ) ."}\n";

                $custom_css .= ".post-cats-list li.cat-".absint( $get_term_id ) ." a:hover, .highlight-slider-wrapper .post-categories li.cat-".absint( $get_term_id ) ." a:hover,.widget .latest-posts-wrapper .post-cat-item.cat-".absint( $get_term_id ) ." a:hover { color: ". esc_attr( $get_cat_color ) ."}\n";

            }

            $custom_css .= ".purenote-container{width: ". esc_attr( $purenote_main_container_width ) ."px}\n";

            $custom_css .= ".purenote-site-layout--boxed #page{width: ". esc_attr( $purenote_boxed_container_width ) ."px}\n";

            // frontpage banner bg type with value
            $purenote_banner_bg_type = purenote_get_customizer_option_value( 'purenote_banner_bg_type' );
            if ( 'bg-image' === $purenote_banner_bg_type ) {
                $purenote_banner_bg_image        = purenote_get_customizer_option_value( 'purenote_banner_bg_image' );
                $purenote_banner_bg_image_url    = wp_get_attachment_image_url( $purenote_banner_bg_image, 'full' );
                $custom_css .= ".purenote-banner-wrapper{background-image:url(". esc_url( $purenote_banner_bg_image_url ) .")}\n";
            } elseif ( 'bg-color' === $purenote_banner_bg_type ) {
                $purenote_banner_bg_color = purenote_get_customizer_option_value( 'purenote_banner_bg_color' );
                $custom_css .= ".purenote-banner-wrapper{background-color: ". esc_attr( $purenote_banner_bg_color ) ."}\n";
            }
            
            if ( ! empty( $custom_css ) ) {
                $output_css .= $custom_css;
            }

            return $output_css;
        }

    endif;

    add_filter( 'purenote_head_css', 'purenote_general_css' );

/*---------------------- Header CSS------------------------ ----*/
if ( ! function_exists( 'purenote_top_header_css' ) ) :

    function purenote_top_header_css( $output_css ) {

        $custom_css = '';
        $top_header_selector = '#top-header.top-header-wrapper'; 
        $top_header_text_color = purenote_get_customizer_option_value( 'purenote_top_header_text_color' );
        $top_header_bg_color   = purenote_get_customizer_option_value( 'purenote_header_bg_color' );

        // Text color
        if ( ! empty( $top_header_text_color ) ) {
            $custom_css .= $top_header_selector . " { color: ". esc_attr( $top_header_text_color ) ."; }\n";
            $custom_css .= $top_header_selector . " * { color: ". esc_attr( $top_header_text_color ) ."; }\n";
            $custom_css .= $top_header_selector . " a { color: ". esc_attr( $top_header_text_color ) ."; }\n";
        }

        // Background color
        if ( ! empty( $top_header_bg_color ) ) {
            $custom_css .= $top_header_selector . " { background-color: ". esc_attr( $top_header_bg_color ) ."; }\n";
        }

        if ( ! empty( $custom_css ) ) {
            $output_css .= "/* Top Header Colors */\n" . $custom_css;
        }

        return $output_css;
    }

endif;

add_filter( 'purenote_head_css', 'purenote_top_header_css', 99 );

    if ( ! function_exists( 'purenote_main_header_css' ) ) :

        /**
         * function to handle the css for header section.
         *
         * @since 1.0.0
         */
        function purenote_main_header_css( $output_css ) {

            $purenote_header_main_bg_type = purenote_get_customizer_option_value( 'purenote_header_main_bg_type' );

            $custom_css = '';

            if ( 'bg-image' === $purenote_header_main_bg_type ) {
                $purenote_header_main_bg_image        = purenote_get_customizer_option_value( 'purenote_header_main_bg_image' );
                $purenote_header_main_bg_image_url    = wp_get_attachment_image_url( $purenote_header_main_bg_image, 'full' );
                if ( ! empty( $purenote_header_main_bg_image_url ) ) {
                    $custom_css .= "background-image:url(". esc_url( $purenote_header_main_bg_image_url ) .")\n";
                }
            } elseif ( 'bg-color' === $purenote_header_main_bg_type ) {
                $purenote_header_main_bg_color = purenote_get_customizer_option_value( 'purenote_header_main_bg_color' );
                $custom_css .= "background-color: ". esc_attr( $purenote_header_main_bg_color ) ."\n";
            }

            if ( ! empty( $custom_css ) ) {
                $output_css .= '/* Main Header CSS */#header{'. $custom_css .'}';
            }

            return $output_css;

        }

    endif;

    add_filter( 'purenote_head_css', 'purenote_main_header_css' );

/*---------------------- Typography CSS-------------------------*/

    if ( ! function_exists( 'purenote_typography_css' ) ) :

    /**
     * function to handle the typography css.
     *
     * @since 1.0.0
     */
    function purenote_typography_css( $output_css ) {

        $custom_css = '';

        /**
         * Body typography
         */
        $purenote_body_font_family       = purenote_get_customizer_option_value( 'purenote_body_font_family' );
        $purenote_body_font_weight       = purenote_get_customizer_option_value( 'purenote_body_font_weight' );
        $purenote_body_font_style        = purenote_get_customizer_option_value( 'purenote_body_font_style' );
        $purenote_body_font_transform    = purenote_get_customizer_option_value( 'purenote_body_font_transform' );
        $purenote_body_font_decoration   = purenote_get_customizer_option_value( 'purenote_body_font_decoration' );

        $custom_css .= "body{
            font-family:        $purenote_body_font_family;
            font-style:         $purenote_body_font_style;
            font-weight:        $purenote_body_font_weight;
            text-decoration:    $purenote_body_font_decoration;
            text-transform:     $purenote_body_font_transform;
        }\n";

        /**
         * H1 to H6 typography
         */
        $purenote_heading_font_family       = purenote_get_customizer_option_value( 'purenote_heading_font_family' );
        $purenote_heading_font_weight       = purenote_get_customizer_option_value( 'purenote_heading_font_weight' );
        $purenote_heading_font_style        = purenote_get_customizer_option_value( 'purenote_heading_font_style' );
        $purenote_heading_font_transform    = purenote_get_customizer_option_value( 'purenote_heading_font_transform' );
        $purenote_heading_font_decoration   = purenote_get_customizer_option_value( 'purenote_heading_font_decoration' );

        $custom_css .= "h1, h2, h3, h4, h5, h6 {
            font-family:        $purenote_heading_font_family;
            font-style:         $purenote_heading_font_style;
            font-weight:        $purenote_heading_font_weight;
            text-decoration:    $purenote_heading_font_decoration;
            text-transform:     $purenote_heading_font_transform;
        }\n";

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

        return $output_css;
    }

endif;

add_filter( 'purenote_head_css', 'purenote_typography_css' );