/* OK ITHAKI R10F27 — official website, guest and QR download in + menu */
(()=>{'use strict';
const SITE='https://www.ok-ithaki.gr/';
const GUEST='https://ok-ithaki.gr/?mode=guest';
const APK='https://www.ok-ithaki.gr/downloads/ok-ithaki.apk';
const esc=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
function openExternal(url){
  try{ if(window.Android?.openExternalUrl){window.Android.openExternalUrl(url);return;} }catch(e){}
  try{ if(window.Android?.openUrl){window.Android.openUrl(url);return;} }catch(e){}
  window.open(url,'_blank','noopener,noreferrer');
}
function qrUrl(text){return 'https://api.qrserver.com/v1/create-qr-code/?size=320x320&data='+encodeURIComponent(text)}
function showQR(){
 document.getElementById('ithSiteQr27')?.remove();
 const x=document.createElement('div');x.id='ithSiteQr27';x.innerHTML=`<div class="ithSiteQrCard27"><button class="ithSiteQrClose27" aria-label="Κλείσιμο">×</button><h2>OK ITHAKI · Λήψη στο κινητό</h2><img src="${qrUrl(APK)}" alt="QR λήψης OK ITHAKI"><p>Σάρωσε το QR από το κινητό για άμεση λήψη από την επίσημη ιστοσελίδα.</p><button class="ithSiteQrDownload27">Άνοιγμα λήψης APK</button><button class="ithSiteQrWeb27">Άνοιγμα www.ok-ithaki.gr</button></div>`;
 document.body.appendChild(x);x.querySelector('.ithSiteQrClose27').onclick=()=>x.remove();x.onclick=e=>{if(e.target===x)x.remove()};x.querySelector('.ithSiteQrDownload27').onclick=()=>openExternal(APK);x.querySelector('.ithSiteQrWeb27').onclick=()=>openExternal(SITE);
}
function css(){if(document.getElementById('ithSiteQrCss27'))return;const s=document.createElement('style');s.id='ithSiteQrCss27';s.textContent=`#ithSiteQr27{position:fixed;inset:0;z-index:2147483647;display:grid;place-items:center;padding:18px;background:rgba(1,7,14,.88);backdrop-filter:blur(12px)}.ithSiteQrCard27{width:min(440px,100%);padding:24px;border:1px solid #328bc1;border-radius:22px;background:linear-gradient(155deg,#09233a,#020b15);color:#fff;text-align:center;box-shadow:0 24px 70px #000}.ithSiteQrCard27 h2{color:#ffd166}.ithSiteQrCard27 img{width:min(300px,80vw);border:8px solid #fff;border-radius:12px}.ithSiteQrCard27 button{display:block;width:100%;margin-top:10px;padding:13px;border-radius:10px;border:1px solid #328bc1;background:#0a3454;color:#fff;font-weight:900}.ithSiteQrClose27{position:absolute!important;width:44px!important;right:16px;top:12px;font-size:24px}.ithSitePlus27{border-color:#d7a747!important;background:linear-gradient(135deg,#11324b,#071725)!important;color:#ffe08a!important}`;document.head.appendChild(s)}
function button(label,action){const b=document.createElement('button');b.type='button';b.className='ithSitePlus27';b.textContent=label;b.onclick=e=>{e.preventDefault();e.stopPropagation();action()};return b}
function suitable(el){if(!el||el.dataset.ithSite27==='1')return false;const t=(el.textContent||'').toLowerCase();const id=(el.id+' '+el.className).toLowerCase();return /δημοσί|δημιουργ|create|publish|κέντρο|μενού/.test(t)||/plus.*menu|create.*menu|publish.*menu|composer.*menu/.test(id)}
function install(){css();const nodes=[...document.querySelectorAll('[id*="plus" i],[class*="plus" i],[id*="create" i],[class*="create" i],[id*="publish" i],[class*="publish" i],dialog,.modal')];nodes.filter(suitable).forEach(el=>{el.dataset.ithSite27='1';const box=document.createElement('div');box.className='ithSiteLinks27';box.append(button('🌐 Επίσημη ιστοσελίδα',()=>openExternal(SITE)),button('👤 Δες ως επισκέπτης',()=>openExternal(GUEST)),button('▣ QR λήψη στο κινητό',showQR));el.appendChild(box)});}
window.ITHAKI_OFFICIAL_SITE=()=>openExternal(SITE);window.ITHAKI_GUEST=()=>openExternal(GUEST);window.ITHAKI_APK_QR=showQR;
new MutationObserver(()=>install()).observe(document.documentElement,{childList:true,subtree:true});addEventListener('DOMContentLoaded',install);setTimeout(install,600);setInterval(install,4000);
})();
