/* OK ITHAKI V249526R4 — SINGLE FEED SHARE / ONE COMMUNITY OWNER / ONE HOME BIL */
(function(){
'use strict';
if(window.__ITHAKI_V249526R4_OWNER__)return;
window.__ITHAKI_V249526R4_OWNER__={version:'V249526R4',singleFeedShare:true,singleCommunityOwner:true,dedupeBeforeRender:true,singleHomeBil:true,bomFreeLauncher:true,at:Date.now()};
window.__ITHAKI_V249526R4_COMMUNITY_OWNER__=true;
const SINGLE_FEED_SHARE_IN_PLACE_R4=true;
const SINGLE_COMMUNITY_RENDER_OWNER_R4=true;
const COMMUNITY_DEDUP_BEFORE_RENDER_R4=true;
const SINGLE_HOME_BIL_R4=true;
const I=()=>window.ITH=window.ITH||{};
const S=()=>window.state||I().state||{};
const $=id=>document.getElementById(id);
let basePostShare=null,lastPost='',lastPostAt=0,observerTimer=0;
function lock(obj,key,fn){try{Object.defineProperty(obj,key,{configurable:false,enumerable:true,get(){return fn},set(){return fn}})}catch(e){try{obj[key]=fn}catch(_e){}}}
function cleanShareLayers(){
 document.querySelectorAll('#ithShareOverlayV249433,#ithFriendPickerV249433').forEach(x=>x.remove());
 const current=[...document.querySelectorAll('#ith526R3ShareChoice')];current.slice(1).forEach(x=>x.remove());
 const legacy=[...document.querySelectorAll('#ith524ShareChoice,#ith526R2ShareChoice')];if(current.length)legacy.forEach(x=>x.remove());else legacy.slice(1).forEach(x=>x.remove());
}
function sharePostSingle(id){
 id=String(id||'');if(!id)return false;
 const now=Date.now();if(id===lastPost&&now-lastPostAt<750)return false;lastPost=id;lastPostAt=now;
 cleanShareLayers();
 try{if(typeof basePostShare==='function')return basePostShare(id)}catch(e){console.warn('R4 share post',e)}
 const o=I(),u=(location.origin||'https://ok-ithaki.gr')+'/?post='+encodeURIComponent(id)+'#post='+encodeURIComponent(id);
 try{if(typeof o.share==='function')return o.share(u,'OK ITHAKI post')}catch(e){}
 return false;
}
function installShareOwner(){
 const o=I();
 if(!basePostShare&&typeof o.sharePost==='function'&&o.sharePost!==sharePostSingle)basePostShare=o.sharePost.bind(o);
 lock(o,'sharePost',sharePostSingle);
 lock(o,'openSharePostV249433',sharePostSingle);
 lock(window,'openSharePostV249433',sharePostSingle);
 const noLegacy=()=>false;lock(o,'externalSharePostV249433',noLegacy);lock(window,'externalSharePostV249433',noLegacy);
 cleanShareLayers();
}
function captureFeedShare(e){
 const b=e.target&&e.target.closest&&e.target.closest('#feedPage button[onclick*="openSharePostV249433"],#feedPage button[onclick*="sharePost("],#feedPage [data-share-post]');
 if(!b)return;
 const oc=String(b.getAttribute('onclick')||''),id=String(b.dataset.sharePost||((oc.match(/(?:openSharePostV249433|sharePost)\s*\(\s*['\"]([^'\"]+)/)||[])[1]||''));
 if(!id)return;
 e.preventDefault();e.stopPropagation();e.stopImmediatePropagation();sharePostSingle(id);
}
function norm(s){return String(s||'').normalize('NFD').replace(/[\u0300-\u036f]/g,'').replace(/[^a-zA-Z0-9\u0370-\u03ff]+/g,' ').replace(/\s+/g,' ').trim().toLocaleLowerCase('el')}
function communityKey(x){const id=String(x?.dataset?.spaceId||x?.getAttribute?.('data-subroom-id')||x?.dataset?.roomId||'').trim();const title=norm(x?.querySelector?.('.who b,b')?.textContent||x?.textContent||'');return{id,title}}
function dedupeCommunityDom(){if(window.__ITHAKI_R10F13_SINGLE_COMMUNITY_RUNTIME__)return 0;
 const shells=[...document.querySelectorAll('#spacesPage #ith516Shell')];shells.slice(0,-1).forEach(x=>x.remove());
 for(const root of document.querySelectorAll('#ith516List,#roomList')){
  const seenId=new Set(),seenTitle=new Set();
  [...root.querySelectorAll(':scope > .ith516Row,:scope > [data-space-id],:scope > [data-subroom-id],:scope > .roomRow')].forEach(x=>{const k=communityKey(x),dup=(k.id&&seenId.has(k.id))||(k.title&&seenTitle.has(k.title));if(dup){x.remove();return}if(k.id)seenId.add(k.id);if(k.title)seenTitle.add(k.title)});
 }
 const cats=$('ith516Cats');if(cats){const seen=new Set();[...cats.querySelectorAll('[data-category]')].forEach(x=>{const k=String(x.dataset.category||'');if(seen.has(k))x.remove();else seen.add(k)})}
}
function dedupeHomeActions(){const h=$('homePage');if(!h)return;const seen=new Set();h.querySelectorAll('.ithActionsV249461 .ithActionV249461').forEach(x=>{const k=String(x.dataset.v249461Route||x.dataset.v249461Action||norm(x.querySelector('b')?.textContent||x.textContent));if(seen.has(k))x.remove();else seen.add(k)})}
const OLD_BIL_IDS=['ithBilGreenTurtleV249461','ithBilMenuV249461','ithBilPopV249461','ithBilStableV249475','ithBilStableMenuV249475','ith523HomeBilCard','ith523BilNotificationCard','ith524BilDock','ith525BilDock','ithProfileBilCardV249476','ithAdminContactCardV249476','ith477BilNotificationCard','ith509BilNotificationCard','socratakiFabV249252','ithSocrates378'];
function oneBil(){
 OLD_BIL_IDS.forEach(id=>$(id)?.remove());
 document.querySelectorAll('.ithBilHomeCardV249472,.bil473Preview,.bil475Preview').forEach(x=>x.remove());
 const docks=[...document.querySelectorAll('#ith526BilDock')];docks.slice(1).forEach(x=>x.remove());
 const d=docks[0];if(d){const on=localStorage.getItem('ith525_bil_enabled')!=='0'&&localStorage.getItem('ith_bil_enabled_v249461')!=='0';const page=String(document.body?.dataset.page||S().page||'home');const notificationOpen=!!(document.body?.classList?.contains('ith526NotificationsOpen')||document.querySelector('#ith526NotificationCenter,#ith526NotificationSettings'));d.hidden=!on||!(page==='home'||notificationOpen)}
}
function css(){if($('ith526R4Css'))return;const s=document.createElement('style');s.id='ith526R4Css';s.textContent=`
#ithShareOverlayV249433,#ithFriendPickerV249433{display:none!important;visibility:hidden!important;pointer-events:none!important}
#ithBilGreenTurtleV249461,#ithBilMenuV249461,#ithBilPopV249461,#ithBilStableV249475,#ithBilStableMenuV249475,#ith523HomeBilCard,#ith523BilNotificationCard,#ith524BilDock,#ith525BilDock,#ithProfileBilCardV249476,#ithAdminContactCardV249476,#ith477BilNotificationCard,#ith509BilNotificationCard,#socratakiFabV249252,#ithSocrates378,.ithBilHomeCardV249472,.bil473Preview,.bil475Preview{display:none!important;visibility:hidden!important;opacity:0!important;pointer-events:none!important}
body[data-page="home"] #ith526BilDock,body.ith526NotificationsOpen #ith526BilDock{display:block!important;visibility:visible!important;opacity:1!important;pointer-events:auto!important}body:not([data-page="home"]):not(.ith526NotificationsOpen) #ith526BilDock{display:none!important}
`;document.head.appendChild(s)}
function maintain(){css();installShareOwner();dedupeCommunityDom();dedupeHomeActions();oneBil();try{localStorage.setItem('ith_frontend_build','V249526R4-single-share-community-bil');document.documentElement.setAttribute('data-ithaki-v249526r4','single-share-community-bil')}catch(e){}}
function install(){
 css();installShareOwner();oneBil();
 document.addEventListener('click',captureFeedShare,true);
 new MutationObserver(()=>{clearTimeout(observerTimer);observerTimer=setTimeout(maintain,35)}).observe(document.body,{subtree:true,childList:true});
 window.addEventListener('ithaki:page-changed',()=>setTimeout(maintain,20));
 ['pageshow','focus'].forEach(n=>window.addEventListener(n,()=>setTimeout(maintain,20)));
 setInterval(maintain,500);maintain();
}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',install,{once:true});else install();
})();
