/* OK ITHAKI V249523 - APK SYNC / SINGLE ACTUAL FILE SHARE / SINGLE BIL OWNER */
(function(){
'use strict';
if(window.__ITHAKI_V249523_SHARE_BIL_OWNER__)return;
window.__ITHAKI_V249523_SHARE_BIL_OWNER__={version:'V249523',singleShareOwner:true,apkSynced:true,singleBilNotifications:true,bilWordsOnHome:true,at:Date.now()};
window.__ITHAKI_V249516_COMMUNITY_SINGLE_OWNER__=true;
window.__ITHAKI_V249517_COMMUNITY_SINGLE_OWNER__=true;
window.__ITHAKI_V249522_COMMUNITY_SINGLE_OWNER__=true;
const I=()=>window.ITH||{};
const $=id=>document.getElementById(id);
const state=window.__ITHAKI_SHARE_V249523__={lastTap:0,activeJobs:new Set()};
const words=[
 'Όταν ακούμε πραγματικά, η απόσταση μικραίνει.',
 'Η καλοσύνη δεν κάνει θόρυβο, αλλά αλλάζει τη διαδρομή.',
 'Μια καθαρή κουβέντα αξίζει περισσότερο από εκατό υποθέσεις.',
 'Η ελευθερία μεγαλώνει όταν συνοδεύεται από σεβασμό.',
 'Το ταξίδι γίνεται ανθρώπινο όταν κανείς δεν μένει μόνος.',
 'Η ηρεμία δεν είναι σιωπή· είναι χώρος για να ακουστεί η αλήθεια.',
 'Η εμπιστοσύνη χτίζεται με μικρές πράξεις που επαναλαμβάνονται.',
 'Να μιλάς καθαρά, να ακούς ήρεμα και να αφήνεις χώρο στον άλλον.'
];
function en(){try{return (localStorage.getItem('ith_ui_language')||localStorage.getItem('ith_ui_lang')||'el')==='en'}catch(e){return false}}
function toast(m,ms=4800){try{if(I().toast)return I().toast(m,ms)}catch(e){}const t=$('toast');if(t){t.textContent=m;t.classList.add('show');clearTimeout(toast._t);toast._t=setTimeout(()=>t.classList.remove('show'),ms)}else console.log(m)}
function apiBase(){try{const b=window.AndroidBridge||window.OKITHAKI_ANDROID;if(b&&typeof b.getServerBase==='function'){const x=String(b.getServerBase()||'').trim();if(x)return x.replace(/\/$/,'')}}catch(e){}return location.origin&&/^https?:/i.test(location.origin)?location.origin:'https://ok-ithaki.gr'}
function fullUrl(u){u=String(u||'').trim();if(!u)return'';try{return new URL(u,apiBase()+'/').toString()}catch(e){return u}}
function safeName(n,f='ITHAKI_file'){n=String(n||'').split(/[?#]/)[0].split('/').pop()||f;try{n=decodeURIComponent(n)}catch(e){}return n.replace(/[\\/:*?"<>|]+/g,'_').slice(0,120)||f}
function mimeFor(n,m=''){if(m&&m!=='application/octet-stream')return m;n=String(n||'').toLowerCase();if(/\.(mp4|m4v)$/.test(n))return'video/mp4';if(/\.webm$/.test(n))return'video/webm';if(/\.(jpg|jpeg)$/.test(n))return'image/jpeg';if(/\.png$/.test(n))return'image/png';if(/\.gif$/.test(n))return'image/gif';if(/\.pdf$/.test(n))return'application/pdf';if(/\.txt$/.test(n))return'text/plain';if(/\.mp3$/.test(n))return'audio/mpeg';if(/\.m4a$/.test(n))return'audio/mp4';return m||'application/octet-stream'}
function token(){try{return localStorage.getItem('ith_public_token')||localStorage.getItem('ith_token')||''}catch(e){return''}}
function device(){try{return localStorage.getItem('ith_device')||localStorage.getItem('ith_device_id')||''}catch(e){return''}}
function room(){try{return localStorage.getItem('ith_room')||'ithaki-phone-test'}catch(e){return'ithaki-phone-test'}}
function bridge(){return window.AndroidBridge||window.OKITHAKI_ANDROID||null}
function tapAllowed(){const now=Date.now();if(now-state.lastTap<850)return false;state.lastTap=now;return true}
function jobKey(prefix,value){return prefix+':'+String(value||'').slice(0,500)}
function beginJob(k){if(state.activeJobs.has(k))return false;state.activeJobs.add(k);setTimeout(()=>state.activeJobs.delete(k),45000);return true}
function endJob(k){state.activeJobs.delete(k)}
function blobData(blob){return new Promise((res,rej)=>{const r=new FileReader();r.onload=()=>res(String(r.result||''));r.onerror=()=>rej(r.error||Error('file_read_failed'));r.readAsDataURL(blob)})}
async function browserBlobShare(blob,name,mime){try{const f=new File([blob],name,{type:mime||blob.type||'application/octet-stream'});if(navigator.canShare&&navigator.canShare({files:[f]})&&navigator.share){await navigator.share({files:[f],title:'OK ITHAKI'});return true}}catch(e){if(e&&e.name==='AbortError')return false;console.warn('browser share',e)}const a=document.createElement('a');a.href=URL.createObjectURL(blob);a.download=name;document.body.appendChild(a);a.click();setTimeout(()=>{URL.revokeObjectURL(a.href);a.remove()},1800);toast(en()?'The file was downloaded because system sharing is unavailable.':'Το αρχείο αποθηκεύτηκε επειδή η συσκευή δεν άνοιξε την κοινοποίηση.');return true}
async function shareBlob(blob,name='ITHAKI_file',mime=''){name=safeName(name);mime=mimeFor(name,mime||blob.type);if(!tapAllowed())return false;const key=jobKey('blob',name+':'+blob.size);if(!beginJob(key))return false;try{const b=bridge();if(b&&typeof b.shareBase64FileV249523==='function'&&blob.size<=24*1024*1024){const r=String(b.shareBase64FileV249523(name,mime,await blobData(blob))||'');if(/^ok/i.test(r))return true;throw Error(r||'native_file_share_failed')}if(b&&typeof b.shareBase64File==='function'&&blob.size<=12*1024*1024){const r=String(b.shareBase64File(name,mime,await blobData(blob))||'');if(/^ok/i.test(r))return true}return await browserBlobShare(blob,name,mime)}catch(e){toast((en()?'File sharing failed: ':'Η κοινοποίηση αρχείου απέτυχε: ')+String(e&&e.message||e),7000);return false}finally{endJob(key)}}
async function shareRemote(url,name='',mime=''){const u=fullUrl(url);name=safeName(name||u);mime=mimeFor(name,mime);if(!u){toast('Δεν υπάρχει πραγματικό αρχείο για κοινοποίηση.');return false}if(!tapAllowed())return false;const key=jobKey('remote',u);if(!beginJob(key))return false;try{const b=bridge();if(b&&typeof b.shareRemoteFileV249523==='function'){toast('Προετοιμασία πραγματικού αρχείου…');const r=String(b.shareRemoteFileV249523(u,name,mime,token(),device(),room())||'');if(/^(queued|ok)/i.test(r))return true;throw Error(r||'native_remote_share_failed')}if(b){toast('Χρειάζεται εγκατάσταση του APK V249523 για πραγματική κοινοποίηση αρχείων.',7000)}const h={};const t=token();if(t)h['X-ITHAKI-TOKEN']=t;const d=device();if(d)h['X-ITHAKI-DEVICE-ID']=d;const r=await fetch(u,{cache:'no-store',credentials:'include',headers:h});if(!r.ok)throw Error('HTTP '+r.status);return await browserBlobShare(await r.blob(),name,mime)}catch(e){toast((en()?'File sharing failed: ':'Η κοινοποίηση αρχείου απέτυχε: ')+String(e&&e.message||e),7000);return false}finally{endJob(key)}}
async function shareText(text,name='ITHAKI_message.txt'){return shareBlob(new Blob([String(text||'')],{type:'text/plain;charset=utf-8'}),name,'text/plain')}
async function shareAny(url,text=''){const u=String(url||'');if(u&&(/\/api\/media\/file\/|\.(mp4|mov|webm|3gp|mkv|avi|jpe?g|png|gif|webp|pdf|docx?|xlsx?|pptx?|zip|rar|7z|mp3|m4a|wav|ogg)(?:[?#]|$)/i.test(u)))return shareRemote(u,safeName(u),'');return shareText([text,u].filter(Boolean).join('\n'),'ITHAKI_share.txt')}
function installShareOwner(){if(window.__ITHAKI_V249526R3_OWNER__)return;const o=I();Object.assign(o,{shareActualFileV249523:shareRemote,shareBlobV249523:shareBlob,shareTextFileV249523:shareText,shareTextFileV249522:shareText,shareMediaFile:async(url,filename='',mime='')=>{await shareRemote(url,filename,mime);return false},shareActualUrlFileV249521:shareRemote,share:shareAny});window.shareMediaFile=o.shareMediaFile;window.shareActualUrlFileV249521=shareRemote;window.__ITHAKI_V249523_SHARE_READY__=true}
function face(){return '<span class="ith523BilFace" aria-hidden="true"><i class="shell"></i><i class="head"><i class="eye l"></i><i class="eye r"></i><i class="mouth"></i></i><i class="foot l"></i><i class="foot r"></i></span>'}
function bilEnabled(){try{return localStorage.getItem('ith_bil_enabled_v249461')!=='0'}catch(e){return true}}
function setBil(v){try{localStorage.setItem('ith_bil_enabled_v249461',v?'1':'0');localStorage.setItem('ithaki_companion_v249258',v?'bil':'none')}catch(e){}renderBil()}
function nextWord(){let i=Number(sessionStorage.getItem('ith523BilWord')||-1);i=(i+1)%words.length;sessionStorage.setItem('ith523BilWord',String(i));return words[i]}
const OLD_BIL_IDS=['ithBilGreenTurtleV249461','ithBilMenuV249461','ithBilPopV249461','ithBilStableV249475','ithBilStableMenuV249475','ithProfileBilCardV249476','ithAdminContactCardV249476','ith477BilNotificationCard','ith509BilNotificationCard'];
function removeOldBil(){OLD_BIL_IDS.forEach(id=>{const x=$(id);if(x)x.remove()});document.querySelectorAll('[data-bil-notification-card],#profilePage [data-bil],#profilePage [id*="bil" i],#profilePage [class*="bil" i]').forEach(x=>{if(!x.closest('#ith523BilNotificationCard')&&!x.closest('#ith523HomeBilCard'))x.remove()})}
function notificationHost(){for(const id of ['notifySettingsV249258','notificationSettingsV249238','ithNotificationSettingsV249238','notificationCenter']){const x=$(id);if(x)return x}const candidates=[...document.querySelectorAll('.memberMenu.show,.previewModal.show,.page.active')];return candidates.find(x=>/ειδοποι|notification/i.test(String(x.textContent||'')))||null}
function renderNotificationBil(){const host=notificationHost();if(!host)return;host.querySelectorAll('[data-bil-notification-card]:not(#ith523BilNotificationCard),#ith477BilNotificationCard,#ith509BilNotificationCard').forEach(x=>x.remove());let d=$('ith523BilNotificationCard');if(d&&d.parentElement!==host)d.remove();if(!d){d=document.createElement('section');d.id='ith523BilNotificationCard';d.className='card ith523BilNotificationCard';d.dataset.bilNotificationCard='single-v249523';host.prepend(d)}const on=bilEnabled();d.innerHTML='<div class="ith523BilRow">'+face()+'<div class="ith523BilGrow"><b>Bil</b><small>'+(en()?'One Bil for calm notification guidance.':'Ένας Bil για ήρεμη καθοδήγηση στις ειδοποιήσεις.')+'</small></div></div><div class="row ith523BilToggle"><button class="btn '+(on?'green':'')+'" data-ith523-bil="1">'+(en()?'Enabled':'Ενεργός')+'</button><button class="btn '+(!on?'green':'')+'" data-ith523-bil="0">'+(en()?'Disabled':'Ανενεργός')+'</button></div>';d.onclick=e=>{const b=e.target.closest('[data-ith523-bil]');if(b)setBil(b.dataset.ith523Bil==='1')}}
function renderHomeBil(){const home=$('homePage');if(!home)return;let d=$('ith523HomeBilCard');if(!bilEnabled()){if(d)d.remove();return}const root=home.querySelector('.ithHomeV249461')||home;if(!(home.classList.contains('active')||document.body?.dataset.page==='home'))return;if(d&& !root.contains(d))d.remove();if(!d){d=document.createElement('section');d.id='ith523HomeBilCard';d.className='ith523HomeBilCard';d.innerHTML='<button class="ith523BilAvatarBtn" type="button" title="Bil">'+face()+'</button><div class="ith523BilWords"><b>Bil</b><p>'+String(sessionStorage.getItem('ith523BilCurrent')||nextWord())+'</p></div><button class="ith523BilNext" type="button" title="Άλλος λόγος">✦</button>';d.querySelector('.ith523BilNext').onclick=()=>{const w=nextWord();sessionStorage.setItem('ith523BilCurrent',w);d.querySelector('p').textContent=w};d.querySelector('.ith523BilAvatarBtn').onclick=()=>{const w=nextWord();sessionStorage.setItem('ith523BilCurrent',w);d.querySelector('p').textContent=w};const wisdom=root.querySelector('.ithWisdomV249461');if(wisdom)wisdom.insertAdjacentElement('afterend',d);else root.prepend(d)}}
function addCss(){if($('ith523Css'))return;const s=document.createElement('style');s.id='ith523Css';s.textContent=`
#ithBilGreenTurtleV249461,#ithBilMenuV249461,#ithBilPopV249461,#ithBilStableV249475,#ithBilStableMenuV249475,#ithProfileBilCardV249476,#ithAdminContactCardV249476{display:none!important;visibility:hidden!important;opacity:0!important;pointer-events:none!important}
.ith523BilFace{position:relative;width:58px;height:52px;display:block;flex:0 0 58px}.ith523BilFace .shell{position:absolute;left:8px;top:21px;width:40px;height:27px;border-radius:55% 55% 43% 43%;background:radial-gradient(circle at 44% 23%,#ffe49c 0 18%,#62bf89 19% 55%,#246b50 56% 100%);box-shadow:inset 0 1px 0 rgba(255,255,255,.35)}.ith523BilFace .head{position:absolute;left:22px;top:2px;width:25px;height:25px;border-radius:50%;background:#7bdaa0}.ith523BilFace .eye{position:absolute;top:7px;width:4px;height:6px;border-radius:50%;background:#10231e}.ith523BilFace .eye.l{left:6px}.ith523BilFace .eye.r{right:6px}.ith523BilFace .mouth{position:absolute;left:8px;top:16px;width:9px;height:4px;border-bottom:2px solid #17392e;border-radius:0 0 9px 9px}.ith523BilFace .foot{position:absolute;top:44px;width:10px;height:6px;border-radius:99px;background:#62bf89}.ith523BilFace .foot.l{left:9px}.ith523BilFace .foot.r{right:7px}
.ith523HomeBilCard{display:flex;align-items:center;gap:12px;width:100%;padding:11px 13px;border-radius:19px;border:1px solid rgba(111,231,169,.28);background:linear-gradient(145deg,rgba(29,93,69,.42),rgba(255,255,255,.055));box-shadow:0 13px 32px rgba(0,0,0,.22);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px)}.ith523BilAvatarBtn,.ith523BilNext{border:0;background:transparent;color:#ffe08a;cursor:pointer;padding:0}.ith523BilWords{min-width:0;flex:1}.ith523BilWords b{font-size:17px;color:#8ee5ac}.ith523BilWords p{margin:3px 0 0;font-size:13px;line-height:1.4;color:#f5fbf7}.ith523BilNext{width:38px;height:38px;border-radius:50%;border:1px solid rgba(255,224,138,.38);background:rgba(255,224,138,.09);font-size:18px}.ith523BilRow{display:flex;align-items:center;gap:11px}.ith523BilGrow{display:flex;flex-direction:column;gap:3px}.ith523BilGrow b{font-size:18px}.ith523BilGrow small{opacity:.78;line-height:1.35}.ith523BilToggle{margin-top:10px}.ith523BilNotificationCard{border:1px solid rgba(111,231,169,.25)!important}
@media(max-width:760px){.ith523HomeBilCard{padding:8px 10px;gap:8px}.ith523BilFace{transform:scale(.88);transform-origin:center}.ith523BilWords b{font-size:15px}.ith523BilWords p{font-size:12px}.ith523BilNext{width:34px;height:34px}}
`;document.head.appendChild(s)}
function renderBil(){if(window.__ITHAKI_V249525_NOTIFICATION_OWNER__)return;removeOldBil()}
function verifyApkSync(){const b=bridge();if(!b)return;try{if(typeof b.getIthakiNativeBuildV249523==='function'){const raw=String(b.getIthakiNativeBuildV249523()||'');document.documentElement.setAttribute('data-ithaki-apk-v249523',raw||'ok');return}if(!sessionStorage.getItem('ith523OldApkWarn')){sessionStorage.setItem('ith523OldApkWarn','1');setTimeout(()=>toast('Ο server είναι V249523. Εγκατέστησε και το νέο APK για να λειτουργήσει η πραγματική κοινοποίηση.',8000),1200)}}catch(e){}}
function install(){addCss();installShareOwner();renderBil();verifyApkSync();window.addEventListener('ithaki:native-share-result',e=>{const d=e.detail||{};if(d.ok)toast('Άνοιξε η κοινοποίηση του πραγματικού αρχείου.');else toast('Η κοινοποίηση απέτυχε: '+String(d.message||''),7000)});new MutationObserver(()=>{clearTimeout(install._m);install._m=setTimeout(()=>{installShareOwner();renderBil()},80)}).observe(document.body,{subtree:true,childList:true});window.addEventListener('ithaki:page-changed',()=>setTimeout(renderBil,60));window.addEventListener('pageshow',()=>{state.activeJobs.clear();setTimeout(()=>{installShareOwner();renderBil();verifyApkSync()},80)});setInterval(()=>{installShareOwner();renderBil()},1800);try{localStorage.setItem('ith_frontend_build','V249523-apk-sync-actual-share-single-bil-home')}catch(e){}document.documentElement.setAttribute('data-ithaki-v249523','apk-sync-actual-share-single-bil-home')}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',install,{once:true});else install();
})();
