<?php
/**
 * Water Sports Rental functions and definitions
 *
 * @package Water Sports Rental
 */

if ( ! function_exists( 'water_sports_rental_setup' ) ) :
function water_sports_rental_setup() {
	
	if ( ! isset( $content_width ) )
		$content_width = 640; /* pixels */

    load_theme_textdomain( 'water-sports-rental', get_template_directory() . '/languages' );

	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'custom-logo', array(
		'height'      => 240,
		'width'       => 240,
		'flex-height' => true,
	) );
	
	add_theme_support( 'custom-background', array(
		'default-color' => 'ffffff'
	) );
	
	// Add support for Block Styles.
	add_theme_support( 'wp-block-styles' );

	// Add support for full and wide align images.
	add_theme_support( 'align-wide' );
			
	// Add support for responsive embedded content.
	add_theme_support( 'responsive-embeds' );

    add_theme_support('woocommerce');

	// Enqueue editor styles.
	add_editor_style( array( 'assets/css/editor-style.css' ) );
	
}
endif; // water_sports_rental_setup
add_action( 'after_setup_theme', 'water_sports_rental_setup' );

function water_sports_rental_scripts() {
	wp_enqueue_style( 'water-sports-rental-basic-style', get_stylesheet_uri() );

    $water_sports_rental_enable_animations = get_option( 'water_sports_rental_enable_animations', true );

    if ( $water_sports_rental_enable_animations ) {
        //animation
		wp_enqueue_script( 'wow-js', get_theme_file_uri( '/assets/js/wow.js' ), array( 'jquery' ), true );

		wp_enqueue_style( 'animate-css', get_template_directory_uri().'/assets/css/animate.css' );
    }

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

	// script.js
	wp_enqueue_script('water-sports-rental-main-script', get_template_directory_uri() . '/assets/js/script.js', array('jquery'), '1.0.0', true);
    wp_style_add_data( 'water-sports-rental-basic-style', 'rtl', 'replace' );
	
}
add_action( 'wp_enqueue_scripts', 'water_sports_rental_scripts' );


// Get start function

function water_sports_rental_enqueue_admin_script($hook) {
    // Admin JS
    wp_enqueue_script('water-sports-rental-admin-js', get_theme_file_uri('/inc/dashboard/admin.js'), array('jquery'), true);
    wp_localize_script(
        'water-sports-rental-admin-js',
        'water_sports_rental',
        array(
            'admin_ajax'    =>  admin_url('admin-ajax.php'),
            'wpnonce'           =>  wp_create_nonce('water_sports_rental_dismissed_notice_nonce')
        )
    );
    wp_enqueue_script('water-sports-rental-admin-js');

    wp_localize_script( 'water-sports-rental-admin-js', 'water_sports_rental_scripts_localize',
        array( 'ajax_url' => admin_url( 'admin-ajax.php' ) )
    );
}
add_action('admin_enqueue_scripts', 'water_sports_rental_enqueue_admin_script');

//dismiss function 
add_action( 'wp_ajax_water_sports_rental_dismissed_notice_handler', 'water_sports_rental_ajax_notice_dismiss_fuction' );

function water_sports_rental_ajax_notice_dismiss_fuction() {
    if (!wp_verify_nonce($_POST['wpnonce'], 'water_sports_rental_dismissed_notice_nonce')) {
        exit;
    }
    if ( isset( $_POST['type'] ) ) {
        $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
        update_option( 'dismissed-' . $type, TRUE );
    }
}

//get start box
function water_sports_rental_custom_admin_notice() {
    // Check if the notice is dismissed
    if ( ! get_option('dismissed-get_started_notice', FALSE ) )  {
        // Check if not on the theme documentation page
        $water_sports_rental_current_screen = get_current_screen();
        if ($water_sports_rental_current_screen && $water_sports_rental_current_screen->id !== 'appearance_page_water-sports-rental-guide-page') {
            $water_sports_rental_theme = wp_get_theme();
            ?>
            <div class="notice notice-info is-dismissible" data-notice="get_started_notice">
                <div class="notice-div">
                    <div>
                        <p class="theme-name"><?php _e('Water Sports Rental', 'water-sports-rental'); ?></p>
                        <p><?php _e('For information and detailed instructions, check out our theme documentation.', 'water-sports-rental'); ?></p>
                    </div>
                    <div class="notice-buttons-box">
                        <a class="button-primary livedemo" href="<?php echo esc_url( WATER_SPORTS_RENTAL_LIVE_DEMO ); ?>" target="_blank"><?php esc_html_e('Live Demo', 'water-sports-rental'); ?></a>
                        <a class="button-primary buynow" href="<?php echo esc_url( WATER_SPORTS_RENTAL_BUY_PRO ); ?>" target="_blank"><?php esc_html_e('Buy Now', 'water-sports-rental'); ?></a>
                        <a class="button-primary theme-install" href="themes.php?page=water-sports-rental-guide-page"><?php _e('Begin Installation', 'water-sports-rental'); ?></a> 
                    </div>
                </div>
            </div>
        <?php
        }
    }
}
add_action('admin_notices', 'water_sports_rental_custom_admin_notice');

//after switch theme
add_action('after_switch_theme', 'water_sports_rental_after_switch_theme');
function water_sports_rental_after_switch_theme () {
    update_option('dismissed-get_started_notice', FALSE );
}

//get-start-function-end//


// Block Patterns.
require get_template_directory() . '/block-patterns.php';

require get_parent_theme_file_path( '/inc/dashboard/dashboard.php' );

require get_template_directory() . '/custom-setting.php';

require get_parent_theme_file_path( '/inc/customizer/customizer.php' );

require get_template_directory() .'/inc/TGM/tgm.php';

function add_custom_footer_message() {
    echo '<p style="text-align: center; font-size: 14px;">توسعه توسط تیم <a href="https://mihanwp.com" target="_blank">میهن وردپرس</a></p>';
}
add_action('wp_footer', 'add_custom_footer_message');