!function(e){"use strict";if(e.AlphaDateTranslator)return;const t=e.AlphaDateTranslateShared;if(!t)return void console.warn("[AHT] translate-shared.js is missing; translation disabled");const a={queue:Promise.resolve(),dynamicKey:"",dynamicKeyLastCheckedAt:0,dynamicKeyFetchFailedAt:0,dynamicKeyDisabledUntil:0,keyRefreshPromise:null};
async function r({forceRefresh:e=!1}={}){await async function(e=!1){if(a.keyRefreshPromise)return a.keyRefreshPromise;a.keyRefreshPromise=(async()=>{const r=Date.now();if(!e){if(a.dynamicKeyLastCheckedAt&&r-a.dynamicKeyLastCheckedAt<t.KEY_REFRESH_INTERVAL_MS)return;if(a.dynamicKeyFetchFailedAt&&r-a.dynamicKeyFetchFailedAt<t.KEY_FETCH_FAIL_COOLDOWN_MS)return}for(const e of t.GOOGLE_TRANSLATE_JS_URLS)try{const n=await t.fetchTextWithTimeout(e,t.KEY_REQUEST_TIMEOUT_MS),s=t.extractGoogleApiKey(n);return a.dynamicKeyLastCheckedAt=r,a.dynamicKeyFetchFailedAt=0,void(s&&s!==t.GOOGLE_TRANSLATE_FALLBACK_KEY?(a.dynamicKey=s,a.dynamicKeyDisabledUntil=0):(a.dynamicKey="",a.dynamicKeyDisabledUntil=0))}catch{}a.dynamicKeyLastCheckedAt=r,a.dynamicKeyFetchFailedAt=r})();try{await a.keyRefreshPromise}finally{a.keyRefreshPromise=null}}(e);const n=[],s=Date.now();return a.dynamicKey&&a.dynamicKey!==t.GOOGLE_TRANSLATE_FALLBACK_KEY&&Number(a.dynamicKeyDisabledUntil||0)<=s&&n.push({type:"dynamic",key:a.dynamicKey}),n.push({type:"fallback",key:t.GOOGLE_TRANSLATE_FALLBACK_KEY}),t.uniqueKeyCandidates(n)}
function n(e,r){const n=String(e||"").trim();n&&n!==t.GOOGLE_TRANSLATE_FALLBACK_KEY&&(a.dynamicKey===n&&(a.dynamicKeyDisabledUntil=Date.now()+t.DYNAMIC_KEY_BAD_COOLDOWN_MS),console.warn("[AHT] dynamic key disabled:",String(r||"dynamic key failed").slice(0,250)))}
e.AlphaDateTranslator=Object.freeze({translateTexts:function(e,s={}){const i=()=>async function(e,s={}){const i=(Array.isArray(e)?e:[]).map((e=>String(e??"")));if(!i.length)return{translated:[],detectedSourceLangs:[],transport:"page",keyType:"none",attempts:[]};const o=t.normalizeLang(s.sourceLang||t.DEFAULT_SOURCE_LANG,t.DEFAULT_SOURCE_LANG),c=t.normalizeLang(s.targetLang||t.DEFAULT_TARGET_LANG,t.DEFAULT_TARGET_LANG),d=await r({forceRefresh:Boolean(s.forceRefreshKey)}),l=[];for(const e of d)try{const r=await t.translateViaGooglePaWithRetries({texts:i,sourceLang:o,targetLang:c,apiKey:e.key,requestLabel:"page-origin translate-pa"});return{...r,transport:"page",keyType:e.type,usedKeyType:e.type,attempts:l}}catch(r){const a=t.normalizeTranslateError(r);a.transport="page",a.keyType=e.type,l.push({transport:"page",keyType:e.type,ok:!1,error:t.serializeError(a)}),"dynamic"===e.type&&"key"===a.classification&&n(e.key,a.message)}throw function(e){const r=e[e.length-1]?.error||{};const n=t.makeTranslateError(r.message||"Translation failed in page transport",{classification:r.classification||"unknown",transport:"page",keyType:r.keyType,status:r.status});return n.attempts=e,n}(l)}(e,s),o=a.queue.then(i,i);return a.queue=o.catch((()=>{})),o},getCandidateKeys:async function(e={}){const t=await r(e);return{keys:t}},getDebugState:function(){return JSON.parse(JSON.stringify({preferredTransport:"page",dynamicKey:a.dynamicKey?"dynamic-present":"",dynamicKeyLastCheckedAt:a.dynamicKeyLastCheckedAt,dynamicKeyFetchFailedAt:a.dynamicKeyFetchFailedAt,dynamicKeyDisabledUntil:a.dynamicKeyDisabledUntil}))}}),console.info("[AHT] Alpha.date shared translate client patched(page-only) loaded")}(window);