<?php

define( 'JASS_MIN_PHP_VERSION', '5.3' );

/*-----------------------------------------------------------------------------------*/
/* Enqueue script and styles */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('jass_enqueue_scripts')) {

	function jass_enqueue_scripts() {

		wp_enqueue_style('jass-style', get_stylesheet_uri(), array() );

		$googleFontsArgs = array(
			'family' =>	str_replace('|', '%7C','Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i'),
			'subset' =>	'latin,latin-ext'
		);

		wp_enqueue_style('google-fonts', add_query_arg ( $googleFontsArgs, "https://fonts.googleapis.com/css" ), array(), '1.0.0' );

		wp_enqueue_style(
			'bootstrap-grid',
			get_template_directory_uri() . '/css/bootstrap-grid.css',
			array(),'4.5.0'
		);

		wp_enqueue_style(
			'owl.carousel',
			get_template_directory_uri() . '/css/owl.carousel.css',
			array(),'2.3.4'
		);

		wp_enqueue_style(
			'owl.theme.default',
			get_template_directory_uri() . '/css/owl.theme.default.css',
			array(),'2.3.4'
		);

		wp_enqueue_script(
			'jass-navigation',
			get_template_directory_uri() . '/js/navigation.js',
			FALSE,
			'1.0',
			TRUE
		);

		wp_enqueue_script(
			'owl.carousel',
			get_template_directory_uri() . '/js/owl.carousel.js',
			array('jquery'),
			'2.3.4',
			TRUE
		);

		wp_enqueue_script(
			'jass-script',
			get_template_directory_uri() . '/js/script.js',
			array('jquery'),
			'1.0',
			TRUE
		);

		if ( is_singular() ) wp_enqueue_script( 'comment-reply' );

		$css = '';

		if ( get_header_image() ) :

			$css .=  '
				header.header {
					background-image: url('.esc_url(get_header_image()).');
					-webkit-background-size: cover !important;
					-moz-background-size: cover !important;
					-o-background-size: cover !important;
					background-size: cover !important;
				}';

		endif;

		if ( get_header_textcolor() ) :

			$css .=  '
				.logo a {
					color: #'.esc_attr(get_header_textcolor()).';
				}';

		endif;

		if ( get_theme_mod('jass_color_overlay') ) :

			$css .=  '
				a:hover,
				a:focus,
				.logo a:hover,
				.logo a:focus,
				#main-menu a:hover,
				#main-menu ul li a:hover,
				#main-menu li:hover > a,
				#main-menu a:focus,
				#main-menu ul li a:focus,
				#main-menu li.focus > a,
				#main-menu li:focus > a,
				#main-menu ul li.current-menu-item > a,
				#main-menu ul li.current_page_item > a,
				#main-menu ul li.current-menu-parent > a,
				#main-menu ul li.current_page_ancestor > a,
				#main-menu ul li.current-menu-ancestor > a {
					color: '.esc_attr(get_theme_mod('jass_color_overlay')).';
				}';

		endif;

		wp_add_inline_style( 'jass-style', $css );

	}

	add_action( 'wp_enqueue_scripts', 'jass_enqueue_scripts' );

}

/*-----------------------------------------------------------------------------------*/
/* Setup theme */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('jass_after_setup_theme')) {

	function jass_after_setup_theme() {

		if ( ! isset( $content_width ) ) $content_width = 900;

		register_nav_menus( array(
			'main-menu' => esc_html__( 'Main menu', 'jass' ),
		));

		add_theme_support('title-tag');
		add_theme_support('automatic-feed-links');
		add_theme_support('post-thumbnails');

		add_image_size(
			'jass_large_thumbnail',
			1110,
			400,
			true
		);

		add_image_size(
			'jass_small_thumbnail',
			730,
			263,
			true
		);

		add_image_size(
			'jass_carousel_thumbnail',
			370,
			270,
			true
		);

		add_theme_support( 'custom-background', array(
		  'default-color' => 'f3f3f3'
		));

		register_default_headers( array(
			'default-image' => array(
				'url'           => get_stylesheet_directory_uri() . '/images/header.jpg',
				'thumbnail_url' => get_stylesheet_directory_uri() . '/images/resized-header.jpg',
				'description'   => esc_html__( 'Default image', 'jass' ),
			),
		));

		add_theme_support( 'custom-header', array(
			'width' => 1920,
			'height' => 300
		));

		require_once( trailingslashit( get_template_directory() ) . '/core/includes/class-notice.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/includes/class-plugin-activation.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/includes/class-welcome-page.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/functions/function-required-plugins.php' );

	}

	add_action( 'after_setup_theme', 'jass_after_setup_theme', 999 );

}

/*-----------------------------------------------------------------------------------*/
/* Get post comments */
/*-----------------------------------------------------------------------------------*/

