text: "use strict";let series=[],favSeries=[];const searchInput=document.querySelector(".js-input"),searchBtn=document.querySelector(".js-button"),apiUrl="https://api.jikan.moe/v3/search/anime?q=",seriesContainer=document.querySelector(".js-animeSeries"),favSeriesContainer=document.querySelector(".js-favSeriesContainer"),resetBtn=document.querySelector(".js-button-reset"),deleteAllFavBtn=document.querySelector(".js-btn-delete-allFav"),handleClickSearchBtn=()=>fetch(apiUrl+searchInput.value).then(e=>e.json()).then(e=>{series=e.results,paintSeries()}),getSeriesHtml=e=>{let t=!1;for(const a of favSeries)if(e.mal_id===a.id){t=!0;break}let a="";return a+=`<li class="${t?"favSeries":""} page__list--serie"><p class="page__list--serieTitle">${e.title}</p>`,e.image_url?a+=`<img class="images" src="${e.image_url}">`:a+="<img src='https://via.placeholder.com/210x295/ffffff/666666/?text=image%20not%20found'>",a+=`<button class="js-favbutton btn__fav--add"data-id="${e.mal_id}" data-image_url=\n  "${e.image_url}" data-title="${e.title}">Añadir a favoritos</button>`,a+="</li>",a},paintSeries=()=>{let e="";for(const t of series)e+=getSeriesHtml(t);seriesContainer.innerHTML=e,addFavBtnListeners()},addFavBtnListeners=()=>{const e=document.querySelectorAll(".btn__fav--add");for(const t of e)t.addEventListener("click",handleClickFavBtn);setInLocalStorage()},handleClickFavBtn=e=>{e.target.parentNode.classList.add("favSeries");let t=e.target.dataset.image_url,a=e.target.dataset.title,i=e.target.dataset.id,s=!1;for(const e of favSeries)if(i===e.id){s=!0;break}if(s){e.target.parentNode.classList.remove("favSeries");const t=favSeries.indexOf(i);favSeries.splice(t,1)}else favSeries.push({id:i,title:a,imageUrl:t});paintFavSeries(),setInLocalStorage()},paintFavSeries=()=>{favSeriesContainer.innerHTML="";for(const e of favSeries)favSeriesContainer.innerHTML+=getFavSerieHtml(e),deleteAllFavBtn.classList.remove("hidden");addFavBtnDeleteListeners()},addFavBtnDeleteListeners=()=>{const e=document.querySelectorAll(".js-delete-favBtn");for(const t of e)t.addEventListener("click",handleClickDeleteFavBtn)},getFavSerieHtml=e=>{let t="";return t+=`<li data-id=>${e.title}</li>`,t+="<div>",t+=`<img class="images" src="${e.imageUrl}"></img>`,t+=`<i class="fas fa-times-circle js-delete-favBtn btn__fav--delete" data-id="${e.id}"></i>`,t+="</div>",t},handleClickResetBtn=()=>{seriesContainer.innerHTML="",series=[]},handleClickDeleteFavBtn=e=>{let t=e.target.dataset.id;for(let e=0;e<favSeries.length;e++)t===favSeries[e].id&&favSeries.splice(e,1);paintFavSeries(),setInLocalStorage()},handleClickDeleteAllFavBtn=()=>{favSeriesContainer.innerHTML="",favSeries=[],deleteAllFavBtn.classList.add("hidden"),paintFavSeries(),paintSeries()},getFromLocalStorage=()=>{const e=localStorage.getItem("favSeries");null!==e&&(favSeries=JSON.parse(e),paintFavSeries())},setInLocalStorage=()=>{const e=JSON.stringify(favSeries);localStorage.setItem("favSeries",e)};getFromLocalStorage(),searchBtn.addEventListener("click",handleClickSearchBtn),resetBtn.addEventListener("click",handleClickResetBtn),deleteAllFavBtn.addEventListener("click",handleClickDeleteAllFavBtn);