<?php 
if ( ! function_exists( 'wheelify_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 wheelify_setup() {
		/*
	     * Make theme available for translation.
	     * Translations can be filed in the /languages/ directory.
	     * If you're building a theme based on Theme Palace, use a find and replace
	     * to change 'enigma' to the name of your theme in all the template files.
	     */
	    load_theme_textdomain( 'wheelify' );

		// 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' );
		add_theme_support( 'wc-product-gallery-zoom' );
	    add_theme_support( 'wc-product-gallery-lightbox' );
	    add_theme_support( 'wc-product-gallery-slider' );	

		/*
		 * 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', 'wheelify' ),
				'footer' => esc_html__( 'Footer-Menu', 'wheelify' ),
			)
		);

		/*
		 * Switch default core markup for search form, comment form, and comments
		 * to output valid HTML5.
		 */
		$args = array(
				'search-form',
				'comment-form',
				'comment-list',
				'gallery',
				'caption',
				'style',
				'script',
			);

		add_theme_support( 'html5', $args );

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

		add_theme_support( 'wp-block-styles' );
		add_theme_support( 'align-wide' ); 
		add_theme_support('responsive-embeds');

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

	    /* Add editor style. */
	    add_theme_support('editor-styles');
	    add_theme_support('dark-editor-style');

	     /*
	     * This theme styles the visual editor to resemble the theme style,
	     * specifically font, colors, icons, and column width.
	    */
	    add_editor_style('/assets/css/editor-style.css');

		/* Allow shortcodes in widgets. */
		add_filter( 'widget_text', 'do_shortcode' );
		 
		// add excerpt support for pages
		add_post_type_support( 'page', 'excerpt' );

		/**
		 * Add support for core custom logo.
		 *
		 * @link https://codex.wordpress.org/Theme_Logo
		*/
		$args = array(
				'height'      => 250,
				'width'       => 250,
				'flex-width'  => true,
				'flex-height' => true,
			);
		add_theme_support( 'custom-logo', $args);
	}
endif;
add_action( 'after_setup_theme', 'wheelify_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 wheelify_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'wheelify_content_width', 640 );
}
add_action( 'after_setup_theme', 'wheelify_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function wheelify_widgets_init() {
	register_sidebar(
		array(
			'name'          => esc_html__( 'Sidebar', 'wheelify' ),
			'id'            => 'sidebar-1',
			'description'   => esc_html__( 'Add widgets here.', 'wheelify' ),
			'before_widget' => '<div id="%1$s" class="blog-sidebar-widgets animate fadeInRight %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h4 class="widgets-title">',
			'after_title'   => '</h4>',
		)
	);

	// Footer Sidebar
	register_sidebar(array(
		'name' => esc_html__( 'Footer Widget Area 1', 'wheelify'),
		'id' => 'footer-widget-area-1',
		'description' => esc_html__( 'The footer widget area 1', 'wheelify'),
		'before_widget' => '<div id="%1$s" class="widgets-col %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="title">',
		'after_title' => '</h3>',
	));	
	
	register_sidebar(array(
		'name' => esc_html__( 'Footer Widget Area 2', 'wheelify'),
		'id' => 'footer-widget-area-2',
		'description' => esc_html__( 'The footer widget area 2', 'wheelify'),
		'before_widget' => '<div id="%1$s" class="widgets-col %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="title">',
		'after_title' => '</h3>',
	));	
	
	register_sidebar(array(
		'name' => esc_html__( 'Footer Widget Area 3', 'wheelify'),
		'id' => 'footer-widget-area-3',
		'description' => esc_html__( 'The footer widget area 3', 'wheelify'),
		'before_widget' => '<div id="%1$s" class="widgets-col %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="title">',
		'after_title' => '</h3>',
	));	
	
	register_sidebar(array(
		'name' => esc_html__( 'Footer Widget Area 4', 'wheelify'),
		'id' => 'footer-widget-area-4',
		'description' => esc_html__( 'The footer widget area 4', 'wheelify'),
		'before_widget' => '<div id="%1$s" class="widgets-col %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="title">',
		'after_title' => '</h3>',
	));	
}
add_action( 'widgets_init', 'wheelify_widgets_init' );

/**
 * Enqueue scripts and styles.
*/
function wheelify_scripts() {
	wp_enqueue_style( 'wheelify-style', get_stylesheet_uri() );
	wp_enqueue_style('styles', get_template_directory_uri()   . '/assets/css/styles.css');
	wp_enqueue_style('bootstrap', get_template_directory_uri()   . '/assets/css/bootstrap-v4.1.3.min.css');
	wp_enqueue_style('animations', get_template_directory_uri()  . '/assets/css/animations.min.css');
	wp_enqueue_style('fontawesome6.4.0', get_template_directory_uri(). '/assets/fontawesome6.6.0/css/all.css');
	wp_enqueue_style('slicknav',   get_template_directory_uri() . '/assets/css/slicknav.css' );
	wp_enqueue_style('wheelify-style-1', get_template_directory_uri() . '/assets/css/custom-style.css');
	wp_enqueue_style('wheelify-woocommerce', get_template_directory_uri() . '/assets/css/woocommerce.css');
	wp_enqueue_style('wheelify-reponsive', get_template_directory_uri()   . '/assets/css/reponsive.css');
	
	/* Web Fonts */		
    wp_enqueue_style('wheelify-google-fonts',esc_url(wheelify_fonts_url()));

    wp_register_script('jquery331',get_template_directory_uri() .'/assets/js/jquery-v3.3.1.min.js', false, '3.3.1');
    wp_enqueue_script('jquery');
	wp_enqueue_script( 'wheelify-navigation', get_template_directory_uri() . '/assets/js/navigation.js', array(), '', true );
	wp_enqueue_script('bootstrap', get_template_directory_uri()  . '/assets/js/bootstrap-v4.1.3.js', array( 'jquery' ), true, true);
	wp_enqueue_script('animations', get_template_directory_uri() . '/assets/js/animations.js', array( 'jquery' ), true, true);
	wp_enqueue_script('owl.carousel.min', get_template_directory_uri() . '/assets/js/owl.carousel.min.js', array( 'jquery' ), true, true);
	wp_enqueue_script('swiper.min', get_template_directory_uri() . '/assets/js/swiper.min.js', array( 'jquery' ), true, true);
	wp_enqueue_script( 'jquery-slicknav',  get_template_directory_uri() . '/assets/js/jquery.slicknav.js', array( 'jquery' ), true, true); 
    wp_enqueue_script( 'slick', 	       get_template_directory_uri() . '/assets/js/slick.js', array( 'jquery' ), true, true);
	wp_enqueue_script('wheelify-custom-script', get_template_directory_uri() . '/assets/js/custom-script.js', array( 'jquery' ), true, true);
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'wheelify_scripts' );

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

        if ( 'off' !== _x( 'on', 'Bree Serif font: on or off', 'wheelify' ) )
        {
            $fonts[] = 'Bree+Serif';
        }
        if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'wheelify' ) )
        {
            $fonts[] = 'Open+Sans';
        }
        if ( 'off' !== _x( 'on', 'Open Sans Condensed font: on or off', 'wheelify' ) )
        {
            $fonts[] = 'Open+Sans+Condensed:300';
        }
        if ( 'off' !== _x( 'on', 'Raleway font: on or off', 'wheelify' ) )
        {
            $fonts[] = 'Raleway:700';
        }
        

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