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