<?php
/**
 * Enqueue scripts and styles.
 */
function lucia_scripts() {
	
	global $lucia_options;
	
	$lucia_options = get_option( LUCIA_TEXTDOMAIN );	
	
	wp_enqueue_style( 'bootstrap',  get_template_directory_uri() .'/assets/vendor/bootstrap/css/bootstrap.css', false, '', false );
	wp_enqueue_style( 'font-awesome',  get_template_directory_uri() .'/assets/vendor/font-awesome/css/font-awesome.min.css', false, '', false );
	
	// Theme stylesheet.	
	wp_enqueue_style( 'lucia-style', get_stylesheet_uri() , false, LUCIA_VERSION, false );
	wp_enqueue_style( 'lucia-frontend',  get_template_directory_uri() .'/assets/css/frontend.css', false, '', false );

	wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/assets/vendor/bootstrap/js/bootstrap.min.js' , array( 'jquery' ), null, true);
	
	wp_enqueue_script( 'respond', get_template_directory_uri() . '/assets/vendor/respond.min.js' , array( 'jquery' ), null, true);
		

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
	
	$preloader_background = esc_attr(lucia_option('preloader_background'));
	$preloader_opacity = esc_attr(lucia_option('preloader_opacity'));
	$preloader_image = esc_attr(lucia_option('preloader_image'));
	
	if (is_numeric($preloader_image)) {
		$image_attributes = wp_get_attachment_image_src($preloader_image, 'full');
		$preloader_image   = $image_attributes[0];
	}
	
	$preloader_bg = "";
	if( $preloader_background != "" ){
		$rgb = lucia_hex2rgb( $preloader_background );
		$preloader_bg = "rgba(".$rgb[0].",".$rgb[1].",".$rgb[2].",".$preloader_opacity.")";
	}
	
	wp_enqueue_script( 'lucia-main', get_template_directory_uri() . '/assets/js/main.js' , array( 'jquery' ), LUCIA_VERSION, true);
	wp_localize_script( 'lucia-main', 'lucia_params', array(
		'ajaxurl'  => admin_url('admin-ajax.php'),
		'themeurl' => get_template_directory_uri(),
	)  );
	
	$custom_css = '';
	$header_text_color = get_header_textcolor();

	if ( 'blank' != $header_text_color ) :
		$custom_css .= ".site-name, .site-tagline { color: ".sanitize_hex_color( $header_text_color )." ; }.site-tagline { display: none; }";
	else:
		$custom_css .= ".site-name,.site-tagline {display: none;}";
	endif;
	
	
	$primary_color = lucia_option('primary_color');
	if( $primary_color != '' ){
	
	 	$primary_color = sanitize_hex_color( $primary_color );
	
		$custom_css .= "a:hover,a:active {color: ".$primary_color.";}header a:hover {color: ".$primary_color.";}.site-nav  > div > ul > li.current > a {color: ".$primary_color.";}.blog-list-wrap .entry-category a {color: ".$primary_color.";}.entry-meta a:hover {color: ".$primary_color.";}.form-control:focus,select:focus,input:focus,textarea:focus,input[type=\"text\"]:focus,input[type=\"password\"]:focus,input[type=\"datetime\"]:focus,input[type=\"datetime-local\"]:focus,input[type=\"date\"]:focus,input[type=\"month\"]:focus,input[type=\"time\"]:focus,input[type=\"week\"]:focus,input[type=\"number\"]:focus,input[type=\"email\"]:focus,input[type=\"url\"]:focus,input[type=\"search\"]:focus,input[type=\"tel\"]:focus,input[type=\"color\"]:focus,.uneditable-input:focus {border-color: ".$primary_color.";}input[type=\"submit\"] {background-color: ".$primary_color.";}.entry-box.grid .img-box-caption .entry-category {background-color: ".$primary_color.";}.widget-title:before {background-color: ".$primary_color.";}.btn-normal,button,.cactus-btn-normal,.woocommerce #respond input#submit.alt,.woocommerce a.button.alt,.woocommerce button.button.alt,.woocommerce input.button.alt {background-color: ".$primary_color.";}.woocommerce #respond input#submit.alt:hover,.woocommerce a.button.alt:hover,.woocommerce button.button.alt:hover,.woocommerce input.button.alt:hover {background-color: ".$primary_color.";}.woocommerce nav.woocommerce-pagination ul li a:focus,.woocommerce nav.woocommerce-pagination ul li a:hover {color: ".$primary_color.";}.lucia-header .lucia-main-nav > li > a:hover,.lucia-header .lucia-main-nav > li.active > a {color: ".$primary_color.";}.lucia-header .lucia-main-nav > li > a:hover, .lucia-header .lucia-main-nav > li.active > a {color:".$primary_color.";}";
	}
	
	// Form styles
	$form_border_style = lucia_option('form_border_style');
	$form_border_width = lucia_option('form_border_width');
	$form_border_color = lucia_option('form_border_color');
	$form_background_color = lucia_option('form_background_color');
	$form_broder_radius = lucia_option('form_broder_radius');
	$custom_css .=  '.form-control, select, textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input{	border-style:'.esc_attr($form_border_style).';	border-width:'.absint($form_border_width).'px;border-color:'.sanitize_hex_color($form_border_color).';	background-color:'.sanitize_hex_color($form_background_color).';border-radius: '.esc_attr($form_broder_radius).'px;}';
	
	// Button styles
	$button_font_size = lucia_option('button_font_size');
	$button_color = lucia_option('button_color');
	$button_text_transform = lucia_option('button_text_transform');
	$button_broder_radius = lucia_option('button_broder_radius');
	$button_border_color = lucia_option('button_border_color');
	$button_background_color = lucia_option('button_background_color');
	$button_border_style = lucia_option('button_border_style');
	$button_border_width = lucia_option('button_border_width');
	$button_border_style = lucia_option('button_border_style');
	
	$custom_css .=  'button,input[type="submit"],.cactus-btn,btn-normal,.woocommerce #respond input#submit,.woocommerce a.button,.woocommerce button.button,.woocommerce input.button{'.((is_numeric($button_font_size) && $button_font_size > 0 )?'font-size: '.absint($button_font_size).'px;':'').'color: '.sanitize_hex_color($button_color).';text-transform: '.esc_attr($button_text_transform).';border-radius: '.esc_attr($button_broder_radius).'px;border-color:'.sanitize_hex_color($button_border_color).';background-color:'.sanitize_hex_color($button_background_color).';border-style:'.esc_attr($button_border_style).';border-width:'.absint($button_border_width).'px;}';
	
	$custom_css = apply_filters( 'lucia_additional_css', $custom_css );

	wp_add_inline_style( 'lucia-style', str_replace('&gt;', '>', stripslashes(wp_filter_nohtml_kses( $custom_css ) ) ) );

}
add_action( 'wp_enqueue_scripts', 'lucia_scripts' );

function lucia_admin_scripts(){
	global $pagenow;
	wp_enqueue_script( 'lucia-admin', get_template_directory_uri().'/assets/js/admin.js', array( 'jquery' ), '', true );
	wp_enqueue_style( 'lucia-admin', get_template_directory_uri() . '/assets/css/admin.css', '', '', false );
	
	wp_localize_script( 'lucia-admin', 'lucia_admin', array(
			'ajaxurl' => admin_url('admin-ajax.php'),
		)  );
		
	}
add_action( 'admin_enqueue_scripts', 'lucia_admin_scripts' );