/* OK ITHAKI V249526R8 — FULL DUPLICATE AUDIT / CANONICAL PLUS / EXTERNAL MESSAGE FORM */
(function(){
'use strict';
if(window.__ITHAKI_V249526R8_OWNER__)return;
window.__ITHAKI_V249526R8_OWNER__={version:'V249526R8',fullDuplicateAudit:true,canonicalPlusMenu:true,externalMessageForm:true,singleExternalOwner:true,nativeStoreDedupe:true,at:Date.now()};
const FULL_DUPLICATE_AUDIT_R8=true,CANONICAL_PLUS_MENU_R8=true,PLUS_MESSAGE_CENTER_ROUTES_EXTERNAL_R8=true,SINGLE_EXTERNAL_CENTER_OWNER_R8=true,NATIVE_EXTERNAL_STORE_DEDUP_R8=true;
const I=()=>window.ITH=window.ITH||{}, $=id=>document.getElementById(id);
const norm=v=>String(v||'').normalize('NFD').replace(/[\u0300-\u036f]/g,'').replace(/\s+/g,' ').trim().toLocaleLowerCase('el');
const bridge=()=>window.OKITHAKI_ANDROID||window.AndroidBridge||null;
function nativeCall(name,...args){try{const b=bridge();if(b&&typeof b[name]==='function')return b[name](...args)}catch(e){console.warn('R8 native',name,e)}return null}
function toast(m,ms=5000){try{if(typeof window.toast==='function')return window.toast(m,ms);if(I().toast)return I().toast(m,ms)}catch(e){}console.log(m)}
function addCss(){if($('ith529R8Css'))return;const s=document.createElement('style');s.id='ith529R8Css';s.textContent=`
#plusSheet.ith529CanonicalPlus{display:none!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:9px!important;padding:12px!important;max-height:min(78dvh,760px)!important;overflow:auto!important;overscroll-behavior:contain!important}
#plusSheet.ith529CanonicalPlus.show{display:grid!important}
#plusSheet .ith529PlusHead{grid-column:1/-1;position:sticky;top:-12px;z-index:4;display:flex;align-items:center;gap:9px;padding:10px;background:rgba(4,18,30,.98);border-bottom:1px solid rgba(154,211,255,.22)}
#plusSheet .ith529PlusHead b{flex:1;color:#ffe39a}.ith529PlusSection{grid-column:1/-1;margin:5px 2px -2px;color:#9ed9f5;font-size:11px;font-weight:950;letter-spacing:.08em;text-transform:uppercase}
#plusSheet [data-r8plus]{min-height:78px!important;display:grid!important;grid-template-columns:38px 1fr!important;gap:8px!important;align-items:center!important;text-align:left!important;padding:10px!important;border-radius:17px!important}
#plusSheet [data-r8plus] b{font-size:24px!important}.ith529PlusText strong{display:block;font-size:13px}.ith529PlusText small{display:block;opacity:.72;font-size:10.5px;margin-top:3px;line-height:1.25}
#plusSheet [data-r8plus="external"]{border-color:rgba(83,226,174,.65)!important;background:linear-gradient(145deg,rgba(7,99,73,.94),rgba(8,45,59,.95))!important}
#ith527ExternalOrganizer[data-r8-owner="1"]{z-index:2147483647!important}
@media(min-width:780px){#plusSheet.ith529CanonicalPlus{grid-template-columns:repeat(4,minmax(0,1fr))!important;width:min(980px,94vw)!important;left:50%!important;right:auto!important;transform:translateX(-50%)!important}}
`;document.head.appendChild(s)}
function state(){return I().state||window.state||{}}
function mediaDestination(){const s=state(),p=String(s.page||document.body?.dataset.page||'home');if(p==='dm'&&s.activeChannel)return{ctx:'dm',target:String(s.activeChannel||'')};if(p==='spaces'&&s.currentSpaceChannel)return{ctx:'space',target:String(s.currentSpaceChannel||s.currentSpace||'')};return{ctx:'feed',target:''}}
function call(name,...args){const f=I()[name]||window[name];if(typeof f==='function')return f.apply(I(),args);return false}
function closePlus(){const p=$('plusSheet');if(p)p.classList.remove('show');return false}
const PLUS_ITEMS=[
 ['section','Δημιουργία και δημοσίευση',''],
 ['camera_photo','📷','Λήψη φωτογραφίας','Κάμερα στη σωστή ενεργή οθόνη'],['camera_video','🎥','Εγγραφή βίντεο','Κάμερα στη σωστή ενεργή οθόνη'],['gallery_photo','🖼️','Φωτογραφία','Επιλογή από συσκευή'],['gallery_video','📼','Βίντεο','Επιλογή από συσκευή'],['audio','🎙️','Εγγραφή ήχου','Μήνυμα ή δημοσίευση'],['file','📎','Αρχείο','Αποστολή στη σωστή φόρμα'],['text','📝','Κείμενο','Κανονική φόρμα δημοσίευσης'],['poll','📊','Ψηφοφορία','Δημιουργία ψηφοφορίας'],
 ['section','Μηνύματα και επικοινωνία',''],
 ['external','📨','Κέντρο Μηνυμάτων','Email, Viber, SMS και άλλες εφαρμογές'],['dm','💬','Προσωπικά μηνύματα','Φίλοι και συνομιλίες'],['message_group','👥','Ομάδα στα Μηνύματα','Νέα ομαδική συνομιλία'],['spaces','🏘️','Κοινότητες / Δωμάτια','Νέα επαγγελματική οθόνη'],['comm_center','📡','Ομάδες / Broadcast','Κέντρο επικοινωνίας'],['forward','↪','Προώθηση','Προώθηση μηνύματος ή αρχείου'],['api_hooks','🔌','API / Webhook','Επαγγελματική σύνδεση'],
 ['section','Ειδοποιήσεις και εργαλεία',''],
 ['notifications','🔔','Κέντρο Ειδοποιήσεων','ΙΘΑΚΗ και εξωτερικές εφαρμογές'],['calendar','📅','Ημερολόγιο ενεργειών','Ανά εφαρμογή και ημερομηνία'],['bil','🐢','Bil','Ρυθμίσεις και ενημέρωση'],['qr','▦','QR','Κοινοποίηση OK ITHAKI'],['host','🌊','Οικοδεσπότης','Επικοινωνία με ΙΘΑΚΗ'],
 ['section','Ειδικές λειτουργίες',''],
 ['bottle','🍾','Μπουκάλι','Πέλαγος των Ψιθύρων'],['anon_wall','🕊️','Ανώνυμος Τοίχος','Ανώνυμη υποστήριξη'],['emergency','🆘','Έκτακτη offline','Τοπικό δίκτυο και βοήθεια']
];
function renderPlus(){addCss();const p=$('plusSheet');if(!p)return false;p.className='plusSheet ith529CanonicalPlus show';const seen=new Set();let html='<div class="ith529PlusHead"><button type="button" class="icon" data-r8plus="close">×</button><b>＋ Κέντρο δημιουργίας & επικοινωνίας</b><span></span></div>';
 for(const x of PLUS_ITEMS){if(x[0]==='section'){html+='<div class="ith529PlusSection">'+x[1]+'</div>';continue}if(seen.has(x[0]))continue;seen.add(x[0]);html+='<button type="button" class="tile" data-r8plus="'+x[0]+'"><b>'+x[1]+'</b><span class="ith529PlusText"><strong>'+x[2]+'</strong><small>'+x[3]+'</small></span></button>'}
 p.innerHTML=html;p.dataset.ithakiOwner='v249526r8';document.documentElement.setAttribute('data-ithaki-r8-plus-count',String(seen.size));return false}
let canonicalExternalBase=null;function captureExternalBase(){if(canonicalExternalBase)return canonicalExternalBase;const c=[I().openProfessionalNotificationOrganizerV249527,window.openProfessionalNotificationOrganizerV249527,I().openExternalMessageCenterV249477].find(f=>typeof f==='function'&&f!==openExternal);if(c)canonicalExternalBase=c;return canonicalExternalBase}
function openExternal(a,b){const initial=String(b||a||'inbox');closePlus();removeForeignExternalCenters();nativeCall('dedupeExternalMessageCenterV249529');const f=captureExternalBase();if(typeof f==='function'){const r=f(initial==='calendar'?'calendar':'inbox');const root=$('ith527ExternalOrganizer');if(root)root.dataset.r8Owner='1';return r}toast('Το επαγγελματικό Κέντρο Μηνυμάτων δεν είναι διαθέσιμο. Χρειάζεται το APK V249529.');return false}
function removeForeignExternalCenters(){document.querySelectorAll('#ith527ExternalOrganizer').forEach((x,i)=>{if(i>0)x.remove()});const old=$('ithProCenterV249477');if(old&&/Εξωτερικ|External Message/i.test(old.textContent||''))old.remove();document.querySelectorAll('#memberMenu #ith477ExtList,#memberMenu #ith477ExternalTabs').forEach(x=>{const host=x.closest('#memberMenu');if(host)host.classList.remove('show')})}
function act(a){closePlus();const d=mediaDestination();if(a==='close')return false;if(a==='external')return openExternal('inbox');if(a==='calendar')return openExternal('calendar');if(a==='dm')return call('page','dm');if(a==='message_group')return call('openClassicMessageGroupCreateV249284');if(a==='spaces')return call('page','spaces');if(a==='comm_center')return call('openCommCenterV249280','groups');if(a==='forward')return call('openCommCenterV249280','forward');if(a==='api_hooks')return call('openCommCenterV249280','api');if(a==='notifications')return call('notifyCenter');if(a==='bil')return call('openNotificationSettingsV249238');if(a==='qr')return call('showQR');if(a==='host')return call('openHostContact');if(a==='bottle')return call('openBottleSeaV249274','compose');if(a==='anon_wall')return call('openAnonymousWallV249283')||call('openCurrentWallV249440')||call('openWallV411');if(a==='emergency')return call('openEmergencyOfflineHubV249283');if(a==='text')return call('page','create');if(a==='poll')return call('openPoll');if(a==='camera_photo')return call('captureMedia',d.ctx,'photo',d.target);if(a==='camera_video')return call('captureMedia',d.ctx,'video',d.target);if(a==='audio')return call('startAudioRecording',d.ctx,d.target);if(a==='gallery_photo')return call('chooseFile',d.ctx,'photo',d.target);if(a==='gallery_video')return call('chooseFile',d.ctx,'video',d.target);if(a==='file')return call('chooseFile',d.ctx,'file',d.target);return false}
function plusCapture(e){if(window.__ITHAKI_V249526R9_OWNER__)return;const plus=e.target.closest('#nav button[data-page="plus"]');if(plus){e.preventDefault();e.stopImmediatePropagation();return renderPlus()}const q=e.target.closest('#plusSheet [data-r8plus]');if(q){e.preventDefault();e.stopImmediatePropagation();return act(q.dataset.r8plus)}}
function semanticElementKey(el){return norm(el.getAttribute('data-key')||el.getAttribute('data-id')||el.getAttribute('data-space-id')||el.getAttribute('data-subroom-id')||el.textContent||'')}
function dedupeChildren(root,selector){if(!root)return 0;const seen=new Set();let removed=0;root.querySelectorAll(selector).forEach(x=>{const k=semanticElementKey(x);if(!k)return;if(seen.has(k)){x.remove();removed++}else seen.add(k)});return removed}
function auditDuplicates(){let removed=0;const singleton=['#ith527ExternalOrganizer','#ith526BilDock','#ithNotifyFabV249238'];for(const sel of singleton){const a=[...document.querySelectorAll(sel)];a.slice(1).forEach(x=>{x.remove();removed++})}
 const p=$('plusSheet');if(p&&p.dataset.ithakiOwner==='v249526r8')removed+=dedupeChildren(p,'[data-r8plus]');
 if(!window.__ITHAKI_R10F13_SINGLE_COMMUNITY_RUNTIME__){const spaces=$('ith516List')||document.querySelector('#spacesPage [data-community-list],#spacesPage .ith516List');if(spaces)removed+=dedupeChildren(spaces,'[data-space-id],[data-subroom-id],.ith516SpaceCard,.ith517SpaceCard')}
 const bells=[...document.querySelectorAll('#ithNotifyFabV249238,.ithNotifyFabV249238,[data-notifications-fab]')],keep=bells.find(x=>x.id==='ithNotifyFabV249238')||bells[0];bells.forEach(x=>{if(x!==keep){x.remove();removed++}});
 document.documentElement.setAttribute('data-ithaki-r8-duplicates-removed',String(removed));window.__ITHAKI_R8_DUPLICATE_AUDIT__={removed,at:Date.now(),plusButtons:p?p.querySelectorAll('[data-r8plus]').length:0,externalCenters:document.querySelectorAll('#ith527ExternalOrganizer').length,bells:document.querySelectorAll('#ithNotifyFabV249238,.ithNotifyFabV249238,[data-notifications-fab]').length};return removed}
function installAliases(){const o=I();captureExternalBase();o.openPlusMenuV249415=renderPlus;o.openCanonicalPlusMenuV249529=renderPlus;o.togglePlus=renderPlus;window.togglePlus=renderPlus;o.openExternalMessageCenterV249477=openExternal;o.openExternalCenterV249508=openExternal;o.openExternalMessagesCenterV249508=openExternal;o.openProfessionalNotificationOrganizerV249527=openExternal;o.openExternalMessageCenterV249529=openExternal;o.renderLocalProfessionalCalendarV249477=()=>openExternal('calendar');window.openProfessionalNotificationOrganizerV249527=openExternal;window.openExternalMessageCenterV249529=openExternal}
function install(){addCss();installAliases();document.addEventListener('click',plusCapture,true);nativeCall('dedupeExternalMessageCenterV249529');auditDuplicates();setInterval(()=>{installAliases();auditDuplicates()},4000);new MutationObserver(()=>{clearTimeout(install.m);install.m=setTimeout(auditDuplicates,90)}).observe(document.body,{childList:true,subtree:true});document.documentElement.setAttribute('data-ithaki-v249526r8','full-dedup-canonical-plus-external-form');try{localStorage.setItem('ith_frontend_build','V249526R8-full-dedup-canonical-plus-external-form')}catch(e){}}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',install,{once:true});else install();
})();
