$(()=>{const n=document.getElementById("game_list"),t=()=>{n&&(n.onclick=n=>{if(n.target.className==="favourite-game-btn"){let t="";t=n.target.checked?"/game/new-favourite":"/game/remove-favourite";$.ajax({type:"POST",data:JSON.stringify({Provider:n.target.dataset.provider,GameCode:n.target.value}),url:t,contentType:"application/json; charset=utf-8",dataType:"json",success:t=>{t.errorCode!=0&&(n.target.checked=!n.target.checked,registerPopup({content:`Unable to update favourite game. ${t.message}`}))},error:()=>{n.target.checked=!n.target.checked,registerPopup({content:"Unable to update favourite game."})}})}})};t()}); $(()=>{const n=document.querySelector("#filter_categories"),t=document.querySelector("#filter_input"),i=document.querySelector("#game_list"),r=document.querySelector("#game_modal"),f=document.querySelector("#game_modal_image"),e=document.querySelector("#game_modal_name"),u=document.querySelector("#game_modal_links");window.initializeSlotGames=o=>{$.ajax({type:"GET",url:`/mobile/slots/games/${o.provider}`,contentType:"application/json; charset=utf-8",dataType:"json",success:s=>{const c=new Set,a=document.createDocumentFragment();s.forEach(n=>{n.categories.forEach(n=>c.add(n.name));const h=document.createElement("img");h.src=/bundles/Slots/`${o.directoryPath}${o.provider}/${n.gameImage}`;h.alt=n.name;const i=document.createElement("div");if(i.className="wrapper-container",i.appendChild(h),n.rtpValue!==null&&isFinite(n.rtpValue)){const u=document.createElement("span");u.className="rtp-title";u.innerText="RTP";const t=document.createElement("div");t.className="rtp-progress-bar";t.style.width=n.rtpValue.toFixed(2)+"%";n.rtpValue<60&&(t.dataset.rtp="low");n.rtpValue>=60&&n.rtpValue<=80&&(t.dataset.rtp="medium");n.rtpValue>80&&(t.dataset.rtp="high");const f=document.createElement("div");f.className="rtp-progress";f.appendChild(t);const e=document.createElement("span");e.className="rtp-percentage";e.innerHTML=n.rtpValue+"%";const r=document.createElement("div");r.className="rtp-container";r.appendChild(u);r.appendChild(f);r.appendChild(e);i.appendChild(r)}const s=document.createElement("div");s.className="game-name-container";const l=document.createElement("div");l.className="game-name";l.innerText=n.name;s.appendChild(l);const t=document.createElement("li");if(t.className="game-item",t.dataset.game=n.name,t._categories=n.categories.filter(n=>n.seqNo>=0),n.isFavourite!==undefined&&n.isFavourite!==null){const i=document.createElement("input");i.type="checkbox";i.dataset.provider=o.provider;i.value=n.gameCode;i.id=n.gameCode;i.className="favourite-game-btn";n.isFavourite&&(i.checked=!0);const r=document.createElement("label");r.htmlFor=n.gameCode;o.altFavouriteBtnPosition?(s.appendChild(i),s.appendChild(r)):(t.appendChild(i),t.appendChild(r))}if(r)i.onclick=()=>{f.src=/bundles/Slots/h.src;e.innerText=n.name;const i=document.createDocumentFragment();if(o.onDemoLinkClicked){const t=document.createElement("a");t.className="free-play";t.innerText=o.translations.demo;t.onclick=()=>o.onDemoLinkClicked(n.gameCode);i.appendChild(t)}const t=document.createElement("a");t.className="play-now";t.dataset.game=n.name;t.href=/bundles/Slots/n.link;t.innerText=o.translations.playNow;i.appendChild(t);u.innerHTML="";u.appendChild(i);$(r).modal()},t.appendChild(i),t.appendChild(s);else{const f=document.createElement("span");if(f.className="link-container",o.onDemoLinkClicked){const t=document.createElement("a");t.className="free-play";t.innerText=o.translations.demo;t.onclick=()=>o.onDemoLinkClicked(n.gameCode);f.appendChild(t)}i.appendChild(f);const r=document.createElement("a");r.className="play-now";r.dataset.game=n.name;r.href=/bundles/Slots/n.link;r.innerText=o.translations.playNow;f.appendChild(r);const e=document.createElement("input");e.type="radio";e.name="game-list-radio-button";const u=document.createElement("label");u.className="inner-game-item";u.appendChild(e);u.appendChild(i);u.appendChild(l);t.appendChild(u)}a.appendChild(t)});i.appendChild(a);const v=document.createDocumentFragment();c.forEach(t=>{if(t==="DEFAULT"){const i=n.querySelector('[data-category=""]');i.dataset.category=t;return}const i=document.createElement("div");i.className="category-filter-link";i.dataset.category=t;i.innerText=t;v.appendChild(i)});n.appendChild(v);const w=i.querySelectorAll(".game-item"),h={name:null,category:null},y=()=>{Array.prototype.slice.call(w).forEach(n=>{const i=n.dataset.game.toLowerCase(),t=n._categories.find(n=>n.name===h.category),r=!h.category||t!==undefined,u=!h.name||i.indexOf(h.name)>=0;r&&u?(n.style.order=t&&t.seqNo||0,$(n).show()):(n.style.order=0,$(n).hide())})};$(t).keyup(function(){h.name=t.value.toLowerCase();y()});$(n).on("click",".category-filter-link",function(){const n=$(this);n.siblings().removeClass("active");n.addClass("active");h.category=this.dataset.category;y()});const p=new URLSearchParams(window.location.search).get("PromotionCategory");if(p){const t=Array.from(c).find(n=>n.toLowerCase()===p.toLowerCase());if(t){n.querySelector(`[data-category="${t}"]`).click();return}}const l=n.querySelector(".active");l&&l.dataset.category!==""&&l.click()}})}});