!function(){"use strict";!function(e){const t=window.searchwpForms?.i18n||{},o=(e,o)=>t[e]||o,i={forms:{},getDefaultFormState:()=>({state:"idle",recognition:null,timeoutId:null,error:null,lastTranscript:"",speechStarted:!1,intentionalStop:!1,tooltipClickHandler:null,tooltipTimerId:null}),ensureFormEntry(e){return this.forms[e]||(this.forms[e]=this.getDefaultFormState()),this.forms[e]},getState(e){return this.forms[e]?this.forms[e].state:"idle"},getActiveFormId(){for(const e in this.forms)if("listening"===this.forms[e].state||"processing"===this.forms[e].state)return e;return null},hasSpeechStarted(e){return!!this.forms[e]&&this.forms[e].speechStarted},setSpeechStarted(e,t){this.ensureFormEntry(e).speechStarted=t},setState(e,t,o={}){const i=this.ensureFormEntry(e);i.state=t,void 0!==o.recognition&&(i.recognition=o.recognition),void 0!==o.error&&(i.error=o.error),void 0!==o.lastTranscript&&(i.lastTranscript=o.lastTranscript),this.updateButtonUI(e)},getRecognition(e){return this.forms[e]?this.forms[e].recognition:null},setRecognition(e,t){this.ensureFormEntry(e).recognition=t},clearTimeout(e){const t=this.forms[e];t&&t.timeoutId&&(clearTimeout(t.timeoutId),t.timeoutId=null)},stopRecognition(e,t=!0){const o=this.forms[e];if(o&&(o.intentionalStop=t,o.recognition))try{const e=o.recognition.abort||o.recognition.stop;"function"==typeof e&&e.call(o.recognition)}catch(e){}},resetToIdle(e){this.stopRecognition(e,!0),this.setSpeechStarted(e,!1),this.setState(e,"idle",{error:null})},setTimeout(e,t){this.ensureFormEntry(e).timeoutId=t},resetTimeout(e,t){this.clearTimeout(e);const o=setTimeout(()=>{this.stopRecognition(e,!0),this.clearTimeout(e)},t);this.setTimeout(e,o)},cleanup(e){this.clearTimeout(e),this.hideTooltip(e),this.stopRecognition(e,!0);const t=this.forms[e];t&&(t.recognition=null),this.setState(e,"idle",{error:null})},updateButtonUI(t){const i=e("#"+t).find(".swp-voice-search-button");if(!i.length)return;const r=this.getState(t);i.removeClass("swp-voice-listening swp-voice-processing").attr("aria-label",i.data("aria-label-idle")||o("voiceSearch","Voice Search")),"listening"===r?i.addClass("swp-voice-listening").attr("aria-label",o("listening","Listening…")):"processing"===r&&i.addClass("swp-voice-processing").attr("aria-label",o("processing","Processing…"))},getTooltipMessage:e=>({"no-speech":o("noSpeech","No speech detected. Please try speaking again."),"audio-capture":o("audioCapture","Microphone not found or unavailable."),"not-allowed":o("notAllowed","Microphone permission denied. Please allow access."),network:o("network","Network error. Please check your connection."),aborted:o("aborted","Voice search cancelled."),"service-not-allowed":o("serviceNotAllowed","Speech recognition service unavailable."),"empty-transcript":o("noSpeech","No speech detected. Please try speaking again.")}[e]||o("defaultError","Voice search error. Please try again.")),createTooltipElement(t){const o=e("#"+t);let i=o.find(".swp-voice-search-tooltip");return i.length||(i=e('
'),o.find(".searchwp-form-input-container").append(i),i.on("click",()=>{this.hideTooltip(t)})),i},showTooltip(t,o,i="error"){const r=this.createTooltipElement(t),s=e("#"+t),n=this.forms[t];n&&n.tooltipTimerId&&(clearTimeout(n.tooltipTimerId),n.tooltipTimerId=null);const c=s.find(".searchwp-form-input-container");if(c.length){const e=50,t=c[0].getBoundingClientRect().top