<?php

    add_action( 'vouge_after_main_css', 'search_style' );
    function search_style() {
        wp_enqueue_style( 'vouge-quick-search', get_theme_file_uri('/modules/search/assets/css/search.css'), false, VOUGE_THEME_VERSION, 'all');
    }

    add_action('wp_ajax_vouge_search_data_fetch' , 'vouge_search_data_fetch');
	add_action('wp_ajax_nopriv_vouge_search_data_fetch','vouge_search_data_fetch');
	function vouge_search_data_fetch(){

        $nonce = $_POST['security'];
        if ( ! wp_verify_nonce( $nonce, 'search_data_fetch_nonce' ) ) {
            die( 'Security check failed' );
        }

        $search_val = vouge_sanitization($_POST['search_val']);

        $the_query = new WP_Query( array( 'posts_per_page' => 6, 's' => $search_val, 'post_type' => array('post', 'product') ) );
        if( $the_query->have_posts() ) :
            while( $the_query->have_posts() ): $the_query->the_post(); ?>
                <li class="quick_search_data_item">
                    <a href="<?php echo esc_url( get_permalink() ); ?>">
                        <?php the_post_thumbnail( 'thumbnail', array( 'class' => ' ' ) ); ?>
                        <span class="quick_search_data_title"> <?php the_title();?> </span>
                    </a>
                </li>
            <?php endwhile;
            wp_reset_postdata();
        else:
            echo'<p>'. esc_html__( 'No Results Found', 'vouge') .'</p>';
        endif;

        die();
}

?>