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