let API_KEY_TRADUCTOR="",URL_API_TRADUCTOR="";const CANTIDAD_MAXIMO_TRADUCIR_POR_GRUPO=100,header=document.querySelector(".bcp_header"),tipoClienteActivo=getLineaServicioActivo().toLowerCase(),tiposCliente=header.querySelectorAll(".bcp_tipo_cliente a"),btnTraductores=header.querySelectorAll(".bcp_traducir li"),btnTraducirEspaniol=btnTraductores[0],btnTraducirQuechua=btnTraductores[1],traducidoQuechuaMobile=header.querySelector("#traducidoQuechua"),btnMenuOpcionesMobile=header.querySelector(".bcp_btn_menu"),contenedorCategoria=header.querySelector(".bcp_categorias");let cintillo=header.querySelector(".bcp_cintillo");const botonesBanca=header.querySelectorAll(".bcp_btn_banca"),botonesOtro=header.querySelectorAll(".bcp_btn_otro"),botonesBuscar=header.querySelectorAll(".bcp_buscar"),modalActualizacionBancaPorInternet=header.querySelector(".bcp_modal_mensaje_actualizacion_banca_internet"),obtenerConfigTraductor=async()=>{try{const e=await fetch("/wcm/connect/resources/templates/header-v5/config-traductor.json?rendermode=json");if(!e.ok)throw new Error(`Error al config traductor: ${e.status}`);const t=await e.json();return{key:t.key,endPoint:t.endPoint}}catch(e){throw console.error("Falló al obtener config traductor:",e),e}};obtenerConfigTraductor().then(e=>{API_KEY_TRADUCTOR=e.key,URL_API_TRADUCTOR=e.endPoint});const agregarUTMTGAB=(e,t)=>{for(const o of e){const e=t(o);agregarParemetrosGet(o,e)}},obteberRfId=(e,t,o=null)=>{const a=`?rfid=header:${prepareString(cleamHTMLSpace(e))}:${prepareString(cleamHTMLSpace(t))}`;return o?a+`:${prepareString(o)}`:a},cleamHTMLSpace=e=>String(e).split(" ").join(" "),activarTipoClienteActivo=()=>{for(const e of tiposCliente)e.textContent.trim().toLowerCase()===tipoClienteActivo&&e.parentNode.classList.add("activo"),e.addEventListener("click",e=>{const t=e.currentTarget.textContent.trim().toLowerCase();digitalData.push({action:{group:"Header",category:"Tipo de Cliente",name:"Click",label:cleanLabel(t)},event:"trackAction"})});if("empresas"===tipoClienteActivo||modalActualizacionBancaPorInternet)for(const e of botonesBanca)e.removeAttribute("href");for(const e of botonesBanca){const t=e.href;t&&(t.href=t+obteberRfId("botones principales","button",e.innerText.trim())),e.addEventListener("click",e=>{const t=e.currentTarget.innerText.trim();digitalData.push({action:{group:"Header",category:"Botones Principales",name:"Click",label:cleanLabel(t)},event:"trackAction"}),"empresas"===tipoClienteActivo&&(bcp_mostrar_modal_jsnativo(header.querySelector(".bcp_modal_bk_empresas")),fnlazy_loader_img_a_demanda(header.querySelectorAll(".bcp_modal_bk_empresas img"))),modalActualizacionBancaPorInternet&&(bcp_mostrar_modal_jsnativo(header.querySelector(".bcp_modal_mensaje_actualizacion_banca_internet")),fnlazy_loader_img_a_demanda(header.querySelectorAll(".bcp_modal_mensaje_actualizacion_banca_internet img")))})}};for(const e of botonesOtro){const t=e.href;e.href=t+obteberRfId("botones principales","button",e.innerText.trim()),e.addEventListener("click",e=>{const t=e.currentTarget.innerText.trim();digitalData.push({action:{group:"Header",category:"Botones Principales",name:"Click",label:cleanLabel(t)},event:"trackAction"})})}for(const e of botonesBuscar)e.addEventListener("click",()=>{digitalData.push({action:{group:"Header",category:"Menu Principal",name:"Click",label:"Busqueda"},event:"trackAction"})});const apiLoadApiTraducir=()=>{try{"undefined"!=typeof gapi&&"function"==typeof gapi.load?gapi.load("client",traducirContenidoEspaniolQuechua):console.error("La función gapi.load no está definida.")}catch(e){console.error("Error al cargar la API de traductor:",e)}};function onGoogleApiLoad(){"true"===getCookie("bcp_traducir_quechua")&&(apiLoadApiTraducir(),btnTraducirQuechua.classList.add("activo"),header.classList.add("quechua"),traducidoQuechuaMobile.parentNode.checked=!0,traducidoQuechuaMobile.parentNode.setAttribute("aria-expanded","true"))}""===getCookie("bcp_traducir_quechua")&&(btnTraducirEspaniol.classList.add("activo"),header.classList.remove("quechua"),traducidoQuechuaMobile.parentNode.checked=!1,traducidoQuechuaMobile.parentNode.setAttribute("aria-expanded","false"));const activarTraducionQuechua=e=>{let t;e?(t="Quechua",btnTraducirQuechua.classList.add("procesando"),setCookie("bcp_traducir_quechua",!0,864e5),header.classList.add("quechua"),traducidoQuechuaMobile.parentNode.checked=!0,traducidoQuechuaMobile.parentNode.parentNode.classList.add("procesando"),traducidoQuechuaMobile.parentNode.setAttribute("aria-expanded","true"),apiLoadApiTraducir()):(t="Espaniol",btnTraducirEspaniol.classList.add("activo"),setCookie("bcp_traducir_quechua",!1,0),traducidoQuechuaMobile.parentNode.checked=!1,globalThis.location.reload()),digitalData.push({action:{group:"Header",category:"Idioma",name:"Click",label:t},event:"trackAction"})},obtenerMenuCategoriaActivo=()=>cleanLabel(header.querySelector(".bcp_categoria.activo .bcp_titulo_categoria span").innerText.trim()),obtenermenuProductoActivo=()=>cleanLabel(header.querySelector(".bcp_producto.activo .bcp_titulo_producto span").innerText.trim()),taggeoOpcionEnlaces=e=>{const t=e.currentTarget,o=cleanLabel(t.innerText.trim()),a=cleanLabel(getLineaServicioActivo().toLowerCase());digitalData.push({action:{group:`Header - ${a}`,category:`Menu - ${obtenerMenuCategoriaActivo()} - ${obtenermenuProductoActivo()}`,name:"Click",label:o},event:"trackAction"})},taggeoProductoEnlace=e=>{const t=cleanLabel(getLineaServicioActivo().toLowerCase()),o=cleanLabel(e);digitalData.push({action:{group:"Header - "+t,category:"Menu - "+obtenerMenuCategoriaActivo(),name:"Click",label:o},event:"trackAction"})},activarProductoDesktop=e=>{const t=e.parentNode;if(t.classList.contains("activo")){const o=header.querySelectorAll(".bcp_producto.activo");for(const e of o)e.classList.remove("activo");t.classList.remove("activo"),t.parentNode.classList.remove("mostrar_detalle"),e.setAttribute("aria-expanded","false")}else{const o=header.querySelectorAll(".bcp_producto.activo");for(const e of o)e.classList.remove("activo"),e.querySelector(".bcp_titulo_producto").setAttribute("aria-expanded","false");t.classList.add("activo"),t.parentNode.classList.add("mostrar_detalle"),e.setAttribute("aria-expanded","true"),fnlazy_loader_backgroundImage_comp_demanda(header.querySelectorAll(".bcp_producto.activo .lazy_loading_demanda"))}},agregarEventoLinkBanner=e=>{const t=cleanLabel(getLineaServicioActivo().toLowerCase()),o=cleanLabel(e.currentTarget.innerText.trim());digitalData.push({action:{group:"Header - "+t,category:`Menu - ${obtenerMenuCategoriaActivo()} - ${obtenermenuProductoActivo()} - Banner`,name:"Click",label:o},event:"trackAction"})},taggearClickProducto=e=>{"A"!==e.currentTarget.tagName&&activarProductoDesktop(e.currentTarget),taggeoProductoEnlace(e.currentTarget.innerText.trim())},mostrarOcultarOpcionesCategoria=e=>{const t=e.currentTarget,o=t.parentNode,a=o.querySelector(".bcp_productos");globalThis.matchMedia("(max-width: 1279px)").matches?manejarVistaMovil(o,t,a):manejarVistaDesktop(o,t,a),traducirContenido(a)};function manejarVistaMovil(e,t,o){e.classList.contains("activo")?desactivarCategoria(e,t,o):activarCategoria(e,t,o)}function manejarVistaDesktop(e,t,o){const a=e.classList.contains("activo");mostrarProductoDeCategoriaSeleccionadaDesktop(e,t,!a),ajustarPosicionProductos(e),o.classList.remove("mostrar_detalle")}function activarCategoria(e,t,o){fnlazy_loader_backgroundImage_comp_demanda(e.querySelectorAll(".lazy_loading_demanda")),cerrarCategoriasActivas(),e.classList.add("activo"),slideDown(o,500),t.setAttribute("aria-expanded","true")}function desactivarCategoria(e,t,o){e.classList.remove("activo"),slideUp(o,200),t.setAttribute("aria-expanded","false")}function cerrarCategoriasActivas(){for(const e of header.querySelectorAll(".bcp_categoria.activo"))e.classList.remove("activo"),e.querySelector(".bcp_titulo_categoria").setAttribute("aria-expanded","false"),slideUp(e.querySelector(".bcp_productos"),0)}function ajustarPosicionProductos(e){const t=e.parentNode.querySelectorAll(".bcp_productos"),o=calcularPosicionIzquierda(e);for(const e of t)e.style.left=o}function calcularPosicionIzquierda(e){if(!e.classList.contains("con_opciones")){const t=332;return`${e.offsetLeft-t+(e.offsetWidth+t)/2}px`}return"100px"}function traducirContenido(e){for(const t of e.querySelectorAll('[data-translate="false"]'))t.dataset.translate=!0;apiLoadApiTraducir()}for(const e of header.querySelectorAll(".bcp_categoria")){const t=e.querySelector(".bcp_titulo_categoria");t&&t.addEventListener("click",mostrarOcultarOpcionesCategoria)}for(const e of header.querySelectorAll(".bcp_categoria .bcp_producto")){for(const t of e.querySelectorAll(".bcp_titulo_producto"))if(t.addEventListener("click",taggearClickProducto),"A"===t.tagName){const e=t.closest(".bcp_categoria").querySelector(".bcp_titulo_categoria span"),o=t.querySelector("span");t.href=t.href+obteberRfId(e.textContent.trim(),o.textContent.trim())}for(const t of e.querySelectorAll(".bcp_volver"))t.addEventListener("click",()=>{for(const e of header.querySelectorAll(".bcp_producto.activo"))e.classList.remove("activo"),e.querySelector(".bcp_titulo_producto").setAttribute("aria-expanded","false")});for(const t of e.querySelectorAll(".bcp_banner a")){t.addEventListener("click",agregarEventoLinkBanner);const e=t.closest(".bcp_categoria"),o=t.closest(".bcp_producto"),a=e.querySelector(".bcp_titulo_categoria span").textContent,r=o.querySelector(".bcp_titulo_producto span").textContent;t.href=t.href+obteberRfId(a,t.innerText,r)}for(const t of e.querySelectorAll(".bcp_enlaces a")){t.addEventListener("click",taggeoOpcionEnlaces);const e=t.closest(".bcp_categoria"),o=t.closest(".bcp_producto"),a=e.querySelector(".bcp_titulo_categoria span").textContent,r=o.querySelector(".bcp_titulo_producto span").textContent;t.href=t.href+obteberRfId(a,t.innerText,r)}}activarTipoClienteActivo(),btnTraducirEspaniol.addEventListener("click",()=>{btnTraducirEspaniol.classList.contains("activo")||activarTraducionQuechua(!1)}),btnTraducirQuechua.addEventListener("click",()=>{btnTraducirQuechua.classList.contains("activo")||activarTraducionQuechua(!0)}),traducidoQuechuaMobile.addEventListener("input",e=>{e.currentTarget.checked?activarTraducionQuechua(!0):activarTraducionQuechua(!1)});const obtenerAltoCintillo=()=>cintillo.getBoundingClientRect().height,cintilloTieneContenido=()=>obtenerAltoCintillo()>0,aplicarMarginTopCintillo=e=>{cintillo.style.marginTop=`${e}px`},cerrarMenu=()=>{header.classList.remove("activo"),btnMenuOpcionesMobile.setAttribute("aria-expanded","false"),header.querySelector(".bcp_nivel1 .bcp_nivel1_mobile ul").classList.remove("activo");for(const e of header.querySelectorAll(".bcp_categorias .bcp_productos"))e.style.display="none",e.classList.remove("activo");for(const e of header.querySelectorAll(".bcp_categorias .bcp_producto.activo, .bcp_categoria.activo"))e.classList.remove("activo");cintilloTieneContenido()&&(cintillo.classList.add("activo"),globalThis.scrollY<=obtenerAltoComenzarScroll()&&aplicarMarginTopCintillo(0))};btnMenuOpcionesMobile.addEventListener("click",()=>{if(header.classList.contains("activo"))cerrarMenu();else{reniciarCategoriaMobile(),fnlazy_loader_img_a_demanda(header.querySelectorAll(".bcp_titulo_categoria img")),btnMenuOpcionesMobile.setAttribute("aria-expanded","true"),header.classList.add("activo"),cintillo.classList.remove("activo"),aplicarMarginTopCintillo(-1*obtenerAltoCintillo());const e=cleanLabel(getLineaServicioActivo().toLowerCase());digitalData.push({action:{group:"Header - "+e,category:"Home",name:"Click",label:"Menu Hamburguer"},event:"trackAction"})}});const mostrarProductoDeCategoriaSeleccionadaDesktop=(e,t,o=!1)=>{for(const e of header.querySelectorAll(".bcp_categoria.activo"))e.classList.remove("activo"),e.querySelector(".bcp_titulo_categoria").setAttribute("aria-expanded","false");for(const e of header.querySelectorAll(".bcp_producto.activo"))e.classList.remove("activo"),e.querySelector(".bcp_titulo_producto").setAttribute("aria-expanded","false");if(o){e.classList.add("activo"),header.classList.add("activo"),t.setAttribute("aria-expanded","true");const o=header.querySelectorAll(".bcp_categoria.activo .bcp_titulo_producto img"),a=header.querySelectorAll(".bcp_producto.activo .lazy_loading_demanda");fnlazy_loader_img_a_demanda(o),fnlazy_loader_backgroundImage_comp_demanda(a)}else header.classList.remove("activo"),e.classList.remove("activo"),t.setAttribute("aria-expanded","false")};document.addEventListener("click",e=>{if(globalThis.matchMedia("(min-width: 1280px)").matches&&!contenedorCategoria.contains(e.target)){header.classList.remove("activo");for(const e of header.querySelectorAll(".bcp_categoria.activo"))e.classList.remove("activo")}});const limpiarCaracteresHexaDecimales=e=>e=(e=(e=(e=e.replaceAll(/'/gm,"'")).replaceAll(/>/gm,"->")).replaceAll(/"/gm,'"')).replaceAll(/&/gm,"&"),procesarContenidoTraducido=e=>{if(!e)return;if(!e.translatedText)return;const t=e.translatedText.split(" | "),[o,a]=t.map(e=>e.trim()),r=document.querySelector(`[id-translate="${o}"]`);if(r){r.innerText=limpiarCaracteresHexaDecimales(a),r.removeAttribute("id-translate");for(const e of btnTraductores)e.classList.remove("activo");btnTraducirQuechua.classList.add("activo"),btnTraducirQuechua.classList.remove("procesando"),traducidoQuechuaMobile.parentNode.parentNode.classList.remove("procesando")}},ejecutarTraduccionContenidoPorGrupos=async e=>{if(e&&0!==e.length)try{await gapi.client.init({apiKey:API_KEY_TRADUCTOR,discoveryDocs:[URL_API_TRADUCTOR]});const t=(await gapi.client.language.translations.translate({q:e,source:"es",target:"qu"})).result.data.translations;if(t)for(const e of t)procesarContenidoTraducido(e)}catch(e){console.log("Error: "+e.result.error.message)}},forzarTraduccionComponentesImportantes=e=>["bcp_header_principal","bcp_footer_ayuda_flotante"].some(t=>e.classList.contains(t));let idTranslate=1;const isComponentVisible=(e,t)=>{const o=e.getBoundingClientRect(),a=t?globalThis.innerHeight:o.top,r=t?0:o.bottom;return a<=globalThis.innerHeight&&r>=0},traducirContenidoEspaniolQuechua=()=>{if("true"!==getCookie("bcp_traducir_quechua"))return;const e=document.querySelectorAll('[data-translate-comp="true"]');for(const t of e)procesarComponenteTraduccion(t)},procesarComponenteTraduccion=e=>{const t=forzarTraduccionComponentesImportantes(e);if(!isComponentVisible(e,t))return;const o=obtenerContenidoTraducir(e);enviarContenidoPorGrupos(o)},obtenerContenidoTraducir=e=>{const t=e.querySelectorAll('[data-translate="true"]'),o=[];for(const e of t){const t=e.textContent?.trim();t&&(o.push(`${idTranslate} | ${t}`),e.setAttribute("id-translate",idTranslate),delete e.dataset.translate,idTranslate++)}return o},enviarContenidoPorGrupos=e=>{let t=[];for(const[o,a]of e.entries()){t.push(a);(o+1)%100==0&&(ejecutarTraduccionContenidoPorGrupos(t),t=[])}t.length>0&&ejecutarTraduccionContenidoPorGrupos(t)};header.querySelector(".bcp_nivel2").addEventListener("scroll",()=>{const e=header.querySelector(".bcp_tipo_cliente.mobile").getBoundingClientRect().top,t=header.querySelector(".bcp_nivel1_mobile");e<64?t.classList.add("boxShadow"):t.classList.remove("boxShadow")});let posicionUltimaScroll=globalThis.scrollY,isScrolling=!1;const estaEnPersonasPymes=()=>"https://www.viabcp.com"===document.querySelector('link[rel="canonical"]').getAttribute("href")||"/pymes"===globalThis.location.pathname,mostrarBotonFixedInferior=e=>{const t=document.querySelector(".bcp_boton_abre_cuenta_inferior");t&&(estaEnPersonasPymes()&&e?t.classList.add("mostrar"):t.classList.remove("mostrar"))},mostrarOcultarFlotante=e=>{const t=document.querySelector(".bcp_footer_ayuda_flotante");t&&(e?t.classList.remove("hide"):t.classList.add("hide"))},obtenerAltoComenzarScroll=()=>globalThis.matchMedia("(min-width: 1280px)").matches?obtenerAltoCintillo():300,reglasCintilloBotonFixedInferior=()=>{const e=globalThis.scrollY,t=document.querySelector(".bcp_contenedor_derecho_reservado"),o=document.querySelector(".bcp_footer_ayuda_flotante"),a=obtenerAltoComenzarScroll(),r=()=>{aplicarMarginTopCintillo(-1*obtenerAltoCintillo())};return e0&&(cintillo.classList.remove("activo"),r(),mostrarBotonFixedInferior(!0),mostrarOcultarFlotante(!0)),isScrolling=!1,void(posicionUltimaScroll=e+obtenerAltoCintillo())):(posicionUltimaScroll-a>0&&(cintillo.classList.remove("activo"),r(),mostrarBotonFixedInferior(!0),mostrarOcultarFlotante(!0),isScrolling=!1,posicionUltimaScroll=e+obtenerAltoCintillo()),e>posicionUltimaScroll&&e>a&&posicionUltimaScroll-a>0&&(cintillo.classList.remove("activo"),r(),mostrarBotonFixedInferior(!0),o.classList.remove("hide")),posicionUltimaScroll=e,void(isScrolling=!1))},reglasCintilloBotonFixedInferiorScroll=()=>{isScrolling||(isScrolling=!0,setTimeout(()=>{reglasCintilloBotonFixedInferior()},200))},reniciarCategoriaMobile=()=>{for(const e of header.querySelectorAll(".bcp_categoria"))globalThis.matchMedia("(min-width: 1280px)").matches?e.querySelector(".bcp_productos").removeAttribute("style"):(e.classList.remove("activo"),header.classList.remove("activo"),slideUp(e.querySelector(".bcp_productos"),0))},btnInferiorAbreCuenta=document.querySelector(".bcp_boton_abre_cuenta_inferior a");if(btnInferiorAbreCuenta){const e=btnInferiorAbreCuenta.querySelector(".bcp_texto").innerText;btnInferiorAbreCuenta.addEventListener("click",t=>{digitalData.push({action:{group:"Header",category:"Barra fixed",name:"Click",label:cleanLabel(e)},event:"trackAction"})}),btnInferiorAbreCuenta.href=btnInferiorAbreCuenta.href+obteberRfId("botones principales","button",e)}document.body.addEventListener("keydown",e=>{"Tab"===e.key&&document.body.classList.add("focus-tab")}),document.addEventListener("DOMContentLoaded",async()=>{const e=['a[aria-haspopup="true"]','.wpthemeMenuDropDown [role="menuitem"]',".wpthemeMenuDropDown",".ibmPortalControl",".wpthemeFrame",".wpthemeMainContent",".ibmPortalControl",".wpthemeControlHeader",".wpthemeComplementaryContent"];for(const t of e)for(const e of document.querySelectorAll(t))e.removeAttribute("aria-label"),e.removeAttribute("aria-labelledby"),e.setAttribute("tabindex","-1"),e.removeAttribute("role")});const pageIdWcm=document.querySelector('.wpthemeMainContent ._wpthemeInner_ [id="asa.page"]');pageIdWcm&&pageIdWcm.remove();const handleTransitionEndCintillo=()=>{aplicarAltoHeaderMenu(!0)};cintillo.addEventListener("transitionend",handleTransitionEndCintillo);const aplicarAltoHeaderMenu=(e=!0)=>{if(globalThis.scrollY>obtenerAltoComenzarScroll())return;const t=header.offsetHeight;header.parentNode.style.marginBottom=`${t}px`,e&&(header.parentNode.style.transition="margin-bottom .2s linear")},refreshAltoHeader=()=>{aplicarAltoHeaderMenu()},observerAltoHeader=new MutationObserver(()=>{aplicarAltoHeaderMenu()}),observerOptions={childList:!0,attributeFilter:["style"]};observerAltoHeader.observe(cintillo,observerOptions),aplicarAltoHeaderMenu(!1);const mediaQueryMobile=globalThis.matchMedia("(max-width: 767px)"),mediaQueryTablet=globalThis.matchMedia("(min-width: 768px) and (max-width: 1279px)"),mediaQueryDesktop=globalThis.matchMedia("(min-width: 1280px)"),handleResponsiveChange=()=>{aplicarAltoHeaderMenu(!1)};async function loadGoogleApiScript(){const e=await fetch("https://apis.google.com/js/api.js");if(e.ok){const t=await e.text(),o=document.createElement("script");o.textContent=t,document.head.appendChild(o)}else console.error("Error loading Google Api script:",e.statusText)}mediaQueryMobile.addEventListener("change",handleResponsiveChange),mediaQueryTablet.addEventListener("change",handleResponsiveChange),mediaQueryDesktop.addEventListener("change",handleResponsiveChange),globalThis.addEventListener("scroll",()=>{setTimeout(()=>{apiLoadApiTraducir()},500),reglasCintilloBotonFixedInferiorScroll()}),globalThis.addEventListener("resize",()=>{apiLoadApiTraducir(),reniciarCategoriaMobile(),reglasCintilloBotonFixedInferior()}),globalThis.addEventListener("orientationchange",()=>{apiLoadApiTraducir(),reglasCintilloBotonFixedInferior()}),document.addEventListener("DOMContentLoaded",function(){loadGoogleApiScript()}),globalThis.addEventListener("load",function(){ibmPortalConfig.isUserLoggedIn&&header.classList.add("preprod")});