/* OK ITHAKI V249526R10F14 — CANONICAL COMMUNITY SHELL / MESSAGE SEND COMPAT / EXACT SETTINGS BUTTON */
(function(){
'use strict';
if(window.__ITHAKI_R10F15_SINGLE_COMMUNITY_RUNTIME__){window.R10F15_COMPATIBILITY_DISABLED=true;return;}
if(window.__ITHAKI_V249526R10F14_OWNER__)return;
window.__ITHAKI_V249526R10F14_OWNER__={version:'V249526R10F14',canonicalCommunityShell:true,legacyShellReplacement:true,messageSendCompatibility:true,exactNotificationSettingsButton:true,at:Date.now()};
window.COMMUNITY_CANONICAL_SHELL_R10F14=true;
window.COMMUNITY_OLD_SHELL_REPLACED_R10F14=true;
window.COMMUNITY_MESSAGE_SEND_COMPAT_R10F14=true;
window.PLUS_EXACT_SETTINGS_BUTTON_R10F14=true;
const I=()=>window.ITH=window.ITH||{},$=id=>document.getElementById(id);
function closePlus(){const p=$('plusSheet');if(p)p.classList.remove('show');return false}
function toast(m,ms=6500){try{const f=I().toast||window.toast;if(typeof f==='function')return f.call(I(),m,ms)}catch(_e){}console.log(m)}
function state(){return I().state||window.state||{}}
function room(){const s=state();try{return String(s.room||localStorage.getItem('ith_room')||'ithaki-phone-test')}catch(_e){return String(s.room||'ithaki-phone-test')}}
function device(){const s=state();try{return String(s.device||localStorage.getItem('ith_device')||'')}catch(_e){return String(s.device||'')}}
function nickname(){const s=state();try{return String(s.name||s.nickname||localStorage.getItem('ith_name')||localStorage.getItem('ith_nickname')||'Μέλος')}catch(_e){return String(s.name||s.nickname||'Μέλος')}}
function currentChannel(){const s=state();return String(s.currentSpaceChannel||(s.currentSpace?('space:'+s.currentSpace):''))}
async function sendPayloadCompat(){
 const args=[...arguments];let channel='',payload='';
 if(args.length>=2){channel=String(args[0]||'');payload=args[1]}
 else {channel=currentChannel();payload=args[0]}
 if(payload&&typeof payload==='object')payload=JSON.stringify(payload);
 payload=String(payload==null?'':payload);
 if(payload&&!/^\s*[\[{]/.test(payload))payload=JSON.stringify({body:payload});
 const exact=I().sendMessagePayload||window.sendMessagePayload;
 if(typeof exact==='function'&&exact!==sendPayloadCompat)return exact.call(I(),channel,payload);
 if(!channel)throw new Error('Δεν έχει επιλεγεί κοινότητα.');
 const token=(()=>{try{return String(localStorage.getItem('ith_public_token')||localStorage.getItem('ith_token')||'')}catch(_e){return''}})();
 const h={'Content-Type':'application/json'};if(token)h['X-ITHAKI-TOKEN']=token;
 const body={room_id:room(),channel,sender_id:device(),nickname:nickname(),language:'el',text:payload};
 const r=await fetch(location.origin.replace(/\/$/,'')+'/api/messages/send',{method:'POST',cache:'no-store',headers:h,body:JSON.stringify(body)});
 let d={};try{d=await r.json()}catch(_e){}
 if(!r.ok)throw new Error(String(d.detail||d.message||('HTTP '+r.status)));
 return d;
}
function installSendCompatibility(){
 const o=I();
 window.sendΜήνυμαPayload=sendPayloadCompat;o.sendΜήνυμαPayload=sendPayloadCompat;
 if(typeof window.sendMessagePayload!=='function'&&typeof o.sendMessagePayload==='function')window.sendMessagePayload=o.sendMessagePayload.bind(o);
 if(typeof o.sendMessagePayload!=='function'&&typeof window.sendMessagePayload==='function')o.sendMessagePayload=window.sendMessagePayload;
}
function openCanonicalCommunities(){
 closePlus();
 const f=I().openCanonicalCommunitiesR10F14||window.openCanonicalCommunitiesR10F14||I().activateSpacesPageV249516||window.activateSpacesPageV249516;
 if(typeof f==='function'&&f!==openCanonicalCommunities)return f.call(I());
 toast('Η νέα οθόνη Κοινοτήτων δεν φορτώθηκε.');return false;
}
function clickRealSettingsMessageButton(){
 const selectors=['#ith526NotificationSettings [data-r3-action="external"]','#ith526NotificationSettings [data-action="external"]','#ith525NotificationSettings [data-action="external"]'];
 const b=document.querySelector(selectors.join(','));
 if(b){b.click();return true}
 return false;
}
function openExactNotificationMessageCenter(){
 closePlus();
 const settings=I().openNotificationSettingsV249238||window.openNotificationSettingsV249238;
 if(typeof settings==='function'){
  settings.call(I());
  requestAnimationFrame(()=>requestAnimationFrame(()=>{
   if(clickRealSettingsMessageButton())return;
   const f=I().openExternalMessageCenterV249477;
   if(typeof f==='function')f.call(I());else toast('Το Κέντρο Μηνυμάτων δεν είναι διαθέσιμο.');
  }));
  return true;
 }
 const f=I().openExternalMessageCenterV249477;
 if(typeof f==='function')return f.call(I());
 toast('Το Κέντρο Μηνυμάτων δεν είναι διαθέσιμο.');return false;
}
function ensureCanonicalShell(){
 if(document.body?.dataset.page!=='spaces')return false;
 const sh=$('ith516Shell');
 if(sh&&sh.dataset.communityOwner==='r10f14')return true;
 const f=I().openCanonicalCommunitiesR10F14||window.openCanonicalCommunitiesR10F14;
 if(typeof f==='function'){f.call(I());return true}
 return false;
}
function install(){
 installSendCompatibility();const o=I();
 o.openCommunitiesR10F14=openCanonicalCommunities;window.openCommunitiesR10F14=openCanonicalCommunities;
 o.openExactNotificationMessageCenterR10F14=openExactNotificationMessageCenter;window.openExactNotificationMessageCenterR10F14=openExactNotificationMessageCenter;
 document.documentElement.setAttribute('data-ithaki-r10f14','canonical-community-shell-message-send-exact-settings-button');
 try{localStorage.setItem('ith_frontend_build','V249526R10F14-canonical-community-shell-message-send-exact-settings-button')}catch(_e){}
 if(document.body?.dataset.page==='spaces')setTimeout(ensureCanonicalShell,0);
}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',install,{once:true});else install();
})();
