<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 * Class DooSearchas_Search_Shortcode
 * Handles the [doosearchas_search_form] shortcode rendering
 */
class DooSearchas_Search_Shortcode {
    public function __construct(){
        add_shortcode('doosearchas_search_form', array($this,'doosearchas_add_shortcode_callback'));
    }
    public function doosearchas_add_shortcode_callback($atts = array(),$content = null,$tag = ''){
        $atts = array_change_key_case((array) $atts, CASE_LOWER);

        extract( shortcode_atts(array(
            'id' => '',
            'orderby' => 'date',
        ), $atts, $tag));

        if( ! empty($id)){
            $id = array_map('absint',explode(',',$id));
        }

        $file = DOOSEARCHAS_SEARCH_PATH . 'views/doosearch-search-shortcode.php';
        if ( file_exists($file) ) {
            ob_start();
            include $file;
            wp_enqueue_script('doosearchas-frontend-js');
            return ob_get_clean();
        }
        return '';
    }
}