<?php
/**
 * @copyright	Copyright (c) 2016 AmyTheme (http://www.amytheme.com). All rights reserved.
 * @license		http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

defined( 'ABSPATH' ) or die;

if ( ! class_exists( 'AmyFramework_Style_Builder' ) ) {
	return;
}

$style_builder	= AmyFramework_Style_Builder::getInstance();

/*
 * Typography
 */
$typography		= amy_get_option( 'typography' );

if ( ! empty( $typography ) ) {
	foreach ( $typography as $font ) {
		if ( ! empty( $font['selector'] ) ) {
			$css	= '';

			$weight	= $font['font']['variant'] != 'regular' ? $font['font']['variant'] : 400;
			$style	= preg_replace( '/[^a-zA-Z]/', '', $font['font']['variant'] );
			$style	= $style && $style != 'regular' ? $style : 'normal';
			$family	= '"' . $font['font']['family'] . '"' . (amy_movie_is_google_font( $font['font']['family'] ) ? ', Arial, sans-serif' : '');
			$css	.= 'font-family: ' . $family . ';';
			$css	.= ! empty( $font['size'] ) ? 'font-size: ' . $font['size'] . ';' : '';
			$css	.= ! empty( $font['line_height'] ) ? 'line-height: ' . $font['line_height'] . ';' : '';
			$css	.= 'font-style: ' . $style . ';';
			$css	.= 'font-weight: ' . $weight . ';';
			$css	.= ! empty( $font['css'] ) ? $font['css'] : '';

			$style_builder->addStyle( $font['selector'], $css );
		}
	}
}

/*
 * Page title
 */
global $post;

$post_id	= isset( $post ) ? $post->ID : 0;
$post_id	= is_home() ? get_option( 'page_for_posts' ) : $post_id;
$post_meta	= get_post_meta( $post_id, '_custom_page_options', true );

$post_title 	= isset( $post_meta['enable_page_title'] ) ? $post_meta['enable_page_title'] : '';
$post_position	= isset( $post_meta['title_position'] ) ? esc_attr( $post_meta['title_position'] ) : '';
$post_bg_color	= isset( $post_meta['title_background'] ) ? $post_meta['title_background'] : '';
$post_bg_img	= isset( $post_meta['title_background_image'] ) ? $post_meta['title_background_image'] : '';
$post_color		= isset( $post_meta['tile_color'] ) ? $post_meta['tile_color'] : '';


if ( $post_title == true ) {
	$bg_img			= wp_get_attachment_image_src( $post_bg_img, 'full' );

	if ( is_array( $bg_img ) && $bg_img != false ) {
		$img_src		= $bg_img[0];
		$img_height		= $bg_img[2];

		$style_builder->addStyle( '.page-id-' . $post_id . ' #amy-page-header .amy-page-title', 'background-image: url("' . $img_src . '")' );
		$style_builder->addStyle( '.page-id-' . $post_id . ' #amy-page-header .amy-page-title', 'height: ' . $img_height . 'px' );
	}

	if ( $post_bg_color ) {
		$style_builder->addStyle( '.page-id-' . $post_id . ' #amy-page-header .amy-page-title', 'background-color: ' . $post_bg_color . '' );
	}

	if ( $post_color ) {
		$style_builder->addStyle( '.page-id-' . $post_id . ' #amy-page-header .amy-page-title h1.page-title', 'color: ' . $post_color . '' );
	}
}

$footer_bg = amy_get_option( 'footer_bg' );

if ( $footer_bg ) {
	$footer_bg_img = wp_get_attachment_image_src( $footer_bg, 'full' );
	$footer_bg_img = $footer_bg_img[0];

	$style_builder->addStyle( '.amy-site-footer', 'background-image: url("' . $footer_bg_img . '")' );
}

/*
 * Skin
 */
$pagetitle_bg_color	= amy_get_option( 'pagetitle_bg_color' );
$pagetitle_bg_img	= amy_get_option( 'pagetitle_bg_img' );
$pagetitle_color	= amy_get_option( 'pagetitle_color' );

if ( $pagetitle_bg_color ) {
	$style_builder->addStyle( '#amy-page-header .amy-page-title', 'background-color:' . $pagetitle_bg_color . '' );
}