if ( ! function_exists( 'jass_list_comments' ) ) {

	function jass_list_comments($comment, $args, $depth) {

?>

		<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">

			<div id="comment-<?php comment_ID(); ?>" class="comment-container">

				<div class="comment-avatar">
					<?php echo get_avatar($comment->comment_author_email, 80, 'retro' ); ?>
				</div>

				<div class="comment-text">

					<header class="comment-author">

						<span class="author"><cite><?php printf( esc_html__('%s has written:','jass'), get_comment_author_link());?> </cite></span>

						<time datetime="<?php echo esc_attr(get_comment_date())?>" class="comment-date">

							<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>">
								<?php printf(esc_html__('%1$s at %2$s','jass'), get_comment_date(),  get_comment_time()) ?>
							</a>

							<?php

								comment_reply_link(
									array_merge(
										$args,
										array(
											'depth' => $depth,
											'max_depth' => $args['max_depth']
										)
									)
								);

								edit_comment_link(esc_html__('(Edit)', 'jass'));

							?>

						</time>

					</header>

					<?php if ($comment->comment_approved == '0') : ?>

						<p><em><?php esc_html_e('Your comment is awaiting approval.','jass') ?></em></p>

					<?php endif; ?>

					<?php comment_text() ?>

				</div>

			</div>

		<?php

	}

}

if (!function_exists('jass_widgets_init')) {

	function jass_widgets_init() {

		register_sidebar(array(

			'name' => esc_html__('Sidebar','jass'),
			'id'   => 'jass-sidebar',
			'description'   => esc_html__('This sidebar will be shown next to the content.', 'jass'),
			'before_widget' => '<div id="%1$s" class="sidebar-widget %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h4 class="title">',
			'after_title'   => '</h4>'

		));

		register_sidebar(array(

			'name' => esc_html__('Footer sidebar','jass'),
			'id'   => 'jass-footer-sidebar',
			'description'   => esc_html__('This sidebar will be shown next at the bottom of your content.', 'jass'),
			'before_widget' => '<div id="%1$s" class="col-md-4 %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h4 class="title">',
			'after_title'   => '</h4>'

		));

	}

	add_action( 'widgets_init', 'jass_widgets_init' );

}

/*-----------------------------------------------------------------------------------*/
/* Exclude sticky posts on home */
/*-----------------------------------------------------------------------------------*/ 

if (!function_exists('jass_exclude_sticky_posts_on_home')) {

	function jass_exclude_sticky_posts_on_home($query) {
		if ( 
			$query->is_home() && 
			$query->is_main_query()
		) {
				$query->set('post__not_in', get_option( 'sticky_posts' ));
		}
	}
	
	//add_action('pre_get_posts', 'jass_exclude_sticky_posts_on_home');

}

function jass_customize_register( $wp_customize ) {

	$wp_customize->add_panel('jass_panel', array(
	  'title' => esc_html__( 'Jass settings', 'jass' ),
	));

	$wp_customize->add_section('jass_content_settings', array(
	  'title' => esc_html__( 'Content settings', 'jass' ),
	  'panel' => 'jass_panel',
	));

	$wp_customize->add_setting( 'jass_content_info', array(
	  'default' => true,
	  'sanitize_callback' => 'jass_checkbox_sanize',
	));

	$wp_customize->add_control( 'jass_content_info', array(
	  'type' => 'checkbox',
	  'section' => 'jass_content_settings',
	  'label' => esc_html__('Content informations.', 'jass'),
	  'description' => esc_html__('Do you want to display the informations of current content?.', 'jass'),
	));

	$wp_customize->add_section('jass_footer_settings', array(
	  'title' => esc_html__( 'Footer settings', 'jass' ),
	  'panel' => 'jass_panel',
	));

	$wp_customize->add_setting( 'jass_footer_text', array(
	  'default' => '',
	  'sanitize_callback' => 'sanitize_textarea_field',
	));

	$wp_customize->add_control( 'jass_footer_text', array(
	  'type' => 'textarea',
	  'section' => 'jass_footer_settings',
	  'label' => esc_html__('Footer text.', 'jass'),
	  'description' => esc_html__('Insert here the content of footer.', 'jass'),
	));

	$wp_customize->add_setting( 'jass_color_overlay', array(
	  'default' => '#8098D0',
	  'sanitize_callback' => 'sanitize_hex_color',
	));

	$wp_customize->add_control( 'jass_color_overlay', array(
	  'type' => 'color',
	  'section' => 'colors',
	  'label' => esc_html__('Color overlay.', 'jass'),
	  'description' => esc_html__('Select a color on mouse hover.', 'jass'),
	));

	function jass_checkbox_sanize( $input ) {
	  return $input ? true : false;
	}

}

add_action( 'customize_register', 'jass_customize_register' );

?>
