/* OK ITHAKI V249526R10F10 — OLD HOME / WORKING COMMUNITIES / MESSAGE CENTER ROUTE */
(function(){
'use strict';
if(window.__ITHAKI_V249526R10F10_OWNER__)return;
window.__ITHAKI_V249526R10F10_OWNER__={version:'V249526R10F10',oldHomeNoTemporaryAvatar:true,communityRuntimeInitFixed:true,communitySingleRecovery:true,plusMessageCenterNotifications:true,at:Date.now()};
window.HOME_OLD_LAYOUT_NO_TEMP_AVATAR_R10F10=true;
window.COMMUNITY_CACHE_INIT_ORDER_FIXED_R10F10=true;
window.COMMUNITY_LOAD_RECOVERY_R10F10=true;
window.PLUS_MESSAGE_CENTER_NOTIFICATIONS_R10F10=true;
window.R10F10_LAST_FRONTEND_OWNER=true;
const I=()=>window.ITH=window.ITH||{},$=id=>document.getElementById(id);
let opening=false,watchTimer=0;
function toast(m,ms=6000){try{if(typeof I().toast==='function')return I().toast(m,ms)}catch(_e){}const t=$('toast');if(t){t.textContent=m;t.classList.add('show');setTimeout(()=>t.classList.remove('show'),ms)}}
function removeTemporaryHome(){['ith537HomeProfileCard','ithR10F9HomeProfile'].forEach(id=>$(id)?.remove());document.querySelectorAll('#homePage .ith537HomeProfileCard,#homePage .ithR10F9HomeProfile').forEach(x=>x.remove())}
function openMessageCenter(){const p=$('plusSheet');if(p)p.classList.remove('show');const f=I().openExternalMessageCenterV249529||I().openProfessionalNotificationOrganizerV249527||I().openExternalMessageCenterV249477||window.openProfessionalNotificationOrganizerV249527;if(typeof f==='function'){f.call(I(),'inbox');return true}if(typeof I().notifyCenter==='function'){I().notifyCenter();toast('Άνοιξε το Κέντρο Ειδοποιήσεων. Επίλεξε Κέντρο Μηνυμάτων.');return true}toast('Το Κέντρο Μηνυμάτων δεν είναι διαθέσιμο.');return false}
function relabelPlus(){document.querySelectorAll('#plusSheet [data-r9plus="external"],#plusSheet [data-r8plus="external"]').forEach(b=>{const strong=b.querySelector('strong');if(strong)strong.textContent='Κέντρο Μηνυμάτων';const small=b.querySelector('small');if(small)small.textContent='Email, Viber, SMS και άλλες εφαρμογές';b.setAttribute('aria-label','Κέντρο Μηνυμάτων')})}
function cardsPresent(){const l=$('ith516List');return !!(l&&l.querySelector('[data-space-id],[data-subroom-id],.ith516Row,.ith517SpaceCard'))}
function showCommunityError(message){const l=$('ith516List');if(!l)return;l.innerHTML='<div class="card dmEmptyV249235"><b>Δεν φορτώθηκαν οι Κοινότητες.</b><small>'+String(message||'Η σύνδεση δεν απάντησε.')+'</small><button type="button" data-r10f10-community-retry>↻ Νέα προσπάθεια</button></div>'}
async function ensureCommunityData(){const load=I().loadSpacesV249516;if(typeof load!=='function')return false;try{await Promise.resolve(load.call(I(),true));return cardsPresent()}catch(e){showCommunityError(e&&e.message);return false}}
function monitorCommunities(){clearTimeout(watchTimer);let rounds=0;const step=async()=>{if(String(document.body?.dataset.page||'')!=='spaces'){opening=false;return}if(cardsPresent()){opening=false;return}rounds++;if(rounds===2)await ensureCommunityData();if(cardsPresent()){opening=false;return}if(rounds>=5){showCommunityError('Πάτησε Νέα προσπάθεια. Η κανονική λειτουργία της εφαρμογής παραμένει ενεργή.');opening=false;return}watchTimer=setTimeout(step,1400)};watchTimer=setTimeout(step,900)}
function openCommunities(){if(opening)return true;opening=true;const activate=I().activateSpacesPageV249516||I().renderSpacesV249516;if(typeof activate!=='function'){opening=false;toast('Η οθόνη Κοινοτήτων δεν φορτώθηκε. Κάνε ανανέωση.');return false}try{activate.call(I());monitorCommunities();return true}catch(e){opening=false;showCommunityError(e&&e.message);return false}}
function installAliases(){const o=I();const base=o.page;if(!base?.__v249526r10f10){const page=function(id){if(String(id)==='spaces')return openCommunities();return typeof base==='function'?base.apply(this,arguments):false};page.__v249526r10f10=true;o.page=page}o.openCommunitiesR10F10=openCommunities;o.openMessageCenterR10F10=openMessageCenter;o.openNamesCenterR10F9=openMessageCenter}
function capture(e){const ext=e.target.closest('#plusSheet [data-r9plus="external"],#plusSheet [data-r8plus="external"]');if(ext){e.preventDefault();e.stopImmediatePropagation();return openMessageCenter()}const retry=e.target.closest('[data-r10f10-community-retry]');if(retry){e.preventDefault();e.stopImmediatePropagation();opening=false;return openCommunities()}const spaces=e.target.closest('[data-page="spaces"],#plusSheet [data-r9plus="spaces"],#plusSheet [data-r8plus="spaces"]');if(spaces){e.preventDefault();e.stopImmediatePropagation();return openCommunities()}}
function scan(){removeTemporaryHome();relabelPlus();installAliases();document.documentElement.setAttribute('data-ithaki-r10f10','old-home-working-communities-message-center')}
function install(){const st=document.createElement('style');st.id='ithR10F10Style';st.textContent='#ith537HomeProfileCard,#ithR10F9HomeProfile{display:none!important}#ith516List [data-r10f10-community-retry]{margin-top:12px;min-height:42px;border-color:var(--green,#36f0a0)}';document.head.appendChild(st);document.addEventListener('click',capture,true);new MutationObserver(()=>{clearTimeout(install._m);install._m=setTimeout(scan,50)}).observe(document.documentElement,{subtree:true,childList:true});window.addEventListener('pageshow',scan);window.addEventListener('ithaki:page-changed',e=>{if(String(e.detail?.page||'')==='spaces')setTimeout(openCommunities,0)});scan()}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',install,{once:true});else install();
})();
