<?php
/**
 * CSS related hooks.
 *
 * This file contains hook functions which are related to CSS.
 *
 * @package Blogism
 */

if ( ! function_exists( 'blogism_trigger_custom_css_action' ) ) :

	/**
	 * Do action theme Custom CSS.
	 *
	 * @since 1.0.0
	 */
	function blogism_trigger_custom_css_action() {

		/**
		 * Hook - blogism_action_theme_custom_css.
		 */
		do_action( 'blogism_action_theme_custom_css' );

	}

endif;

add_action( 'wp_head', 'blogism_trigger_custom_css_action', 99 );

if ( ! function_exists( 'blogism_add_theme_custom_font_css' ) ) :

	/**
	 * Inject theme custom font CSS.
	 *
	 * @since 1.0.0
	 */
	function blogism_add_theme_custom_font_css() {

		$custom_css = '';

		$font_settings = blogism_get_font_family_theme_settings_options();

		$required_fonts = array();

		if ( ! empty( $font_settings ) ) {
			foreach ( $font_settings as $key => $val ) {
				$option_value = blogism_get_option( $key );
				if ( ! empty( $option_value ) && $val['default'] !== $option_value ) {
					$required_fonts[ $key ] = $option_value;
				}
			}
		}
		if ( empty( $required_fonts ) ) {

			// We do not need extra CSS.
			return;
		}

		foreach ( $required_fonts as $key => $font ) {

			$family = blogism_get_font_family_from_key( $font );

			if ( ! empty( $family ) ) {

				switch ( $key ) {
					case 'font_site_default':
						$custom_css .= 'body{font-family:' . $family . '}' . "\n";
					break;

					case 'font_site_title':
						$custom_css .= '.site-title{font-family:' . $family . '}' . "\n";
					break;

					case 'font_site_tagline':
						$custom_css .= '.site-description{font-family:' . $family . '}' . "\n";
					break;

					case 'font_heading_tags':
						$custom_css .= 'h1,h2,h3,h4,h5,h6{font-family:' . $family . '}' . "\n";
					break;

					case 'font_content_title':
						$custom_css .= '.entry-header .entry-title{font-family:' . $family . '}' . "\n";
					break;

					case 'font_content_body':
						$custom_css .= '#content{font-family:' . $family . '}' . "\n";
					break;

					case 'font_navigation':
						$custom_css .= '#site-navigation ul li a{font-family:' . $family . '}' . "\n";
					break;

					default:
					break;
				}
			}
		}

		// Render style.
		if ( ! empty( $custom_css ) ) {
			echo '<style type="text/css">';
			echo $custom_css;
			echo '</style>';
		}

	}

endif;

add_action( 'blogism_action_theme_custom_css', 'blogism_add_theme_custom_font_css' );


