<?php
/**
 * elinalite functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package elina-lite-portfolio-gallery
 */

if ( ! defined( 'ELINALITE_VERSION' ) ) {
	// Replace the version number of the theme on each release.
	define( 'ELINALITE_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 elinalite_setup() {
	/*
		* Make theme available for translation.
		* Translations can be filed in the /languages/ directory.
		* If you're building a theme based on elinalite, use a find and replace
		* to change 'elinalite' to the name of your theme in all the template files.
		*/
	load_theme_textdomain( 'elinalite', 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' );

	// Starter Support to help users when preview theme find menu and etc
	add_theme_support( 'starter-content' );


	/*
		* 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(
			'menu-1' => esc_html__( 'Primary', 'elina-lite-portfolio-gallery' ),
		)
	);


// Change the class of the submenu (child menu)
function elinalite_nav_submenu_class($classes, $args, $depth) {
    // Change only at the first level of sub-menu depth
    if ($depth === 0) {
        $classes = ['dropdown-menu']; // Change the class to 'dropdown-menu'
    }
    return $classes;
}

// Apply the filter to change sub-menu class
add_filter('nav_menu_submenu_css_class', 'elinalite_nav_submenu_class', 10, 3);


// Child Menu 
// This function modifies the start of each menu item
function custom_menu_item_markup($item_output, $item, $depth, $args) {
    // If the menu item has child items (is a parent)
    if (in_array('menu-item-has-children', (array) $item->classes)) {
        // Add a custom anchor tag with dropdown attributes
        $dropdown_indicator = '<a href="#" data-toggle="dropdown" class="dropdown-toggle" aria-haspopup="true">';
        $dropdown_indicator .= $item->title; // Add the item title
        $dropdown_indicator .= ' <span class="caret"></span>'; // Add the caret
        $dropdown_indicator .= '</a>'; // Close the custom anchor tag

        // Return the modified output
        return $dropdown_indicator;
    }

    // If the item does not have children, return the original output
    return $item_output;
}

// Apply this filter to customize the menu items' start element
add_filter('walker_nav_menu_start_el', 'custom_menu_item_markup', 10, 4);

// Modify the CSS classes for menu items
function custom_menu_item_classes($classes, $item, $args, $depth) {
    // If the menu item has children (is a dropdown parent)
    if (in_array('menu-item-has-children', $classes)) {
        $classes[] = 'dropdown'; // Add the 'dropdown' class
    }
    
    return $classes; // Return the modified classes array
}

// Apply this filter to add custom CSS classes to menu items
add_filter('nav_menu_css_class', 'custom_menu_item_classes', 10, 4);

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

	// Set up the WordPress core custom background feature.
/*	add_theme_support(
		'custom-background',
		apply_filters(
			'elinalite_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_action( 'after_setup_theme', 'elinalite_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 elinalite_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'elinalite_content_width', 640 );
}
add_action( 'after_setup_theme', 'elinalite_content_width', 0 );
/**
 * @since 1.0.0
 * Add WooCommerce product support to theme
 */

function elinalite_woocommerce_support() {
    // Add WooCommerce support
    add_theme_support( 'woocommerce' );
    // Add support for WooCommerce gallery features
    add_theme_support( 'wc-product-gallery-zoom' );
    add_theme_support( 'wc-product-gallery-lightbox' );
    add_theme_support( 'wc-product-gallery-slider' );
}
add_action( 'after_setup_theme', 'elinalite_woocommerce_support' ); 


/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function elinalite_widgets_init() {
	register_sidebar(
		array(
			'name'          => esc_html__( 'Sidebar', 'elina-lite-portfolio-gallery' ),
			'id'            => 'sidebar-1',
			'description'   => esc_html__( 'Add widgets here.', 'elina-lite-portfolio-gallery' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);
}
add_action( 'widgets_init', 'elinalite_widgets_init' );

/**
 * Enqueue scripts and styles.
 */
function elinalite_scripts() {
    // Enqueue styles
    wp_enqueue_style('elinalite-style', get_stylesheet_uri(), array(), ELINALITE_VERSION);
    wp_enqueue_style('elinalite-fontawesome', get_template_directory_uri() . '/css/fontawesome.min.css', array(), '5.15.1', 'all');
    wp_enqueue_style('elinalite-brands', get_template_directory_uri() . '/css/brands.min.css', array(), '5.15.1', 'all');
    wp_enqueue_style('elinalite-solid', get_template_directory_uri() . '/css/solid.min.css', array(), '5.15.1', 'all');
    wp_enqueue_style('elinalite-lineicons', get_template_directory_uri() . '/css/LineIcons.css', array(), '1.0', 'all');
    wp_enqueue_style('elinalite-bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), '4.5.3', 'all');
    wp_enqueue_style('elinalite-default-style', get_template_directory_uri() . '/css/style.css', array(), '4.5.3', 'all');
    wp_enqueue_style('elinalite-flexslider', get_template_directory_uri() . '/css/flexslider.css', array(), '2.7.2', 'all');
	wp_enqueue_style('elinalite-magnific-popup', get_template_directory_uri() . '/css/magnific-popup.css', array(), '1.2.0', 'all');
    wp_enqueue_style('elinalite-animate', get_template_directory_uri() . '/css/animate.min.css', array(), '3.5.1', 'all');
    wp_enqueue_style('elinalite-owlcarousel', get_template_directory_uri() . '/css/owl.carousel.min.css', array(), '2.3.4', 'all');
    wp_enqueue_style('elinalite-wow', get_template_directory_uri() . '/css/wow.css', array(), '5.2.0', 'all');
    wp_style_add_data('elinalite-style', 'rtl', 'replace');

    // Enqueue Google Fonts
    wp_enqueue_style('elinalite-playfair-display', 'https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400..900;1,400..900&display=swap');
    wp_enqueue_style('elinalite-roboto', 'https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
    wp_enqueue_style('elinalite-titillium-web', 'https://fonts.googleapis.com/css2?family=Titillium+Web:wght@400;600;700&display=swap');
    wp_enqueue_style('elinalite-open-sans', 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&display=swap');
    wp_enqueue_style('elinalite-montserrat', 'https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;700&display=swap');
	
    // Enqueue scripts with jQuery dependency
    wp_enqueue_script('jquery');
    wp_enqueue_script('elinalite-navigation', get_template_directory_uri() . '/js/navigation.js', array('jquery'), ELINALITE_VERSION, true);
    wp_enqueue_script('elinalite-owlcarousel', get_template_directory_uri() . '/js/owl.carousel.min.js', array('jquery'), '2.3.4', true);
    wp_enqueue_script('elinalite-flexslider', get_template_directory_uri() . '/js/jquery.flexslider.js', array('jquery'), '2.1', true);
	wp_enqueue_script('elinalite-magnific-popup', get_template_directory_uri() . '/js/jquery.magnific-popup.min.js', array('jquery'), '1.2.0', true);
    wp_enqueue_script('elinalite-isotope', get_template_directory_uri() . '/js/isotope.pkgd.min.js', array('jquery'), '3.0.6', true);
    wp_enqueue_script('elinalite-appear', get_template_directory_uri() . '/js/jquery.appear.js', array('jquery'), ELINALITE_VERSION, true);
    wp_enqueue_script('elinalite-countTo', get_template_directory_uri() . '/js/jquery.countTo.js', array('jquery'), ELINALITE_VERSION, true);
    wp_enqueue_script('elinalite-waypoints', get_template_directory_uri() . '/js/jquery.waypoints.min.js', array('jquery'), '4.0.1', true);
    wp_enqueue_script('elinalite-bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '4.5.3', true);
    wp_enqueue_script('elinalite-stellar', get_template_directory_uri() . '/js/jquery.stellar.js', array('jquery'), '0.6.2', true);
    wp_enqueue_script('elinalite-wow', get_template_directory_uri() . '/js/wow.min.js', array('jquery'), '1.1.3', true);
    wp_enqueue_script('elinalite-scripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'), ELINALITE_VERSION, true);
    wp_enqueue_script('elinalite-fitvids', get_template_directory_uri() . '/js/jquery.fitvids.js', array('jquery'), '1.1', true);

    // Enqueue comment reply script on singular pages with comments open
    if (is_singular() && comments_open() && get_option('thread_comments')) {
        wp_enqueue_script('comment-reply');
    }
}
add_action('wp_enqueue_scripts', 'elinalite_scripts');
/**
 * Manu Walker
 */

require get_template_directory() . '/inc/Custom_Walker_Nav_Menu.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';

/**
 * Customizer additions.
 */
//require get_template_directory() . '/inc/multiplecheckbox.php';
/**
 * Customizer additions.
 */

 /**
 * Customizer additions.
 */
require get_template_directory() . '/inc/custom-controls/custom-control.php';
//require get_template_directory() . '/inc/custom-controls/note/class-note-control.php';
//require get_template_directory() . '/inc/custom-controls/radioimg/class-radio-image-control.php';

/**
 * Customizer additions.
 */
//require_once get_template_directory() . '/inc/spintech-customizer.php';
require get_template_directory() . '/inc/customizer.php';

/**
 * Custom functions that act independently of the theme templates.
 */
require get_template_directory() . '/inc/extras.php';


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

require get_template_directory() . '/inc/jetpack.php';

/**
 * Go To Pro
 */

 
 function elinalite_admin_notice() {
    ?>
    <div class="notice notice-info is-dismissible">
        <p>
            <a href="https://pixelonetry.com/downloads/elina-creative-one-page-wordpress-theme/" target="_blank">
                <input type="button" value="Upgrade to Pro, unlock many features" class="button button-primary button-large req_btn">
            </a>
        </p>
    </div>
    <?php
}

add_action('admin_notices', 'elinalite_admin_notice');

/**
 * Starter Function
 */

if ( ! function_exists( 'elinalite_starter_content' ) ) {
	/**
	 * Starter content for preview without widgets
	 *
	 * @param $starter
	 *
	 * @return mixed
	 */
	function elinalite_starter_content( $starter ) {
		// Pages setup
		$starter['posts'] = array(
			'front'   => array(
				'post_type'    => 'page',
				'post_title'   => esc_html__( 'Home', 'elina-lite-portfolio-gallery' ),
				'thumbnail'    => '{{image-cup}}',
			),
			'about'   => array(
				'post_type'  => 'page',
				'post_title' => esc_html__( 'About', 'elina-lite-portfolio-gallery' ),
				'thumbnail'  => '{{image-cup}}',
			),
			'contact' => array(
				'post_type'  => 'page',
				'post_title' => esc_html__( 'Contact', 'elina-lite-portfolio-gallery' ),
				'thumbnail'  => '{{image-cup}}',
			),
			'blog'    => array(
				'post_type'  => 'page',
				'post_title' => esc_html__( 'Blog', 'elina-lite-portfolio-gallery' ),
				'thumbnail'  => '{{image-cup}}',
			),
		);

		// Options setup
		$starter['options'] = array(
			'show_on_front'  => 'page',
			'page_on_front'  => '{{front}}',
			'page_for_posts' => '{{blog}}',
		);

		// Navigation Menu setup
		$starter['nav_menus'] = array(
			'menu-1' => array( // 'primary' should match the menu location registered in your theme
				'name'  => esc_html__( 'Primary Menu', 'elina-lite-portfolio-gallery' ),
				'items' => array(
					'link_home',   // Home link
					'page_about',  // About page link
					'page_contact',// Contact page link
					'page_blog',   // Blog page link
				),
			),
		);

		return $starter;
	}
}
add_filter( 'elinalite_filter_starter_content', 'elinalite_starter_content' );

