<?php

/**
 * Signify Pro functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Signify
 */

/**
 * Add an HTML class to MediaElement.js container elements to aid styling.
 *
 * Extends the core _wpmejsSettings object to add a new feature via the
 * MediaElement.js plugin API.
 */
function signify_mejs_add_container_class()
{
	if (! wp_script_is('mediaelement', 'done')) {
		return;
	}
?>
	<script>
		(function() {
			var settings = window._wpmejsSettings || {};

			settings.features = settings.features || mejs.MepDefaults.features;

			settings.features.push('signify_class');

			MediaElementPlayer.prototype.buildsignify_class = function(player, controls, layers, media) {
				if (!player.isVideo) {
					var container = player.container[0] || player.container;

					container.style.height = '';
					container.style.width = '';
					player.options.setDimensions = false;
				}

				if (jQuery('#' + player.id).parents('#sticky-playlist-section').length) {
					player.container.addClass('signify-mejs-container signify-mejs-sticky-playlist-container');

					jQuery('#' + player.id).parent().children('.wp-playlist-tracks').addClass('displaynone');

					var volume_slider = controls[0].children[5];

					if (jQuery('#' + player.id).parent().children('.wp-playlist-tracks').length > 0) {
						var playlist_button =
							jQuery('<div class="mejs-button mejs-playlist-button mejs-toggle-playlist">' +
								'<button type="button" aria-controls="mep_0" title="Toggle Playlist"></button>' +
								'</div>')

							// append it to the toolbar
							.appendTo(jQuery('#' + player.id))

							// add a click toggle event
							.on('click', function() {
								jQuery('#' + player.id).parent().children('.wp-playlist-tracks').slideToggle();
								jQuery(this).toggleClass('is-open')
							});

						var play_button = controls[0].children[0];

						// Add next button after volume slider
						var next_button =
							jQuery('<div class="mejs-button mejs-next-button mejs-next">' +
								'<button type="button" aria-controls="' + player.id +
								'" title="Next Track"></button>' +
								'</div>')

							// insert after volume slider
							.insertAfter(play_button)

							// add a click toggle event
							.on('click', function() {
								jQuery('#' + player.id).parent().find('.wp-playlist-next').trigger('click');
							});

						// Add prev button after volume slider
						var previous_button =
							jQuery('<div class="mejs-button mejs-previous-button mejs-previous">' +
								'<button type="button" aria-controls="' + player.id +
								'" title="Previous Track"></button>' +
								'</div>')

							// insert after volume slider
							.insertBefore(play_button)

							// add a click toggle event
							.on('click', function() {
								jQuery('#' + player.id).parent().find('.wp-playlist-prev').trigger('click');
							});
					}
				} else {
					player.container.addClass('signify-mejs-container');
					if (jQuery('#' + player.id).parent().children('.wp-playlist-tracks').length > 0) {
						var play_button = controls[0].children[0];

						// Add next button after volume slider
						var next_button =
							jQuery('<div class="mejs-button mejs-next-button mejs-next">' +
								'<button type="button" aria-controls="' + player.id +
								'" title="Next Track"></button>' +
								'</div>')

							// insert after volume slider
							.insertAfter(play_button)

							// add a click toggle event
							.on('click', function() {
								jQuery('#' + player.id).parent().find('.wp-playlist-next').trigger('click');
							});

						// Add prev button after volume slider
						var previous_button =
							jQuery('<div class="mejs-button mejs-previous-button mejs-previous">' +
								'<button type="button" aria-controls="' + player.id +
								'" title="Previous Track"></button>' +
								'</div>')

							// insert after volume slider
							.insertBefore(play_button)

							// add a click toggle event
							.on('click', function() {
								jQuery('#' + player.id).parent().find('.wp-playlist-prev').trigger('click');
							});
					}
				}
			}
		})();
	</script>
<?php
}
add_action('wp_print_footer_scripts', 'signify_mejs_add_container_class');

