<?php
/**
 * Resort Motel functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package resort_motel
 */

$resort_motel_theme_data = wp_get_theme();
if( ! defined( 'RESORT_MOTEL_THEME_VERSION' ) ) define ( 'RESORT_MOTEL_THEME_VERSION', $resort_motel_theme_data->get( 'Version' ) );
if( ! defined( 'RESORT_MOTEL_THEME_NAME' ) ) define( 'RESORT_MOTEL_THEME_NAME', $resort_motel_theme_data->get( 'Name' ) );
if( ! defined( 'RESORT_MOTEL_THEME_TEXTDOMAIN' ) ) define( 'RESORT_MOTEL_THEME_TEXTDOMAIN', $resort_motel_theme_data->get( 'TextDomain' ) );


if ( ! function_exists( 'resort_motel_setup' ) ) :
	
	function resort_motel_setup() {
		
		load_theme_textdomain( 'resort-motel', get_template_directory() . '/languages' );

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

		add_theme_support( 'woocommerce' );

		add_theme_support( 'post-thumbnails' );

		register_nav_menus(
			array(
				'primary' => esc_html__( 'Primary', 'resort-motel' ),
			)
		);

		add_theme_support(
			'html5',
			array(
				'search-form',
				'comment-form',
				'comment-list',
				'gallery',
				'caption',
				'style',
				'script',
				'woocommerce',
			)
		);

		add_theme_support( 'post-formats', array(
			'image',
			'video',
			'gallery',
			'audio', 
		) );

		add_theme_support(
			'custom-background',
			apply_filters(
				'resort_motel_custom_background_args',
				array(
					'default-color' => 'ffffff',
					'default-image' => '',
				)
			)
		);

		add_theme_support( 'customize-selective-refresh-widgets' );

		add_theme_support(
			'custom-logo',
			array(
				'height'      => 250,
				'width'       => 250,
				'flex-width'  => true,
				'flex-height' => true,
			)
		);

		add_theme_support( 'align-wide' );

		add_theme_support( 'responsive-embeds' );
	}
endif;
add_action( 'after_setup_theme', 'resort_motel_setup' );

function resort_motel_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'resort_motel_content_width', 640 );
}
add_action( 'after_setup_theme', 'resort_motel_content_width', 0 );

