import{n as e}from"./appConfig-CDeG57c-.js";var t=e=>String(e??``).trim(),n=e=>String(e||``).toLowerCase(),r=`jdduibi_ui_language_v1`,i=`jdduibi-ui-language-change`,a=e=>{let t=String(e||``).trim().toLowerCase();return t?t.startsWith(`en`)?`en-US`:t.startsWith(`zh`)?`zh-CN`:``:``},o=()=>{try{let e=globalThis?.localStorage;return a(e?.getItem?.(`jdduibi_ui_language_v1`))||null}catch{return null}},s=e=>{let t=a(e)||`zh-CN`;try{(globalThis?.localStorage)?.setItem?.(r,t)}catch{}try{(globalThis?.window)?.dispatchEvent?.(new CustomEvent(i,{detail:{lang:t}}))}catch{}return t},c=e=>{let t=globalThis?.window;if(!t?.addEventListener)return()=>{};let n=t=>{let n=a(t?.detail?.lang);n&&e(n)},r=t=>{if(t.key!==`jdduibi_ui_language_v1`)return;let n=a(t.newValue);n&&e(n)};return t.addEventListener(i,n),t.addEventListener(`storage`,r),()=>{try{t.removeEventListener(i,n)}catch{}try{t.removeEventListener(`storage`,r)}catch{}}},l=()=>{let e=o();if(e)return e;try{let e=chrome?.i18n?.getUILanguage?.(),t=a(e);if(t)return t;if(e)return e}catch{}return`zh-CN`},u=null,d=0,f=!1,p=async()=>{let t=Date.now();if(u&&t-d<8e3)return u;if(u=(await e())?.privacy||null,d=t,!f){f=!0;try{chrome.runtime?.onMessage?.addListener?.(e=>{String(e?.type||``)===`SETTINGS_UPDATED`&&(u=null,d=0)})}catch{}}return u};export{a,n as i,l as n,s as o,t as r,c as s,p as t};