import{n as k,u as R,j as e,B as h,k as f,I as y,S as W,f as T,g as O,h as F,i as B,c as L,L as C,l as g,m as U}from"./index-O0BQoyzo.js";import{r as x}from"./react-Cb2sDjhD.js";import{u as z,a as A,g as q}from"./use-settings-DMdaoWsB.js";import{E as K,a as X}from"./eye-CFhg5BTa.js";import{L as N}from"./loader-circle-9VUMGitw.js";import{R as D}from"./refresh-ccw-D2CWiyU_.js";import{C as J}from"./circle-check-CewnjFgv.js";import{E as Q}from"./external-link-DRVp9-lb.js";import{X as V}from"./x-DG-JKVw_.js";import{S as P}from"./save-DB0BDYTs.js";import{M as Z}from"./map-pin-BXYvvHry.js";import"./useQuery-PdiC7-sY.js";/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const G=k("Earth",[["path",{d:"M21.54 15H17a2 2 0 0 0-2 2v4.54",key:"1djwo0"}],["path",{d:"M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17",key:"1tzkfa"}],["path",{d:"M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05",key:"14pb5j"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Y=k("FileText",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);function ue(){const{t:i}=R(["settings","common"]),[s,r]=x.useState(!1),a=z({reveal:s});return e.jsxs("div",{className:"mx-auto flex max-w-4xl flex-col gap-6",children:[e.jsxs("header",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("h1",{className:"text-xl font-semibold",children:i("viewerSettings.title")}),e.jsxs(h,{variant:"ghost",size:"sm",className:"ml-auto",onClick:()=>r(t=>!t),disabled:a.isFetching,"aria-label":i(s?"viewerSettings.hide":"viewerSettings.reveal"),children:[s?e.jsx(K,{className:"h-4 w-4"}):e.jsx(X,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:i(s?"viewerSettings.hide":"viewerSettings.reveal")})]}),e.jsxs(h,{variant:"ghost",size:"sm",onClick:()=>void a.refetch(),disabled:a.isFetching,"aria-label":i("actions.refresh",{ns:"common"}),children:[a.isFetching?e.jsx(N,{className:"h-4 w-4 animate-spin"}):e.jsx(D,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:i("actions.refresh",{ns:"common"})})]})]}),e.jsx("p",{className:"text-sm text-text-dim",children:i("viewerSettings.subtitle")})]}),a.isLoading?e.jsx("div",{className:"h-64 rounded-md bg-surface-2 animate-pulse"}):e.jsxs(e.Fragment,{children:[e.jsx($,{env:a.data?.env??{}}),e.jsx(ee,{env:a.data?.env??{}})]})]})}function M(i){return{enabled:i.IMHUB_VIEWER_ENABLED==="1"||i.IMHUB_VIEWER_ENABLED?.toLowerCase()==="true",publicUrl:i.IMHUB_VIEWER_PUBLIC_BASE_URL??"",tunnelMode:i.IMHUB_VIEWER_TUNNEL_MODE==="quick"?"quick":"off",noDefaultRemote:i.IMHUB_VIEWER_NO_DEFAULT_REMOTE==="1"||i.IMHUB_VIEWER_NO_DEFAULT_REMOTE?.toLowerCase()==="true",chars:i.IMHUB_VIEWER_CHARS??"",lines:i.IMHUB_VIEWER_LINES??"",codeLines:i.IMHUB_VIEWER_CODE_LINES??"",maxPastes:i.IMHUB_VIEWER_MAX_PASTES??""}}function $({env:i}){const{t:s}=R(["settings","common"]),r=A(),a=q(),[t,d]=x.useState(()=>M(i)),[w,S]=x.useState("");x.useEffect(()=>{const n=M(i),m=JSON.stringify(n);m!==w&&(d(n),S(m))},[i.IMHUB_VIEWER_ENABLED,i.IMHUB_VIEWER_PUBLIC_BASE_URL,i.IMHUB_VIEWER_TUNNEL_MODE,i.IMHUB_VIEWER_CHARS,i.IMHUB_VIEWER_LINES,i.IMHUB_VIEWER_CODE_LINES,i.IMHUB_VIEWER_MAX_PASTES,i.IMHUB_VIEWER_NO_DEFAULT_REMOTE]);const c=x.useMemo(()=>M(i),[i]),b=x.useMemo(()=>JSON.stringify(t)!==JSON.stringify(c),[t,c]);function o(n,m){d(j=>({...j,[n]:m}))}async function _(){const n={};if(t.enabled!==c.enabled&&(n.IMHUB_VIEWER_ENABLED=t.enabled?"1":"0"),t.publicUrl!==c.publicUrl&&(n.IMHUB_VIEWER_PUBLIC_BASE_URL=t.publicUrl.trim()||null),t.tunnelMode!==c.tunnelMode&&(n.IMHUB_VIEWER_TUNNEL_MODE=t.tunnelMode),t.chars!==c.chars&&(n.IMHUB_VIEWER_CHARS=t.chars.trim()||null),t.lines!==c.lines&&(n.IMHUB_VIEWER_LINES=t.lines.trim()||null),t.codeLines!==c.codeLines&&(n.IMHUB_VIEWER_CODE_LINES=t.codeLines.trim()||null),t.maxPastes!==c.maxPastes&&(n.IMHUB_VIEWER_MAX_PASTES=t.maxPastes.trim()||null),t.noDefaultRemote!==c.noDefaultRemote&&(n.IMHUB_VIEWER_NO_DEFAULT_REMOTE=t.noDefaultRemote?"1":null),Object.keys(n).length!==0)try{await r.mutateAsync({updates:n}),g.success(s("viewerSettings.toast.saved"))}catch(m){g.error(U(m,s).message)}}function I(){d(c)}const l=a.data,H=l?.effectivePublicUrl;return e.jsxs("section",{className:"rounded-md border border-border bg-surface",children:[e.jsxs("header",{className:"flex items-center gap-2 border-b border-border px-4 py-3",children:[e.jsx(Y,{className:"h-4 w-4 text-text-dim"}),e.jsx("h2",{className:"text-sm font-semibold",children:s("viewerSettings.viewer.title")}),t.enabled?e.jsx(f,{variant:"success",children:s("viewerSettings.viewer.on")}):e.jsx(f,{variant:"outline",children:s("viewerSettings.viewer.off")})]}),e.jsx("p",{className:"px-4 pt-2 text-xs text-text-dim",children:s("viewerSettings.viewer.subtitle")}),e.jsx("div",{className:"flex items-center gap-3 px-4 py-3",children:e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:n=>{const m=n.target.checked;d(j=>({...j,enabled:m,noDefaultRemote:m?j.noDefaultRemote:!1}))},className:"h-4 w-4 accent-accent cursor-pointer"}),e.jsx("span",{className:"font-medium",children:s("viewerSettings.viewer.enableLabel")})]})}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 px-4 pb-3 sm:grid-cols-2",children:[e.jsx(u,{label:s("viewerSettings.viewer.publicUrl"),hint:s("viewerSettings.viewer.publicUrlHint"),children:e.jsx(y,{value:t.publicUrl,onChange:n=>o("publicUrl",n.target.value),placeholder:"https://agim.example.com",className:"font-mono text-xs"})}),e.jsx(u,{label:s("viewerSettings.viewer.tunnelMode"),hint:s("viewerSettings.viewer.tunnelHint"),children:e.jsxs(W,{value:t.tunnelMode,onValueChange:n=>o("tunnelMode",n),children:[e.jsx(T,{children:e.jsx(O,{})}),e.jsxs(F,{children:[e.jsx(B,{value:"off",children:s("viewerSettings.viewer.tunnelOff")}),e.jsx(B,{value:"quick",children:s("viewerSettings.viewer.tunnelQuick")})]})]})}),e.jsx(u,{label:s("viewerSettings.viewer.noDefaultRemote"),hint:s("viewerSettings.viewer.noDefaultRemoteHint"),children:e.jsxs("label",{className:L("inline-flex items-center gap-2 text-xs",!t.enabled&&"opacity-50 cursor-not-allowed"),children:[e.jsx("input",{type:"checkbox",checked:t.noDefaultRemote,disabled:!t.enabled,onChange:n=>o("noDefaultRemote",n.target.checked),className:"h-4 w-4 accent-accent cursor-pointer disabled:cursor-not-allowed"}),e.jsx("span",{children:s("viewerSettings.viewer.noDefaultRemoteLabel")})]})})]}),t.tunnelMode==="quick"&&e.jsxs("div",{className:"mx-4 mb-3 rounded-md border border-border bg-surface-2 p-3",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4 text-text-dim"}),e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-text-dim",children:s("viewerSettings.viewer.tunnelStatus")}),e.jsxs(h,{variant:"ghost",size:"sm",className:"ml-auto",onClick:()=>void a.refetch(),disabled:a.isFetching,"aria-label":s("viewerSettings.viewer.refreshTunnel"),children:[a.isFetching?e.jsx(N,{className:"h-4 w-4 animate-spin"}):e.jsx(D,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:s("viewerSettings.viewer.refreshTunnel")})]})]}),l?e.jsxs("div",{className:"flex flex-col gap-1 text-xs",children:[e.jsx(p,{label:s("viewerSettings.viewer.tunnelRunning"),children:l.tunnel.running?e.jsxs("span",{className:"inline-flex items-center gap-1 text-success",children:[e.jsx(J,{className:"h-3 w-3"}),s("viewerSettings.viewer.yes")]}):e.jsx("span",{className:"text-text-dim",children:s("viewerSettings.viewer.no")})}),e.jsx(p,{label:s("viewerSettings.viewer.tunnelUrl"),children:l.tunnel.url?e.jsxs("a",{href:l.tunnel.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 break-all font-mono text-info hover:underline",children:[l.tunnel.url,e.jsx(Q,{className:"h-3 w-3 shrink-0"})]}):e.jsx("span",{className:"text-text-muted",children:"—"})}),e.jsx(p,{label:s("viewerSettings.viewer.effectiveUrl"),children:H?e.jsx("span",{className:"break-all font-mono text-text",children:H}):e.jsx("span",{className:"text-text-muted",children:"—"})}),e.jsx(p,{label:s("viewerSettings.viewer.binary"),children:l.tunnel.binaryFound?e.jsx("span",{className:"font-mono text-text",children:l.tunnel.binaryPath}):e.jsx("span",{className:"text-warning",children:s("viewerSettings.viewer.binaryMissing")})}),l.tunnel.lastError&&e.jsx(p,{label:s("viewerSettings.viewer.lastError"),children:e.jsx("span",{className:"break-words text-danger",children:l.tunnel.lastError})})]}):e.jsx("p",{className:"text-xs text-text-dim",children:s("viewerSettings.viewer.tunnelLoading")})]}),e.jsx("h3",{className:"border-t border-border px-4 pt-3 text-xs font-semibold uppercase tracking-wide text-text-dim",children:s("viewerSettings.viewer.thresholds")}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 px-4 py-3 sm:grid-cols-4",children:[e.jsx(u,{label:s("viewerSettings.viewer.chars"),hint:s("viewerSettings.viewer.charsHint"),children:e.jsx(E,{value:t.chars,onChange:n=>o("chars",n),min:100,max:1e4,placeholder:"500"})}),e.jsx(u,{label:s("viewerSettings.viewer.lines"),hint:s("viewerSettings.viewer.linesHint"),children:e.jsx(E,{value:t.lines,onChange:n=>o("lines",n),min:5,max:200,placeholder:"12"})}),e.jsx(u,{label:s("viewerSettings.viewer.codeLines"),hint:s("viewerSettings.viewer.codeLinesHint"),children:e.jsx(E,{value:t.codeLines,onChange:n=>o("codeLines",n),min:5,max:200,placeholder:"10"})}),e.jsx(u,{label:s("viewerSettings.viewer.maxPastes"),hint:s("viewerSettings.viewer.maxPastesHint"),children:e.jsx(E,{value:t.maxPastes,onChange:n=>o("maxPastes",n),min:100,max:1e6,placeholder:"10000"})})]}),b&&e.jsxs("div",{className:"flex items-center gap-2 border-t border-border px-4 py-3",children:[e.jsx(f,{variant:"info",children:s("viewerSettings.dirtyHint")}),e.jsxs(h,{variant:"ghost",size:"sm",className:"ml-auto",onClick:I,disabled:r.isPending,children:[e.jsx(V,{className:"h-4 w-4"}),s("viewerSettings.discard")]}),e.jsxs(h,{size:"sm",onClick:()=>void _(),disabled:r.isPending,children:[r.isPending?e.jsx(N,{className:"h-4 w-4 animate-spin"}):e.jsx(P,{className:"h-4 w-4"}),r.isPending?s("viewerSettings.saving"):s("viewerSettings.save")]})]})]})}function v(i){return/\*{3,}/.test(i)}function ee({env:i}){const{t:s}=R(["settings","common"]),r=A(),a=i.IMHUB_BAIDU_MAP_AK??"",[t,d]=x.useState(a),[w,S]=x.useState("");x.useEffect(()=>{a!==w&&(d(a),S(a))},[a,w]);const c=!!a,b=t!==a&&!(v(t)&&t===a),o=t.length>0&&!v(t)&&t.length!==32;async function _(){if(b&&!v(t))try{await r.mutateAsync({updates:{IMHUB_BAIDU_MAP_AK:t.trim()||null}}),g.success(s("viewerSettings.baidu.toast.saved"))}catch(l){g.error(U(l,s).message)}}async function I(){try{await r.mutateAsync({updates:{IMHUB_BAIDU_MAP_AK:null}}),d(""),g.success(s("viewerSettings.baidu.toast.cleared"))}catch(l){g.error(U(l,s).message)}}return e.jsxs("section",{className:"rounded-md border border-border bg-surface",children:[e.jsxs("header",{className:"flex items-center gap-2 border-b border-border px-4 py-3",children:[e.jsx(Z,{className:"h-4 w-4 text-text-dim"}),e.jsx("h2",{className:"text-sm font-semibold",children:s("viewerSettings.baidu.title")}),c?e.jsx(f,{variant:"success",children:s("viewerSettings.baidu.configured")}):e.jsx(f,{variant:"outline",children:s("viewerSettings.baidu.empty")})]}),e.jsx("p",{className:"px-4 pt-2 text-xs text-text-dim",children:s("viewerSettings.baidu.subtitle")}),e.jsxs("div",{className:"px-4 py-3",children:[e.jsx(C,{htmlFor:"baidu-ak",className:"text-xs font-medium",children:"IMHUB_BAIDU_MAP_AK"}),e.jsx(y,{id:"baidu-ak",value:t,onChange:l=>d(l.target.value),placeholder:s("viewerSettings.baidu.placeholder"),autoComplete:"off",className:L("mt-1 font-mono text-xs",v(t)&&"text-text-muted")}),o&&e.jsx("p",{className:"mt-1 text-[11px] text-warning",children:s("viewerSettings.baidu.suspicious",{length:t.length})}),e.jsx("p",{className:"mt-1 text-[11px] text-text-dim",children:s("viewerSettings.baidu.hint")})]}),e.jsxs("div",{className:"flex items-center gap-2 border-t border-border px-4 py-3",children:[e.jsxs(h,{variant:"ghost",size:"sm",onClick:()=>void I(),disabled:!c||r.isPending,className:"text-danger hover:text-danger",children:[e.jsx(V,{className:"h-4 w-4"}),s("viewerSettings.baidu.clear")]}),e.jsx("span",{className:"ml-auto"}),b&&e.jsxs(h,{size:"sm",onClick:()=>void _(),disabled:r.isPending||v(t),children:[r.isPending?e.jsx(N,{className:"h-4 w-4 animate-spin"}):e.jsx(P,{className:"h-4 w-4"}),r.isPending?s("viewerSettings.saving"):s("viewerSettings.save")]})]})]})}function u({label:i,hint:s,children:r}){return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(C,{className:"text-xs font-medium",children:i}),r,s&&e.jsx("p",{className:"text-[11px] text-text-dim",children:s})]})}function p({label:i,children:s}){return e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsxs("span",{className:"shrink-0 font-medium text-text-dim",children:[i,":"]}),e.jsx("span",{className:"min-w-0 flex-1",children:s})]})}function E({value:i,onChange:s,min:r,max:a,placeholder:t}){return e.jsx(y,{type:"number",inputMode:"numeric",min:r,max:a,value:i,onChange:d=>s(d.target.value),placeholder:t})}export{ue as default};
//# sourceMappingURL=viewer-Dz6k0YKp.js.map
