import{u as E,r as n,j as t,t as r,c as D,ag as q,e as M,b4 as U,i as L,f as $,v as F,$ as _,S as z}from"./index-iQt3bUih.js";const u={useperfthreads:{arg:"useperfthreads",type:"bool",default:!1,category:"perf",label:"useperfthreads(效能執行緒)",warn:"官方註記:v1.0 之後不設定這三個多執行緒旗標,反而可能效能更好——非必開,建議實測比較。"},NoAsyncLoadingThread:{arg:"NoAsyncLoadingThread",type:"bool",default:!1,category:"perf",label:"NoAsyncLoadingThread(停用非同步載入執行緒)"},UseMultithreadForDS:{arg:"UseMultithreadForDS",type:"bool",default:!1,category:"perf",label:"UseMultithreadForDS(伺服器多執行緒)"},NumberOfWorkerThreadsServer:{arg:"NumberOfWorkerThreadsServer",type:"int",default:0,min:0,max:128,category:"perf",label:"工作執行緒數(NumberOfWorkerThreadsServer)",hint:"0 = 不指定(交給系統)。需搭配上面的多執行緒旗標才有意義。"},publiclobby:{arg:"publiclobby",type:"bool",default:!0,category:"general",label:"列為社群伺服器(publiclobby)",hint:"開啟後伺服器會出現在社群伺服器列表。"},logformat:{arg:"logformat",type:"enum",default:"text",choices:["text","json"],category:"general",label:"日誌格式(logformat)"}},H=Object.keys(u),R={perf:"啟動參數(效能 / 多執行緒)",general:"啟動參數"},T=(c,a)=>c[a]??u[a].default;function G({client:c,instanceId:a,category:o}){E();const s=n.useMemo(()=>H.filter(e=>u[e].category===o),[o]),[l,d]=n.useState(null),[N,A]=n.useState(null),[m,y]=n.useState({}),[p,j]=n.useState(""),[h,x]=n.useState(null),[v,S]=n.useState(null),[b,w]=n.useState(!1),f=n.useCallback(async()=>{try{const e=await c.launchOptions(a);d(e.launchOptions),A(e.queryPort),y(Object.fromEntries(s.map(i=>[i,T(e.launchOptions,i)]))),j(e.queryPort===null?"":String(e.queryPort)),x(null)}catch(e){x(e instanceof Error?e.message:String(e))}},[c,a,s]);n.useEffect(()=>{f()},[f]);const g=n.useMemo(()=>l?s.filter(e=>m[e]!==T(l,e)):[],[m,l,s]),O=o==="general"&&(N===null?"":String(N))!==p,C=g.length+(O?1:0);if(!l)return t.jsx("p",{className:"text-ink-muted",children:h??r("載入中…")});const P=async()=>{w(!0),x(null);try{const e={};if(g.length>0&&(e.launchOptions=Object.fromEntries(g.map(i=>[i,m[i]]))),O){const i=p.trim();e.queryPort=i===""?null:Number(i)}await c.updateLaunchOptions(a,e),S(r("已儲存,重啟伺服器後生效")),setTimeout(()=>S(null),3e3),await f()}catch(e){x(e instanceof Error?e.message:String(e))}finally{w(!1)}};return t.jsxs("div",{className:`${D} flex flex-col gap-3`,children:[t.jsxs("h3",{className:"inline-flex items-center gap-2 text-sm font-extrabold",children:[t.jsx(q,{className:"size-4 text-pal"})," ",r(R[o])]}),h&&t.jsx("p",{className:M,children:h}),v&&t.jsx("p",{className:"rounded-xl bg-grass/10 px-3 py-2 text-[13px] font-bold text-grass",children:v}),o==="general"&&t.jsxs("div",{className:"flex flex-col gap-1.5 border-b border-line pb-3",children:[t.jsxs("label",{className:U,children:[r("Steam 查詢埠(queryport)"),t.jsx("input",{type:"number",className:`${L} w-32`,value:p,min:1024,max:65535,placeholder:"1024–65535",onChange:e=>j(e.target.value)})]}),t.jsx("p",{className:"text-xs text-ink-muted",children:r("同機多台伺服器的查詢埠必須不同,否則儲存時會回報衝突。")})]}),t.jsx("div",{className:"flex flex-col divide-y divide-line",children:s.map(e=>t.jsx(W,{optionKey:e,value:m[e]??u[e].default,onChange:i=>y(k=>({...k,[e]:i}))},e))}),C>0&&t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-xl border-2 border-sun/50 bg-card-soft p-3",children:[t.jsx("span",{className:"text-[13px] font-bold text-ink-muted",children:r("小心~您有 {n} 項變更尚未儲存!(重啟伺服器後生效)",{n:C})}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("button",{className:$,onClick:()=>void f(),disabled:b,children:r("重置")}),t.jsx("button",{className:F,onClick:P,disabled:b,children:b?r("儲存中…"):r("確定修改")})]})]})]})}function W({optionKey:c,value:a,onChange:o}){E();const s=u[c];return t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-6 gap-y-2 py-3",children:[t.jsxs("div",{className:"min-w-64 flex-1",children:[t.jsx("p",{className:"text-sm font-bold",children:r(s.label)}),t.jsx("p",{className:"font-mono text-xs text-ink-muted",children:c}),s.hint&&t.jsx("p",{className:"mt-1 max-w-xl text-xs text-ink-muted",children:r(s.hint)}),s.warn&&t.jsxs("p",{className:"mt-1 inline-flex max-w-xl items-start gap-1.5 text-xs text-sun",children:[t.jsx(_,{className:"mt-0.5 size-3.5 shrink-0"}),r(s.warn)]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[s.type==="bool"&&t.jsx("button",{type:"button",role:"switch","aria-checked":!!a,"aria-label":r(s.label),onClick:()=>o(!a),className:`relative h-7 w-12 rounded-full transition ${a?"bg-grass":"bg-line"}`,children:t.jsx("span",{className:`absolute top-1 size-5 rounded-full bg-white shadow transition-all ${a?"left-6":"left-1"}`})}),s.type==="int"&&t.jsx("input",{type:"number",className:`${L} w-28 text-right`,value:String(a),min:s.min,max:s.max,onChange:l=>{const d=Number(l.target.value);Number.isNaN(d)||o(Math.trunc(d))}}),s.type==="enum"&&t.jsx(z,{className:"min-w-36",value:String(a),onChange:l=>o(l.target.value),children:(s.choices??[]).map(l=>t.jsx("option",{value:l,children:l},l))})]})]})}export{G as L};
