<?php
/**
 * Enqueue admin scripts and styles.
 *
 * @author      CodeGearThemes
 * @category    WordPress
 * @package     Acoustics
 * @version     1.0.0
 *
 */
function acoustics_load_admin_scripts() {

  	wp_register_style( 'acoustics-admin-style', get_template_directory_uri() . '/assets/admin/css/admin.style.css', false, '1.0.0' );
    wp_enqueue_style( 'acoustics-admin-style' );

}
add_action( 'admin_enqueue_scripts', 'acoustics_load_admin_scripts' );

/**
 * Enqueue scripts and styles.
 */
function acoustics_scripts() {

	$min = '';
	$defaults = json_encode(
		array(
			'font' 			=> 'System default',
			'regularweight' => '400',
			'category' 		=> 'sans-serif'
		)
	);

	$acoustics_site_width 					= get_theme_mod( 'acoustics_container_width', '1180').'px';

	$acoustics_accent_color					= get_theme_mod( 'acoustics_website_accent_color', '#000000' );

	$acoustics_link_color					= get_theme_mod( 'acoustics_link_color', '#000000' );
	$acoustics_link_color_hover				= get_theme_mod( 'acoustics_link_color_hover', '#121212' );

	$acoustics_base_color					= get_theme_mod( 'acoustics_website_text_color', '#757575' );
	$acoustics_heading_color				= get_theme_mod( 'acoustics_website_heading_color', '#121212' );
	$acoustics_base_background				= get_theme_mod( 'background_color', '#ffffff' );

	$acoustics_form_color						= get_theme_mod( 'acoustics_form_field_color', '#212121');
	$acoustics_border_color 					= get_theme_mod( 'acoustics_border_color', '#e6e6e6' );
	$acoustics_form_field_background			= get_theme_mod( 'acoustics_form_field_background', '#ffffff' );

	$font_body 						= json_decode( get_theme_mod( 'acoustics_base_font', $defaults ), true );
	if ( 'System default' === $font_body['font'] ) {
		$acoustics_base_fonts			= '-apple-system, BlinkMacSystemFont, Roboto, Oxygen-Sans, Ubuntu, Cantarell, sans-serif';
	}else{
		$acoustics_base_fonts			= $font_body['font'];
	}

	$acoustics_base_font_size			= get_theme_mod('acoustics_base_font_size_desktop', '16' ).'px';
	$acoustics_base_tablet_font_size	= get_theme_mod('acoustics_base_font_size_tablet', '14' ).'px';
	$acoustics_base_mobile_font_size	= get_theme_mod('acoustics_base_font_size_mobile', '14' ).'px';

	$acoustics_base_font_weight = 'normal';
	if( isset( $font_body['regularweight'] ) ){
		$acoustics_base_font_weight		= $font_body['regularweight'];
	}

	$acoustics_base_font_style		= get_theme_mod('acoustics_base_font_style', 'normal');
	$acoustics_base_line_height 	= get_theme_mod( 'acoustics_base_line_height', '1.4' );
	$acoustics_base_letter_spacing 	= get_theme_mod( 'acoustics_base_letter_spacing', '0' );
	$acoustics_base_text_transform 	= get_theme_mod( 'sacoustics_base_text_transform', 'none' );

	$font_heading = json_decode( get_theme_mod( 'acoustics_heading_font', $defaults ), true  );
	if ( 'System default' === $font_heading['font'] ) {
		$acoustics_heading_fonts			= '-apple-system, BlinkMacSystemFont, Roboto, Oxygen-Sans, Ubuntu, Cantarell, sans-serif';
	}else{
		$acoustics_heading_fonts			= $font_heading['font'];
	}

	$acoustics_heading_font_weight = 'bold';
	if( isset( $font_heading['regularweight'] ) ){
		$acoustics_heading_font_weight		= $font_heading['regularweight'];
	}

	$acoustics_heading_font_style		= get_theme_mod( 'acoustics_heading_font_style', 'normal');
	$acoustics_heading_line_height 		= get_theme_mod( 'acoustics_heading_line_height', '1.4' );
	$acoustics_heading_letter_spacing 	= get_theme_mod( 'acoustics_heading_letter_spacing', '0' );
	$acoustics_heading_text_transform 	= get_theme_mod( 'acoustics_heading_text_transform', 'none' );

	$acoustics_heading_fontsizeh1 			= get_theme_mod( 'acoustics_heading_h1_font_size_desktop' , '40' );
	$acoustics_heading_fontsizeh2			= get_theme_mod( 'acoustics_heading_h2_font_size_desktop' , '32' );
	$acoustics_heading_fontsizeh3			= get_theme_mod( 'acoustics_heading_h3_font_size_desktop' , '28' );
	$acoustics_heading_fontsizeh4			= get_theme_mod( 'acoustics_heading_h4_font_size_desktop' , '24' );
	$acoustics_heading_fontsizeh5			= get_theme_mod( 'acoustics_heading_h5_font_size_desktop' , '20' );
	$acoustics_heading_fontsizeh6			= get_theme_mod( 'acoustics_heading_h6_font_size_desktop' , '16' );

	$acoustics_heading_tablet_fontsizeh1 		= get_theme_mod( 'acoustics_heading_h1_font_size_tablet' , '36' );
	$acoustics_heading_tablet_fontsizeh2		= get_theme_mod( 'acoustics_heading_h2_font_size_tablet' , '28' );
	$acoustics_heading_tablet_fontsizeh3		= get_theme_mod( 'acoustics_heading_h3_font_size_tablet' , '24' );
	$acoustics_heading_tablet_fontsizeh4		= get_theme_mod( 'acoustics_heading_h4_font_size_tablet' , '20' );
	$acoustics_heading_tablet_fontsizeh5		= get_theme_mod( 'acoustics_heading_h5_font_size_tablet' , '16' );
	$acoustics_heading_tablet_fontsizeh6		= get_theme_mod( 'acoustics_heading_h6_font_size_tablet' , '16' );

	$acoustics_heading_mobile_fontsizeh1 		= get_theme_mod( 'acoustics_heading_h1_font_size_mobile' , '28' );
	$acoustics_heading_mobile_fontsizeh2		= get_theme_mod( 'acoustics_heading_h2_font_size_mobile' , '22' );
	$acoustics_heading_mobile_fontsizeh3		= get_theme_mod( 'acoustics_heading_h3_font_size_mobile' , '18' );
	$acoustics_heading_mobile_fontsizeh4		= get_theme_mod( 'acoustics_heading_h4_font_size_mobile' , '16' );
	$acoustics_heading_mobile_fontsizeh5		= get_theme_mod( 'acoustics_heading_h5_font_size_mobile' , '16' );
	$acoustics_heading_mobile_fontsizeh6		= get_theme_mod( 'acoustics_heading_h6_font_size_mobile' , '16' );

	$font_menu = json_decode( get_theme_mod( 'acoustics_menu_font', $defaults ), true  );
	if ( 'System default' === $font_menu['font'] ) {
		$acoustics_menu_fonts			= '-apple-system, BlinkMacSystemFont, Roboto, Oxygen-Sans, Ubuntu, Cantarell, sans-serif';
	}else{
		$acoustics_menu_fonts			= $font_menu['font'];
	}

	$acoustics_menu_font_weight = 'normal';
	if( isset( $font_menu['regularweight'] ) ){
		$acoustics_menu_font_weight		= $font_menu['regularweight'];
	}

	$acoustics_menu_font_size					= get_theme_mod( 'acoustics_menu_font_size_desktop', 16 ).'px';
	$acoustics_menu_font_size_tablet			= get_theme_mod( 'acoustics_menu_font_size_tablet', 16 ).'px';
	$acoustics_menu_font_size_mobile			= get_theme_mod( 'acoustics_menu_font_size_mobile', 16 ).'px';
	$acoustics_menu_text_transform			= get_theme_mod( 'acoustics_menu_text_transform', 'uppercase' );
	$acoustics_menu_line_height 				= get_theme_mod( 'acoustics_menu_line_height', 1.6 );


	$acoustics_button_color						= get_theme_mod( 'acoustics_button_color', '#ffffff' );
	$acoustics_button_color_hover				= get_theme_mod( 'acoustics_button_color_hover', '#ffffff' );
	$acoustics_button_background				= get_theme_mod( 'acoustics_button_background_color', '#000000' );
	$acoustics_button_background_hover			= get_theme_mod( 'acoustics_button_background_color_hover', '#121212' );
	$acoustics_button_border_color				= get_theme_mod( 'acoustics_button_border_color', '#000000' );
	$acoustics_button_border_color_hover		= get_theme_mod( 'acoustics_button_border_color_hover', '#121212' );

	$acoustics_button_desktop_font_size			= get_theme_mod( 'acoustics_button_font_size_desktop', 14 ).'px';
	$acoustics_button_tablet_font_size			= get_theme_mod( 'acoustics_button_font_size_tablet', 14 ).'px';
	$acoustics_button_mobile_font_size			= get_theme_mod( 'acoustics_button_font_size_mobile', 14 ).'px';

	$acoustics_button_text_transform			= get_theme_mod( 'acoustics_button_text_transform', 'none' );
	$acoustics_button_letter_spacing			= get_theme_mod( 'acoustics_button_letter_spacing', 0 );

	$acoustics_button_border_radius					= get_theme_mod( 'acoustics_button_border_radius', 4 ).'px';
	$acoustics_button_desktop_top_bottom_padding	= get_theme_mod( 'acoustics_button_top_bottom_padding_desktop', 16 ).'px';
	$acoustics_button_tablet_top_bottom_padding		= get_theme_mod( 'acoustics_button_top_bottom_padding_desktop', 16 ).'px';
	$acoustics_button_mobile_top_bottom_padding		= get_theme_mod( 'acoustics_button_top_bottom_padding_desktop', 16 ).'px';

	$acoustics_content_card_color 					= get_theme_mod( 'acoustics_content_card_color', '#262626' );
	$acoustics_content_card_heading_color 			= get_theme_mod( 'acoustics_content_card_heading_color', '#212121' );
	$acoustics_content_card_background_color 		= get_theme_mod( 'acoustics_content_card_background_color', '#FBFBF9' );

	$acoustics_custom_styles = "
		:root{
			--theme--font-scale: 1;
			--theme--site-width: $acoustics_site_width;

			--theme--base-color: ".esc_attr( $acoustics_base_color ).";
			--theme--heading-color:	". esc_attr ( $acoustics_heading_color ) .";
			--theme--base-background: ".esc_attr( $acoustics_base_background ).";
			--theme--accent-color:	". esc_attr( $acoustics_accent_color ) .";

			--theme--link-color:	". esc_attr( $acoustics_link_color ) .";
			--theme--link-color-hover:	". esc_attr( $acoustics_link_color_hover ) .";

			--theme--base-font-size:		". absint( $acoustics_base_font_size ) ."px;
			--theme--base-tablet-font-size: ". absint( $acoustics_base_tablet_font_size ) ."px;
			--theme--base-mobile-font-size: ". absint( $acoustics_base_mobile_font_size ) ."px;
			--theme--base-font-family:		". esc_attr ( $acoustics_base_fonts ) .";
			--theme--base-font-weight:		". esc_attr ( $acoustics_base_font_weight ) .";
			--theme--base-font-style:		". esc_attr ( $acoustics_base_font_style ) .";
			--theme--base-line-height:		". esc_attr ( $acoustics_base_line_height ) .";
			--theme--base-letter-spacing:	". esc_attr ( $acoustics_base_letter_spacing ) ."px;
			--theme--base-text-transform:	". esc_attr ( $acoustics_base_text_transform ) .";

			--theme--heading-size1:	". absint( $acoustics_heading_fontsizeh1 ) ."px;
			--theme--heading-size2: ". absint( $acoustics_heading_fontsizeh2 ) ."px;
			--theme--heading-size3: ". absint( $acoustics_heading_fontsizeh3 ) ."px;
			--theme--heading-size4: ". absint( $acoustics_heading_fontsizeh4 ) ."px;
			--theme--heading-size5: ". absint( $acoustics_heading_fontsizeh5 ) ."px;
			--theme--heading-size6: ". absint( $acoustics_heading_fontsizeh6 ) ."px;

			--theme--heading-tablet-size1: ". absint( $acoustics_heading_tablet_fontsizeh1 ) ."px;
			--theme--heading-tablet-size2: ". absint( $acoustics_heading_tablet_fontsizeh2 ) ."px;
			--theme--heading-tablet-size3: ". absint( $acoustics_heading_tablet_fontsizeh3 ) ."px;
			--theme--heading-tablet-size4: ". absint( $acoustics_heading_tablet_fontsizeh4 ) ."px;
			--theme--heading-tablet-size5: ". absint( $acoustics_heading_tablet_fontsizeh5 ) ."px;
			--theme--heading-tablet-size6: ". absint( $acoustics_heading_tablet_fontsizeh6 ) ."px;

			--theme--heading-mobile-size1: ". absint( $acoustics_heading_mobile_fontsizeh1 ) ."px;
			--theme--heading-mobile-size2: ". absint( $acoustics_heading_mobile_fontsizeh2 ) ."px;
			--theme--heading-mobile-size3: ". absint( $acoustics_heading_mobile_fontsizeh3 ) ."px;
			--theme--heading-mobile-size4: ". absint( $acoustics_heading_mobile_fontsizeh4 ) ."px;
			--theme--heading-mobile-size5: ". absint( $acoustics_heading_mobile_fontsizeh5 ) ."px;
			--theme--heading-mobile-size6: ". absint( $acoustics_heading_mobile_fontsizeh6 ) ."px;

			--theme--heading-font-weight: ". esc_attr ( $acoustics_heading_font_weight ) .";
			--theme--heading-font-style: ". esc_attr ( $acoustics_heading_font_style ) .";
			--theme--heading-font-family: ". esc_attr ( $acoustics_heading_fonts ) .";
			--theme--heading-line-height: ". esc_attr ( $acoustics_heading_line_height ) .";
			--theme--heading-letter-spacing: ". esc_attr ( $acoustics_heading_letter_spacing ) ."px;
			--theme--heading-text-transform: ". esc_attr ( $acoustics_heading_text_transform ) .";

			--theme--menu-font-family: " . esc_attr ( $acoustics_menu_fonts ) .";
			--theme--menu-font-weight: " . esc_attr ( $acoustics_menu_font_weight ) .";

			--theme--menu-font-size: ". esc_attr ( $acoustics_menu_font_size ) .";
			--theme--menu-font-size-tablet: ". esc_attr ( $acoustics_menu_font_size_tablet ) .";
			--theme--menu-font-size-mobile: ". esc_attr ( $acoustics_menu_font_size_mobile ) .";
			--theme--menu-text-transform: ". esc_attr ( $acoustics_menu_text_transform ) .";
			--theme--menu-line-height: ". esc_attr ( $acoustics_menu_line_height ) .";

			--theme--form-color: ". esc_attr ( $acoustics_form_color ) .";
			--theme--border-color: ". esc_attr ( $acoustics_border_color ) .";
			--theme--form-background-color: ". esc_attr ( $acoustics_form_field_background ) .";

			--theme--button-color: ". esc_attr ( $acoustics_button_color ) .";
			--theme--button-color-hover: ". esc_attr ( $acoustics_button_color_hover ) .";
			--theme--button-background-color: ". esc_attr ( $acoustics_button_background ) .";
			--theme--button-background-color-hover: ". esc_attr ( $acoustics_button_background_hover ) .";
			--theme--button-border-color: ". esc_attr ( $acoustics_button_border_color ) .";
			--theme--button-border-color-hover: ". esc_attr ( $acoustics_button_border_color_hover ) .";

			--theme--button-desktop-font-size: " . esc_attr ( $acoustics_button_desktop_font_size ) .";
			--theme--button-tablet-font-size: " . esc_attr ( $acoustics_button_tablet_font_size ) .";
			--theme--button-mobile-font-size: " . esc_attr ( $acoustics_button_mobile_font_size ) .";

			--theme--button-text-transform: " . esc_attr ( $acoustics_button_text_transform ) .";
			--theme--button-letter-spacing: " . esc_attr ( $acoustics_button_letter_spacing ) ."px;

			--theme--button-desktop-top-bottom-padding: " . esc_attr ( $acoustics_button_desktop_top_bottom_padding ) .";
			--theme--button-tablet-top-bottom-padding: " . esc_attr ( $acoustics_button_tablet_top_bottom_padding ) .";
			--theme--button-mobile-top-bottom-padding: " . esc_attr ( $acoustics_button_mobile_top_bottom_padding ) .";

			--theme--button-border-radius: " . esc_attr ( $acoustics_button_border_radius ) .";

			--theme--content-card-color: ". esc_attr ( $acoustics_content_card_color ) .";
			--theme--content-card-heading-color: ". esc_attr ( $acoustics_content_card_heading_color ) .";
			--theme--content-card-background: ". esc_attr ( $acoustics_content_card_background_color ) .";
		}";

	wp_enqueue_style( 'acoustics-google-fonts', acoustics_google_fonts_url(), array(), acoustics_google_fonts_version() );

	wp_enqueue_style( 'owl-carousel', get_template_directory_uri() . '/assets/vendor/owlslider/css/owl.carousel.css' , array(), '2.3.4' );
	wp_enqueue_style( 'acoustics-theme-style', ACOUSTICS_THEME_URI . '/assets/public/css/theme'.$min.'.css', array(), ACOUSTICS_VERSION);
	wp_enqueue_style( 'acoustics-header-style', ACOUSTICS_THEME_URI . '/assets/public/css/header/header'.$min.'.css', array(), ACOUSTICS_VERSION);
	wp_enqueue_style( 'acoustics-theme-lite-style', ACOUSTICS_THEME_URI . '/assets/public/css/theme.lite'.$min.'.css', array(), ACOUSTICS_VERSION);
	wp_add_inline_style( 'acoustics-theme-style', $acoustics_custom_styles );

	wp_enqueue_script( 'acoustics-navigation', get_template_directory_uri() . '/assets/vendor/navigation/js/navigation.js', array(), ACOUSTICS_VERSION, true );
	wp_enqueue_script( 'acoustics-skip-link-focus-fix', get_template_directory_uri() . '/assets/vendor/automattic/js/skip-link-focus-fix.js', array(), ACOUSTICS_VERSION, true );

	wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . '/assets/vendor/owlslider/js/owl.carousel.js', array('jquery'), '2.3.4', true );
	wp_enqueue_script( 'acoustics-theme-scripts', get_template_directory_uri() . '/assets/public/js/theme.js', array(), ACOUSTICS_VERSION, true );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}

add_action( 'wp_enqueue_scripts', 'acoustics_scripts' );


/**
 * Scripts low priority
 */
function acoustics_public_scripts_priority_low(){

	$min = '';
	$minified = get_theme_mod( 'acoustics_load_minified_assets', 0 );
	if( $minified ){
		$min = '.min';
	}

	$builder_type = get_theme_mod( 'acoustics_builder_type', 'editor' );
    if( $builder_type === 'editor' ){
		wp_enqueue_style( 'acoustics-theme-editor-style', get_template_directory_uri() . '/assets/public/css/theme.editor'.$min.'.css', array(), ACOUSTICS_VERSION);
    }

}
add_action('wp_footer', 'acoustics_public_scripts_priority_low');
