(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e=`http://127.0.0.1:5000/api`,t=document.getElementById(`searchInput`),n=document.getElementById(`clearSearchBtn`),r=document.getElementById(`resultsList`),i=document.getElementById(`logOutput`),a=document.getElementById(`appIdLabel`),o=document.getElementById(`gameNameLabel`),s=document.getElementById(`depotsLabel`),c=document.getElementById(`dlcsLabel`),l=document.getElementById(`addSteamBtn`),u=document.getElementById(`addCartBtn`),d=document.getElementById(`viewCartBtn`);t.value=``,n.style.display=`none`,setInterval(f,1e3);async function f(){try{m(await(await fetch(`${e}/state`)).json())}catch(e){console.error(`Backend not running`,e)}}var p=[];function m(e){i.textContent=e.log_output||``,i.parentElement.scrollTop=i.parentElement.scrollHeight,e.is_fetching_details?(a.textContent=`App ID: ${e.current_app_id}`,o.textContent=`Game: ${e.current_game_name}`,s.innerHTML=`Depots: <div class="wavy-loader" style="padding:0; margin-left:8px; display:inline-flex;"><div></div><div></div><div></div></div>`,c.innerHTML=`DLCs: <div class="wavy-loader" style="padding:0; margin-left:8px; display:inline-flex;"><div></div><div></div><div></div></div>`):(a.textContent=`App ID: ${e.current_app_id}`,o.textContent=`Game: ${e.current_game_name}`,s.textContent=`Depots: ${e.current_depots_count}`,c.textContent=`DLCs: ${e.current_dlcs_count}`),l.disabled=!e.add_to_steam_enabled,u.disabled=!e.add_to_cart_enabled,d.disabled=e.cart_count===0,d.innerHTML=`<span class="material-symbols-rounded">${e.cart_count>0?`shopping_cart`:`shopping_cart_off`}</span> View Cart (${e.cart_count})`,e.is_searching?(r.innerHTML=`
      <div style="display:flex; justify-content:center; align-items:center; padding: 24px;">
        <svg class="circle-loader" viewBox="0 0 50 50">
          <circle class="path" cx="25" cy="25" r="20" fill="none" stroke-width="5"></circle>
        </svg>
      </div>
    `,p=null):JSON.stringify(p)!==JSON.stringify(e.search_results)&&(p=e.search_results,h(p))}function h(e){r.innerHTML=``,e.forEach((e,t)=>{let n=document.createElement(`li`);n.style.animationDelay=`${t*.03}s`,n.innerHTML=`
      <div class="list-item-content">
        <div class="list-item-title">${e.title}</div>
        <div class="list-item-subtitle">App ID: ${e.app_id}</div>
      </div>
    `,n.onclick=()=>{document.querySelectorAll(`#resultsList li`).forEach(e=>e.classList.remove(`active`)),n.classList.add(`active`),_(`select_result`,{index:t})},r.appendChild(n)})}function g(){t.value.trim()&&fetch(`${e}/search`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({query:t.value.trim()})})}t.addEventListener(`input`,()=>{n.style.display=t.value.length>0?`block`:`none`}),n.addEventListener(`click`,()=>{t.value=``,n.style.display=`none`,t.focus(),_(`clear_search`)}),t.addEventListener(`keypress`,e=>{e.key===`Enter`&&g()}),l.addEventListener(`click`,()=>_(`add_to_steam`)),u.addEventListener(`click`,()=>_(`add_to_cart`)),d.addEventListener(`click`,async()=>{try{let t=await(await fetch(`${e}/cart`)).json(),n=document.getElementById(`cartItemsList`);n.innerHTML=``,t.length===0?n.innerHTML=`<li>Your cart is empty</li>`:t.forEach(e=>{let t=document.createElement(`li`);t.innerHTML=`
          <div class="list-item-content">
            <div class="list-item-text">
              <div class="list-item-title">${e.title}</div>
              <div class="list-item-subtitle">App ID: ${e.app_id}</div>
            </div>
            <button class="remove-cart-item-btn" onclick="removeCartItem('${e.app_id}')">
              <span class="material-symbols-rounded">remove_shopping_cart</span>
            </button>
          </div>
        `,n.appendChild(t)}),document.getElementById(`cartModal`).showModal()}catch(e){console.error(`Failed to load cart`,e)}}),document.getElementById(`cartCloseBtn`).addEventListener(`click`,()=>{S(`cartModal`)}),document.getElementById(`cartClearBtn`).addEventListener(`click`,async()=>{await _(`clear_cart`),S(`cartModal`)}),document.getElementById(`cartDownloadBtn`).addEventListener(`click`,async()=>{await _(`download_cart`),S(`cartModal`)});async function _(t,n={}){await fetch(`${e}/action`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:t,...n})})}window.removeCartItem=async e=>{await _(`remove_from_cart`,{app_id:e}),document.getElementById(`viewCartBtn`).click()};var v=document.getElementById(`settingsBtn`),y=document.getElementById(`settingsModal`),b=document.getElementById(`settingsCancelBtn`),x=document.getElementById(`settingsSaveBtn`);v.addEventListener(`click`,async()=>{try{let t=await fetch(`${e}/settings`);if(!t.ok){alert(`HTTP Error: `+t.status);return}let n=await t.json();document.getElementById(`settingThemeColor`).value=n.theme_color||`#1d2020`,document.getElementById(`settingAccentColor`).value=n.accent_color||`#93d2d0`,document.getElementById(`settingAddApps`).checked=n.add_to_additional_apps??!0,y.showModal()}catch(e){console.error(`Failed to load settings`,e)}}),b.addEventListener(`click`,()=>{S(`settingsModal`)}),x.addEventListener(`click`,async()=>{let t=document.getElementById(`settingThemeColor`).value,n=document.getElementById(`settingAccentColor`).value,r={theme_color:t,accent_color:n,add_to_additional_apps:document.getElementById(`settingAddApps`).checked};document.documentElement.style.setProperty(`--md-sys-color-surface`,t),document.documentElement.style.setProperty(`--md-sys-color-primary`,n);try{await fetch(`${e}/settings`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)}),S(`settingsModal`)}catch(e){console.error(`Failed to save settings`,e)}});function S(e){let t=document.getElementById(e);t.classList.add(`closing`),t.addEventListener(`animationend`,function e(){t.classList.remove(`closing`),t.close(),t.removeEventListener(`animationend`,e)},{once:!0})}async function C(){try{let t=await fetch(`${e}/settings`);if(t.ok){let e=await t.json();e.theme_color&&document.documentElement.style.setProperty(`--md-sys-color-surface`,e.theme_color),e.accent_color&&document.documentElement.style.setProperty(`--md-sys-color-primary`,e.accent_color)}}catch(e){console.error(`Failed to load initial settings`,e)}}C(),f(),_(`clear_search`),_(`clear_cart`);var w=!1,T,E,D=null;document.addEventListener(`mousedown`,e=>{let t=e=>{if(!e||e===document.body||e===document.documentElement)return null;let n=window.getComputedStyle(e).overflowY;return(n===`auto`||n===`scroll`)&&e.scrollHeight>e.clientHeight?e:t(e.parentElement)},n=t(e.target),r=e.target.tagName===`BUTTON`||e.target.tagName===`INPUT`||e.target.closest(`.md-btn`)||e.target.closest(`.icon-btn`)||e.target.closest(`li`);n&&!r&&(w=!0,D=n,T=e.pageY-D.offsetTop,E=D.scrollTop,D.style.cursor=`grabbing`)}),document.addEventListener(`mouseleave`,()=>{w=!1,D&&(D.style.cursor=``)}),document.addEventListener(`mouseup`,()=>{w=!1,D&&(D.style.cursor=``)}),document.addEventListener(`mousemove`,e=>{if(!w||!D)return;e.preventDefault();let t=(e.pageY-D.offsetTop-T)*1.5;D.scrollTop=E-t});