if (! function_exists('signify_setup')) :
	/**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * Note that this function is hooked into the after_setup_theme hook, which
	 * runs before the init hook. The init hook is too late for some features, such
	 * as indicating support for post thumbnails.
	 */
	function signify_setup()
	{
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on Signify Pro, use a find and replace
		 * to change 'signify-pro' to the name of your theme in all the template files.
		 */
		load_theme_textdomain('signify-pro', get_parent_theme_file_path('/languages'));

		// Add default posts and comments RSS feed links to head.
		add_theme_support('automatic-feed-links');

		/*
		 * This theme styles the visual editor to resemble the theme style,
		 * specifically font, colors, and column width.
		 *
		 * Google fonts url addition
		 *
		 * Font Awesome addition
		 */

		$color_scheme = get_theme_mod('color_scheme', 'default');

		// Set editor style file according to color scheme chosen.
		$editor_style_url = "css/editor-styles/editor-style-{$color_scheme}.css";

		add_editor_style(
			array(
				$editor_style_url,
				signify_fonts_url(),
				get_template_directory_uri() . '/css/font-awesome/css/all.min.css',
			)
		);

		/*
		 * Let WordPress manage the document title.
		 * By adding theme support, we declare that this theme does not use a
		 * hard-coded <title> tag in the document head, and expect WordPress to
		 * provide it for us.
		 */
		add_theme_support('title-tag');

		/*
		 * Enable support for Post Thumbnails on posts and pages.
		 *
		 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
		 */
		add_theme_support('post-thumbnails');

		// Used in Portfolio
		set_post_thumbnail_size(666, 666, true); // Ratio 1:1

		// Used in featured slider
		add_image_size('signify-slider', 1920, 1080, true);

		// Used in featured content
		add_image_size('signify-featured-content', 440, 330, true);

		// Used in Photography 3:2 ratio
		add_image_size('signify-photography', 507, 338, true);

		// Used in promotion headline
		add_image_size('signify-promotion-headline', 920, 690, true);

		// This theme uses wp_nav_menu() in one location.
		register_nav_menus(
			array(
				'menu-top'       => esc_html__('Header Top Menu', 'signify-pro'),
				'social-top'     => esc_html__('Social Menu at Top', 'signify-pro'),
				'menu-1'         => esc_html__('Primary', 'signify-pro'),
				'social-menu'    => esc_html__('Header Social Menu', 'signify-pro'),
				'social-contact' => esc_html__('Social on Contact Section', 'signify-pro'),
				'social-footer'  => esc_html__('Footer Social Menu', 'signify-pro'),
				'menu-footer'    => esc_html__('Footer Menu', 'signify-pro'),
			)
		);

		/*
		 * Switch default core markup for search form, comment form, and comments
		 * to output valid HTML5.
		 */
		add_theme_support(
			'html5',
			array(
				'comment-form',
				'comment-list',
				'gallery',
				'caption',
			)
		);

		// Add theme support for selective refresh for widgets.
		add_theme_support('customize-selective-refresh-widgets');

		/**
		 * Add support for core custom logo.
		 *
		 * @link https://codex.wordpress.org/Theme_Logo
		 */
		add_theme_support(
			'custom-logo',
			array(
				'height'      => 250,
				'width'       => 250,
				'flex-width'  => true,
				'flex-height' => true,
			)
		);

		/**
		 * Add support for essential widget image.
		 *
		 */
		add_theme_support('ew-newsletter-image');

		// Add support for Block Styles.
		add_theme_support('wp-block-styles');

		// Add support for full and wide align images.
		add_theme_support('align-wide');

		// Add support for editor styles.
		add_theme_support('editor-styles');

		// Add support for responsive embeds.
		add_theme_support('responsive-embeds');

		// Add custom editor font sizes.
		add_theme_support(
			'editor-font-sizes',
			array(
				array(
					'name'      => esc_html__('Extra small', 'signify-pro'),
					'shortName' => esc_html__('XSS', 'signify-pro'),
					'size'      => 13,
					'slug'      => 'extra-small',
				),
				array(
					'name'      => esc_html__('Small', 'signify-pro'),
					'shortName' => esc_html__('S', 'signify-pro'),
					'size'      => 16,
					'slug'      => 'small',
				),
				array(
					'name'      => esc_html__('Normal', 'signify-pro'),
					'shortName' => esc_html__('M', 'signify-pro'),
					'size'      => 18,
					'slug'      => 'normal',
				),
				array(
					'name'      => esc_html__('Large', 'signify-pro'),
					'shortName' => esc_html__('L', 'signify-pro'),
					'size'      => 42,
					'slug'      => 'large',
				),
				array(
					'name'      => esc_html__('Huge', 'signify-pro'),
					'shortName' => esc_html__('XL', 'signify-pro'),
					'size'      => 56,
					'slug'      => 'huge',
				),
			)
		);

		// Add support for custom color scheme.
		add_theme_support(
			'editor-color-palette',
			array(
				array(
					'name'  => esc_html__('White', 'signify-pro'),
					'slug'  => 'white',
					'color' => '#ffffff',
				),
				array(
					'name'  => esc_html__('Black', 'signify-pro'),
					'slug'  => 'black',
					'color' => '#000000',
				),
				array(
					'name'  => esc_html__('Eighty Black', 'signify-pro'),
					'slug'  => 'eighty-black',
					'color' => '#151515',
				),
				array(
					'name'  => esc_html__('Sixty Five Black', 'signify-pro'),
					'slug'  => 'sixty-five-black',
					'color' => '#363636',
				),
				array(
					'name'  => esc_html__('Gray', 'signify-pro'),
					'slug'  => 'gray',
					'color' => '#444444',
				),
				array(
					'name'  => esc_html__('Medium Gray', 'signify-pro'),
					'slug'  => 'medium-gray',
					'color' => '#777777',
				),
				array(
					'name'  => esc_html__('Light Gray', 'signify-pro'),
					'slug'  => 'light-gray',
					'color' => '#f9f9f9',
				),
				array(
					'name'  => esc_html__('Bright Pink', 'signify-pro'),
					'slug'  => 'bright-pink',
					'color' => '#f5808c',
				),
				array(
					'name'  => esc_html__('Dark Yellow', 'signify-pro'),
					'slug'  => 'dark-yellow',
					'color' => '#ffa751',
				),
				array(
					'name'  => esc_html__('Yellow', 'signify-pro'),
					'slug'  => 'yellow',
					'color' => '#ffbf00',
				),
				array(
					'name'  => esc_html__('Red', 'signify-pro'),
					'slug'  => 'red',
					'color' => '#db4f3d',
				),
				array(
					'name'  => esc_html__('Blue', 'signify-pro'),
					'slug'  => 'blue',
					'color' => '#008ec2',
				),
				array(
					'name'  => esc_html__('Dark Blue', 'signify-pro'),
					'slug'  => 'dark-blue',
					'color' => '#133ec2',
				),
			)
		);

		/**
		 * Adds support for Catch Breadcrumb.
		 */
		add_theme_support(
			'catch-breadcrumb',
			array(
				'content_selector'   => '.site-content .wrapper .content-area',
				'breadcrumb_dynamic' => 'before',
			)
		);
	}
