$(()=>{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.initializeSlotGames=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/slots/games/${o.provider}`,contentType:"application/json; charset=utf-8",dataType:"json",success:h=>{const c=84,l=89,y=new Set,w=document.createDocumentFragment(),v=document.body.dataset.loggedIn;let b=[];v==="true"&&$.ajax({type:"POST",url:"/account/get-favourite-games",dataType:"json","async":!1,success:function(n){b=n}});h.forEach(n=>{n.categories.forEach(n=>y.add(n.name));const a=document.createElement("img");a.src=`${o.directoryPath}${o.provider}/${n.gameImage}`;a.alt=n.name;const i=document.createElement("div");if(i.className="wrapper-container",i.appendChild(a),n.rtpChanged!==null&&isFinite(n.rtpChanged.from)&&isFinite(n.rtpChanged.to)){const f=document.createElement("span");f.className="rtp-title";f.innerText="RTP";const t=document.createElement("div"),e=n.rtpChanged.from.toFixed(2),s=n.rtpChanged.to.toFixed(2);t.className="rtp-progress-bar";t.dataset.rtpFrom=e;t.dataset.rtpTo=s;t.style.width=e+"%";t.style.setProperty("--from-value",`${e}%`);t.style.setProperty("--to-value",`${s}%`);n.rtpChanged.from=c&&n.rtpChanged.from<=l&&t.style.setProperty("--from-color","var(--medium)");n.rtpChanged.from>l&&t.style.setProperty("--from-color","var(--high)");n.rtpChanged.to=c&&n.rtpChanged.to<=l&&t.style.setProperty("--to-color","var(--medium)");n.rtpChanged.to>l&&t.style.setProperty("--to-color","var(--high)");t.dataset.rtpFrom!="medium"&&t.dataset.rtpTo!="medium"?t.style.setProperty("--transition-color","var(--medium)"):t.style.setProperty("--transition-color","var(--from-color)");const o=document.createElement("div");o.className="rtp-progress";o.appendChild(t);const u=document.createElement("span");u.className="rtp-percentage";u.dataset.rtpFrom=Math.ceil(n.rtpChanged.from);u.dataset.rtpTo=Math.ceil(n.rtpChanged.to);const r=document.createElement("div");r.className="rtp-container";r.appendChild(f);r.appendChild(o);r.appendChild(u);i.appendChild(r)}else if(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=c&&n.rtpValue<=l&&(t.dataset.rtp="medium");n.rtpValue>l&&(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=Math.ceil(n.rtpValue)+"%";const r=document.createElement("div");r.className="rtp-container";r.appendChild(u);r.appendChild(f);r.appendChild(e);i.appendChild(r)}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._categories=n.categories.filter(n=>n.seqNo>=0),v==="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";b.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(v==="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.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=v==="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)}w.appendChild(t)});i.appendChild(w);const k=document.createDocumentFragment();y.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;k.appendChild(i)});n.appendChild(k);const nt=i.querySelectorAll(".game-item"),a={name:null,category:null},d=()=>{Array.prototype.slice.call(nt).forEach(n=>{const i=n.dataset.game.toLowerCase(),t=n._categories.find(n=>n.name===a.category),r=!a.category||t!==undefined,u=!a.name||i.indexOf(a.name)>=0;r&&u?(n.style.order=t&&t.seqNo||0,$(n).show()):(n.style.order=0,$(n).hide())})};$(t).keyup(function(){a.name=t.value.toLowerCase();d()});$(n).on("click",".category-filter-link",function(){const n=$(this);n.siblings().removeClass("active");n.addClass("active");a.category=this.dataset.category;d()});const g=new URLSearchParams(window.location.search).get("PromotionCategory");if(g){const t=Array.from(y).find(n=>n.toLowerCase()===g.toLowerCase());if(t){n.querySelector(`[data-category="${t}"]`).click();return}}const p=n.querySelector(".active");p&&p.dataset.category!==""&&p.click()}})}});