if ( ! function_exists( 'blogism_add_theme_custom_color_css' ) ) :

	/**
	 * Inject theme custom color CSS.
	 *
	 * @since 1.0.0
	 */
	function blogism_add_theme_custom_color_css() {

		$custom_css = '';

		$color_settings = blogism_get_color_theme_settings_options();

		$default = blogism_get_default_colors();

		$required_colors = array();

		if ( ! empty( $color_settings ) ) {
		  foreach ($color_settings as $key => $val ) {
		    $option_value = blogism_get_option( $key );
		    if ( ! empty( $option_value ) && $default[$key] != $option_value ) {
		      $required_colors[ $key ] = $option_value;
		    }
		  }
		}
		if ( empty( $required_colors ) ) {
		  // We do not need extra CSS.
		  return;
		}

		foreach ( $required_colors as $key => $color ) {

			switch ( $key ) {

				// Basic.
				case 'color_basic_text':
				  $custom_css .= 'body{color:' . $color . '}' . "\n";
				  break;
				case 'color_basic_link':
				  $custom_css .= 'a,a:visited{color:' . $color . '}' . "\n";
				  $custom_css .= '#mobile-trigger i,.meta-nav{background-color:' . $color . '}' . "\n";
				   $custom_css .= '.meta-nav{border-color:' . $color . '}' . "\n";
				  break;
				case 'color_basic_link_hover':
				  $custom_css .= 'a:hover,a:active,a:focus{color:' . $color . '}' . "\n";
				  break;
				case 'color_basic_heading':
				  $custom_css .= 'h1,h2,h3,h4,h5,h6{color:' . $color . '}' . "\n";
				  break;
				case 'color_basic_button_text':
				$custom_css .= 'a.custom-button,.custom-button:visited, button, a.button, input[type="button"], input[type="reset"], input[type="submit"], button:visited, a.button:visited, a.custom-button:visited, #infinite-handle span button:visited, input[type="button"]:visited, input[type="reset"]:visited, input[type="submit"]:visited{color:' . $color . '}' . "\n";

				 case 'color_basic_button_background':
				  $custom_css .= 'a.custom-button,.custom-button:visited, button, a.button, input[type="button"], input[type="reset"], input[type="submit"]{background-color:' . $color . '}' . "\n";

				case 'color_basic_button_text_hover':
				  $custom_css .= 'a.custom-button:hover, button:hover, a.button:hover, input[type="button"]:hover, input[type="reset"]:hover, input[type="submit"]:hover, #infinite-handle span button:focus, button:focus, a.button:focus, a.custom-button:focus, input[type="button"]:focus, input[type="reset"]:focus, input[type="submit"]:focus, #infinite-handle span button:active, button:active, a.custom-button:active, input[type="button"]:active, input[type="reset"]:active, input[type="submit"]:active{color:' . $color . '}' . "\n";



				case 'color_basic_button_background_hover':
				  $custom_css .= ' a.custom-button:hover, button:hover, a.button:hover, input[type="button"]:hover, input[type="reset"]:hover, input[type="submit"]:hover, #infinite-handle span button:focus, button:focus, a.button:focus, a.custom-button:focus, input[type="button"]:focus, input[type="reset"]:focus, input[type="submit"]:focus, #infinite-handle span button:active, button:active, a.custom-button:active, input[type="button"]:active, input[type="reset"]:active, input[type="submit"]:active{background-color:' . $color . '}' . "\n";
				 

				// Top Header.
				case 'color_top_header_background':
				  $custom_css .= '#tophead {background-color:' . $color . '}' . "\n";
				  break;
				case 'color_top_header_icon':
				  $custom_css .= '#tophead .blogism_widget_social ul li a,#tophead .blogism_widget_social ul li a:visited{color:' . $color . '}' . "\n";
				  break;
				case 'color_top_header_icon_hover':
				  $custom_css .= '#tophead .blogism_widget_social ul li a:hover::before, #tophead .blogism_widget_social ul li a:focus::before,#tophead .blogism_widget_social ul li a:active::before{color:' . $color . '}' . "\n";
				break;
				case 'color_top_header_icon_background':
				  $custom_css .= '#tophead .blogism_widget_social ul li a::before,#tophead .blogism_widget_social ul li a:visited{background-color:' . $color . '}' . "\n";
				break;
				  case 'color_top_header_icon_background_hover':
				$custom_css .= '#tophead .blogism_widget_social ul li a:hover::before, #tophead .blogism_widget_social ul li a:focus::before,#tophead .blogism_widget_social ul li a:active::before{background-color:' . $color . '}' . "\n";
				break;


				// Header.
				case 'color_header_background':
				  $custom_css .= '#masthead,.custom-header-enabled .site-branding {background-color:' . $color . '}' . "\n";
				   $custom_css .= '.custom-header-enabled .branding-inner-wrapper{border-color:' . $color . '}' . "\n";
				  break;
				case 'color_header_title':
				  $custom_css .= '#site-identity .site-title > a,#site-identity .site-title > a:visited{color:' . $color . '}' . "\n";
		        break;
				case 'color_header_title_hover':
				  $custom_css .= '#site-identity .site-title > a:hover,#site-identity .site-title > a:active,#site-identity .site-title > a:focus{color:' . $color . '}' . "\n";
				  break;
				case 'color_header_tagline':
				  $custom_css .= '.site-description{color:' . $color . '}' . "\n";
				  break;


			   // Primary Menu.
				case 'color_primary_menu_background':
				  $custom_css .= '.site-header-menu,.main-navigation ul ul li{background-color:' . $color . '}' . "\n";
				case 'color_primary_menu_background':
				  $custom_css .= '.main-navigation ul ul::before{border-bottom-color:' . $color . '}' . "\n";
				break;

				case 'color_primary_menu_link':
				  $custom_css .= '.main-navigation ul li a,.dropdown-toggle::after,.main-navigation ul li a:visited{color:' . $color . '}' . "\n";
				  break;
				case 'color_primary_menu_link_hover':
				  $custom_css .= '.main-navigation ul li a:hover,.main-navigation li.current-menu-item > a,.main-navigation li.current_page_item > a,.main-navigation ul li:hover > a,.main-navigation ul  li a:hover, .main-navigation ul  li a:focus, .main-navigation ul  li a:active, .main-navigation ul  li.current-menu-item > a, .main-navigation ul  li.current-menu-ancestor > a, .main-navigation  ul li:hover > a, .main-navigation ul  li:hover > a, .main-navigation ul  li:hover > a{color:' . $color . '}' . "\n";
				  break;

				case 'color_primary_menu_link_hover_background':
				  $custom_css .= '.main-navigation ul li a:hover, .main-navigation  ul li a:focus, .main-navigation ul  li a:active, .main-navigation ul li.current-menu-item > a, .main-navigation ul  li.current-menu-ancestor > a, .main-navigation ul  li:hover > a, .main-navigation ul  li:hover > a, .main-navigation  ul li:hover > a,.main-navigation ul ul li a:hover, .main-navigation ul ul li a:focus, .main-navigation ul ul li a:active, .main-navigation ul ul li.current-menu-item > a, .main-navigation ul ul li.current-menu-ancestor > a, .main-navigation ul ul li:hover > a, .main-navigation ul ul li:hover > a, .main-navigation ul ul li:hover > a{background-color:' . $color . '}' . "\n";
				  break;

				
			   // Featured Block.
				case 'color_featured_block_background':
				  $custom_css .= '#featured-block{background-color:' . $color . '}' . "\n";
				  break;
				case 'color_featured_block_title':
				  $custom_css .= '#featured-block .featured-block-item-title a, #featured-block .featured-block-item-title a:visited{color:' . $color . '}' . "\n";
		        break;
				case 'color_featured_block_title_hover':
				  $custom_css .= '#featured-block .featured-block-item-title a:hover,#featured-block .featured-block-item-title a:focus,#featured-block .featured-block-item-title a:active{color:' . $color . '}' . "\n";
				  break;
				case 'color_featured_block_title_background':
				  $custom_css .= '#featured-block .featured-block-item-title a, #featured-block .featured-block-item-title a:visited{background-color:' . $color . '}' . "\n";
				  break;

				// Content.
				case 'color_content_background':
				  $custom_css .= '#content{background-color:' . $color . '}' . "\n";
				  break;
				  case 'color_primary_content_background':
				  $custom_css .= '#primary .entry-content-wrapper,.blog .entry-content-inner, .archive .entry-content-inner, .single .entry-content-inner{background-color:' . $color . '}' . "\n";
				  break;
				case 'color_content_title':
				  $custom_css .= '#primary .entry-title,#primary .entry-title a{color:' . $color . '}' . "\n";
				  break;
				 case 'color_content_title_link_hover':
				  $custom_css .= '#primary .entry-title a:hover,#primary .entry-title a:active,#primary .entry-title a:focus{color:' . $color . '}' . "\n";
				  break;
				case 'color_content_text':
				  $custom_css .= '#primary {color:' . $color . '}' . "\n";
				  break;
				case 'color_content_link':
				  $custom_css .= '#primary article a{color:' . $color . '}' . "\n";
				  break;
				case 'color_content_link_hover':
				  $custom_css .= '#primary article a:hover{color:' . $color . '}' . "\n";
				  break;
				case 'color_content_meta_link':
				  $custom_css .= '#primary .entry-meta > span a,#primary .entry-footer > span a{color:' . $color . '}' . "\n";
				  $custom_css .= '.entry-footer .entry-meta > span{border-color:' . $color . '}' . "\n";
				  
				  break;
				case 'color_content_meta_link_hover':
				  $custom_css .= '#primary .entry-meta > span a:hover,#primary  .entry-footer > span a:hover{color:' . $color . '}' . "\n";
				  break;

				case 'color_content_meta_icon':
				  $custom_css .= '#primary .entry-meta > span::before,#primary  .entry-footer > span::before{color:' . $color . '}' . "\n";
				  break;

				case 'color_content_meta_date_day':
				  $custom_css .= '.entry-header .entry-meta span span.entry-day,
				  .entry-header .entry-meta a:visited span span.entry-day{color:' . $color . '}' . "\n";
			  
				  break;

				case 'color_content_meta_date_day_hover':
				  $custom_css .= '.entry-header .entry-meta a:hover span.entry-day, .entry-header .entry-meta a:focus span.entry-day, .entry-header .entry-meta a:active span.entry-day{color:' . $color . '}' . "\n";
				  break;

				case 'color_content_meta_date_day_background':
				  $custom_css .= '.entry-header .entry-meta span.entry-day,
				  .entry-header .entry-meta  a:visited span.entry-day{background-color:' . $color . '}' . "\n";
				  
				  break;
				case 'color_content_meta_date_day_background_hover':
				  $custom_css .= '.entry-header .entry-meta a:hover span.entry-day, .entry-header .entry-meta a:focus span.entry-day, .entry-header .entry-meta a:active span.entry-day{background-color:' . $color . '}' . "\n";
				  break;

				case 'color_content_meta_date_month':
				  $custom_css .= '.entry-header .entry-meta span.entry-month,.entry-header .entry-meta a:visited span.entry-month{color:' . $color . '}' . "\n";
			  
				  break;
				case 'color_content_meta_date_month_hover':
				  $custom_css .= '.entry-header .entry-meta a:hover span.entry-month,.entry-header .entry-meta a:active span.entry-month,
				  .entry-header .entry-meta a:focus span.entry-month{color:' . $color . '}' . "\n";
				  break;

				case 'color_content_meta_date_month_background':
				  $custom_css .= '.entry-header .entry-meta span.entry-month,.entry-header .entry-meta a:visited span.entry-month{background-color:' . $color . '}' . "\n";
				  
				  break;
				case 'color_content_meta_date_month_background_hover':
				  $custom_css .= '.entry-header .entry-meta a:hover span.entry-month,.entry-header .entry-meta a:active span.entry-month,
				  .entry-header .entry-meta a:focus span.entry-month{background-color:' . $color . '}' . "\n";
				  break;
				 case 'color_content_border':
				  $custom_css .= '.entry-content-wrapper{border-color:' . $color . '}' . "\n";
				  $custom_css .= '.tag-post-formats .entry-content-inner::before, .blog .hentry .entry-content-inner::before{background-color:' . $color . '}' . "\n";
				  
				  break;
				case 'color_content_post_formate_icon':
				  $custom_css .= '.tag-post-formats .entry-content-inner::before, .blog .hentry .entry-content-inner::before{color:' . $color . '}' . "\n";
				  break; 


				// Sidebar.
				 case 'color_sidebar_widget_background':
				  $custom_css .= '.sidebar .widget{background-color:' . $color . '}' . "\n";
				  break;
				case 'color_sidebar_title':
				  $custom_css .= '.sidebar .widget-title{color:' . $color . '}' . "\n";
				  break;
				case 'color_sidebar_title_background':
				  $custom_css .= '.sidebar .widget-title{background-color:' . $color . '}' . "\n";
				  break;
				case 'color_sidebar_text':
				  $custom_css .= '.sidebar{color:' . $color . '}' . "\n";
				  break;
				case 'color_sidebar_link':
				  $custom_css .= '.sidebar .widget a,.sidebar .widget a:visited{color:' . $color . '}' . "\n";

				  break;
				case 'color_sidebar_link_hover':
				  $custom_css .= '.sidebar .widget a:hover,.sidebar .widget a:focus,.sidebar .widget a:active{color:' . $color . '}' . "\n";
				  break;
				case 'color_sidebar_list_icon':
				  $custom_css .= '.sidebar ul li::before{color:' . $color . '}' . "\n";
				  $custom_css .= '.sidebar .widget-title{border-color:' . $color . '}' . "\n";

				  break;

				// Footer area.
				case 'color_footer_area_background':
				  $custom_css .= '#colophon{background-color:' . $color . '}' . "\n";
				  break;
				case 'color_footer_area_text':
				  $custom_css .= '#colophon{color:' . $color . '}' . "\n";
				  break;
				case 'color_footer_area_link':
				  $custom_css .= '#colophon a,#colophon a:visited{color:' . $color . '}' . "\n";
				  break;
				case 'color_footer_area_link_hover':
				  $custom_css .= '#colophon a:hover,#colophon a:active,#colophon a:focus{color:' . $color . '}' . "\n";
				  break;

				// Go To Top.
			    case 'color_goto_top_icon':
				  $custom_css .= '#btn-scrollup i.fa{color:' . $color . '}' . "\n";
				  break;
				case 'color_goto_top_icon_hover':
				  $custom_css .= '#btn-scrollup i.fa:hover{color:' . $color . '}' . "\n";
				  break;
				case 'color_goto_top_background':
				  $custom_css .= '#btn-scrollup{background-color:' . $color . '}' . "\n";
				  break;
				case 'color_goto_top_background_hover':
				  $custom_css .= '#btn-scrollup:hover{background-color:' . $color . '}' . "\n";
				  break;


				// Pagination.
				case 'color_pagination_link':
				  $custom_css .= '.navigation .nav-links a,.navigation .nav-links a:visited, .pagination .nav-links .page-numbers,.pagination .nav-links .page-numbers:visited,#primary #infinite-handle span button{color:' . $color . '}' . "\n";
				  break;
				case 'color_pagination_link_hover':
				  $custom_css .= '.navigation .nav-links a:active,.navigation .nav-links a:focus,.navigation .nav-links a:hover,.pagination .nav-links .current, .pagination .nav-links a:hover, .pagination .nav-links a:active, .pagination .nav-links a:focus,#primary #infinite-handle span button:hover,#primary  #infinite-handle span button:focus{color:' . $color . '}' . "\n";
				  break;
				case 'color_pagination_link_background':
				  $custom_css .= '.pagination .nav-links .page-numbers,.pagination .nav-links .page-numbers:visited,#primary #infinite-handle span button,#primary #infinite-handle span button{background-color:' . $color . '}' . "\n";
				  break;
				case 'color_pagination_link_background_hover':
				  $custom_css .= '.pagination .nav-links .current, .pagination .nav-links a:hover, .pagination .nav-links a:active, .pagination .nav-links a:focus,#primary #infinite-handle span button:active,#primary #infinite-handle span button:hover,#primary  #infinite-handle span button:focus{background-color:' . $color . '}' . "\n";
				  break;

				// Breadcrumb.
				case 'color_breadcrumb_background':
				  $custom_css .= '#breadcrumb{background-color:' . $color . '}' . "\n";
				  break;
				case 'color_breadcrumb_link':
				  $custom_css .= '#crumbs a,#breadcrumb a{color:' . $color . '}' . "\n";
				  break;
				case 'color_breadcrumb_link_hover':
				  $custom_css .= '#crumbs a:hover,#breadcrumb a:hover{color:' . $color . '}' . "\n";
				  break;
				case 'color_breadcrumb_text':
				  $custom_css .= '#breadcrumb,#breadcrumb .breadcrumb-trail li::after, #crumbs li::after{color:' . $color . '}' . "\n";
				  break;

				// Footer Widgets.
				case 'color_footer_widgets_background':
				  $custom_css .= '#footer-widgets{background-color:' . $color . '}' . "\n";
				  break;
				case 'color_footer_widgets_title':
				  $custom_css .= '#footer-widgets .widget-title{color:' . $color . '}' . "\n";
				  $custom_css .= '#footer-widgets .separator{background-color:' . $color . '}' . "\n";
				  break;
				case 'color_footer_widgets_text':
				  $custom_css .= '#footer-widgets {color:' . $color . '}' . "\n";
				  break;
				case 'color_footer_widgets_link':
				  $custom_css .= '#footer-widgets a,#footer-widgets a:visited{color:' . $color . '}' . "\n";
				  $custom_css .= '#footer-widgets h3.widget-title::after{background-color:' . $color . '}' . "\n";
				break;

				case 'color_footer_widgets_link_hover':
				  $custom_css .= '#footer-widgets a:hover,#footer-widgets a:active,#footer-widgets a:focus{color:' . $color . '}' . "\n";
				    $custom_css .= '#footer-widgets ul li::before{color:' . $color . '}' . "\n";
				  
				  break;

				// Home Page Widgets.
				case 'color_home_widgets_background':
				  $custom_css .= '#sidebar-front-page-widget-area{background-color:' . $color . '}' . "\n";
				  break;
				case 'color_home_widgets_title':
				  $custom_css .= '#sidebar-front-page-widget-area .widget-title{color:' . $color . '}' . "\n";
				  break;
				 case 'color_home_widgets_subtitle':
				  $custom_css .= '#sidebar-front-page-widget-area .widget-subtitle{color:' . $color . '}' . "\n";
				  break;
				case 'color_home_widgets_text':
				  $custom_css .= '#sidebar-front-page-widget-area,#sidebar-front-page-widget-area p{color:' . $color . '}' . "\n";
				  break;
				case 'color_home_widgets_link':
				  $custom_css .= '#sidebar-front-page-widget-area a,#sidebar-front-page-widget-area a:visited{color:' . $color . '}' . "\n";
				  break;
				case 'color_home_widgets_link_hover':
				  $custom_css .= '#sidebar-front-page-widget-area a:hover,#sidebar-front-page-widget-area a:active,#sidebar-front-page-widget-area a:focus{color:' . $color . '}' . "\n";
				  break;

			  default:
			    break;

			}

		}

		// Render style.
		if ( ! empty( $custom_css ) ) {
		  echo '<style type="text/css">';
		  echo $custom_css;
		  echo '</style>';
		}

	}

endif;

add_action( 'blogism_action_theme_custom_css', 'blogism_add_theme_custom_color_css', 25 );
