<?php
/**
 * pepsport_Customizer Class
 * Makes adjustments to Storefront cores Customizer implementation.
 *
 * @author   WooThemes
 * @since    1.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'pepsport_Customizer' ) ) {

class pepsport_Customizer {

	/**
	 * Setup class.
	 *
	 * @since 1.0
	 */
	public function pepsport_construct() {
		global $storefront_version;

		add_action( 'wp_enqueue_scripts',	             array( $this, 'pepsport_add_customizer_css' ),						1000 );
		add_filter( 'storefront_setting_default_values', array( $this, 'get_pepsport_defaults' ) );

	}

	/**
	 * Returns an array of the desired default Storefront options
	 * @return array
	 */
	public function get_pepsport_defaults() {
		return apply_filters( 'pepsport_default_settings', $args = array(
			

			'storefront_text_color'						=> '#444444',
			'storefront_accent_color'					=> '#333333',
			'background_color'				            => '#111111',
			'storefront_heading_color'					=> '#222222',
			
			'storefront_header_background_color'		=> '#222222',
			'storefront_header_link_color'				=> '#ffffff',
			'storefront_header_text_color'				=> '#ffffff',

			'storefront_button_background_color'		=> '#666666',
			'storefront_button_text_color'				=> '#ffffff',
			'storefront_button_alt_background_color'	=> '#333333',
			'storefront_button_alt_text_color'			=> '#ffffff',

			'storefront_footer_heading_color'			=> '#ffffff',
			'storefront_footer_background_color'		=> '#222222',
			'storefront_footer_link_color'				=> '#ffffff',
			'storefront_footer_text_color'				=> '#ffffff',


		) );
	}

	/**
	 * Set default Customizer settings based on Storechild design.
	 * @uses get_pepsport_defaults()
	 * @return void
	 */
	public function pepsport_edit_default_customizer_settings( $wp_customize ) {
		foreach ( pepsport_Customizer::get_pepsport_defaults() as $mod => $val ) {
			$setting = $wp_customize->get_setting( $mod );

			if ( is_object( $setting ) ) {
				$setting->default = $val;
			}
		}
	}

	/**
	 * Returns a default theme_mod value if there is none set.
	 * @uses get_pepsport_defaults()
	 * @return void
	 */
	public function pepsport_default_theme_mod_values() {
		foreach ( pepsport_Customizer::get_pepsport_defaults() as $mod => $val ) {
			add_filter( 'theme_mod_' . $mod, function( $setting ) use ( $val ) {
				return $setting ? $setting : $val;
			});
		}
	}



	/**
	 * Add CSS using settings obtained from the theme options.
	 * @return void
	 */
	public function pepsport_add_customizer_css() {
		$header_text_color			= get_theme_mod( 'storefront_header_text_color' );
		$header_link_color			= get_theme_mod( 'storefront_header_link_color' );
		$accent_color				= get_theme_mod( 'storefront_accent_color' );
		$footer_link_color			= get_theme_mod( 'storefront_footer_link_color' );
		$footer_heading_color		= get_theme_mod( 'storefront_footer_heading_color' );
		$footer_text_color			= get_theme_mod( 'storefront_footer_text_color' );
		$button_background_color	= get_theme_mod( 'storefront_button_background_color' );
		$button_text_color			= get_theme_mod( 'storefront_button_text_color' );
		$header_background_color	= get_theme_mod( 'storefront_header_background_color' );

		$darken_factor				= -115;
		$lighten_factor				= 115;
		$style						= '

			.main-navigation ul li a:hover,
			.main-navigation ul li:hover > a,
			.site-title a:hover,
			a.cart-contents:hover,
			.site-header-cart .widget_shopping_cart a:hover,
			.site-footer a:not(.button):hover,
			.site-header-cart:hover > li > a,
			.site-header ul.menu li.current-menu-item > a {
				color: ' . storefront_adjust_color_brightness( $header_link_color, -90 ) . ';
			}
			a:hover,
			ul.products li.product h3:hover {
				color: '. storefront_adjust_color_brightness ($accent_color, -100). ';	
			}
			.product_list_widget a:hover {
				color: '. storefront_adjust_color_brightness($accent_color, -90) . ';
			}

			.woocommerce-breadcrumb a:hover {
				color: ' . storefront_adjust_color_brightness( $header_link_color, -90 )  . ';
			}
			header ::-webkit-input-placeholder,
			.site-search .widget_product_search form:before {
				color: '.storefront_adjust_color_brightness( $header_link_color, -90 ) .';
			}

			.single-product div.product .summary .price {
				color: ' . $accent_color . ';
			}

			.header-widget-region {
				color: ' . $footer_text_color . ';
			}

			.header-widget-region a:not(.button) {
				color: ' . $footer_link_color . ';
			}


			.header-widget-region h1, .header-widget-region h2, .header-widget-region h3, .header-widget-region h4, .header-widget-region h5, .header-widget-region h6 {
				color: ' . $footer_heading_color . ';
			}

			.main-navigation ul li.smm-active li ul.products li.product h3,
			.main-navigation ul li.smm-active li ul.products li.product .price {
				color: ' . $header_text_color . ';
			}
			table.cart td.product-remove,
			table.cart td.actions {
				border-top-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], 400 ). ';
			}
			table th {
				background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], 250 ) . ';
			}

			table tbody td {
				background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], 245	 ) . ';
			}

			table tbody tr:nth-child(2n) td,
			fieldset,
			fieldset legend {
				background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], 240 ) . ';
			}

				.site-header-cart .widget_shopping_cart,
				.main-navigation ul.menu ul.sub-menu,
				.main-navigation ul.nav-menu ul.children {
					background-color: ' . storefront_adjust_color_brightness( $header_background_color, -15 ) . ';
				}
						#order_review {
				background-color: ' .storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], 250 ). ';
			}

			#payment .payment_methods > li .payment_box,
			#payment .place-order {
				background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], 250 ) . ';
			}

			#payment .payment_methods > li:not(.woocommerce-notice) {
				background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], 240 ) . ';
			}

			#payment .payment_methods > li:not(.woocommerce-notice):hover {
				background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], 250 ) . ';
			}
						.pagination .page-numbers li .page-numbers.current, .woocommerce-pagination .page-numbers li .page-numbers.current {
				background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], $darken_factor ) . ';
				color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['text_color'], 240 ) . ';
			}

			#comments .comment-list .comment-content .comment-text {
				background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], 245 ) . ';
			}


			}';

		wp_add_inline_style( 'storefront-child-style', $style );
	}
}
}



return new pepsport_Customizer();

