<?php

/**
 * Dark Fitness functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package dark_fitness
 */

$dark_fitness_theme_data = wp_get_theme();
if( ! defined( 'DARK_FITNESS_THEME_VERSION' ) ) define ( 'DARK_FITNESS_THEME_VERSION', $dark_fitness_theme_data->get( 'Version' ) );
if( ! defined( 'DARK_FITNESS_THEME_NAME' ) ) define( 'DARK_FITNESS_THEME_NAME', $dark_fitness_theme_data->get( 'Name' ) );
if( ! defined( 'DARK_FITNESS_THEME_TEXTDOMAIN' ) ) define( 'DARK_FITNESS_THEME_TEXTDOMAIN', 
	$dark_fitness_theme_data->get( 'TextDomain' ) );

if ( ! defined( 'DARK_FITNESS_VERSION' ) ) {
	// Replace the version number of the theme on each release.
	define( 'DARK_FITNESS_VERSION', '1.0.0' );
}

if ( ! function_exists( 'dark_fitness_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 dark_fitness_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on Dark Fitness, use a find and replace
		 * to change 'dark-fitness' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'dark-fitness', get_template_directory() . '/languages' );

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

		/*
		 * 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' );

		add_theme_support( 'woocommerce' );

		/*
		 * 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' );

		// This theme uses wp_nav_menu() in one location.
		register_nav_menus(
			array(
				'primary' => esc_html__( 'Primary', 'dark-fitness' ),
				'social'  => esc_html__( 'Social', 'dark-fitness' ),
			)
		);

		/*
		 * Switch default core markup for search form, comment form, and comments
		 * to output valid HTML5.
		 */
		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', 
		) );
		

		// Set up the WordPress core custom background feature.
		add_theme_support(
			'custom-background',
			apply_filters(
				'dark_fitness_custom_background_args',
				array(
					'default-color' => 'ffffff',
					'default-image' => '',
				)
			)
		);

		// 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 theme support for gutenberg block.
		 */
		add_theme_support( 'align-wide' );
		
		add_theme_support( 'responsive-embeds' );

		/*  Demo Import */
		require get_parent_theme_file_path( '/theme-wizard/config.php' );

		/**
		 * Customizer additions.
		 */
		require get_template_directory() . '/inc/customizer.php';
	}
endif;
add_action( 'after_setup_theme', 'dark_fitness_setup' );

/**
 * 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 dark_fitness_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'dark_fitness_content_width', 640 );
}
add_action( 'after_setup_theme', 'dark_fitness_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function dark_fitness_widgets_init() {
	register_sidebar(
		array(
			'name'          => esc_html__( 'Sidebar', 'dark-fitness' ),
			'id'            => 'sidebar-1',
			'description'   => esc_html__( 'Add widgets here.', 'dark-fitness' ),
			'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.
	$dark_fitness_footer_widget_column = get_theme_mod('dark_fitness_footer_widget_column','4');
	for ($i=1; $i<=$dark_fitness_footer_widget_column; $i++) {
		register_sidebar( array(
			'name' => __( 'Footer', 'dark-fitness' )  . $i,
			'id' => 'dark-fitness-footer-widget-' . $i,
			'description' => __( 'The Footer Widget Area', 'dark-fitness' )  . $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', 'dark_fitness_widgets_init' );

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

	// Slick style.
	wp_enqueue_style( 'dark-fitness-slick-style', get_template_directory_uri() . '/assets/css/slick' . $min . '.css', array(), '1.8.1' );

	// Fontawesome style.
	wp_enqueue_style( 'dark-fitness-fontawesome-style', get_template_directory_uri() . '/assets/css/fontawesome' . $min . '.css', array(), '5.15.4' );

	// Google fonts.
	wp_enqueue_style( 'dark-fitness-google-fonts', wptt_get_webfont_url( dark_fitness_get_fonts_url() ), array(), null );

	// Main style.
	wp_enqueue_style( 'dark-fitness-style', get_template_directory_uri() . '/style.css', array(), DARK_FITNESS_VERSION );

	// RTL style.
	wp_style_add_data('dark-fitness-style', 'rtl', 'replace');

	if (get_theme_mod('dark_fitness_enable_animation', true) == true){
		// Animate CSS
		wp_enqueue_style( 'animate-style', get_template_directory_uri() . '/assets/css/animate.css' );
		// Wow script.
		wp_enqueue_script( 'wow-jquery', get_template_directory_uri() . '/assets/js/wow.js', array('jquery'),'' ,true );
	}
	
	// Navigation script.
	wp_enqueue_script( 'dark-fitness-navigation-script', get_template_directory_uri() . '/assets/js/navigation' . $min . '.js', array(), DARK_FITNESS_VERSION, true );

	// Slick script.
	wp_enqueue_script( 'dark-fitness-slick-script', get_template_directory_uri() . '/assets/js/slick' . $min . '.js', array( 'jquery' ), '1.8.1', true );

	// Custom script.
	wp_enqueue_script( 'dark-fitness-custom-script', get_template_directory_uri() . '/assets/js/custom' . $min . '.js', array( 'jquery' ), DARK_FITNESS_VERSION, true );

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

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

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

/**
 * Include wptt webfont loader.
 */
