import{c as h,a as u,i as f,b as g}from"./_plugin-vue_export-helper-D7RxQbao.js";import{S as y,N as v}from"./Navbar-CToVr4mZ.js";import{P as F,a as b,_ as k}from"./Checkbox-D-0ssBb5.js";import{T as S,S as w}from"./trash-2-DOhaGh0B.js";import{S as x}from"./save-BmeYyGU2.js";import{R as C}from"./rotate-ccw-qcoK-O4N.js";import{F as j}from"./file-text-Cg1_0lFN.js";/**
 * @license lucide-vue-next v0.577.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const E=h("layers-plus",[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 .83.18 2 2 0 0 0 .83-.18l8.58-3.9a1 1 0 0 0 0-1.831z",key:"zzgyd3"}],["path",{d:"M16 17h6",key:"1ook5g"}],["path",{d:"M19 14v6",key:"1ckrd5"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 .825.178",key:"1ia9y3"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l2.116-.962",key:"jksky3"}]]);/**
 * @license lucide-vue-next v0.577.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const M=h("square-pen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);/**
 * @license lucide-vue-next v0.577.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const P=h("terminal",[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]);/**
 * @license lucide-vue-next v0.577.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const T=h("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),L=u({components:{Navbar:v,Checkbox:k,Edit:M,FileText:j,LayersPlus:E,Play:b,Plus:F,RotateCcw:C,Save:x,Search:w,Shield:y,Terminal:P,Trash2:S,X:T},data(){return{apps:[],showEditForm:!1,editForm:null,detachedCmd:"",coverSearching:!1,coverFinderBusy:!1,coverCandidates:[],coverSearchQuery:"",platform:""}},created(){fetch("./api/apps").then(e=>e.json()).then(e=>{console.log(e),this.apps=e.apps}),fetch("./api/config").then(e=>e.json()).then(e=>this.platform=e.platform)},methods:{newApp(){this.editForm={name:"",output:"",cmd:"",index:-1,"exclude-global-prep-cmd":!1,elevated:!1,"auto-detach":!0,"wait-all":!0,"exit-timeout":5,"prep-cmd":[],detached:[],"image-path":""},this.editForm.index=-1,this.showEditForm=!0},editApp(e){this.editForm=JSON.parse(JSON.stringify(this.apps[e])),this.editForm.index=e,this.editForm["prep-cmd"]===void 0&&(this.editForm["prep-cmd"]=[]),this.editForm.detached===void 0&&(this.editForm.detached=[]),this.editForm["exclude-global-prep-cmd"]===void 0&&(this.editForm["exclude-global-prep-cmd"]=!1),this.editForm.elevated===void 0&&this.platform==="windows"&&(this.editForm.elevated=!1),this.editForm["auto-detach"]===void 0&&(this.editForm["auto-detach"]=!0),this.editForm["wait-all"]===void 0&&(this.editForm["wait-all"]=!0),this.editForm["exit-timeout"]===void 0&&(this.editForm["exit-timeout"]=5),this.showEditForm=!0},showDeleteForm(e){confirm("Are you sure to delete "+this.apps[e].name+"?")&&fetch("./api/apps/"+e,{method:"DELETE",headers:{"Content-Type":"application/json"}}).then(o=>{o.status===200&&document.location.reload()})},addPrepCmd(){let e={do:"",undo:""};this.platform==="windows"&&(e={...e,elevated:!1}),this.editForm["prep-cmd"].push(e)},deletePrepCmd(e){this.editForm["prep-cmd"].splice(e,1)},addDetached(){this.editForm.detached.push("")},showCoverFinder(){this.coverCandidates=[],this.coverSearchQuery="",this.performCoverSearch()},performCoverSearch(){this.coverSearching=!0,this.coverCandidates=[];const e=this.coverSearchQuery.trim()||this.editForm.name.toString();function a(r){let s=r.substring(0,Math.min(r.length,2)).toLowerCase().replaceAll(/[^a-z\d]/g,"");return s||"@"}function o(r){if(!r)return Promise.resolve([]);let s=r.replaceAll(/\s+/g,".").toLowerCase(),l="https://raw.githubusercontent.com/LizardByte/GameDB/gh-pages",m=a(r);return fetch(`${l}/buckets/${m}.json`).then(function(i){if(!i.ok)throw new Error("Failed to search covers");return i.json()}).then(i=>Promise.all(Object.keys(i).map(t=>i[t].name.replaceAll(/\s+/g,".").toLowerCase().startsWith(s)?fetch(`${l}/games/${t}.json`).then(function(n){return n.json()}).catch(()=>null):null).filter(t=>t))).then(i=>i.filter(t=>t&&t.cover&&t.cover.url).map(t=>{const d=t.cover.url,n=d.lastIndexOf("."),c=d.lastIndexOf("/");if(n<0||c<0)return null;const p=d.substring(c+1,n);return{name:t.name,key:`igdb_${t.id}`,url:`https://images.igdb.com/igdb/image/upload/t_cover_big/${p}.jpg`,saveUrl:`https://images.igdb.com/igdb/image/upload/t_cover_big_2x/${p}.png`}}).filter(t=>t))}o(e).then(r=>this.coverCandidates=r).finally(()=>this.coverSearching=!1)},useCover(e){this.coverFinderBusy=!0,fetch("./api/covers/upload",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e.key,url:e.saveUrl})}).then(a=>{if(!a.ok)throw new Error("Failed to download covers");return a.json()}).then(a=>{this.editForm["image-path"]=a.path;const o=this.$refs.coverFinderModal;if(o){const r=g.Modal.getInstance(o);r&&r.hide()}}).finally(()=>this.coverFinderBusy=!1)},save(){this.editForm["image-path"]=this.editForm["image-path"].toString().replace(/"/g,""),fetch("./api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(this.editForm)}).then(e=>{e.status===200&&document.location.reload()})},handleImageError(e){e.target.style.display="none";const a=e.target.nextElementSibling;a&&a.classList.contains("app-poster-placeholder")&&(a.style.display="flex")}}});f(L);
