<?php

/**
 * Wedding Planning Services functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Wedding Planning Services
 */

define( 'WEDDING_PLANNING_SERVICES_URL', trailingslashit( get_template_directory_uri() ) );

if ( ! function_exists( 'wedding_planning_services_setup' ) ) {

	load_theme_textdomain( 'wedding-planning-services', get_template_directory() . '/languages' );

	/**
	 * 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.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	function wedding_planning_services_setup() {

		// Add theme support
		add_theme_support( 'automatic-feed-links' );
		add_theme_support( 'wp-block-styles' );
		add_theme_support( 'title-tag' );
		add_theme_support( 'post-thumbnails' );
		add_theme_support( 'editor-styles' );
		add_theme_support( 'html5', array( 'comment-form', 'comment-list' ) );
		add_theme_support( 'responsive-embeds' );
		add_theme_support( 'customize-selective-refresh-widgets' );

		require get_template_directory() .'/inc/core/main.php';
	}
}
add_action( 'after_setup_theme', 'wedding_planning_services_setup' );

/**
 * Enqueue scripts and styles
 */
function wedding_planning_services_scripts() {
	$version = wp_get_theme( 'wedding-planning-services' )->get( 'Version' );
	// Stylesheet
	wp_enqueue_style( 'wedding-planning-services-styles', get_theme_file_uri( '/style.css' ), array(), $version );
	wp_enqueue_style( 'animate', get_template_directory_uri() . '/assets/css/animate.css', array(), $version, 'all' );

	if ( file_exists( get_template_directory() . '/assets/css/theme-style.css' ) ) {
		wp_enqueue_style( 'wedding-planning-services-theme-style', get_template_directory_uri() . '/assets/css/theme-style.css',  array(), $version );
	}

	$deps = array( 'wedding-planning-services-animate' );
	global $wp_styles;
	if ( in_array( 'wc-blocks-vendors-style', $wp_styles->queue ) ) {
		$deps[] = 'wc-blocks-vendors-style';
	}

	if ( is_rtl() ) {
    	wp_enqueue_style( 'style-rtl-css', get_template_directory_uri() . '/assets/css/style-rtl.css', array( 'wedding-planning-services-styles' ), $version );
	}

	wp_enqueue_style( 'fontawesome-style', esc_url(get_template_directory_uri()).'/assets/fontawesome/css/all.css' );

	// Scripts
	$deps = array( 'jquery' );
	wp_enqueue_script( 'animate', get_template_directory_uri() . '/assets/js/wow.js', $deps, $version );

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

/**
 * Add editor styles
 */
function wedding_planning_services_editor_style() {
    wp_enqueue_style( 'wedding-planning-services-editor-style', get_template_directory_uri() . '/assets/css/editor-style.css' );
}
add_action( 'enqueue_block_assets', 'wedding_planning_services_editor_style' );

/**
 * Enqueue assets scripts for both backend and frontend
 */
function wedding_planning_services_block_assets()
{
    wp_enqueue_style( 'wedding-planning-services-blocks-style', get_template_directory_uri() . '/assets/css/blocks.css' );
}
add_action( 'enqueue_block_assets', 'wedding_planning_services_block_assets' );

function wedding_planning_services_enqueue_admin_script($hook) {
    // Enqueue admin JS for notices
    wp_enqueue_script('wedding-planning-services-welcome-notice', get_template_directory_uri() . '/inc/core/wedding-planning-services-welcome-notice.js', array('jquery'), '', true);
    
    // Localize script to pass data to JavaScript
    wp_localize_script('wedding-planning-services-welcome-notice', 'wedding_planning_services_localize', array(
        'ajax_url' => admin_url('admin-ajax.php'),
        'nonce' => wp_create_nonce('wedding_planning_services_welcome_nonce'),
        'dismiss_nonce' => wp_create_nonce('wedding_planning_services_welcome_nonce'), // Nonce for dismissal
        'redirect_url' => admin_url('themes.php?page=wedding-planning-services-guide-page')
    ));
}
add_action('admin_enqueue_scripts', 'wedding_planning_services_enqueue_admin_script');


/**
 * Load core file
 */
require get_theme_file_path( '/inc/core/init.php' );

/**
 * Getstart
 */

require get_template_directory() .'/inc/core/customizer-notice/wedding-planning-services-customizer-notify.php';

load_template( trailingslashit( get_template_directory() ) . '/inc/core/class-upgrade-pro.php' );