<?php 
defined('ABSPATH') or die("You can't access this file directly.");

add_action('wp_enqueue_scripts', 'QC_VOICEWIDGET_voice_search_scripts');
function QC_VOICEWIDGET_voice_search_scripts(){

    wp_enqueue_style( 'qc_voice_search_awesome', QC_VOICEWIDGET_PLUGIN_URL . 'assets/css/font-awesome.min.css', array(), '' );
    wp_enqueue_style( 'qc_voice_search_css', QC_VOICEWIDGET_PLUGIN_URL . 'inc/voice-search/css/voice_search_stt.css', array(), '' );
    
    wp_enqueue_script( 'qc_voice_search_languages_option', QC_VOICEWIDGET_PLUGIN_URL . 'inc/voice-search/js/stt-languages-option.js', ['jquery'], QC_VOICEWIDGET_VERSION, true );

    wp_enqueue_script( 'qc-voice-search-frontend-js', QC_VOICEWIDGET_PLUGIN_URL .  'inc/voice-search/js/stt_voice_search.js', ['jquery'], QC_VOICEWIDGET_VERSION, true );

    $stt_unique_id  = get_option('qc_voice_search_stt_unique_field_id');
    $qc_voice_search_stt_lang_settings  = get_option('qc_voice_search_stt_lang_settings') ? get_option('qc_voice_search_stt_lang_settings') : '';
    $qc_voice_search_stt_form_auto_submit  = get_option('qc_voice_search_stt_form_auto_submit') ? get_option('qc_voice_search_stt_form_auto_submit') : '';
    $qc_voice_search_stt_style  = get_option('qc_voice_search_stt_style') ? get_option('qc_voice_search_stt_style') : '';
    $qc_voice_search_remove_submit  = get_option('qc_voice_search_remove_submit') ? get_option('qc_voice_search_remove_submit') : '';

    $lang_settings = '';
    if($qc_voice_search_stt_lang_settings== 'on'){

        $lang_settings = '<div class="qc_voice_search_audio_status"> 
                            <select class="qc_voice_search_language" id="qc_voice_search_language"></select>
                        </div>';
    }


    $data = '<div class="qc_voice_search_wrapper '.$qc_voice_search_stt_style.'">
                    <a class="qc_voice_search_audio_record" href="#">
                        <i aria-hidden="true" class="fa fa-microphone"></i> 
                    </a>
                    '.$lang_settings.'
                </div>';

    wp_localize_script( 'qc-voice-search-frontend-js', 'qc_voice_search_form', [
        'nonce'                     => wp_create_nonce( 'wpvoicemessage-nonce' ),
        'ajaxurl'                   => admin_url( 'admin-ajax.php' ),
        'audio_record_num_channel'  => 1,
        'convert_recorded_audio'    => 'wav',
        'qc_search_allow_control'   => get_option('qc_voice_search_stt_form_control') ? get_option('qc_voice_search_stt_form_control') : 'off',
        'qc_search_form_auto_submit'=> get_option('qc_voice_search_stt_form_auto_submit') ? get_option('qc_voice_search_stt_form_auto_submit') : 'off',
        'qc_search_remove_submit'   => get_option('qc_voice_search_remove_submit') ? get_option('qc_voice_search_remove_submit') : 'off',
        'qc_search_lang_code'       => get_option('qc_voice_to_speech_stt_lang_code') ? get_option('qc_voice_to_speech_stt_lang_code') : 'en',
        'qc_search_data'            => $data,
        'QC_VOICEWIDGET_ASSETS_URL' => QC_VOICEWIDGET_PLUGIN_URL . 'assets/audio/'
    ]);


}