function resort_motel_widgets_init() {
	register_sidebar(
		array(
			'name'          => esc_html__( 'Sidebar', 'resort-motel' ),
			'id'            => 'sidebar-1',
			'description'   => esc_html__( 'Add widgets here.', 'resort-motel' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title"><span>',
			'after_title'   => '</span></h2>',
		)
	);

	// Regsiter 4 footer widgets.
	$resort_motel_footer_widget_column = get_theme_mod('resort_motel_footer_widget_column','4');
	for ($i=1; $i<=$resort_motel_footer_widget_column; $i++) {
		register_sidebar( array(
			'name' => __( 'Footer  ', 'resort-motel' )  . $i,
			'id' => 'resort-motel-footer-widget-' . $i,
			'description' => __( 'The Footer Widget Area', 'resort-motel' )  . $i,
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget' => '</aside>',
			'before_title' => '<div class="widget-header"><h4 class="widget-title">',
			'after_title' => '</h4></div>',
		) );
	}
}
add_action( 'widgets_init', 'resort_motel_widgets_init' );

//Change number of products per page 
add_filter( 'loop_shop_per_page', 'resort_motel_products_per_page' );
function resort_motel_products_per_page( $cols ) {
  	return  get_theme_mod( 'resort_motel_products_per_page',9);
}

// Change number or products per row 
add_filter('loop_shop_columns', 'resort_motel_loop_columns');
	if (!function_exists('resort_motel_loop_columns')) {
	function resort_motel_loop_columns() {
		return get_theme_mod( 'resort_motel_products_per_row', 3 );
	}
}

/**
 * Enqueue scripts and styles.
 */
function resort_motel_scripts() {
	// Append .min if SCRIPT_DEBUG is false.
	$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

	// Slick style.
	wp_enqueue_style( 'resort-motel-slick-style', get_template_directory_uri() . '/resource/css/slick' . $min . '.css', array(), '1.8.1' );

	// Fontawesome style.
	wp_enqueue_style( 'font-awesome-css', esc_url(get_template_directory_uri())."/resource/css/fontawesome-all.css" );

	// Main style.
	wp_enqueue_style( 'resort-motel-style', get_template_directory_uri() . '/style.css', array(), RESORT_MOTEL_THEME_VERSION );
	
	// RTL style.
	wp_style_add_data('resort-motel-style', 'rtl', 'replace');

	if (get_theme_mod('resort_motel_enable_animation', true) == true){
		// Animate CSS
		wp_enqueue_style( 'animate-style', get_template_directory_uri() . '/resource/css/animate.css' );
		// Wow script.
		wp_enqueue_script( 'wow-jquery', get_template_directory_uri() . '/resource/js/wow.js', array('jquery'),'' ,true );
	}

	// Navigation script.
	wp_enqueue_script( 'resort-motel-navigation-script', get_template_directory_uri() . '/resource/js/navigation' . $min . '.js', array(), RESORT_MOTEL_THEME_VERSION, true );

	// Slick script.
	wp_enqueue_script( 'resort-motel-slick-script', get_template_directory_uri() . '/resource/js/slick' . $min . '.js', array( 'jquery' ), '1.8.1', true );


	// Custom script.
	wp_enqueue_script( 'resort-motel-custom-script', get_template_directory_uri() . '/resource/js/custom' . '.js', array( 'jquery' ), RESORT_MOTEL_THEME_VERSION, true );

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

	// Include the file.
	require_once get_theme_file_path( 'theme-library/function-files/wptt-webfont-loader.php' );

	// Load the webfont.
	wp_enqueue_style(
		'poppins',
		wptt_get_webfont_url( 'https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap' ),
		array(),
		'1.0'
	);

	// Load the webfont.
	wp_enqueue_style(
		'playfair',
		wptt_get_webfont_url( 'https://fonts.googleapis.com/css2?family=Playfair+Display+SC:ital,wght@0,400;0,700;0,900;1,400;1,700;1,900&display=swap' ),
		array(),
		'1.0'
	);

}
add_action( 'wp_enqueue_scripts', 'resort_motel_scripts' );

/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/theme-library/custom-header.php';

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/theme-library/function-files/template-tags.php';

/**
 * Functions which enhance the theme by hooking into WordPress.
 */
require get_template_directory() . '/theme-library/function-files/template-functions.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/theme-library/customizer.php';

/**
 * Breadcrumb
 */
require get_template_directory() . '/theme-library/function-files/class-breadcrumb-trail.php';

/**
 * Getting Started
*/
require get_template_directory() . '/theme-library/getting-started/getting-started.php';

/**
 * Google Fonts
 */
require get_template_directory() . '/theme-library/function-files/google-fonts.php';

/**
 * Dynamic CSS
 */
require get_template_directory() . '/theme-library/dynamic-css.php';


function resort_motel_links_setup() {
	if ( ! defined( 'RESORT_MOTEL_PREMIUM_PAGE' ) ) {
	define('RESORT_MOTEL_PREMIUM_PAGE',__('https://asterthemes.com/products/motel-wordpress-theme','resort-motel'));
	}
	if ( ! defined( 'RESORT_MOTEL_THEME_PAGE' ) ) {
		define('RESORT_MOTEL_THEME_PAGE',__('https://asterthemes.com/products/resort-motel','resort-motel'));
	}
	if ( ! defined( 'RESORT_MOTEL_SUPPORT' ) ) {
	define('RESORT_MOTEL_SUPPORT',__('https://wordpress.org/support/theme/resort-motel/','resort-motel'));
	}
	if ( ! defined( 'RESORT_MOTEL_REVIEW' ) ) {
	define('RESORT_MOTEL_REVIEW',__('https://wordpress.org/support/theme/resort-motel/reviews/','resort-motel'));
	}
	if ( ! defined( 'RESORT_MOTEL_PRO_DEMO' ) ) {
	define('RESORT_MOTEL_PRO_DEMO',__('https://demo.asterthemes.com/resort-motel/','resort-motel'));
	}
	if ( ! defined( 'RESORT_MOTEL_THEME_DOCUMENTATION' ) ) {
	define('RESORT_MOTEL_THEME_DOCUMENTATION',__('https://demo.asterthemes.com/docs/resort-motel-free/','resort-motel'));
	}
	if ( ! defined( 'RESORT_MOTEL_PREMIUM_DOCUMENTATION' ) ) {
	define('RESORT_MOTEL_PREMIUM_DOCUMENTATION',__('https://demo.asterthemes.com/docs/resort-motel-pro/','resort-motel'));
	}
	if ( ! defined( 'RESORT_MOTEL_BUNDLE_PAGE' ) ) {
		define('RESORT_MOTEL_BUNDLE_PAGE',__('https://asterthemes.com/products/wp-theme-bundle','resort-motel'));
	}
}
add_action('after_setup_theme', 'resort_motel_links_setup');

/**
 * Demo Import
 */
add_action( 'init', 'resort_motel_load_theme_wizard' );
function resort_motel_load_theme_wizard() {
    require get_parent_theme_file_path( '/theme-wizard/config.php' );
}

/**
 * Customizer Settings Functions
*/
require get_template_directory() . '/theme-library/function-files/customizer-settings-functions.php';


// Enqueue Customizer live preview script
function resort_motel_customizer_live_preview() {
    wp_enqueue_script(
        'resort-motel-customizer',
        get_template_directory_uri() . '/js/customizer.js',
        array('jquery', 'customize-preview'),
        '',
        true
    );
}
add_action('customize_preview_init', 'resort_motel_customizer_live_preview');

// Featured Image Dimension
function resort_motel_blog_post_featured_image_dimension(){
	if(get_theme_mod('resort_motel_blog_post_featured_image_dimension') == 'custom' ) {
		return true;
	}
	return false;
}

add_filter( 'woocommerce_enable_setup_wizard', '__return_false' );