<?php
 
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'Kktfwp_Inline_Css' ) ) {
  
	class Kktfwp_Inline_Css {

			
		public static function customizer_output() {
			
			$out = '';	
			
			$menu = '.menu-wrapper, .main-nav .sub-menu, .kk_menu_classic .menu-wrapper, .kk_menu_classic .main-nav .sub-menu, .dark-skin.kk_menu_classic .menu-wrapper, .dark-skin.kk_menu_classic .main-nav .sub-menu, .kk_menu_default_hidden .menu-helper, .kk_menu_left_boxed .menu-wrapper, .kk_menu_left_boxed .main-nav .sub-menu, .kk_menu_left_boxed.kk-grid-active .menu-wrapper, .kk_menu_left_boxed.kk-grid-active .main-nav .sub-menu { background-color: %1$s; }';	

			$out .= sprintf( $menu, kktfwp_menuColor() );
			
			// Menu background 2
			$out .= self::generate_css( '.kk_menu_left_boxed .kk-mobile-trigger span, .kk_menu_left_boxed .kk-mobile-trigger span:before, .kk_menu_left_boxed .kk-mobile-trigger span:after, .kk_menu_default .kk-mobile-trigger span, .kk_menu_default .kk-mobile-trigger span:before, .kk_menu_default .kk-mobile-trigger span:after, .kk_menu_default_hidden .kk-mobile-trigger span, .kk_menu_default_hidden .kk-mobile-trigger span:before, .kk_menu_default_hidden .kk-mobile-trigger span:after, .kk_menu_default_hidden .kk-menu-trigger span, .kk_menu_default_hidden .kk-menu-trigger span:before, .kk_menu_default_hidden .kk-menu-trigger span:after, .kk-menu-open .kk-menu-trigger span:before, .kk-menu-open .kk-menu-trigger span:after, .kk_menu_fullscreen.kk-menu-open .kk-menu-trigger span:before, .kk_menu_fullscreen.kk-menu-open .kk-menu-trigger span:after', 'background-color', 'kktfwp_menu_txt_color' );		
			
			// Menu text
			$out .= self::generate_css( '.main-nav li a, .kk_menu_default_hidden .kk-search i, .kk_menu_default_hidden.kk-fs-g .kk-info-trigger, .kk_menu_default_hidden.kk-template-fullscreen .kk-thumbs-trigger, .kk_menu_classic .menu-wrapper, .dark-skin.kk_menu_classic .menu-wrapper, .main-mobile-menu,	.kktfwp-mobile-burger,	.main-mobile-menu .mobile-wrapper ul li a', 'color', 'kktfwp_menu_txt_color' );			
							
			// Accent color
			$out .= self::generate_css( '.blog-title a:hover, .blog-meta a:hover, .format-standard .blog-thumb a:hover, .format-image .blog-thumb a:hover, .flickr_badge_image a:hover, .portfolio-thumb a:hover, .widget-img a:hover, .sub-footer a:hover, a:hover, .page.dark-skin .inner-content a:hover, .current-menu-item, .blog-entry a:not(.wp-block-button__link):not(.wp-block-file__button):not(.post-page-numbers):not(.more-link),	.post-entry a:not(.wp-block-button__link):not(.wp-block-file__button):not(.post-page-numbers):not(.more-link), .home-teaser a, .social li a:hover, .kk-content-fullwidth .kk-parallax-wrapper .blog-meta a:hover', 'color', 'kktfwp_accent_color' );
			
			// Secondary accent color
			$out .= self::generate_css( '.main-nav .sub-menu li a:hover, .kk_menu_default .main-nav .current-menu-parent .current-menu-item  > a, .kk_menu_default .main-nav .menu-item-has-children .current-menu-parent > a, .kk_menu_default_hidden .main-nav .current-menu-parent .current-menu-item  > a, .kk_menu_default_hidden .main-nav .menu-item-has-children .current-menu-parent > a, .kk_menu_left_boxed .main-nav .current-menu-parent .current-menu-item  > a, .kk_menu_left_boxed .main-nav .menu-item-has-children .current-menu-parent > a, ul#thumb-list li:hover, ul#thumb-list li.current-thumb, .pagination .current, input[type="reset"]:hover, .blog-entry .moretag:hover, .bg-slider-ctrl span:hover, .woocommerce .container table.shop_table th, .woocommerce-page .container table.shop_table th, .post.sticky .sticky-post, .over-more, .over-more-title', 'color', 'kktfwp_secondary_accent_color' );
			
			//Background accent color
			$out .= self::generate_css( '.main-nav .sub-menu li a:hover, .kk_menu_default .main-nav .current-menu-parent .current-menu-item  > a, .kk_menu_default .main-nav .menu-item-has-children .current-menu-parent > a, .kk_menu_default_hidden .main-nav .current-menu-parent .current-menu-item  > a, .kk_menu_default_hidden .main-nav .menu-item-has-children .current-menu-parent > a, .kk_menu_left_boxed .main-nav .current-menu-parent .current-menu-item  > a, .kk_menu_left_boxed .main-nav .menu-item-has-children .current-menu-parent > a, ul#thumb-list li:hover, ul#thumb-list li.current-thumb, .pagination .current, input[type="reset"]:hover, .blog-entry .moretag:hover, .bg-slider-ctrl span:hover, .woocommerce .container table.shop_table th, .woocommerce-page .container table.shop_table th, .post.sticky .sticky-post, .single .post-tags a:hover, .tipsy-inner, .kk-loader, #filter-trigger, #filter ul, .over-more, .over-more-title', 'background-color', 'kktfwp_accent_color' );
			
			// Border accent color
			$out .= self::generate_css( '.woocommerce #content input.button:hover, .woocommerce #respond input#submit:hover, .woocommerce a.button:hover, .woocommerce button .button:hover, .woocommerce input.button:hover, .woocommerce-page #content input.button:hover, .woocommerce-page #respond input#submit:hover, .woocommerce-page a.button:hover, .woocommerce-page button.button:hover, .woocommerce-page input.button:hover, .woocommerce ul.products li.product a.added_to_cart:hover, .woocommerce-page ul.products li.product a.added_to_cart:hover, .woocommerce #respond input#submit.alt:hover, .woocommerce a.button.alt:hover, .woocommerce button.button.alt:hover, .woocommerce input.button.alt:hover, .pagination .current, .page-links .current, .pagination a:hover, .page-links a:hover, .blog-entry .more-link:hover, .single .post-tags a:hover, .moretag:hover, .main-nav ul li a:hover, .main-nav .current-menu-parent > a, blockquote, .wp-block-quote.is-large, .wp-block-quote.is-style-large, .linkto:hover .gallery-title, .linkto:hover .portfolio-title, input.submit:hover, input[type="submit"]:hover, .kk_vc .wpb_accordion .wpb_accordion_wrapper .wpb_accordion_header.ui-state-active a, .kk_vc .vc_tta.vc_general .vc_tta-panel.vc_active a, .more-link:hover, .kk-preloader:before', 'border-color', 'kktfwp_accent_color' );	
			
			// Border-top-color
			$out .= self::generate_css( '.kk-content-fullwidth.kk-parallax-title.kk-parallax-title-fullheight .kk-parallax-wrapper .is-loading.kk-down:after', 'border-top-color', 'kktfwp_accent_color' );	

			wp_add_inline_style( 'kktfwp-style', $out );	
		}

		/**
		 * This will generate a line of CSS for use in header output. If the setting
		 * ($mod_name) has no defined value, the CSS will not be output.
		 * 
		 * @uses get_theme_mod()
		 * @param string $selector CSS selector
		 * @param string $style The name of the CSS *property* to modify
		 * @param string $mod_name The name of the 'theme_mod' option to fetch
		 * @param string $prefix Optional. Anything that needs to be output before the CSS property
		 * @param string $postfix Optional. Anything that needs to be output after the CSS property
		 * @param bool $echo Optional. Whether to print directly to the page (default: true).
		 * @return string Returns a single line of CSS with selectors and a property.
		 */
		 
		protected static function generate_css( $selector, $style, $mod_name, $mod_subname='', $prefix='', $postfix='' ) {

			$return = '';
			$mod = get_theme_mod( $mod_name );			
			
			if ( is_array( $mod ) ) {
				if ( ! array_key_exists( $mod_subname, $mod ) ) return;	
				$mod = $mod[$mod_subname];
			}

			if ( ! ( empty( $mod ) && $mod !== 0 ) ) {				
				
				if ( $style === 'opacity' ) $mod = $mod/100;
				
				if ( $mod_name === 'kktfwp_content_opacity' ) {
					
					$format = '%s { %s: rgba(255,255,255, %s); }';
					
					if ( get_theme_mod( 'kktfwp_color_scheme', 'dark' ) === 'dark' ) $format = '%s { %s: rgba(0,0,0, %s); }';
						
					$return = sprintf( $format,
						$selector,
						$style,
						$mod/100
						);
					
				} else {

					$return = sprintf('%s { %s:%s; }',
						$selector,
						$style,
						$prefix.$mod.$postfix
						);
				}
			}
			return $return;
		}
	}
	
	add_action( 'wp_enqueue_scripts', array( 'Kktfwp_Inline_Css', 'customizer_output'), 10 );
}