<?php
/**
 * Add custom css to frontend.
 *
 * @package hoot
 * @subpackage chromatic
 * @since chromatic 1.0.0
 */

add_action('wp_head', 'hoot_custom_css');

/**
 * Custom CSS built from user theme options
 * For proper sanitization, always use functions from hoot/functions/css-styles.php
 *
 * @since 1.0.0
 * @access public
 */
function hoot_custom_css() {
	$css = '';
	$accent_color = hoot_get_option( 'accent_color' );
	$accent_color_20 = hoot_color_increase( $accent_color, 20, 20 );
	$accent_font = hoot_get_option( 'accent_font' );

	$cssrules = array();

	// Hoot Grid
	$cssrules['.grid'] = hoot_css_grid_width();

	// Base Typography and HTML
	$cssrules['a'] = hoot_css_rule( 'color', $accent_color );
	$cssrules['.invert-typo'] = array(
		hoot_css_rule( 'background', $accent_color ),
		hoot_css_rule( 'color', $accent_font )
		);
	$cssrules['.invert-typo a, .invert-typo h1, .invert-typo h2, .invert-typo h3, .invert-typo h4, .invert-typo h5, .invert-typo h6, .invert-typo .title'] = hoot_css_rule( 'color', $accent_font );
	$cssrules['input[type="submit"], #submit, .button'] = array(
		hoot_css_rule( 'background', $accent_color ),
		hoot_css_rule( 'color', $accent_font )
		);
	$cssrules['input[type="submit"]:hover, #submit:hover, .button:hover'] = hoot_css_rule( 'background', $accent_color_20 );
	$cssrules['#submit a, .button a'] = hoot_css_rule( 'color', $accent_font );

	// Layout
	$cssrules['body'] = hoot_css_background( hoot_get_option( 'background' ) );
	if ( hoot_get_option( 'site_layout' ) == 'boxed' ) {
		$cssrules['#page-wrapper'] = hoot_css_background( hoot_get_option( 'box_background' ) );
	}

	// Header
	$cssrules['#site-title, #site-title a'] = hoot_css_rule( 'color', $accent_color );

	// Sidebars and Widgets
	$cssrules['.content-block-icon'] = array(
		hoot_css_rule( 'color', $accent_color ),
		hoot_css_rule( 'background', $accent_font ),
		hoot_css_rule( 'border-color', $accent_color ),
		);
	$cssrules['.content-block-icon.icon-style-square'] = array(
		hoot_css_rule( 'color', $accent_font ),
		hoot_css_rule( 'background', $accent_color ),
		);
	$cssrules['.content-blocks-widget .content-block:hover .content-block-icon.icon-style-circle'] = array(
		hoot_css_rule( 'color', $accent_font ),
		hoot_css_rule( 'background', $accent_color ),
		);
	$cssrules['.content-blocks-widget .content-block:hover .content-block-icon.icon-style-square'] = array(
		hoot_css_rule( 'color', $accent_color ),
		hoot_css_rule( 'background', $accent_font ),
		);

	// Light Slider
	$cssrules['.lSSlideOuter .lSPager.lSpg > li:hover a, .lSSlideOuter .lSPager.lSpg > li.active a'] = hoot_css_rule( 'background-color', $accent_color );

	// Allow CSS to be modified
	$cssrules = apply_filters( 'hoot_dynamic_css', $cssrules );


	/** Print CSS Rules **/

	foreach ( $cssrules as $selector => $rules ) {
		$css .= $selector . ' {';
		if ( is_array( $rules ) ) {
			foreach ( $rules as $rule ) {
				$css .= $rule . ' ';
			}
		} else {
			$css .= $rules;
		}
		$css .= ' }' . "\n";
	}

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

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

}