endif;
add_action('after_setup_theme', 'signify_setup');

/**
 * Count the number of footer sidebars to enable dynamic classes for the footer
 *
 */
function signify_footer_sidebar_class()
{
	$count = 0;

	if (is_active_sidebar('sidebar-2')) {
		$count++;
	}

	if (is_active_sidebar('sidebar-3')) {
		$count++;
	}

	if (is_active_sidebar('sidebar-4')) {
		$count++;
	}

	if (is_active_sidebar('sidebar-5')) {
		$count++;
	}

	$class = '';

	switch ($count) {
		case '1':
			$class = 'one';
			break;
		case '2':
			$class = 'two';
			break;
		case '3':
			$class = 'three';
			break;
		case '4':
			$class = 'four';
			break;
	}

	if ($class) {
		echo 'class="widget-area footer-widget-area ' . esc_attr($class) . '"';
	}
}

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function signify_content_width()
{
	$GLOBALS['content_width'] = apply_filters('signify_content_width', 880);
}
add_action('after_setup_theme', 'signify_content_width', 0);

if (! function_exists('signify_template_redirect')) :
	/**
	 * Set the content width in pixels, based on the theme's design and stylesheet for different value other than the default one
	 *
	 * @global int $content_width
	 */
	function signify_template_redirect()
	{
		$layout = signify_get_theme_layout();

		if ('no-sidebar-full-width' === $layout) {
			$GLOBALS['content_width'] = 1440;
		}
	}
