$(()=>{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"),i=document.querySelector("#filter_input"),t=document.querySelector("#game_list"),r=document.querySelector("#game_modal"),u=document.querySelector("#game_modal_image"),e=document.querySelector("#game_modal_name"),f=document.querySelector("#game_modal_links");window.initializeRaceGames=o=>{$.ajax({type:"GET",url:`/mobile/race/games/${o.provider}`,contentType:"application/json; charset=utf-8",dataType:"json",success:s=>{const c=new Set,l=document.createDocumentFragment();s.forEach(n=>{c.add(n.category);const a=document.createElement("img");a.src=`${o.directoryPath}${o.provider}/${n.gameImage}`;a.alt=n.name;const s=document.createElement("div");s.className="wrapper-container";s.appendChild(a);const h=document.createElement("div");h.className="game-name-container";const v=document.createElement("div");v.className="game-name";v.innerText=n.name;h.appendChild(v);const i=document.createElement("li");if(i.className="game-item",i.dataset.game=n.name,i.dataset.category=n.category,n.isFavourite!==undefined&&n.isFavourite!==null){const t=document.createElement("input");t.type="checkbox";t.dataset.provider=o.provider;t.value=n.gameCode;t.id=n.gameCode;t.className="favourite-game-btn";n.isFavourite&&(t.checked=!0);const r=document.createElement("label");r.htmlFor=n.gameCode;o.altFavouriteBtnPosition?(h.appendChild(t),h.appendChild(r)):(i.appendChild(t),i.appendChild(r))}if(r)s.onclick=()=>{if(t.dataset.isLoggedIn==="true")window.location.href=n.link;else{u.src=a.src;u.alt=n.name;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=n.link;t.innerText=o.translations.playNow;i.appendChild(t);f.innerHTML="";f.appendChild(i);$(r).modal()}},i.appendChild(s),i.appendChild(h);else{const u=document.createElement("span");if(u.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);u.appendChild(t)}s.appendChild(u);const t=document.createElement("a");t.className="play-now";t.dataset.game=n.name;t.href=n.link;t.innerText=o.translations.playNow;u.appendChild(t);const f=document.createElement("input");f.type="radio";f.name="game-list-radio-button";const r=document.createElement("label");r.className="inner-game-item";r.appendChild(f);r.appendChild(s);r.appendChild(v);i.appendChild(r)}l.appendChild(i)});t.appendChild(l);const a=document.createDocumentFragment();c.forEach(n=>{const t=document.createElement("div");t.className="category-filter-link";t.dataset.category=n;t.innerText=n;a.appendChild(t)});n.appendChild(a);const p=t.querySelectorAll(".game-item"),h={name:null,category:null},v=()=>{Array.prototype.slice.call(p).forEach(n=>{const t=n.dataset.game.toLowerCase(),i=n.dataset.category,r=!h.category||i===h.category,u=!h.name||t.indexOf(h.name)>=0;r&&u?$(n).show():$(n).hide()})};$(i).keyup(function(){h.name=i.value.toLowerCase();v()});$(n).on("click",".category-filter-link",function(){const n=$(this);n.siblings().removeClass("active");n.addClass("active");h.category=this.dataset.category;v()});const y=new URLSearchParams(window.location.search).get("PromotionCategory");if(y){const t=Array.from(c).find(n=>n.toLowerCase()===y.toLowerCase());if(t){n.querySelector(`[data-category="${t}"]`).click();return}}}})}});