text: "use strict";let inputName=document.querySelector(".js-inputName");const button=document.querySelector(".js-button");let results=document.querySelector(".js-results"),favSeries=document.querySelector(".js-favs");const resetBtn=document.querySelector(".js-btnReset");let seriesList=[],favorites=[];const getDataFromApi=()=>{const e=inputName.value;fetch("http://api.tvmaze.com/search/shows?q="+e).then(e=>e.json()).then(e=>{seriesList=e,console.log(seriesList),paintSeriesCatalogue()}).catch(e=>{console.log("Ha habido un error",e)})};function fullInputSearch(e){if(""===inputName.value)return alert("Write a serie name")}button.addEventListener("click",fullInputSearch);const paintSeriesCatalogue=()=>{let e="";for(let t=0;t<seriesList.length;t+=1){let s=seriesList[t],i="";s===favorites[t]&&(i="color"),e+=`<article class="serie serie__btn js-selectFav ${i}" id="${s.show.id}" data-index="${t}" data-id="${s.show.id}">`,null!==s.show.image?e+=`<img src="${s.show.image.medium}  " class="serie__img" alt="${s.show.name} " />`:e+=`<img src="https://via.placeholder.com/210x295/ffffff/666666/?text=TV" class="serie__img" alt="${s.show.name} " />`,e+=`<h4 class="serie__title">${seriesList[t].show.name} </h4>`,e+=`<h5 class="serie__title">${seriesList[t].show.premiered} </h5>`,e+="</article>"}document.querySelector(".js-results").innerHTML=e;listenSearchClick()},listenSearchClick=()=>{const e=document.querySelectorAll(".js-selectFav");for(let t of e)t.addEventListener("click",saveFavorites)};function saveFavorites(e){const t=parseInt(e.currentTarget.id),s=seriesList.find(e=>e.show.id===t);favorites.push(s),paintSeriesFavorites(),saveInfo(),resetBtn.innerHTML='<button class="finder__btn">Reset</>'}const paintSeriesFavorites=e=>{let t="";for(let e=0;e<favorites.length;e+=1){let s=favorites[e];t+='<li class= "list">',t+=`<article class="serieFav" id="${s.show.id}"\n            data-index="${e}"\n            data-id="${s.show.id}">`,null!==s.show.image?t+=`<img src="${s.show.image.medium}  " class="serie__img" alt="${s.show.name} " />`:t+=`<img src="https://via.placeholder.com/210x295/ffffff/666666/?text=TV" class="serie__img" alt="${s.show.name} " />`,t+=`<h4 class="serie__title">${favorites[e].show.name}     </h4>`,t+="</article>",t+="</li>"}document.querySelector(".js-favs").innerHTML=t};button.addEventListener("click",getDataFromApi),button.addEventListener("click",paintSeriesCatalogue),getInfo(favorites);const resetFavorites=e=>{console.log("me han clickado"),favorites=[],saveInfo(),paintSeriesFavorites(),listenSearchClick(),resetBtn.classList.add("hidden")};function saveInfo(){localStorage.setItem("favoriteSerie",JSON.stringify(favorites))}function getInfo(){const e=JSON.parse(localStorage.getItem("favoriteSerie"));null!==e&&(favorites=e)}resetBtn.addEventListener("click",resetFavorites);