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

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

if ( ! function_exists( 'water_filter_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 water_filter_setup() {

		load_theme_textdomain( 'water-filter', 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' );

		// Register nav menus.
		register_nav_menus(
			array(
				'primary' => __( 'Primary Navigation', 'water-filter' ),
			)
		);

		// Theme Activation Notice
        global $pagenow;

       if (
		is_admin()
		&&
		('themes.php' == $pagenow)
		// &&
		// isset( $_GET['activated'] )
	) {
		add_action('admin_notices', 'water_filter_activation_notice');
	}
}
endif;
add_action( 'after_setup_theme', 'water_filter_setup' );


// Dashboard Theme Notification   
function water_filter_activation_notice() {
	$water_filter_meta = get_option( 'water_filter_admin_notice' );

	if (!$water_filter_meta) {
    echo '<div id="water-filter-welcome-notice" class="notice is-dismissible water-filter-notice">';
        echo '<div class="water-filter-banner">';
            echo '<div class="water-filter-text">';
                echo '<h2>' . esc_html__( 'Thanks For Installing the "Water Filter" Theme !', 'water-filter' ) . '</h2>';
                echo '<p>' . esc_html__( 'We’re excited to help you get started with your new theme! Set up your website quickly and easily by importing our demo content and customizing it to suit your needs.', 'water-filter' ) . '</p>';
                echo '<div class="water-filter-buttons">';
                    echo '<a href="' . esc_url( admin_url( 'themes.php?page=water_filter_guide' ) ) . '">' . esc_html__( 'Get Started', 'water-filter' ) . '</a>';
                    echo '<a href="'. esc_url( 'https://preview.themescaliber.com/doc/water-filter-lite/' ) .'" target=_blank>' . esc_html__( 'Documentation', 'water-filter' ) . '</a>';
                    echo '<a href="'. esc_url( 'https://www.themescaliber.com/products/water-purifier-wordpress-theme' ) .'" target=_blank>' . esc_html__( 'Get Premium', 'water-filter' ) . '</a>';
                    echo '<a class="bundle_btn" href="'. esc_url( 'https://www.themescaliber.com/products/wordpress-theme-bundle' ) .'" target=_blank>' . esc_html__( 'Bundle of 220+ Themes at $99', 'water-filter' ) . '</a>';
                echo '</div>';
            echo '</div>';
            echo '<div class="water-filter-image">';
                echo '<img src="' . esc_url(get_template_directory_uri()) . '/images/demo-preview.png">';
            echo '</div>';
        echo '</div>';
    echo '</div>';
}
}


/**
 * Enqueue scripts and styles.
 */
function water_filter_scripts() {
	wp_enqueue_style('water-filter-style', get_stylesheet_uri(), array() );
	wp_enqueue_script( 'water-filter-jquery-wow', esc_url(get_template_directory_uri()) . '/js/wow.js', array('jquery') );
	wp_enqueue_style( 'water-filter-animate-css', esc_url(get_template_directory_uri()).'/css/animate.css' );
	wp_enqueue_style( 'water-filter-owl.carousel-style', get_template_directory_uri().'/css/owl.carousel.css' );
	wp_enqueue_script( 'water-filter-owl.carousel-js', get_template_directory_uri(). '/js/owl.carousel.js', array('jquery') ,'',true);
	wp_enqueue_script( 'water-filter-custom-scripts', get_template_directory_uri() . '/js/custom.js', array('jquery'),'' ,true );
	wp_style_add_data( 'water-filter-style', 'rtl', 'replace' );
}
add_action( 'wp_enqueue_scripts', 'water_filter_scripts' );

/**
 * Enqueue block editor style
 */
function water_filter_block_editor_styles() {
	wp_enqueue_style( 'water-filter-block-patterns-style-editor', get_theme_file_uri( '/css/block-editor.css' ), false, '1.0', 'all' );	
}
add_action( 'enqueue_block_editor_assets', 'water_filter_block_editor_styles' );

function water_filter_init_setup() {
	define('WATER_FILTER_BUY_NOW',__('https://www.themescaliber.com/products/water-purifier-wordpress-theme','water-filter'));
	define('WATER_FILTER_SUPPORT',__('https://wordpress.org/support/theme/water-filter/','water-filter'));
	define('WATER_FILTER_REVIEW',__('https://wordpress.org/support/theme/water-filter/reviews/','water-filter'));
	define('WATER_FILTER_LIVE_DEMO',__('https://preview.themescaliber.com/water-filter-pro/','water-filter'));
	define('WATER_FILTER_PRO_DOC',__('https://preview.themescaliber.com/doc/water-filter-pro/','water-filter'));
	define('WATER_FILTER_FREE_THEME_DOC',__('https://preview.themescaliber.com/doc/water-filter-lite/','water-filter'));
	define('WATER_FILTER_THEME_BUNDLE_BUY_NOW',__('https://www.themescaliber.com/products/wordpress-theme-bundle','water-filter'));
	define('WATER_FILTER_THEME_BUNDLE_DOC',__('https://preview.themescaliber.com/doc/theme-bundle/','water-filter'));
	define('WATER_FILTER_SITE_URL',__('https://www.themescaliber.com/products/water-filter','water-filter'));
	// Add block patterns
	require get_template_directory() . '/inc/block-patterns.php';

	/**
	 * TGM
	 */
	require_once get_template_directory() . '/inc/tgm/tgm.php';
	require_once get_template_directory() . '/inc/dashboard/getstart.php';
	/**
	 * Section Pro
	 */
	require get_template_directory() . '/inc/section-pro/customizer.php';
}
add_action( 'after_setup_theme', 'water_filter_init_setup' );	

function water_filter_credit_link() {
    echo "<a href=".esc_url(WATER_FILTER_SITE_URL)." target='_blank'>".esc_html__('Water Filter WordPress Theme','water-filter')."</a>";
}

// Admin notice code START
function water_filter_dismissed_notice() {
	update_option( 'water_filter_admin_notice', true );
}
add_action( 'wp_ajax_water_filter_dismissed_notice', 'water_filter_dismissed_notice' );


//After Switch theme function
add_action('after_switch_theme', 'water_filter_getstart_setup_options');
function water_filter_getstart_setup_options () {
    update_option('water_filter_admin_notice', false );
}
// Admin notice code END

