import{b as t,r as l}from"./tailwind-BjeOSL3a.js";const u={openai:"OpenAI",openrouter:"OpenRouter",deepseek:"DeepSeek",google:"Google Translate",microsoft:"Microsoft Translate",custom:"Custom API"};function p(e){if(!e.useCustomAI)return null;switch(e.aiProvider){case"openai":return e.openaiApiKey.trim()?null:{code:"missing-api-key",provider:"openai"};case"openrouter":return e.openrouterApiKey.trim()?null:{code:"missing-api-key",provider:"openrouter"};case"deepseek":return e.deepseekApiKey.trim()?null:{code:"missing-api-key",provider:"deepseek"};case"custom":{const r=[];return e.customBaseUrl.trim()||r.push("baseUrl"),e.customApiKey.trim()||r.push("apiKey"),e.customModel.trim()||r.push("model"),r.length>0?{code:"incomplete-custom",missing:r}:null}case"google":case"microsoft":return null}}function s(e){switch(e.aiProvider){case"openai":return e.openaiModel;case"openrouter":return e.openrouterModel;case"deepseek":return e.deepseekModel;case"custom":return e.customModel;case"google":case"microsoft":return""}}function v(e,r){switch(e.kind){case"backend":return r("options.engine.backend");case"plain":return u[e.provider];case"llm":return e.model?`${u[e.provider]} · ${e.model}`:u[e.provider]}}function A(e,r){if(!e.useCustomAI)return{kind:"backend"};const o=e.aiProvider;if(o==="google"||o==="microsoft")return r==="selection"?{kind:"backend",fallbackFrom:o}:{kind:"plain",provider:o};const n=p(e);return n?r==="page"?{kind:"llm",provider:o,model:s(e),issue:n}:{kind:"backend",issue:n}:{kind:"llm",provider:o,model:s(e)}}const a="extensionUpdateAvailable";async function d(){await t.storage.local.remove(a)}async function m(){const r=(await t.storage.local.get(a))[a];return r!=null&&r.version?t.runtime.getManifest().version===r.version?(await d(),null):r:null}function b(){t.runtime.reload()}function f(e){const r=(o,n)=>{var i;if(n==="local"&&a in o){const c=(i=o[a])==null?void 0:i.newValue;e(c??null)}};return t.storage.onChanged.addListener(r),()=>t.storage.onChanged.removeListener(r)}function g(){const[e,r]=l.useState(null);return l.useEffect(()=>(m().then(r),f(n=>{if(n&&t.runtime.getManifest().version===n.version){r(null);return}r(n)})),[]),e}export{u as A,b as a,v as f,p as g,A as r,g as u};
