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

if ( ! defined( 'HAIR_DRESSER_AND_SALON_VERSION' ) ) {
	// Replace the version number of the theme on each release.
	define( 'HAIR_DRESSER_AND_SALON_VERSION', wp_get_theme()->get( 'Version' ) );
}

if ( ! function_exists( 'hair_dresser_and_salon_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 hair_dresser_and_salon_setup() {

		load_theme_textdomain( 'hair-dresser-and-salon', get_template_directory() . '/languages' );

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

		add_theme_support( 'align-wide' );

		add_theme_support( 'woocommerce' );

		// Add support for block styles.
		add_theme_support( 'wp-block-styles' );

		// Enqueue editor styles.
		add_editor_style( 'style.css' );

		// Add support for core custom logo.
		add_theme_support(
			'custom-logo',
			array(
				'height'      => 192,
				'width'       => 192,
				'flex-width'  => true,
				'flex-height' => true,
			)
		);

		// Experimental support for adding blocks inside nav menus
		add_theme_support( 'block-nav-menus' );

		// Add support for experimental link color control.
		add_theme_support( 'experimental-link-color' );

	}
endif;
add_action( 'after_setup_theme', 'hair_dresser_and_salon_setup' );

function hair_dresser_and_salon_scripts() {
    wp_enqueue_style('hair-dresser-and-salon-style', get_stylesheet_uri(), array() );
    wp_enqueue_script('jquery-wow', get_template_directory_uri() . '/js/wow.js', array('jquery'), HAIR_DRESSER_AND_SALON_VERSION );
    wp_enqueue_style('animate-css', get_template_directory_uri() . '/css/animate.css', array(), HAIR_DRESSER_AND_SALON_VERSION );

    //font-awesome
    wp_enqueue_style( 'fontawesome', get_template_directory_uri() . '/font-awesome/css/all.css', array(), '6.7.0' );

    wp_enqueue_style( 'owl.carousel-style', get_template_directory_uri().'/css/owl.carousel.css', array(), HAIR_DRESSER_AND_SALON_VERSION );
    
    wp_enqueue_script( 
        'owl-carousel',
        get_template_directory_uri() . '/js/owl.carousel.js', 
        array('jquery'), 
        HAIR_DRESSER_AND_SALON_VERSION,
        true 
    );

    // Custom scripts should depend on Owl Carousel and jQuery
    wp_enqueue_script(
        'hair-dresser-and-salon-custom-scripts', 
        get_template_directory_uri() . '/js/custom.js', 
        array('jquery', 'owl-carousel'), // Add owl-carousel dependency
        HAIR_DRESSER_AND_SALON_VERSION, // Consistent versioning
        true 
    );
    
    wp_style_add_data( 'hair-dresser-and-salon-style', 'rtl', 'replace' );
}
add_action( 'wp_enqueue_scripts', 'hair_dresser_and_salon_scripts' );

/**
 * Enqueue block editor style
 */
function hair_dresser_and_salon_block_editor_styles() {

	wp_enqueue_style( 'hair-dresser-and-salon-block-patterns-style-editor', get_theme_file_uri( '/css/block-editor.css' ), false, '1.0', 'all' );
}
add_action( 'enqueue_block_editor_assets', 'hair_dresser_and_salon_block_editor_styles' );


function hair_dresser_and_salon_init_setup() {

	require_once get_theme_file_path( '/inc/customizer.php' );

	// Add block patterns
	require get_template_directory() . '/inc/block-patterns.php';

	/**
     * Demo Import
     */
    require get_parent_theme_file_path( '/inc/get-started/demo-import-settings.php' );

    if ( ! defined( 'HAIR_DRESSER_AND_SALON_FREE_THEME_URL' ) ) {
        define( 'HAIR_DRESSER_AND_SALON_FREE_THEME_URL', 'https://www.seothemesexpert.com/products/hair-dresser-and-salon' );
    }
    if ( ! defined( 'HAIR_DRESSER_AND_SALON_PRO_THEME_URL' ) ) {
        define( 'HAIR_DRESSER_AND_SALON_PRO_THEME_URL', 'https://www.seothemesexpert.com/products/hair-salon-wordpress-theme' );
    }
    if ( ! defined( 'HAIR_DRESSER_AND_SALON_FREE_DOC_URL' ) ) {
        define( 'HAIR_DRESSER_AND_SALON_FREE_DOC_URL', 'https://demo.seothemesexpert.com/documentation/hair-dresser-and-salon-free/' );
    }
    if ( ! defined( 'HAIR_DRESSER_AND_SALON_DEMO_THEME_URL' ) ) {
        define( 'HAIR_DRESSER_AND_SALON_DEMO_THEME_URL', 'https://demo.seothemesexpert.com/hair-dresser-and-salon-pro/' );
    }
    if ( ! defined( 'HAIR_DRESSER_AND_SALON_RATE_THEME_URL' ) ) {
        define( 'HAIR_DRESSER_AND_SALON_RATE_THEME_URL', 'https://wordpress.org/support/theme/hair-dresser-and-salon/reviews/' );
    }
    if ( ! defined( 'HAIR_DRESSER_AND_SALON_SUPPORT_THEME_URL' ) ) {
        define( 'HAIR_DRESSER_AND_SALON_SUPPORT_THEME_URL', 'https://wordpress.org/support/theme/hair-dresser-and-salon/' );
    }
    if ( ! defined( 'HAIR_DRESSER_AND_SALON_THEME_BUNDLE_URL' ) ) {
        define( 'HAIR_DRESSER_AND_SALON_THEME_BUNDLE_URL', 'https://www.seothemesexpert.com/products/wordpress-theme-bundle' );
    }
}
add_action( 'after_setup_theme', 'hair_dresser_and_salon_init_setup' );


// Show Admin Notice
function hair_dresser_and_salon_promo_notice() {
    if (get_option('hair_dresser_and_salon_notice_dismissed')) {
        return;
    }

    if (isset($_GET['page']) && $_GET['page'] === 'hairdresserandsalon-wizard') {
        return;
    }

    $hair_dresser_and_salon_theme = wp_get_theme();
    $hair_dresser_and_salon_theme_title = $hair_dresser_and_salon_theme->get( 'Name' );
    $hair_dresser_and_salon_theme_version = $hair_dresser_and_salon_theme->get( 'Version' );

    ?>
    <div class="notice hair-dresser-and-salon-notice is-dismissible">
        <div>
            <h3>
                <span><?php echo esc_html( '(Version: ' . $hair_dresser_and_salon_theme_version . ')' ); ?></span><br>
                <?php esc_html_e( 'Thank you for choosing,', 'hair-dresser-and-salon'); ?>
                <?php echo esc_html( $hair_dresser_and_salon_theme_title ); ?> <?php esc_html_e( '!!!', 'hair-dresser-and-salon'); ?>
            </h3>
            <p><?php esc_html_e( 'Welcome! You can now easily start building your website using our beautiful and user-friendly themes. No need to worry about setup — with our one-click demo importer, your site can look just like the demo in minutes. All the tools and information you need to get started are right here!', 'hair-dresser-and-salon'); ?></p>
            <a class="button button-primary hair-dresser-and-salon-buy-now" href="<?php echo esc_url(admin_url('themes.php?page=hairdresserandsalon-wizard')); ?>" target="_blank">
                <?php esc_html_e( 'Get Started', 'hair-dresser-and-salon') ?>
            </a>
            <a class="button button-primary hair-dresser-and-salon-bundle-button" target="_blank" href="<?php echo esc_url( HAIR_DRESSER_AND_SALON_THEME_BUNDLE_URL ); ?>">
                <?php echo esc_html__( 'Get All 60+ Themes @ $79', 'hair-dresser-and-salon' ); ?>
            </a>
        </div>
        <div class="hair-dresser-and-salon-image-wrap">
            <img src="<?php echo esc_url(get_stylesheet_directory_uri() . '/screenshot.png'); ?>">
        </div>
        <canvas id="hair-dresser-and-salon-notice-confetti"></canvas>
    </div>
    <?php
}
add_action('admin_notices', 'hair_dresser_and_salon_promo_notice');

add_action('wp_ajax_hair_dresser_and_salon_dismiss_notice', 'hair_dresser_and_salon_dismiss_notice');
function hair_dresser_and_salon_dismiss_notice() {
    update_option('hair_dresser_and_salon_notice_dismissed', true);
    wp_send_json_success();
}

add_action('after_switch_theme', 'hair_dresser_and_salon_reset_notice_on_activation');
function hair_dresser_and_salon_reset_notice_on_activation() {
    delete_option('hair_dresser_and_salon_notice_dismissed');
}

function hair_dresser_and_salon_enqueue_admin_assets() {
    wp_enqueue_script(
        'hair-dresser-and-salon-confetti',
        get_template_directory_uri() . '/inc/get-started/assets/js/confetti/confetti.min.js',
        ['jquery'],
        null,
        true
    );

    wp_enqueue_script(
        'hair-dresser-and-salon-notice-confetti-js',
        get_template_directory_uri() . '/inc/get-started/assets/js/plugin-update-notice.js',
        ['hair-dresser-and-salon-confetti'],
        null,
        true
    );

    wp_enqueue_script(
        'hair-dresser-and-salon-notice-dismiss',
        get_template_directory_uri() . '/inc/get-started/assets/js/notice-dismiss.js',
        ['jquery'],
        null,
        true
    );
}
add_action('admin_enqueue_scripts', 'hair_dresser_and_salon_enqueue_admin_assets');