import{k as le,j as c,t as F,h as K,m as E,p as l,q as ae,i as _,v as ne,n as v,x as d,A as W,w as se,s as ie}from"./web.Os7kOAdY.js";import{g as M,t as oe}from"./i18n-runtime._BAkvU05.js";var re=W("<div class=panel style=display:flex;flex-direction:column;gap:14px><div class=tool-grid-2><div class=tool-field><span class=tool-label></span><input class=tool-input type=number></div><div class=tool-field><span class=tool-label></span><select class=tool-input></select></div></div><div class=tool-field><span class=tool-label></span><select class=tool-input></select></div><div class=tool-field><span class=tool-label></span><input class=tool-input readonly></div><p class=tool-hint></p><p class=tool-hint>"),B=W("<option><!$><!/> <!$><!/>");const P="taitan_exchange_rates",G="taitan_exchange_rates_ts",ce=14400*1e3,$={CNY:"人民币",USD:"美元",EUR:"欧元",GBP:"英镑",JPY:"日元",KRW:"韩元",HKD:"港币",TWD:"新台币",SGD:"新加坡元",AUD:"澳元",CAD:"加元",CHF:"瑞士法郎",THB:"泰铢",MYR:"马来西亚令吉"},J=Object.keys($),j={USD:1,CNY:7.25,EUR:.92,GBP:.79,JPY:149.5,KRW:1340,HKD:7.82,TWD:32.3,SGD:1.34,AUD:1.53,CAD:1.37,CHF:.88,THB:35.8,MYR:4.68};async function de(){try{const u=localStorage.getItem(G),i=localStorage.getItem(P);if(u&&i&&Date.now()-parseInt(u)<ce)return JSON.parse(i)}catch{}try{const n=(await(await fetch("https://api.exchangerate-api.com/v4/latest/USD")).json()).rates;return localStorage.setItem(P,JSON.stringify(n)),localStorage.setItem(G,String(Date.now())),n}catch{return j}}function ge(){const[u,i]=c(M(),{equals:!1}),n=e=>oe(e,u());F(()=>{const e=s=>{const p=s.detail?.locale;p&&i(p)};window.addEventListener("taitan:locale-change",e),i(M()),ie(()=>window.removeEventListener("taitan:locale-change",e))});const[o,k]=c("USD"),[r,O]=c("CNY"),[T,q]=c("1"),[y,z]=c(j),[Q,V]=c(!0);F(()=>{de().then(e=>{z(e),V(!1)})});const X=K(()=>{const e=parseFloat(T()),s=y();return isNaN(e)||!s[o()]||!s[r()]?"":(e*s[r()]/s[o()]).toFixed(4).replace(/\.?0+$/,"")}),Z=K(()=>{const e=y();return!e[o()]||!e[r()]?"":`1 ${$[o()]} ≈ ${(e[r()]/e[o()]).toFixed(4)} ${$[r()]}`});return(()=>{var e=E(re),s=e.firstChild,p=s.firstChild,A=p.firstChild,L=A.nextSibling,ee=p.nextSibling,H=ee.firstChild,S=H.nextSibling,N=s.nextSibling,w=N.firstChild,f=w.nextSibling,R=N.nextSibling,Y=R.firstChild,I=Y.nextSibling,U=R.nextSibling,te=U.nextSibling;return l(A,()=>n("金额")),L.$$input=t=>q(t.currentTarget.value),l(H,()=>n("从")),S.addEventListener("change",t=>k(t.currentTarget.value)),l(S,()=>J.map(t=>(()=>{var a=E(B),x=a.firstChild,[g,h]=v(x.nextSibling),m=g.nextSibling,C=m.nextSibling,[b,D]=v(C.nextSibling);return d(a,"value",t),l(a,t,g,h),l(a,()=>$[t],b,D),a})())),l(w,()=>n("到")),f.addEventListener("change",t=>O(t.currentTarget.value)),l(f,()=>J.map(t=>(()=>{var a=E(B),x=a.firstChild,[g,h]=v(x.nextSibling),m=g.nextSibling,C=m.nextSibling,[b,D]=v(C.nextSibling);return d(a,"value",t),l(a,t,g,h),l(a,()=>$[t],b,D),a})())),l(Y,()=>n("结果")),l(U,(()=>{var t=ae(()=>!!Q());return()=>t()?"加载汇率中...":Z()})()),l(te,()=>n("汇率来自 exchangerate-api.com，缓存 4 小时；获取失败时使用近似值。")),_(()=>se(I,"placeholder",n("自动计算"))),_(()=>d(L,"value",T())),_(()=>d(S,"value",o())),_(()=>d(f,"value",r())),_(()=>d(I,"value",X())),ne(),e})()}le(["input"]);export{ge as default};
