/* OK ITHAKI V249526R10F8 — APP LANGUAGE FIRST START / ENGLISH REFERENCE / LEXICON 1 / ARGOS */
(function(){
'use strict';
if(window.__ITHAKI_V249526R10F8_REFERENCE_LANGUAGE__)return;
window.__ITHAKI_V249526R10F8_REFERENCE_LANGUAGE__={version:'V249526R10F8',firstStart:true,englishReference:true,lexicon1:true,argosPairs:true,profileAuto:true};
window.APP_LANGUAGE_FIRST_START_R10F8=true;
window.ENGLISH_REFERENCE_TRANSLATION_R10F8=true;
window.LEXICON1_UNKNOWN_WORD_LEARNING_R10F8=true;
window.ARGOS_REFERENCE_PAIR_ON_DEMAND_R10F8=true;
window.PROFILE_AUTO_CONTENT_TRANSLATION_R10F8=true;
window.PERSISTENT_ARGOS_MODELS_R10F8=true;
window.R10F8_LAST_FRONTEND_OWNER=true;
const I=()=>window.ITH=window.ITH||{};
const S=()=>window.state||I().state||{};
const $=id=>document.getElementById(id);
function lang(){try{return String(localStorage.getItem('ith_global_language_r10f7')||localStorage.getItem('ith_ui_lang')||'el').toLowerCase().split('-')[0]}catch(_e){return'el'}}
function api(path){let b=String(S().api||'').replace(/\/+$/,'');if(!b||/appassets\.androidplatform\.net/i.test(b))b='https://ok-ithaki.gr';return /^https?:/i.test(path)?path:b+path}
function autoEnabled(){try{return localStorage.getItem('ith_auto_translate_content_r10f8')!=='0'}catch(_e){return true}}
function isUserContent(e){return !!e?.closest?.('.bubble,.msgBody,.commentText,.postBody,.ith534PostText,.ith534Reply,.bottleItemV249274,.bottleReplyBoxV249274,.spaceMessage,.communityMessage,[data-message-id],[data-wall],[data-reply-id]')}
function restoreUserContent(){document.querySelectorAll('[data-r10f7-original-text]').forEach(e=>{if(!isUserContent(e))return;if(e.childNodes.length===1&&e.firstChild.nodeType===3)e.firstChild.nodeValue=e.dataset.r10f7OriginalText;delete e.dataset.r10f7OriginalText;delete e.dataset.r10f7TranslatedLang})}
async function translateText(text,target=lang(),source='auto'){
 text=String(text||'');if(!text.trim()||source===target)return text;
 try{const r=await fetch(api('/api/bridge/translate/reference_v249526r10f8'),{method:'POST',headers:{'Content-Type':'application/json'},credentials:'include',body:JSON.stringify({text,source_lang:source,target_lang:target,allow_external:true})});if(!r.ok)throw new Error('HTTP '+r.status);const d=await r.json();return String(d.translated||d.text||text)}catch(_e){return text}
}
async function translateBatch(texts,target=lang(),source='auto'){
 const clean=(texts||[]).map(x=>typeof x==='string'?x:String(x?.text||''));if(!clean.length)return[];
 try{const r=await fetch(api('/api/bridge/translate/reference_batch_v249526r10f8'),{method:'POST',headers:{'Content-Type':'application/json'},credentials:'include',body:JSON.stringify({texts:clean,source_lang:source,target_lang:target,allow_external:true})});if(!r.ok)throw new Error('HTTP '+r.status);const d=await r.json();return (d.translations||[]).map((x,i)=>String(x?.translated||x||clean[i]))}catch(_e){return clean}
}
function syncLexiconLanguage(){const c=lang();if(c&&c!=='en')try{localStorage.setItem('ith_lexicon_other_language_r10f8',c)}catch(_e){} }
function decorateProfile(){const m=$('ith537FullProfileModal');if(!m)return;const cb=$('ith537AutoContent');if(cb&&!cb.dataset.r10f8Bound){cb.dataset.r10f8Bound='1';cb.addEventListener('change',()=>{localStorage.setItem('ith_auto_translate_content_r10f8',cb.checked?'1':'0');if(!cb.checked)restoreUserContent();document.dispatchEvent(new CustomEvent('ithaki:auto-content-translation-changed',{detail:{enabled:cb.checked}}))})}}
function ensureLexiconOwner(){
 document.querySelectorAll('#ithRedBook374').forEach((e,i)=>{if(i)e.remove()});
 const b=$('ithRedBook374');if(b&&!b.dataset.r10f8Owner){b.dataset.r10f8Owner='1';b.onclick=ev=>{ev?.preventDefault?.();ev?.stopPropagation?.();if(typeof window.ITHAKI_OPEN_LEXICON1_R10F8==='function')window.ITHAKI_OPEN_LEXICON1_R10F8();return false}}
}
function install(){
 syncLexiconLanguage();
 I().translateText=translateText;I().translateBatchR10F8=translateBatch;I().openLexicon1R10F8=()=>window.ITHAKI_OPEN_LEXICON1_R10F8?.();
 window.ITHAKI_TRANSLATE_REFERENCE_R10F8=translateText;window.ITHAKI_TRANSLATE_REFERENCE_BATCH_R10F8=translateBatch;
 document.documentElement.setAttribute('data-ithaki-r10f8','english-reference-lexicon1-argos');
 document.addEventListener('ithaki:global-language-changed',()=>{syncLexiconLanguage();setTimeout(()=>{ensureLexiconOwner();decorateProfile()},30)});
 document.addEventListener('ithaki:auto-content-translation-changed',e=>{if(!e.detail?.enabled)restoreUserContent()});
 const mo=new MutationObserver(()=>{ensureLexiconOwner();decorateProfile();if(!autoEnabled())restoreUserContent()});mo.observe(document.documentElement,{subtree:true,childList:true});
 ensureLexiconOwner();decorateProfile();if(!autoEnabled())restoreUserContent();setInterval(()=>{ensureLexiconOwner();decorateProfile()},3000)
}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',install,{once:true});else install();
})();