if ( $pagetitle_bg_img ) {
	$src 			= wp_get_attachment_image_src( $pagetitle_bg_img, 'full' );
	$src			= $src[0];
	$height			= wp_get_attachment_image_src( $pagetitle_bg_img, 'full' )[2];
	$height			= $height[0];

	$style_builder->addStyle( '#amy-page-header .amy-page-title', 'background-image: url("' . $src . '")' );
	$style_builder->addStyle( '#amy-page-header .amy-page-title', 'height: ' . $height . 'px' );
}

if ( $pagetitle_color ) {
	$style_builder->addStyle( '#amy-page-header .amy-page-title h1', 'color:' . $pagetitle_color . '!important' );
}

$logo_top 		= amy_get_option( 'logo_padding_top' );
$logo_bot		= amy_get_option( 'logo_padding_bottom' );

$disable_skin	= amy_get_option( 'disable_skin' );
$skin_color		= amy_get_option( 'skin_color' );
$skin_custom	= amy_get_option( 'skin_custom' );

if ( ! empty( $logo_top ) ) {
	$style_builder->addStyle( '#amy-site-logo h1, #amy-site-logo img', 'padding-top: ' . (int) $logo_top . 'px' );
}

if ( ! empty( $logo_bot ) ) {
	$style_builder->addStyle( '#amy-site-logo h1, #amy-site-logo img', 'padding-bottom: ' . (int) $logo_bot . 'px' );
}

if ( $skin_color == 'red' ) {
	$site_color	= '#ec6060';
} else if ( $skin_color == 'pink' ) {
	$site_color = '#e3187c';
} else if ( $skin_color == 'blue' ) {
	$site_color = '#3aa2d7';
} else if ( $skin_color == 'custom' ) {
	$site_color = $skin_custom;
} else {
	$site_color = '';
}

