<?php
/**
 * Expert Travel Agent functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Expert Travel Agent
 */

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

if ( ! function_exists( 'expert_travel_agent_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 expert_travel_agent_setup() {

		load_theme_textdomain( 'expert-travel-agent', 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,
			)
		);

        add_theme_support( 'custom-background', apply_filters( 'expert_travel_agent_custom_background', array(
            'default-color' => 'ffffff',
            'default-image' => '',
        )));

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

function expert_travel_agent_scripts() {
    wp_enqueue_style('expert-travel-agent-style', get_stylesheet_uri(), array() );
    wp_enqueue_script('jquery-wow', get_template_directory_uri() . '/js/wow.js', array('jquery'));
    wp_enqueue_style('animate-css', get_template_directory_uri() . '/css/animate.css');

	//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(), EXPERT_TRAVEL_AGENT_VERSION );
	wp_enqueue_script( 'owl.carousel-js', get_template_directory_uri(). '/js/owl.carousel.js', array('jquery') ,EXPERT_TRAVEL_AGENT_VERSION,true);

    // Custom scripts should depend on JS and jQuery
    wp_enqueue_script('expert-travel-agent-custom-scripts', get_template_directory_uri() . '/js/custom.js',  array('jquery'),'' ,true );
    wp_style_add_data( 'expert-travel-agent-style', 'rtl', 'replace' );
}
add_action( 'wp_enqueue_scripts', 'expert_travel_agent_scripts' );

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

	wp_enqueue_style( 'expert-travel-agent-block-patterns-style-editor', get_theme_file_uri( '/css/block-editor.css' ), false, '1.0', 'all' );
}
add_action( 'enqueue_block_editor_assets', 'expert_travel_agent_block_editor_styles' );


function expert_travel_agent_init_setup() {

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

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


    if ( ! defined( 'EXPERT_TRAVEL_AGENT_FREE_THEME_URL' ) ) {
        define( 'EXPERT_TRAVEL_AGENT_FREE_THEME_URL', 'https://www.seothemesexpert.com/products/expert-travel-agent' );
    }
    if ( ! defined( 'EXPERT_TRAVEL_AGENT_PRO_THEME_URL' ) ) {
        define( 'EXPERT_TRAVEL_AGENT_PRO_THEME_URL', 'https://www.seothemesexpert.com/products/travel-agent-website-template' );
    }
    if ( ! defined( 'EXPERT_TRAVEL_AGENT_FREE_DOC_URL' ) ) {
        define( 'EXPERT_TRAVEL_AGENT_FREE_DOC_URL', 'https://demo.seothemesexpert.com/documentation/expert-travel-agent/' );
    }
    if ( ! defined( 'EXPERT_TRAVEL_AGENT_DEMO_THEME_URL' ) ) {
        define( 'EXPERT_TRAVEL_AGENT_DEMO_THEME_URL', 'https://demo.seothemesexpert.com/expert-travel-agent/' );
    }
    if ( ! defined( 'EXPERT_TRAVEL_AGENT_RATE_THEME_URL' ) ) {
        define( 'EXPERT_TRAVEL_AGENT_RATE_THEME_URL', 'https://wordpress.org/support/theme/expert-travel-agent/reviews/#new-post' );
    }
    if ( ! defined( 'EXPERT_TRAVEL_AGENT_SUPPORT_THEME_URL' ) ) {
        define( 'EXPERT_TRAVEL_AGENT_SUPPORT_THEME_URL', 'https://wordpress.org/support/theme/expert-travel-agent/' );
    }
    if ( ! defined( 'EXPERT_TRAVEL_AGENT_THEME_BUNDLE_URL' ) ) {
        define( 'EXPERT_TRAVEL_AGENT_THEME_BUNDLE_URL', 'https://www.seothemesexpert.com/products/wordpress-theme-bundle' );
    }
}
add_action( 'after_setup_theme', 'expert_travel_agent_init_setup' );


// Show Admin Notice
function expert_travel_agent_promo_notice() {
    if (get_option('expert_travel_agent_notice_dismissed')) {
        return;
    }

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

    $expert_travel_agent_theme = wp_get_theme();
    $expert_travel_agent_theme_title = $expert_travel_agent_theme->get( 'Name' );
    $expert_travel_agent_theme_version = $expert_travel_agent_theme->get( 'Version' );

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

add_action('wp_ajax_expert_travel_agent_dismiss_notice', 'expert_travel_agent_dismiss_notice');
function expert_travel_agent_dismiss_notice() {
    update_option('expert_travel_agent_notice_dismissed', true);
    wp_send_json_success();
}

add_action('after_switch_theme', 'expert_travel_agent_reset_notice_on_activation');
function expert_travel_agent_reset_notice_on_activation() {
    delete_option('expert_travel_agent_notice_dismissed');
}

function expert_travel_agent_enqueue_admin_assets() {
    wp_enqueue_script(
        'expert-travel-agent-confetti',
        get_template_directory_uri() . '/inc/get-started/assets/js/confetti/confetti.min.js',
        ['jquery'],
        null,
        true
    );

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

    wp_enqueue_script(
        'expert-travel-agent-notice-dismiss',
        get_template_directory_uri() . '/inc/get-started/assets/js/notice-dismiss.js',
        ['jquery'],
        null,
        true
    );
}
add_action('admin_enqueue_scripts', 'expert_travel_agent_enqueue_admin_assets');