require_once get_theme_file_path( 'inc/wptt-webfont-loader.php' );

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

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

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

/**
 * Google Fonts
 */
require get_template_directory() . '/inc/google-fonts.php';

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

/**
 * Breadcrumb
 */
require get_template_directory() . '/inc/class-breadcrumb-trail.php';

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

/**
 * Customizer Settings Functions
*/
require get_template_directory() . '/inc/customizer-settings-functions.php';

function dark_fitness_links_setup() {
	if ( ! defined( 'DARK_FITNESS_PREMIUM_PAGE' ) ) {
	define('DARK_FITNESS_PREMIUM_PAGE',__('https://asterthemes.com/products/fitness-wordpress-theme','dark-fitness'));
	}
	if ( ! defined( 'DARK_FITNESS_THEME_PAGE' ) ) {
		define('DARK_FITNESS_THEME_PAGE',__('https://asterthemes.com/products/dark-fitness','dark-fitness'));
	}
	if ( ! defined( 'DARK_FITNESS_SUPPORT' ) ) {
	define('DARK_FITNESS_SUPPORT',__('https://wordpress.org/support/theme/dark-fitness/','dark-fitness'));
	}
	if ( ! defined( 'DARK_FITNESS_REVIEW' ) ) {
	define('DARK_FITNESS_REVIEW',__('https://wordpress.org/support/theme/dark-fitness/reviews/','dark-fitness'));
	}
	if ( ! defined( 'DARK_FITNESS_PRO_DEMO' ) ) {
	define('DARK_FITNESS_PRO_DEMO',__('https://demo.asterthemes.com/fitness-wordpress-theme/','dark-fitness'));
	}
	if ( ! defined( 'DARK_FITNESS_THEME_DOCUMENTATION' ) ) {
	define('DARK_FITNESS_THEME_DOCUMENTATION',__('https://demo.asterthemes.com/docs/dark-fitness-free/','dark-fitness'));
	}
	if ( ! defined( 'DARK_FITNESS_PREMIUM_DOCUMENTATION' ) ) {
	define('DARK_FITNESS_PREMIUM_DOCUMENTATION',__('https://demo.asterthemes.com/docs/dark-fitness-pro/','dark-fitness'));
	}
	if ( ! defined( 'DARK_FITNESS_BUNDLE_PAGE' ) ) {
		define('DARK_FITNESS_BUNDLE_PAGE',__('https://asterthemes.com/products/wp-theme-bundle','dark-fitness'));
	}
}
add_action('after_setup_theme', 'dark_fitness_links_setup');

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

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

add_filter( 'woocommerce_enable_setup_wizard', '__return_false' );