if ( ! $disable_skin ) {
	$c1 = '
		a:hover, a:focus,
		.amy-primary-navigation ul.nav-menu li ul li > a:hover, 
		.amy-primary-navigation ul.nav-menu li ul li:hover > a, 
		.amy-primary-navigation ul.nav-menu li ul li.active > a,
		.amy-pagination a,
		.amy-widget-list.list-movie .entry-content .duration,
		.amy-title,
		.amy-mv-showtime h3,
		.amy-tab-nav ul li.active a,
		.slide-content h2 a .last_word,
		.amy-arrow:hover,
		.amy-mv-grid.layout4 .back .entry-title a,
		.amy-mv-search ul.filter-action li:hover, .amy-mv-search ul.filter-action li.active,
		.amy-mv-grid.layout2 .entry-date,
		.amy-mv-grid.layout3 .back .entry-time,
		.amy-mv-blog.layout2 .entry-item .entry-title a:hover,
		.amy-mv-list .entry-item .entry-content .duration,
		.amy-mv-list .entry-item .entry-content h2 a:hover,
		.amy-widget-comingsoon ul li a:hover,
		.single-movie .entry-info .duration,
		.single-movie .entry-action .entry-share ul li a:hover,
		.amy-list-comments h3,
		.amy-list-comments .comment-body footer i,
		.amy-list-comments .comment-reply-link,
		.entry-related > h3,
		.amy-main-content.single-post .comment-reply-title,
		.widget_tag_cloud .amy-widget-title h4, 
		.widget_archive .amy-widget-title h4, 
		.widget_calendar .amy-widget-title h4, 
		.widget_categories .amy-widget-title h4, 
		.widget_pages .amy-widget-title h4, 
		.widget_meta .amy-widget-title h4, 
		.widget_recent_comments .amy-widget-title h4, 
		.widget_recent_entries .amy-widget-title h4, 
		.widget_rss .amy-widget-title h4, 
		.widget_search .amy-widget-title h4, 
		.widget_text .amy-widget-title h4, 
		.widget_nav_menu .amy-widget-title h4,
		.amy-widget-module.contact .phone,
		article.post .entry-info .entry-share ul li a:hover,
		#amy-page-header .amy-breadcrumb a:hover,
		.amy-footer-widgets .widget_tag_cloud ul li a:hover, 
		.amy-footer-widgets .widget_archive ul li a:hover, 
		.amy-footer-widgets .widget_calendar ul li a:hover, 
		.amy-footer-widgets .widget_categories ul li a:hover, 
		.amy-footer-widgets .widget_pages ul li a:hover, 
		.amy-footer-widgets .widget_meta ul li a:hover, 
		.amy-footer-widgets .widget_recent_comments ul li a:hover, 
		.amy-footer-widgets .widget_recent_entries ul li a:hover, 
		.amy-footer-widgets .widget_rss ul li a:hover, 
		.amy-footer-widgets .widget_search ul li a:hover, 
		.amy-footer-widgets .widget_text ul li a:hover, 
		.amy-footer-widgets .widget_nav_menu ul li a:hover,
		.amy-site-footer a:hover,
		.amy-mv-grid.layout1 .pic-caption .desc-mv a:hover,
		.amy-mv-grid.layout1 .entry-title a:hover,
		.amy-mv-grid.layout2 .entry-title a:hover,
		.amy-mv-grid.layout3 .back .entry-title a:hover,
		.amy-mv-grid.layout3 .back .movie-char-info a:hover,
		.amy-mv-grid.layout4 .back .desc-mv a:hover,
		.amy-mv-grid.layout4 .back .entry-button a:hover
	';

	$style_builder->addStyle( $c1, 'color: ' . $site_color . '' );


	$c2 = '
		.amy-mv-search input[type="submit"],
		.amy-pagination span.current,
		.amy-pagination a:hover,
		.amy-widget-module.social ul li a:hover,
		.amy-mv-ratelist table td.point,
		.amy-widget-list.list-movie .entry-content .mrate .rate,
		.amy-mv-showtime h3 span,
		.amy-tab-nav ul li.active a::after,
		.slide-content .slide-button i,
		.amy-mv-slide ul.slick-dots li.slick-active button,
		.amy-mv-grid.layout1 .pic-caption .pg,
		.amy-mv-grid.layout1 .right-info .pg,
		.amy-mv-grid.layout1 .pic-caption .rate,
		.amy-mv-grid.layout1 .pic-caption .entry-button .fa,
		.amy-mv-blog.layout1 .entry-btn,
		.amy-primary-navigation ul.nav-menu > li > a::after,
		.amy-mv-grid.layout4 .grid-item:hover .front .rate,
		.amy-mv-grid.layout4 .back .pg,
		.amy-mv-grid.layout4 .back .entry-button .fa,
		.amy-mv-grid.layout2 .rate,
		.amy-mv-grid.layout3 .back .pg,
		.amy-mv-grid.layout3 .back .entry-button .fa,
		.amy-mv-grid.layout3 .back .rate,
		.home2-section4 .amy-title::after, 
		.home2-section5 .amy-title::after,
		.amy-mv-blog.layout2 .entry-item .entry-cat,
		.amy-mv-list .entry-item .entry-content .pg,
		.amy-mv-list .entry-item .entry-content .mrate .rate,
		.amy-mv-grid.layout2 .amy-date-filter li:hover,
		.single-movie .entry-info .pg,
		.single-movie .entry-action .rate,
		input[type="reset"], 
		input[type="submit"],
		.single-cinema .cinema-details .bg-dl,
		article.post .entry-meta .entry-date,
		.amy-404 .amy-404-btn a.btn-home
	';

	$style_builder->addStyle( $c2, 'background-color: ' . $site_color . '' );


	$c3 = '
		.amy-primary-navigation ul.nav-menu li > ul,
		.amy-primary-navigation ul.nav-menu > li > a:hover::after, 
		.amy-primary-navigation ul.nav-menu > li:hover > a::after, 
		.amy-primary-navigation ul.nav-menu > li.current-menu-item > a::after,
		.amy-pagination span.current,
		.amy-pagination a:hover,
		.amy-title,
		select: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
	';

	$style_builder->addStyle( $c3, 'border-color: ' . $site_color . '' );


	$c4 = '
		.amy-tab-nav ul li.active a,
		.amy-mv-grid.layout1 .entry-thumb,
		.amy-mv-grid.layout4 .grid-item .entry-item,
		.amy-list-comments h3,
		.entry-related > h3,
		.amy-main-content.single-post .comment-reply-title,
		.widget_tag_cloud .amy-widget-title h4, 
		.widget_archive .amy-widget-title h4, 
		.widget_calendar .amy-widget-title h4, 
		.widget_categories .amy-widget-title h4, 
		.widget_pages .amy-widget-title h4, 
		.widget_meta .amy-widget-title h4, 
		.widget_recent_comments .amy-widget-title h4, 
		.widget_recent_entries .amy-widget-title h4, 
		.widget_rss .amy-widget-title h4, 
		.widget_search .amy-widget-title h4, 
		.widget_text .amy-widget-title h4, 
		.widget_nav_menu .amy-widget-title h4,
		.amy-mv-carousel .carousel-item .carousel-thumb
	';

	$style_builder->addStyle( $c4, 'border-bottom-color: ' . $site_color . '' );
}
