var module_225961440039=void function(){"use strict";const FOCUSABLE_SELECTOR=["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(",");let googleSearchPromise;function initializeModule(moduleElement){if("true"===moduleElement.dataset.searchInitialized)return;moduleElement.dataset.searchInitialized="true";const openButton=moduleElement.querySelector("[data-bncrmb-open]"),closeButton=moduleElement.querySelector("[data-bncrmb-close]"),dialog=moduleElement.querySelector("[data-bncrmb-dialog]"),panel=moduleElement.querySelector("[data-bncrmb-panel]"),googleContainer=moduleElement.querySelector("[data-bncrmb-google]"),status=moduleElement.querySelector("[data-bncrmb-status]"),engineId=moduleElement.dataset.searchEngineId,placeholder=moduleElement.dataset.searchPlaceholder;let isRendered=!1,lastFocusedElement=null,suggestionsObserver=null;function setSearchPlaceholder(){const input=googleContainer.querySelector("input.gsc-input");return!!input&&(input.placeholder=placeholder,input.setAttribute("aria-label",placeholder),!0)}function renderGoogleSearch(){return isRendered?Promise.resolve():function(engineId){return window.google&&window.google.search&&window.google.search.cse?Promise.resolve(window.google.search.cse):googleSearchPromise||(googleSearchPromise=new Promise(function(resolve,reject){const existingScript=document.querySelector('script[src*="cse.google.com/cse.js"]'),script=existingScript||document.createElement("script");let attempts=0;existingScript||(script.async=!0,script.src="https://cse.google.com/cse.js?cx="+encodeURIComponent(engineId),script.addEventListener("error",function(){reject(new Error("No fue posible descargar Google Programmable Search."))},{once:!0}),document.head.appendChild(script)),function waitForApi(){window.google&&window.google.search&&window.google.search.cse?resolve(window.google.search.cse):(attempts+=1,attempts>100?reject(new Error("No fue posible cargar Google Programmable Search.")):window.setTimeout(waitForApi,100))}()}),googleSearchPromise)}(engineId).then(function(cse){if(!cse.element||"function"!=typeof cse.element.render)throw new Error("La API de Google Search no está disponible.");if(cse.element.render({div:googleContainer.id,tag:"search",gname:googleContainer.id}),isRendered=!0,status&&(status.hidden=!0),!setSearchPlaceholder()){const observer=new MutationObserver(function(){setSearchPlaceholder()&&observer.disconnect()});observer.observe(googleContainer,{childList:!0,subtree:!0})}}).catch(function(){status&&(status.hidden=!1,status.textContent="No fue posible cargar el buscador. Inténtalo nuevamente.")})}function markGoogleSuggestions(){document.querySelectorAll(".gssb_c").forEach(function(suggestions){suggestions.classList.contains("bncrmb__suggestions")||suggestions.classList.add("bncrmb__suggestions")})}function closeDialog(){dialog.hidden||(dialog.classList.remove("is-open"),dialog.setAttribute("aria-hidden","true"),openButton.setAttribute("aria-expanded","false"),document.body.classList.remove("bncrmb-page-lock"),suggestionsObserver&&(suggestionsObserver.disconnect(),suggestionsObserver=null),document.querySelectorAll(".bncrmb__suggestions").forEach(function(suggestions){suggestions.classList.remove("bncrmb__suggestions")}),window.setTimeout(function(){dialog.classList.remove("is-opening"),dialog.hidden=!0},window.matchMedia("(prefers-reduced-motion: reduce)").matches?0:180),lastFocusedElement&&"function"==typeof lastFocusedElement.focus?lastFocusedElement.focus():openButton.focus())}openButton&&closeButton&&dialog&&panel&&googleContainer&&(openButton.addEventListener("click",function(){lastFocusedElement=document.activeElement,dialog.hidden=!1,dialog.setAttribute("aria-hidden","false"),openButton.setAttribute("aria-expanded","true"),document.body.classList.add("bncrmb-page-lock"),suggestionsObserver||(suggestionsObserver=new MutationObserver(markGoogleSuggestions),suggestionsObserver.observe(document.body,{childList:!0,subtree:!0}),markGoogleSuggestions()),window.requestAnimationFrame(function(){dialog.classList.add("is-opening"),dialog.classList.add("is-open"),closeButton.focus()}),renderGoogleSearch()}),closeButton.addEventListener("click",closeDialog),dialog.addEventListener("click",function(event){panel.contains(event.target)||closeDialog()}),dialog.addEventListener("keydown",function(event){if("Escape"===event.key)return event.preventDefault(),void closeDialog();if("Tab"!==event.key)return;const focusableElements=Array.prototype.filter.call(dialog.querySelectorAll(FOCUSABLE_SELECTOR),function(element){return!element.hidden&&null!==element.offsetParent}),firstElement=focusableElements[0],lastElement=focusableElements[focusableElements.length-1];firstElement&&lastElement?event.shiftKey&&document.activeElement===firstElement?(event.preventDefault(),lastElement.focus()):event.shiftKey||document.activeElement!==lastElement||(event.preventDefault(),firstElement.focus()):(event.preventDefault(),closeButton.focus())}))}function initializeAll(){document.querySelectorAll("[data-bncrmb]").forEach(initializeModule)}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",initializeAll,{once:!0}):initializeAll()}(); //# sourceURL=https://48395929.fs1.hubspotusercontent-na1.net/hubfs/48395929/hub_generated/module_assets/1/225961440039/1794243139126/module_bncr-modulo-busqueda.js