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

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

if ( ! function_exists( 'style_accessories_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 style_accessories_setup() {

		load_theme_textdomain( 'style-accessories', 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', 'style_accessories_setup' );

function style_accessories_scripts() {
    wp_enqueue_style('style-accessories-style', get_stylesheet_uri(), array() );
    wp_enqueue_script('jquery-wow', get_template_directory_uri() . '/js/wow.js', array('jquery'), STYLE_ACCESSORIES_VERSION );
    wp_enqueue_style('animate-css', get_template_directory_uri() . '/css/animate.css', array(), STYLE_ACCESSORIES_VERSION );

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

    // Custom scripts should depend 
    wp_enqueue_script(
        'style-accessories-custom-scripts', 
        get_template_directory_uri() . '/js/custom.js', 
        array('jquery',), 
        STYLE_ACCESSORIES_VERSION, // Consistent versioning
        true 
    );
    
    wp_style_add_data( 'style-accessories-style', 'rtl', 'replace' );
}
add_action( 'wp_enqueue_scripts', 'style_accessories_scripts' );

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

	wp_enqueue_style( 'style-accessories-block-patterns-style-editor', get_theme_file_uri( '/css/block-editor.css' ), false, '1.0', 'all' );
}
add_action( 'enqueue_block_editor_assets', 'style_accessories_block_editor_styles' );


function style_accessories_init_setup() {

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

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

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

    if ( ! defined( 'STYLE_ACCESSORIES_FREE_THEME_URL' ) ) {
        define( 'STYLE_ACCESSORIES_FREE_THEME_URL', 'https://www.seothemesexpert.com/products/style-accessories' );
    }
    if ( ! defined( 'STYLE_ACCESSORIES_PRO_THEME_URL' ) ) {
        define( 'STYLE_ACCESSORIES_PRO_THEME_URL', 'https://www.seothemesexpert.com/products/jewellery-website-template' );
    }
    if ( ! defined( 'STYLE_ACCESSORIES_FREE_DOC_URL' ) ) {
        define( 'STYLE_ACCESSORIES_FREE_DOC_URL', 'https://demo.seothemesexpert.com/documentation/style-accessories/' );
    }
    if ( ! defined( 'STYLE_ACCESSORIES_DEMO_THEME_URL' ) ) {
        define( 'STYLE_ACCESSORIES_DEMO_THEME_URL', 'https://demo.seothemesexpert.com/jewellery-boutique/' );
    }
    if ( ! defined( 'STYLE_ACCESSORIES_RATE_THEME_URL' ) ) {
        define( 'STYLE_ACCESSORIES_RATE_THEME_URL', 'https://WordPress.org/support/theme/style-accessories/reviews/' );
    }
    if ( ! defined( 'STYLE_ACCESSORIES_SUPPORT_THEME_URL' ) ) {
        define( 'STYLE_ACCESSORIES_SUPPORT_THEME_URL', 'https://WordPress.org/support/theme/style-accessories/' );
    }
    if ( ! defined( 'STYLE_ACCESSORIES_THEME_BUNDLE_URL' ) ) {
        define( 'STYLE_ACCESSORIES_THEME_BUNDLE_URL', 'https://www.seothemesexpert.com/products/WordPress-theme-bundle' );
    }
}
add_action( 'after_setup_theme', 'style_accessories_init_setup' );


// Show Admin Notice
function style_accessories_promo_notice() {
    if (get_option('style_accessories_notice_dismissed')) {
        return;
    }

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

    $style_accessories_theme = wp_get_theme();
    $style_accessories_theme_title = $style_accessories_theme->get( 'Name' );
    $style_accessories_theme_version = $style_accessories_theme->get( 'Version' );

    ?>
    <div class="notice style-accessories-notice is-dismissible">
        <div>
            <h3>
                <span><?php echo esc_html( '(Version: ' . $style_accessories_theme_version . ')' ); ?></span><br>
                <?php esc_html_e( 'Thank you for choosing,', 'style-accessories'); ?>
                <?php echo esc_html( $style_accessories_theme_title ); ?> <?php esc_html_e( '!!!', 'style-accessories'); ?>
            </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!', 'style-accessories'); ?></p>
            <a class="button button-primary style-accessories-buy-now" href="<?php echo esc_url(admin_url('themes.php?page=styleaccessories-wizard')); ?>" target="_blank">
                <?php esc_html_e( 'Get Started', 'style-accessories') ?>
            </a>
            <a class="button button-primary style-accessories-bundle-button" target="_blank" href="<?php echo esc_url( STYLE_ACCESSORIES_THEME_BUNDLE_URL ); ?>">
                <?php echo esc_html__( 'Get All 60+ Themes @ $79', 'style-accessories' ); ?>
            </a>
        </div>
        <div class="style-accessories-image-wrap">
            <img src="<?php echo esc_url(get_stylesheet_directory_uri() . '/screenshot.png'); ?>">
        </div>
        <canvas id="style-accessories-notice-confetti"></canvas>
    </div>
    <?php
}
add_action('admin_notices', 'style_accessories_promo_notice');

add_action('wp_ajax_style_accessories_dismiss_notice', 'style_accessories_dismiss_notice');
function style_accessories_dismiss_notice() {
    update_option('style_accessories_notice_dismissed', true);
    wp_send_json_success();
}

add_action('after_switch_theme', 'style_accessories_reset_notice_on_activation');
function style_accessories_reset_notice_on_activation() {
    delete_option('style_accessories_notice_dismissed');
}

function style_accessories_enqueue_admin_assets() {
    wp_enqueue_script(
        'style-accessories-confetti',
        get_template_directory_uri() . '/inc/get-started/assets/js/confetti/confetti.min.js',
        ['jquery'],
        null,
        true
    );

    wp_enqueue_script(
        'style-accessories-notice-confetti-js',
        get_template_directory_uri() . '/inc/get-started/assets/js/plugin-update-notice.js',
        ['style-accessories-confetti'],
        null,
        true
    );

    wp_enqueue_script(
        'style-accessories-notice-dismiss',
        get_template_directory_uri() . '/inc/get-started/assets/js/notice-dismiss.js',
        ['jquery'],
        null,
        true
    );
}
add_action('admin_enqueue_scripts', 'style_accessories_enqueue_admin_assets');