!function(e){var n={};function t(o){if(n[o])return n[o].exports;var a=n[o]={i:o,l:!1,exports:{}};return e[o].call(a.exports,a,a.exports,t),a.l=!0,a.exports}t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var a in e)t.d(o,a,function(n){return e[n]}.bind(null,a));return o},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=0)}([function(e,n,t){"use strict";let o;t.r(n);var a=o={updateArticles:function(e){e.detail.nodes.length>0&&e.detail.nodes.forEach(e=>{e.classList.add("ue-c-cover-content--is-new")})},appendGenericMessage:function(){const e=window.document.createElement("div"),n=document.createTextNode("Contenido Actualizado");e.appendChild(n),e.style.cssText="\n position: fixed;\n top: 64px;\n left: 50%;\n transform: translateX(-50%);\n height: 35px;\n width: 190px;\n display: flex;\n justify-content: center;\n align-items: center;\n font-size: 12px;\n border-radius: 20px;\n background-color: #ffffff;\n border: 1px solid #d0d0d0;\n color: #666666;\n font-weight: 500;\n box-shadow: none;\n font-family: 'Roboto', sans-serif;\n ";const t=document.getElementsByTagName("body")[0];t.insertBefore(e,t.childNodes[0]),setTimeout(()=>{e.remove()},2e3)},observeArticle:function(e){const n=new IntersectionObserver((function(e){e[0].intersectionRatio>=.2&&(e[0].target.classList.add("ue-c-cover-content--in-viewport"),e[0].target.addEventListener("animationend",()=>{e[0].target.classList.remove("ue-c-cover-content--in-viewport"),n.unobserve(e[0].target)}))}),{root:null,rootMargin:"-160px 0px -60% 0px",threshold:.2}),t=e.detail.articleNode;n.observe(t)}};const i={authLambda:"https://diok7qf6vb.execute-api.eu-west-1.amazonaws.com/default/jwt_auth",tokenStorage:"RetuxToken",graceSeconds:600,discoveryComponentsEvent:"discoveryRetuxComponent",completeDiscoveryComponentEvent:"discoveryCompleteRetuxComponent",activeChannelsUrl:"https://components.unidadeditorial.es/lib/retux/cli-engine/v1/em_active_channels.json",realtimeConnectionWaitSeconds:30,tokenExpirationSeconds:3600,globalVarRegisteredRetuxComponents:"retuxDiscoverComponents",globalVarCompleteRegisteredRetuxComponents:"retuxRegisteredComponents"},r={refreshBadge:{name:"ELMUNDO REALTIME CHANNELS",componentName:"refreshBadge",host:"www.elmundo.es",url_path:{"/":{channels:[{channelName:"em_homepage_refresh_premium",profiles:[{profile:"heavy-user"},{profile:"heavy-plus"},{profile:"default",cond:{"max-messages":1,ttl:"86400",field:"isPremium",field_value:!0,storage:"retux_refreshBadge"}}]},{channelName:"em_homepage_refresh"}],channelsEvaluation:"unique"},"/pruebas-abierto/rafa/retux/":{channels:[{channelName:"em_homepage_refresh_premium",profiles:[{profile:"heavy-user"},{profile:"heavy-plus"},{profile:"default",cond:{"max-messages":1,ttl:"86400",field:"isPremium",field_value:!0,storage:"retux_refreshBadge"}}]},{channelName:"em_homepage_refresh"}],channelsEvaluation:"unique"}}},retuxInbox:{name:"ELMUNDO REALTIME INBOX",componentName:"retuxInbox",host:"www.elmundo.es",url_path:{"*":{channels:[{channelNamePrefix:"em_messages",channelNameSuffixes:["*"],profiles:[{profile:"heavy-user"},{profile:"heavy-plus"},{profile:"premium"}]},{channelNamePrefix:"em_articles",channelNameSuffixes:["/","espana","andalucia","madrid","cataluna","comunidad-valenciana","baleares","pais-vasco","economia","internacional","deportes","deportes/futbol","deportes/tenis","deportes/baloncesto","deportes/ciclismo","deportes/formula-1","deportes/motociclismo","cultura","cultura/cine","cultura/musica","cultura/toros","cultura/laesferadepapel","cultura/literatura","cultura/teatro","loc","tecnologia","nosotras","television","ciencia-y-salud","bazar","cronica","papel","f5","viajes","yodona","yodona/moda","yodona/lifestyle","yodona/fitness","yodona/belleza","yodona/horoscopo","yodona/pareja","yodona/celebrieties","yodona/valientes","vida-sana","vida-sana/sexo","vida-sana/familia","metropoli","metropoli/otros-planes","metropoli/cine","metropoli/gastronomia","metropoli/restaurantes","metropoli/teatro","metropoli/musica","motor","motor/anuario-moto","opinion","blogs"],profiles:[{profile:"espana"},{profile:"madrid"},{profile:"andalucia"},{profile:"baleares"},{profile:"cataluna"},{profile:"comunidad-valenciana"},{profile:"pais-vasco"},{profile:"economia"},{profile:"internacional"},{profile:"opinion"},{profile:"deportes"},{profile:"deportes/futbol"},{profile:"deportes/baloncesto"},{profile:"deportes/ciclismo"},{profile:"deportes/tenis"},{profile:"deportes/formula-1"},{profile:"motociclismo"},{profile:"loc"},{profile:"loc/casa-real"},{profile:"loc/celebrities"},{profile:"television"},{profile:"ciencia-y-salud"},{profile:"yodona"},{profile:"yodona/moda"},{profile:"yodona/belleza"},{profile:"yodona/lifestyle"},{profile:"yodona/valientes"},{profile:"yodona/horoscopo"},{profile:"yodona/fitness"},{profile:"yodona/pareja"},{profile:"cultura"},{profile:"cine"},{profile:"musica"},{profile:"toros"},{profile:"la-esfera-de-papel"},{profile:"literatura"},{profile:"metropoli"},{profile:"f5"},{profile:"papel"},{profile:"bazar"},{profile:"viajes"},{profile:"motor"},{profile:"vida-sana"},{profile:"vida-sana/sexo"},{profile:"vida-sana/familia"},{profile:"cronica"},{profile:"tecnologia"}]}],channelsEvaluation:"multiple"}}}};class l{getConfig(e){return r[e]}getNavigationConfig(e,n){let t=null;if(e&&n){let o=this.getConfig(e);if(!o)throw new Error("[RetuxCliConfigChannel]: Error, no config found for component : "+e);if(n&&o&&o.url_path)if(o.url_path[n])t=o.url_path[n];else{if(!o.url_path["*"])throw new Error("[RetuxCliConfigChannel]: Error, no channel found for component : "+e+" in the url: "+n);t=o.url_path["*"]}}return t}}class s{constructor(){this.realtime,this.localToken,this.activeChannelListInfo,this.activeChannelsList="",this.activeConnection=!1}async init(){if(this.localToken=this._getTokenFromStorage(),i&&i.activeChannelsUrl)try{if(this.activeChannelListInfo=await this.obtainActiveChannelListInfo(i.activeChannelsUrl),this.activeChannelListInfo.stopRetux||!this.activeChannelListInfo.activeChannels)throw new Error("[RetuxCli]: No realizamos conexion a realtime provider debido a parametro de configuraciĆ³n");this.activeChannelsList=this.activeChannelListInfo.activeChannels}catch(e){throw new Error(e)}}_getTokenFromStorage(){let e=!1;if(!i||!i.tokenStorage)throw new Error("[RetuxCli]: Error, no config for retux tokenStorage");try{localStorage.getItem(i.tokenStorage)&&(e=JSON.parse(localStorage.getItem(i.tokenStorage)))}catch(e){throw new Error("[RetuxCli]: Error in parsing localStorage token")}return e}_setTokenToStorage(e){if(e&&i&&i.tokenStorage)try{localStorage.setItem(i.tokenStorage,JSON.stringify(e))}catch(e){throw new Error("[RetuxCli]: Error almacenando token in Storage "+e)}}connectToRealTime(e){let n="";if(!i||!i.authLambda)throw new Error(" Error, no config for retux auth lambda");n=i.authLambda;let t=3e4;i&&i.realtimeConnectionWaitSeconds&&(t=1e3*i.realtimeConnectionWaitSeconds),window.setTimeout(()=>{let t=!1;if(this.activeChannelListInfo&&this.activeChannelListInfo.stopRetux)throw new Error("[RetuxCli]: No realizamos conexion a realtime provider debido a parametro de configuraciĆ³n");{let o=(new Date).getTime()-1e3*i.graceSeconds;this.localToken&&this.localToken.token&&this.localToken.timestamp&&!(this.localToken.timestamp<=o)||(t=!0),this._realtimeConnectionWrapper(n,t).then(n=>{this.realtime=n,this.realtimeConnectionCallback(e)}).catch(e=>{console.error(e.message)})}},t)}async _realtimeConnectionWrapper(e,n){let t;try{t=n?await this._revalidateToken():this.localToken.token;let o=new Ably.Realtime({token:t,authUrl:e});return Promise.resolve(o)}catch(e){return Promise.reject(e)}}_revalidateToken(){let e="";if(!i||!i.authLambda)throw new Error(" Error, no config for retux auth lambda");return e=i.authLambda,fetch(e).then(e=>e.json()).then(e=>{let n=new Date,t=i&&i.tokenExpirationSeconds?i.tokenExpirationSeconds:"3600";n.setTime(n.getTime()+1e3*t);const o={token:e,timestamp:n.getTime()};return this._setTokenToStorage(o),e}).catch(e=>{throw new Error("[RetuxCli]: Fetching lambda JWT failed.")})}disconnectChannel(e){e&&e.unsubscribe()}realtimeConnectionCallback(e){this.realtime.connection.once("connected",()=>{this.activeConnection=!0,e&&e()})}createRealtimeChannelCommunication(e,n,t,o,a){if(this.realtime&&e&&n){if(this.isChannelActive(e)){let i=this.realtime.channels.get(e);return i.subscribe(e=>{let i=e.data.payload;const r=new CustomEvent(n,{detail:i});window.document.dispatchEvent(r),a&&o&&t&&a(e,t,o)}),i}return-1}return-2}async obtainActiveChannelListInfo(e){if(e)return fetch(e).then(e=>e.json()).then(e=>e).catch(e=>{throw new Error("[RetuxCli]: Fetching Active channels fail.")});throw new Error("[RetuxCli]: Error no channelsUrl parameter in obtainActiveChannel.")}isChannelActive(e){let n="";if(e.includes(":")){n=e.split(":")[0]}else n=e;return!(!this.activeChannelsList||!this.activeChannelsList.includes(n))}}const c={storageKey:"dmpue_segs",profiles:[{name:"heavy-user",value:"f0e"},{name:"heavy-plus",value:"7kp"},{name:"espana",value:"gxl"},{name:"madrid",value:"010"},{name:"andalucia",value:"185"},{name:"baleares",value:"mam"},{name:"cataluna",value:"hgz"},{name:"comunidad-valenciana",value:"xc3"},{name:"pais-vasco",value:"3ds"},{name:"economia",value:"m4q"},{name:"internacional",value:"az4"},{name:"opinion",value:"l6p"},{name:"deportes",value:"jl4"},{name:"deportes/futbol",value:"ver"},{name:"deportes/baloncesto",value:"j14"},{name:"deportes/ciclismo",value:"rqd"},{name:"deportes/tenis",value:"h1i"},{name:"deportes/formula-1",value:"vw7"},{name:"motociclismo",value:"bcm"},{name:"loc",value:"600"},{name:"loc/casa-real",value:"6zf"},{name:"loc/celebrities",value:"rlq"},{name:"television",value:"9f9"},{name:"ciencia-y-salud",value:"op4"},{name:"yodona",value:"7ye"},{name:"yodona/moda",value:"gqw"},{name:"yodona/belleza",value:"1im"},{name:"yodona/lifestyle",value:"k7z"},{name:"yodona/valientes",value:"2j5"},{name:"yodona/horoscopo",value:"ylm"},{name:"yodona/fitness",value:"hbg"},{name:"yodona/pareja",value:"2f5"},{name:"cultura",value:"0p1"},{name:"cine",value:"2aa"},{name:"musica",value:"bwt"},{name:"toros",value:"tmu"},{name:"la-esfera-de-papel",value:"ll2"},{name:"literatura",value:"e99"},{name:"metropoli",value:"yde"},{name:"f5",value:"540"},{name:"papel",value:"llm"},{name:"bazar",value:"k9k"},{name:"viajes",value:"51y"},{name:"motor",value:"51y"},{name:"zen",value:"5h3"},{name:"zen/sexo",value:"ygb"},{name:"cronica",value:"ygb"},{name:"tecnologia",value:"qry"},{name:"default"}],premiumStorageKey:"suscriptor",premiumField:"isPremium"};class m{constructor(){this.retux_user_profile=[]}initUserProfiles(){let e=[];if(c&&c.storageKey&&c.profiles&&c.profiles.length)try{let n=localStorage.getItem(c.storageKey);c.profiles.forEach(t=>{t.name&&(t.value?n&&n.includes(t.value)&&(e[t.name]=!0):e[t.name]=!0)})}catch(e){throw new Error("Error accediendo a localStorage en profiles:"+e)}this._isUserPremium(c)&&(e.premium=!0),this.retux_user_profile=e}_isUserPremium(){if(c&&c.premiumStorageKey&&c.premiumField)try{let e=c.premiumField,n=c.premiumStorageKey,t=sessionStorage.getItem(n);if(t){let n=JSON.parse(t.toString());if(n&&n[e])return!0}}catch(e){throw new Error("[Retux-cli]: no sessionStorage or invalid premium parse")}return!1}userMatchProfile(e){return!!(e&&this.retux_user_profile&&this.retux_user_profile[e])}}class u{constructor(){this.componentsRegistration=[],this.retuxComponents=[],this.realtimeProv,this.retuxUserProfiles,this.retuxNavigation,this.componentChannels}async initRetuxCli(){if(!this.isStorageAvailable())throw new Error("[RetuxCli]: Error, no localStorage available. Stop connecting.");try{this.realtimeProv=new s;await this.realtimeProv.init();this.retux_navigation=this.obtainCurrentNavigationChannelInfo(),this.retuxUserProfiles=new m,this.retuxUserProfiles.initUserProfiles(),this.componentChannels=new l,this.manageDiscovery(),this.realtimeProv.connectToRealTime(this.onConnectionCallback.bind(this))}catch(e){throw e}}obtainCurrentNavigationChannelInfo(){let e="",n="";if(window.location&&window.location.pathname&&window.location.host)return e=window.location.pathname,"/index.html"===e&&(e=e.replace(/index\.html/g,"")),n=window.location.host,e}onConnectionCallback(){this.componentsRegistration.forEach(e=>{e.componentName&&e.internalCustomEvent&&this.connectToChannel(e.componentName)})}manageDiscovery(){if(!i||!i.discoveryComponentsEvent)throw new Error("[RetuxCli]: Error no config for Retux Discovery Event.");window.document.addEventListener(i.discoveryComponentsEvent,e=>{e&&e.detail&&this.handleDiscoveryComponent(e.detail)}),this.manageAlreadyRegisteredComponents()}manageAlreadyRegisteredComponents(){i&&i.globalVarRegisteredRetuxComponents&&window[i.globalVarRegisteredRetuxComponents]&&window[i.globalVarRegisteredRetuxComponents].length&&window[i.globalVarRegisteredRetuxComponents].map(e=>{this.handleDiscoveryComponent(e)})}isStorageAvailable(){try{return localStorage.setItem("test","test"),localStorage.removeItem("test"),!0}catch(e){return!1}}async handleDiscoveryComponent(e){if(e&&e.componentName){let t,o=e.componentName;if(this.componentsRegistration.push(e),this.retuxComponents[o])return;switch(this.retuxComponents[o]={},e.internalCustomEvent&&(this.retuxComponents[o].internalCustomEvent=e.internalCustomEvent),e.internalDisconnectCustomEvent&&(this.retuxComponents[o].internalDisconnectCustomEvent=e.internalDisconnectCustomEvent),e.internalCustomEvent&&(t=this.obtainRealtimeChannel(this.retux_navigation,o)),t&&t.length>0&&(this.retuxComponents[o].channels=[],t.forEach(e=>{let n={};n.channelName=e.channelName,n.channelType=e.type,t.condition&&(n.condition=e.condition),this.retuxComponents[o].channels.push(n)})),e.componentName){case"refreshBadge":e.internalDisconnectCustomEvent&&"function"==typeof a.appendGenericMessage&&window.document.addEventListener("em-retux-refresh-badge-disconnected",()=>{this.disconnectChannel(o,a.appendGenericMessage)});break;case"recentArticles":"function"==typeof a.updateArticles&&window.document.addEventListener("em-retux-refresh",a.updateArticles),"function"==typeof a.observeArticle&&window.document.addEventListener("em-retux-link-clicked",a.observeArticle)}if(i&&i.globalVarCompleteRegisteredRetuxComponents&&(window[i.globalVarCompleteRegisteredRetuxComponents]=window[i.globalVarCompleteRegisteredRetuxComponents]||[],window[i.globalVarCompleteRegisteredRetuxComponents].push(e.componentName)),i&&i.completeDiscoveryComponentEvent){var n=new CustomEvent(i.completeDiscoveryComponentEvent,{detail:{componentName:e.componentName}});window.document.dispatchEvent(n)}this.realtimeProv.activeConnection&&e.internalCustomEvent&&this.connectToChannel(o)}}checkConditionAfterMessageReceived(e,n,t){let o=1,a=!0;if(t&&t.storage&&t.ttl&&t["max-messages"]&&(t.field&&(o=0,a=!1,e&&e.data&&e.data.payload&&e.data.payload.forEach(e=>{e[t.field]==t.field_value&&(o++,a=!0)})),a)){try{let e=JSON.parse(localStorage.getItem(t.storage))||{};!e||!e.timestamp||e.timestamp+t.ttl<(new Date).getTime()?(e.counter=o,e.timestamp=(new Date).getTime()):e.counter?e.counter+=o:e.counter=o,localStorage.setItem(t.storage,JSON.stringify(e))}catch(e){throw new Error("Excepcion Storage:"+e)}let e=this.obtainRealtimeChannel(this.retux_navigation,n);e&&e.channelName&&e.channelName!==this.retuxComponents[n].channelName&&this.changeRealTimeChannel(n,e)}}obtainRealtimeChannel(e,n){try{let t=this.componentChannels.getNavigationConfig(n,e);if(null==t)throw new Error("No active channel for given navigation path or profile");return this.getRealtimeChannel(t,e)}catch(e){return null}}getRealtimeChannel(e,n){if(e&&e.channels&&e.channels.length)return e.channelsEvaluation&&"multiple"==e.channelsEvaluation?this.getRealtimeChannelMultiple(e,n):this.getRealtimeChannelUnique(e)}getRealtimeChannelMultiple(e,n){let t=[],o=[];return e.channels.forEach(e=>{let a={};if(e.channelNamePrefix&&e.channelNameSuffixes&&e.channelNameSuffixes.length&&n){let i=-1,r=!1,l=!1;if(1==e.channelNameSuffixes.length&&"*"==e.channelNameSuffixes[0])l=!0;else{let t=/(.*)\/[0-9]{4}\/[0-9]{2}\/[0-9]{2}.*\.html/gim.exec(n);if(t&&t.length>1&&""!=t[1]){let o=t[1].substring(1,n.length);i=e.channelNameSuffixes.indexOf(o)}else if("/"==n)r=!0;else{let t=n.substring(1,n.length).replace(".html","");i=e.channelNameSuffixes.indexOf(t)}}i<0&&r&&"/"==n||i<0&&l?a.channelName=e.channelNamePrefix:i>=0&&(1==e.channelNameSuffixes.length&&"*"==e.channelNameSuffixes[0]?a.channelName=e.channelNamePrefix:a.channelName=e.channelNamePrefix+":"+e.channelNameSuffixes[i]),a.channelName&&o.indexOf(a.channelName)<0&&(a.type="nav",t.push(a),o.push(a.channelName))}e.channelNamePrefix&&e.profiles?e.profiles&&e.profiles.forEach(n=>{if(a={},n.profile&&this.retuxUserProfiles.userMatchProfile(n.profile)){if(n.cond){let t=n.cond;this.evaluateConditions(t)&&(a.channelName=e.channelNamePrefix+":"+n.profile,a.condition=t)}else a.channelName=e.channelNamePrefix+":"+n.profile;a.type="profile",o.indexOf(a.channelName)<0&&(t.push(a),o.push(a.channelName))}}):e.channelName&&!e.profiles&&(a.channelName=e.channelName,t.push(a))}),t}getRealtimeChannelUnique(e){let n={},t=!1;return e.channels.forEach(e=>{if(!t)if(e.channelName&&!e.profiles)n.channelName=e.channelName,n.type="nav",t=!0;else if(e.profiles){let o=e.profiles,a=!1;o.forEach(o=>{if(!a&&o.profile&&this.retuxUserProfiles.userMatchProfile(o.profile))if(o.cond){let i=o.cond;this.evaluateConditions(i)&&(a=!0,t=!0,n.channelName=e.channelName,n.condition=i,n.type="profile")}else a=!0,t=!0,n.channelName=e.channelName,n.type="profile"})}}),[n]}evaluateConditions(e){let n;if(e&&e.storage){try{if(n=JSON.parse(localStorage.getItem(e.storage)),!n)return!0;if(e.ttl){if(n.timestamp&&n.timestamp+1e3*e.ttl<(new Date).getTime())return!0;if(e["max-messages"]&&(!n.counter||n.counter{let o;o=t.condition?this.realtimeProv.createRealtimeChannelCommunication(t.channelName,n.internalCustomEvent,e,t.condition,this.checkConditionAfterMessageReceived.bind(this)):this.realtimeProv.createRealtimeChannelCommunication(t.channelName,n.internalCustomEvent,e),this.retuxComponents[e].providerChannels.push(o)})}}reactToContentLoaded(e,n){n&&n.detail&&0===n.detail.nIndex&&this.realtimeProv.activeConnection&&e&&this.retuxComponents&&this.retuxComponents[e]&&""===this.retuxComponents[e].channel&&this.connectToChannel(e)}}try{(new u).initRetuxCli()}catch(e){console.log("Error retux: "+e)}}]);