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

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

/**
 * 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 storez_setup() {
	/*
		* Make theme available for translation.
		* Translations can be filed in the /languages/ directory.
		* If you're building a theme based on StoreZ, use a find and replace
		* to change 'storez' to the name of your theme in all the template files.
		*/
	load_theme_textdomain( 'storez', 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' );

	/*
		* 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', 'storez' ),
		'top_nav' => esc_html__( 'Top bar Navigation', 'storez' ),
		'product_catalog' => esc_html__( 'Product Catalog', 'storez' ),
	) );

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

	// Set up the WordPress core custom background feature.
	add_theme_support( 'custom-background', apply_filters( 'storez_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_image_size( 'storez_woocommerce_single_thumb', '600', '600', true );
}
add_action( 'after_setup_theme', 'storez_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 storez_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'storez_content_width', 1170 );
}
add_action( 'after_setup_theme', 'storez_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function storez_widgets_init() {
	
	register_sidebar(array(
        'name'          => esc_html__('Sidebar', 'storez'),
        'id'            => 'sidebar',
        'class'         => 'sidebar',
        'description'   => esc_html__('Sidebar Widget Area', 'storez'),
        'before_widget' => '<div id="%1$s" class="sidebar-widget widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<div class="widget-heading"><h3 class="widget-title">',
        'after_title'   => '</h3></div>',
    ));
    
    register_sidebar(array(
        'name'          => esc_html__('WooCommerce Sidebar', 'storez'),
        'id'            => 'woocommerce-sidebar',
        'class'         => 'woocommerce-sidebar',
        'description'   => esc_html__( 'WooCommerce Widget Area', 'storez' ),
        'before_widget' => '<div id="%1$s" class="woocommerce-widget sidebar-widget widget open %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<div class="widget-heading"><h3 class="widget-title">',
        'after_title'   => '</h3><div class="wc-sidebar-toggle"><i class="fa fa-wc-toggle"></i></div></div>',
    ));

    register_sidebar(array(
        'name'          => esc_html__('Product Sidebar', 'storez'),
        'id'            => 'woocommerce-product-sidebar',
        'class'         => 'woocommerce-product-sidebar',
        'description'   => esc_html__( 'Product Widget Area', 'storez' ),
        'before_widget' => '<div id="%1$s" class="woocommerce-product-sidebar sidebar-widget widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<div class="widget-heading"><h3 class="widget-title">',
        'after_title'   => '</h3></div>',
    ));
    
    register_sidebar(array(
        'name'          => esc_html__('FrontPage Products Widget Area', 'storez'),
        'id'            => 'front-page-products-widget-area',
        'class'         => 'front-page-products-widget-area',
        'description'   => esc_html__( 'FrontPage Products Widget Area Column', 'storez' ),
        'before_widget' => '<div id="%1$s" class="front-page-widget front-page-product-widget widget %2$s"><div class="container"><div class="front-page-widget-inner">',
        'after_widget'  => '<div class="clear"></div></div></div></div>',
        'before_title'  => '<div class="section-heading"><h2 class="section-title">',
        'after_title'   => '</h2></div>',
    ));
    
    register_sidebar(array(
        'name'          => esc_html__('FrontPage Product Widget Area Column ', 'storez'),
        'id'            => 'front-page-widget-area-column',
        'class'         => 'front-page-widget-area-column',
        'description'   => esc_html__( 'FrontPage Widget Area Column', 'storez' ),
        'before_widget' => '<div id="%1$s" class="col-md-3 col-sm-6 front-page-widget-area-column widget %2$s"><div class="widget-inner">',
        'after_widget'  => '</div></div>',
        'before_title'  => '<div class="section-heading"><h3 class="section-title">',
        'after_title'   => '</h3></div>',
	));
    

    for ($i=1; $i <= 4; $i++){
	    register_sidebar(array(
	        'name'          => sprintf(esc_html__('Footer Widget Area Column %s', 'storez'), $i),
	        'id'            => 'footer-widget-area-col-'.$i,
	        'class'         => 'footer-widget-area-col-'.$i,
	        'description'   => sprintf(esc_html__('Footer Widget Area Column %s', 'storez'), $i),
	        'before_widget' => '<div id="%1$s" class="footer-widget widget %2$s"><div class="widget-inner">',
	        'after_widget'  => '</div></div>',
	        'before_title'  => '<div class="widget-heading"><h3 class="widget-title">',
	        'after_title'   => '</h3></div>',
	    ));
	}
}
add_action( 'widgets_init', 'storez_widgets_init' );

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

	wp_enqueue_style( 'bootstrap', get_template_directory_uri() . "/css/bootstrap.min.css", array(), _STOREZ_VERSION );
	wp_enqueue_style( 'owl-carousel', get_template_directory_uri() . "/css/owl.carousel.min.css", array(), _STOREZ_VERSION );
	wp_enqueue_style( 'owl-carousel-theme', get_template_directory_uri() . "/css/owl.theme.default.min.css", array(), _STOREZ_VERSION );
	wp_enqueue_style( 'simpleLightbox', get_template_directory_uri() . "/css/simpleLightbox.min.css", array(), _STOREZ_VERSION );
	wp_enqueue_style( 'font-awesome', get_template_directory_uri() . "/css/font-awesome.min.css", array(), _STOREZ_VERSION );
	wp_enqueue_style( 'animate', get_template_directory_uri() . "/css/animate.min.css", array(), _STOREZ_VERSION );
	wp_enqueue_style( 'storez-nav-style', get_template_directory_uri() . "/css/main-nav.min.css", array(), _STOREZ_VERSION );
	wp_style_add_data( 'storez-nav-style', 'rtl', 'replace' );

	wp_enqueue_style( 'storez-style', get_template_directory_uri() . "/css/style.min.css", array(), _STOREZ_VERSION );
	wp_style_add_data( 'storez-style', 'rtl', 'replace' );


	wp_enqueue_script( 'bootstrap-bundle', get_template_directory_uri() . '/js/bootstrap.bundle.min.js', array(), _STOREZ_VERSION, true );
	wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . '/js/owl.carousel.min.js', array(), _STOREZ_VERSION, true );
	wp_enqueue_script( 'simplelightbox', get_template_directory_uri() . '/js/simpleLightbox.min.js', array(), _STOREZ_VERSION, true );
	wp_enqueue_script( 'storez-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _STOREZ_VERSION, true );
	wp_enqueue_script( 'storez-custom-script', get_template_directory_uri() . '/js/custom-script.js', array('jquery'), _STOREZ_VERSION, true );
	wp_localize_script( 'storez-custom-script', 'storez_script_obj', array(
    	'rtl' => is_rtl(),
    	'sticky_header' => get_theme_mod( 'storez_sticky_header_enable', true ),
    ));


	

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

	wp_enqueue_script('respond', get_template_directory_uri() . '/js/respond.min.js');
    wp_script_add_data('respond', 'conditional', 'lt IE 9');

    wp_enqueue_script('html5shiv', get_template_directory_uri() . '/js/html5shiv.js');
    wp_script_add_data('html5shiv', 'conditional', 'lt IE 9');
}
add_action( 'wp_enqueue_scripts', 'storez_scripts' );

function storez_customize_controls_enqueue_scripts() {
	wp_enqueue_style('font-awesome', get_template_directory_uri() . "/css/font-awesome.min.css");
    wp_enqueue_style('storez-customizer-css', get_template_directory_uri() . '/css/customizer-control-style.css', array());
    wp_enqueue_script('storez-customizer-script', get_template_directory_uri() . '/js/customizer-script.js', array( 'jquery', 'customize-controls' ), false, true);
}
add_action('customize_controls_enqueue_scripts', 'storez_customize_controls_enqueue_scripts');


require get_template_directory() . '/inc/sanitize-cb.php';
require get_template_directory() . '/inc/custom-header.php';
require get_template_directory() . '/inc/template-tags.php';
require get_template_directory() . '/inc/template-functions.php';
require get_template_directory() . '/inc/customizer.php';
require get_template_directory() . '/inc/menu-walker.php';
require get_template_directory() . '/inc/themefarmer-functions.php';
require get_template_directory() . '/inc/class-tgm-plugin-activation.php';



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

/**
 * Load WooCommerce compatibility file.
 */
if ( class_exists( 'WooCommerce' ) ) {
	require get_template_directory() . '/inc/woocommerce.php';
}