endif;
add_action('template_redirect', 'signify_template_redirect');

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function signify_widgets_init()
{
	$args = array(
		'before_widget' => '<section id="%1$s" class="widget %2$s"> <div class="widget-wrap">',
		'after_widget'  => '</div></section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	);

	register_sidebar(
		array(
			'name'        => esc_html__('Sidebar', 'signify-pro'),
			'id'          => 'sidebar-1',
			'description' => esc_html__('Add widgets here.', 'signify-pro'),
		) + $args
	);

	register_sidebar(
		array(
			'name'        => esc_html__('Footer 1', 'signify-pro'),
			'id'          => 'sidebar-2',
			'description' => esc_html__('Add widgets here to appear in your footer.', 'signify-pro'),
		) + $args
	);

	register_sidebar(
		array(
			'name'        => esc_html__('Footer 2', 'signify-pro'),
			'id'          => 'sidebar-3',
			'description' => esc_html__('Add widgets here to appear in your footer.', 'signify-pro'),
		) + $args
	);

	register_sidebar(
		array(
			'name'        => esc_html__('Footer 3', 'signify-pro'),
			'id'          => 'sidebar-4',
			'description' => esc_html__('Add widgets here to appear in your footer.', 'signify-pro'),
		) + $args
	);

	register_sidebar(
		array(
			'name'        => esc_html__('Footer 4', 'signify-pro'),
			'id'          => 'sidebar-5',
			'description' => esc_html__('Add widgets here to appear in your footer.', 'signify-pro'),
		) + $args
	);

	if (class_exists('Catch_Instagram_Feed_Gallery_Widget') || class_exists('Catch_Instagram_Feed_Gallery_Widget_Pro')) {
		register_sidebar(
			array(
				'name'        => esc_html__('Instagram', 'signify-pro'),
				'id'          => 'sidebar-instagram',
				'description' => esc_html__('Appears above footer. This sidebar is only for Widget from plugin Catch Instagram Feed Gallery Widget and Catch Instagram Feed Gallery Widget Pro', 'signify-pro'),
			) + $args
		);
	}

	if (class_exists('WooCommerce')) {
		//Optional Primary Sidebar for Shop
		register_sidebar(
			array(
				'name'        => esc_html__('WooCommerce Sidebar', 'signify-pro'),
				'id'          => 'sidebar-woo',
				'description' => esc_html__('This is Optional Sidebar for WooCommerce Pages', 'signify-pro'),
			) + $args
		);
	}

	// Registering 404 Error Page Content
	register_sidebar(
		array(
			'name'          => esc_html__('404 Page Not Found Content', 'signify-pro'),
			'id'            => 'sidebar-notfound',
			'description'   => esc_html__('Replaces the default 404 Page Not Found Content', 'signify-pro'),
			'before_widget' => '<section id="%1$s" class="widget %2$s"> <div class="widget-wrap">',
			'after_widget'  => '</div></section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);

	//Optional Sidebar for Hompeage instead of main sidebar
	register_sidebar(
		array(
			'name'        => esc_html__('Optional Homepage Sidebar', 'signify-pro'),
			'id'          => 'sidebar-optional-homepage',
			'description' => esc_html__('This is Optional Sidebar for Homepage', 'signify-pro'),
		) + $args
	);

	//Optional Sidebar for Archive instead of main sidebar
	register_sidebar(
		array(
			'name'        => esc_html__('Optional Archive Sidebar', 'signify-pro'),
			'id'          => 'sidebar-optional-archive',
			'description' => esc_html__('This is Optional Sidebar for Archive', 'signify-pro'),
		) + $args
	);

	//Optional Sidebar for Page instead of main sidebar
	register_sidebar(
		array(
			'name'        => esc_html__('Optional Page Sidebar', 'signify-pro'),
			'id'          => 'sidebar-optional-page',
			'description' => esc_html__('This is Optional Sidebar for Page', 'signify-pro'),
		) + $args
	);

	//Optional Sidebar for Post instead of main sidebar
	register_sidebar(
		array(
			'name'        => esc_html__('Optional Post Sidebar', 'signify-pro'),
			'id'          => 'sidebar-optional-post',
			'description' => esc_html__('This is Optional Sidebar for Post', 'signify-pro'),
		) + $args
	);

	//Optional Sidebar one for page and post
	register_sidebar(
		array(
			'name'        => esc_html__('Optional Sidebar One', 'signify-pro'),
			'id'          => 'sidebar-optional-one',
			'description' => esc_html__('This is Optional Sidebar One', 'signify-pro'),
		) + $args
	);

	//Optional Sidebar two for page and post
	register_sidebar(
		array(
			'name'        => esc_html__('Optional Sidebar Two', 'signify-pro'),
			'id'          => 'sidebar-optional-two',
			'description' => esc_html__('This is Optional Sidebar Two', 'signify-pro'),
		) + $args
	);

	//Optional Sidebar Three for page and post
	register_sidebar(
		array(
			'name'        => esc_html__('Optional Sidebar Three', 'signify-pro'),
			'id'          => 'sidebar-optional-three',
			'description' => esc_html__('This is Optional Sidebar Three', 'signify-pro'),
		) + $args
	);

	//Optional Sidebar Six Footer Newsletter
	register_sidebar(
		array(
			'name'          => esc_html__('Newsletter', 'signify-pro'),
			'id'            => 'sidebar-newsletter',
			'description'   => esc_html__('This is for Newsletter Template Widget Area.', 'signify-pro'),
			'before_widget' => '<section id="%1$s" class="widget %2$s">
		<div class="widget-wrap"><div class="widget-inner">',
			'after_widget'  => '</div></div></section>',
			'before_title'  => '<div class="section-title-wrapper"><h2 class="section-title">',
			'after_title'   => '</h2></div>',
		)
	);
}
add_action('widgets_init', 'signify_widgets_init');

if (! function_exists('signify_fonts_url')) :
	/**
	 * Register Google fonts for Signify Pro
	 *
	 * Create your own signify_fonts_url() function to override in a child theme.
	 *
	 * @since 1.0.0
	 *
	 * @return string Google fonts URL for the theme.
	 */
	function signify_fonts_url()
	{
		$fonts_url = '';
		$fonts     = array();
		$subsets   = 'latin,latin-ext';

		$font_values = array();
		$fonts_list  = signify_font_family_options();

		foreach ($fonts_list as $key => $font_list) {
			$font_values[] = get_theme_mod($key, $font_list['default']);
		}

		$web_fonts = array(
			'allan'               => 'Allan',
			'allerta'             => 'Allerta',
			'amaranth'            => 'Amaranth',
			'amatic-sc'           => 'Amatic SC',
			'bitter'              => 'Bitter',
			'cabin'               => 'Cabin',
			'cantarell'           => 'Cantarell',
			'crimson-text'        => 'Crimson+Text',
			'cuprum'              => 'Cuprum',
			'dancing-script'      => 'Dancing Script',
			'droid-sans'          => 'Droid Sans',
			'droid-serif'         => 'Droid Serif',
			'exo'                 => 'Exo',
			'exo-2'               => 'Exo 2',
			'istok-web'           => 'Istok Web',
			'josefin-sans'        => 'Josefin Sans',
			'lato'                => 'Lato',
			'lobster'             => 'Lobster',
			'lora'                => 'Lora',
			'mrs-saint-delafield' => 'Mrs Saint Delafield',
			'montserrat'          => 'Montserrat',
			'muli'                => 'Muli',
			'nobile'              => 'Nobile',
			'noto-serif'          => 'Noto Serif',
			'neuton'              => 'Neuton',
			'open-sans'           => 'Open Sans',
			'oswald'              => 'Oswald',
			'oxygen'              => 'Oxygen',
			'patua-one'           => 'Patua One',
			'poppins'             => 'Poppins',
			'playfair-display'    => 'Playfair Display',
			'pt-sans'             => 'PT Sans',
			'pt-serif'            => 'PT Serif',
			'rubik'               => 'Rubik',
			'quattrocento-sans'   => 'Quattrocento Sans',
			'roboto'              => 'Roboto',
			'roboto-slab'         => 'Roboto Slab',
			'source-sans-pro'     => 'Source Sans Pro',
			'ubuntu'              => 'Ubuntu',
			'varela'              => 'Varela',
			'yanone-kaffeesatz'   => 'Yanone Kaffeesatz',
		);

		$font_values = array_unique($font_values); // Make the array of fonts unique so that same font is not loaded twice.

		$font_values = array_intersect($font_values, array_keys($web_fonts)); // Intersect selected fonts and webfonts to only recover fonts that need loading.

		foreach ($font_values as $font_value) {
			$fonts[] = $web_fonts[$font_value] . ':300,400,500,600,700,400italic,700italic';
		}

		if ($fonts) {
			$fonts_url = add_query_arg(
				array(
					'family' => urlencode(implode('|', $fonts)),
					'subset' => urlencode($subsets),
				),
				'https://fonts.googleapis.com/css'
			);
		}

		if (! get_theme_mod('signify_load_font_cdn')) {
			require_once get_theme_file_path('inc/wptt-webfont-loader.php');

			$fonts_url = wptt_get_webfont_url($fonts_url);
		}

		return esc_url($fonts_url);
	}
endif;

/**
 * Handles JavaScript detection.
 *
 * Adds a `js` class to the root `<html>` element when JavaScript is detected.
 *
 * @since 1.0.0
 */
function signify_javascript_detection()
{
	echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action('wp_head', 'signify_javascript_detection', 0);

/**
 * Enqueue scripts and styles.
 */
function signify_scripts()
{
	$min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';

	// Add custom fonts, used in the main stylesheet.
	wp_enqueue_style('signify-fonts', signify_fonts_url(), array(), null);

	// Theme stylesheet.
	wp_enqueue_style('signify-style', get_stylesheet_uri(), null, date('Ymd-Gis', filemtime(get_template_directory() . '/style.css')));

	// Theme block stylesheet.
	wp_enqueue_style('signify-block-style', get_theme_file_uri('/css/blocks.css'), array('signify-style'), '1.0');

	// Load the html5 shiv.
	wp_enqueue_script('signify-html5', get_template_directory_uri() . '/js/html5' . $min . '.js', null, '3.7.3');

	wp_script_add_data('signify-html5', 'conditional', 'lt IE 9');

	// Font Awesome
	wp_enqueue_style('font-awesome', get_template_directory_uri() . '/css/font-awesome/css/all.min.css', array(), '6.7.2', 'all');

	wp_enqueue_script('signify-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix' . $min . '.js', array(), '201800703', true);

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

	wp_register_script('jquery-match-height', get_template_directory_uri() . '/js/jquery.matchHeight' . $min . '.js', array('jquery'), '201800703', true);

	$deps[] = 'jquery';

	$enable_featured_content = get_theme_mod('signify_featured_content_option', 'disabled');
	$enable_contact          = get_theme_mod('signify_contact_section_option', 'disabled');

	if (signify_check_section($enable_featured_content) || signify_check_section($enable_contact)) {
		$deps[] = 'jquery-match-height';
	}

	$enable_portfolio = get_theme_mod('signify_portfolio_option', 'disabled');

	if (signify_check_section($enable_portfolio)) {
		// Isotope JS.
		wp_register_script('jquery-isotope', get_template_directory_uri() . '/js/isotope' . $min . '.js', array(), '2.0.1', true);

		$deps[] = 'jquery-isotope';
	}

	//Slider Scripts
	$enable_slider      = signify_check_section(get_theme_mod('signify_slider_option', 'disabled'));
	$enable_logo_slider = signify_check_section(get_theme_mod('signify_logo_slider_option', 'disabled'));

	$enable_testimonial_slider = signify_check_section(get_theme_mod('signify_testimonial_option', 'disabled'));
	$enable_team_slider        = signify_check_section(get_theme_mod('signify_team_option', 'disabled'));

	$slider_trans_in       = get_theme_mod('signify_slider_transition_in', 'default');
	$slider_trans_out      = get_theme_mod('signify_slider_transition_out', 'default');
	$testimonial_trans_in  = get_theme_mod('signify_testimonial_transition_in', 'default');
	$testimonial_trans_out = get_theme_mod('signify_testimonial_transition_out', 'default');
	$logo_slider_trans_in  = get_theme_mod('signify_logo_slider_transition_in', 'default');
	$logo_slider_trans_out = get_theme_mod('signify_logo_slider_transition_out', 'default');
	$team_trans_in         = get_theme_mod('signify_team_transition_in', 'default');
	$team_trans_out        = get_theme_mod('signify_team_transition_out', 'default');

	if ($enable_slider || $enable_testimonial_slider || $enable_logo_slider || $enable_team_slider) {
		// Enqueue owl carousel css. Must load CSS before JS.
		wp_enqueue_style('owl-carousel-core', get_theme_file_uri('css/owl-carousel/owl.carousel.min.css'), null, '2.3.4');
		wp_enqueue_style('owl-carousel-default', get_theme_file_uri('css/owl-carousel/owl.theme.default.min.css'), null, '2.3.4');

		if (($enable_slider && ('default' !== $slider_trans_in || 'default' !== $slider_trans_out))
			|| ($enable_logo_slider && ('default' !== $logo_slider_trans_in || 'default' !== $logo_slider_trans_out))
			|| ($enable_testimonial_slider && ('default' !== $testimonial_trans_in || 'default' !== $testimonial_trans_out))
			|| ($enable_team_slider && ('default' !== $team_trans_in || 'default' !== $team_trans_out))
		) {
			wp_enqueue_style('animate', get_theme_file_uri('css/animate.css'), null, '3.7.0');
		}

		// Enqueue script
		wp_enqueue_script('owl-carousel', get_theme_file_uri() . '/js/owl.carousel' . $min . '.js', array('jquery'), '2.3.4', true);

		$deps[] = 'owl-carousel';
	}

	$enable_video   = signify_check_section(get_theme_mod('signify_featured_video_option', 'disabled'));
	$video_lightbox = get_theme_mod('signify_featured_video_show_lightbox', 'enabled');

	$promotion_video = get_theme_mod('signify_featured_video_link');

	if (($enable_video && 'enabled' === $video_lightbox) || $promotion_video) {
		//Flashy for video section
		wp_enqueue_style('signify-flashy', get_theme_file_uri('css/flashy.min.css'));

		wp_enqueue_script('signify-jquery-flashy', get_theme_file_uri() . '/js/jquery.flashy' . $min . '.js', array('jquery'), '201800703', true);

		$deps[] = 'signify-jquery-flashy';
	}

	if ($enable_video) {
		// Enqueue fitvid
		wp_enqueue_script('jquery-fitvids', get_template_directory_uri() . '/js/fitvids' . $min . '.js', array('jquery'), '1.1', true);
	}

	wp_enqueue_script('signify-script', get_template_directory_uri() . '/js/functions' . $min . '.js', $deps, '201800703', true);

	wp_localize_script(
		'signify-script',
		'signifyOptions',
		array(
			'screenReaderText'   => array(
				'expand'   => esc_html__('expand child menu', 'signify-pro'),
				'collapse' => esc_html__('collapse child menu', 'signify-pro'),
			),
			'sliderOptions'      => array(
				'transitionIn'      => esc_js($slider_trans_in),
				'transitionOut'     => esc_js($slider_trans_out),
				'nav'               => esc_js(! get_theme_mod('signify_slider_nav', 0)),
				'autoplay'          => esc_js(! get_theme_mod('signify_slider_autoplay', 1)),
				'loop'              => esc_js(get_theme_mod('signify_slider_loop')),
				'transitionTimeout' => esc_js(get_theme_mod('signify_slider_transition_timeout', 4)),
				'dots'              => esc_js(! get_theme_mod('signify_slider_dots', 0)),
			),
			'logoSliderOptions'  => array(
				'transitionIn'      => esc_js($logo_slider_trans_in),
				'transitionOut'     => esc_js($logo_slider_trans_out),
				'nav'               => esc_js(! get_theme_mod('signify_logo_slider_nav')),
				'autoplay'          => esc_js(! get_theme_mod('signify_logo_slider_autoplay')),
				'loop'              => esc_js(get_theme_mod('signify_logo_slider_loop')),
				'transitionTimeout' => esc_js(get_theme_mod('signify_logo_slider_transition_timeout', 4)),
				'layout'            => esc_js(get_theme_mod('signify_logo_slider_layout', 5)),
				'dots'              => esc_js(! get_theme_mod('signify_logo_slider_dots', 0)),
			),
			'testimonialOptions' => array(
				'transitionIn'      => esc_js($testimonial_trans_in),
				'transitionOut'     => esc_js($testimonial_trans_out),
				'autoplay'          => esc_js(! get_theme_mod('signify_testimonial_autoplay', 0)),
				'loop'              => esc_js(! get_theme_mod('signify_testimonial_loop', 1)),
				'transitionTimeout' => esc_js(get_theme_mod('signify_testimonial_transition_timeout', 4)),
				'dots'              => esc_js(! get_theme_mod('signify_testimonial_dots', 1)),
			),
			'teamOptions'        => array(
				'transitionIn'      => esc_js($team_trans_in),
				'transitionOut'     => esc_js($team_trans_out),
				'nav'               => esc_js(! get_theme_mod('signify_team_nav', 1)),
				'autoplay'          => esc_js(! get_theme_mod('signify_team_autoplay', 1)),
				'loop'              => esc_js(! get_theme_mod('signify_team_loop', 1)),
				'transitionTimeout' => esc_js(get_theme_mod('signify_team_transition_timeout', 4)),
				'dots'              => esc_js(! get_theme_mod('signify_team_dots', 1)),
			),
			'rtl'                => is_rtl(),
		)
	);

	// Remove Media CSS, we have ouw own CSS for this.
	wp_deregister_style('wp-mediaelement');
}
add_action('wp_enqueue_scripts', 'signify_scripts');

/**
 * Enqueue editor styles for Gutenberg
 */
function signify_block_editor_styles()
{
	$color_scheme = get_theme_mod('color_scheme', 'default');

	// Set block style file according to color scheme chosen.
	$block_style_url = "css/editor-block-styles/editor-blocks-{$color_scheme}.css";

	// Block styles.
	wp_enqueue_style('signify-block-editor-style', get_theme_file_uri($block_style_url));

	// Add custom fonts.
	wp_enqueue_style('signify-fonts', signify_fonts_url(), array(), null);

	// Font Awesome
	wp_enqueue_style('font-awesome', get_template_directory_uri() . '/css/font-awesome/css/font-awesome.css', array(), '4.7.0', 'all');
}
add_action('enqueue_block_editor_assets', 'signify_block_editor_styles');

if (! function_exists('signify_excerpt_length')) :
	/**
	 * Sets the post excerpt length to n words.
	 *
	 * function tied to the excerpt_length filter hook.
	 * @uses filter excerpt_length
	 *
	 * @since 1.0.0
	 */
	function signify_excerpt_length($length)
	{
		if (is_admin()) {
			return $length;
		}

		// Getting data from Customizer Options
		$length = get_theme_mod('signify_excerpt_length', 20);

		return absint($length);
	}
endif; //signify_excerpt_length
add_filter('excerpt_length', 'signify_excerpt_length', 999);

if (! function_exists('signify_excerpt_more')) :
	/**
	 * Replaces "[...]" (appended to automatically generated excerpts) with ... and a option from customizer
	 *
	 * @return string option from customizer prepended with an ellipsis.
	 */
	function signify_excerpt_more($more)
	{
		if (is_admin()) {
			return $more;
		}

		$more_tag_text = get_theme_mod('signify_excerpt_more_text', esc_html__('Continue reading', 'signify-pro'));

		$link = sprintf(
			'<p><a href="%1$s" class="more-link">%2$s</a></p>',
			esc_url(get_permalink()),
			/* translators: %s: Name of current post */
			wp_kses_data($more_tag_text) . '<span class="screen-reader-text">' . get_the_title(get_the_ID()) . '</span>'
		);

		return $link;
	}
endif;
add_filter('excerpt_more', 'signify_excerpt_more');

if (! function_exists('signify_custom_excerpt')) :
	/**
	 * Adds Continue reading link to more tag excerpts.
	 *
	 * function tied to the get_the_excerpt filter hook.
	 *
	 * @since 1.0.0
	 */
	function signify_custom_excerpt($output)
	{
		if (has_excerpt() && ! is_attachment()) {
			$more_tag_text = get_theme_mod('signify_excerpt_more_text', esc_html__('Continue reading', 'signify-pro'));

			$link = sprintf(
				'<a href="%1$s" class="more-link">%2$s</a>',
				esc_url(get_permalink()),
				/* translators: %s: Name of current post */
				wp_kses_data($more_tag_text) . '<span class="screen-reader-text">' . get_the_title(get_the_ID()) . '</span>'
			);

			$link = ' &hellip; ' . $link;

			$output .= $link;
		}

		return $output;
	}
endif; //signify_custom_excerpt
add_filter('get_the_excerpt', 'signify_custom_excerpt');

if (! function_exists('signify_more_link')) :
	/**
	 * Replacing Continue reading link to the_content more.
	 *
	 * function tied to the the_content_more_link filter hook.
	 *
	 * @since 1.0.0
	 */
	function signify_more_link($more_link, $more_link_text)
	{
		$more_tag_text = get_theme_mod('signify_excerpt_more_text', esc_html__('Continue reading', 'signify-pro'));

		return ' &hellip; ' . str_replace($more_link_text, wp_kses_data($more_tag_text), $more_link);
	}
endif; //signify_more_link
add_filter('the_content_more_link', 'signify_more_link', 10, 2);

/**
 * Checks if there are options already present from free version and adds it to the Pro theme options
 *
 * @since 1.0.0
 * @hook after_theme_switch
 */
function signify_setup_options($old_theme_name)
{
	if ($old_theme_name) {
		$old_theme_slug    = sanitize_title($old_theme_name);
		$free_version_slug = array(
			'signify',
			'signify-dark',
			'signify-education',
			'signify-wedding',
			'signify-photography',
			'signify-ecommerce',
			'signify-tune',
			'signify-music-dark',
		);

		$pro_version_slug = 'signify-pro';

		$free_options = get_option('theme_mods_' . $old_theme_slug);

		// Perform action only if theme_mods_signify free version exists.
		if (in_array($old_theme_slug, $free_version_slug) && $free_options && '1' !== get_theme_mod('free_pro_migration')) {
			$new_options = wp_parse_args(get_theme_mods(), $free_options);

			if ('signify-dark' === $old_theme_slug) {
				$free_options['color_scheme'] = 'dark';
			}

			if ('signify-education' === $old_theme_slug) {
				$free_options['color_scheme']          = 'education';
				$free_options['signify_header_layout'] = 'header-style-two';
			}

			if ('signify-wedding' === $old_theme_slug) {
				$free_options['color_scheme']               = 'wedding';
				$free_options['signify_hero_content_style'] = 'style-two';
				$free_options['signify_events_style']       = 'style-two';
				$free_options['signify_events_type']        = 'page';
			}

			if ('signify-photography' === $old_theme_slug) {
				$free_options['color_scheme']                      		= 'photography';
				$free_options['signify_header_media_text_alignment']	= 'text-align-center';
				$free_options['signify_header_media_content_alignment']	= 'content-align-center';
				$free_options['signify_header_layout']			   		= 'header-style-two';
				$free_options['signify_hero_content_txt_align']    		= 'text-align-center';
				$free_options['signify_promo_head_image_position'] 		= 'content-align-center';
				$free_options['signify_body_font'] 				   		= 'oxygen';
				$free_options['signify_title_font'] 			   		= 'oswald';
				$free_options['signify_tagline_font'] 			   		= 'oxygen';
				$free_options['signify_content_title_font'] 	   		= 'oswald';
				$free_options['signify_headings_font'] 	  	       		= 'oswald';
				$free_options['signify_section_title_font'] 	   		= 'oswald';
			}

			if ('signify-corporate' === $old_theme_slug) {
				$free_options['color_scheme']                      = 'corporate';
				$free_options['signify_header_layout']			   = 'header-style-two';
				$free_options['signify_promo_head_image_position'] = 'content-align-center';
				$free_options['signify_body_font'] 				   = 'open-sans';
				$free_options['signify_title_font'] 			   = 'open-sans';
				$free_options['signify_tagline_font'] 			   = 'open-sans';
				$free_options['signify_content_title_font'] 	   = 'poppins';
				$free_options['signify_headings_font'] 	  	       = 'poppins';
				$free_options['signify_section_title_font'] 	   = 'poppins';
			}

			if ('signify-ecommerce' === $old_theme_slug) {
				$free_options['color_scheme'] 					   = 'ecommerce';
				$free_options['signify_woocommerce_layout']		   = 'right-sidebar';
			}

			if ('signify-tune' === $old_theme_slug) {
				$free_options['color_scheme']                      = 'tune';
				$free_options['signify_header_layout']			   = 'header-style-two';
				$free_options['signify_body_font'] 				   = 'open-sans';
				$free_options['signify_title_font'] 			   = 'open-sans';
				$free_options['signify_tagline_font'] 			   = 'open-sans';
				$free_options['signify_content_title_font'] 	   = 'poppins';
				$free_options['signify_headings_font'] 	  	       = 'poppins';
				$free_options['signify_section_title_font'] 	   = 'poppins';
			}

			if ('signify-music-dark' === $old_theme_slug) {
				$free_options['color_scheme']                      = 'music-dark';
				$free_options['signify_header_layout']			   = 'header-style-two';
				$free_options['signify_body_font'] 				   = 'open-sans';
				$free_options['signify_title_font'] 			   = 'open-sans';
				$free_options['signify_tagline_font'] 			   = 'open-sans';
				$free_options['signify_content_title_font'] 	   = 'poppins';
				$free_options['signify_headings_font'] 	  	       = 'poppins';
				$free_options['signify_section_title_font'] 	   = 'poppins';
			}

			if (update_option('theme_mods_' . $pro_version_slug, $free_options)) {
				// Set Migration Parameter to true so that this script does not run multiple times.
				set_theme_mod('free_pro_migration', '1');
			}
		}
	}
}
add_action('after_switch_theme', 'signify_setup_options');

/**
 * Load theme updater functions.
 */
function signify_theme_updater()
{
	if (is_admin()) {
		require_once get_template_directory() . '/updater/theme-updater.php';
	}
}
add_action('after_setup_theme', 'signify_theme_updater');

/**
 * Load TGMPA.
 */
require_once get_parent_theme_file_path('/inc/tgm.php');

/**
 * Implement the Custom Header feature
 */
require get_parent_theme_file_path('/inc/custom-header.php');

/**
 * Custom template tags for this theme
 */
require get_parent_theme_file_path('/inc/template-tags.php');

/**
 * Functions which enhance the theme by hooking into WordPress
 */
require get_parent_theme_file_path('/inc/template-functions.php');

/**
 * Customizer additions
 */
require get_parent_theme_file_path('/inc/customizer/customizer.php');

/**
 * Color Scheme additions
 */
require get_parent_theme_file_path('/inc/color-scheme.php');

/**
 * Include Events
 */
require get_parent_theme_file_path('/inc/events.php');

/**
 * Load Jetpack compatibility file
 */
if (defined('JETPACK__VERSION')) {
	require get_parent_theme_file_path('/inc/jetpack.php');
}

/**
 * Load Metabox
 */
require get_parent_theme_file_path('/inc/metabox/metabox.php');

/**
 * Load Social Widgets
 */
require get_parent_theme_file_path('/inc/widget-social-icons.php');

/**
 * Load Theme About Page
 */
require get_parent_theme_file_path('/inc/admin/admin.php');

/**
 * Load Events.
 */
require get_parent_theme_file_path('/inc/events.php');

/**
 * Load Timeline.
 */
require get_parent_theme_file_path('/inc/timeline.php');

// Load Demo Import Class
if (class_exists('CatchThemesDemoImportPlugin')) :
	require(get_template_directory() . '/inc/support/ctdi/demo-import.php');
endif;
