/* OK ITHAKI V249521 SPECIAL - COMMUNITY APP SCREENS / FEED VIDEO / NATIVE FILE SHARE / CLEAN AVATARS */
(function(){
'use strict';
if(window.__ITHAKI_V249521_SPECIAL__)return;
window.__ITHAKI_V249521_SPECIAL__={version:'V249521',communityAppScreens:true,feedStyleCommunityVideo:true,nativeRemoteFileShare:true,unifiedCleanAvatars:true,storyAvatarNoLetters:true,finalCommunityAudit:true,at:Date.now()};
window.__ITHAKI_V249521_SPECIAL_OWNER__=true;
const I=()=>window.ITH||{},S=()=>window.state||I().state||{},$=id=>document.getElementById(id);
const esc=s=>String(s??'').replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
const js=s=>String(s??'').replace(/\\/g,'\\\\').replace(/'/g,"\\'").replace(/\r?\n/g,'\\n');
function room(){return String(S().room||localStorage.getItem('ith_room')||'ithaki-phone-test')}
function sid(){return String(S().currentSpace||String(S().currentSpaceChannel||'').replace(/^space:/,''))}
function device(){return String(S().device||localStorage.getItem('ith_device')||'')}
function nickname(){return String(S().name||localStorage.getItem('ith_name')||localStorage.getItem('ith_nickname')||'Μέλος')}
function active(){return document.body?.getAttribute('data-page')==='spaces'&&!!sid()&&!!$('spaceMsgs')}
function base(){return location.origin.replace(/\/$/,'')}
function headers(json=false){const h={};if(json)h['Content-Type']='application/json';try{const t=localStorage.getItem('ith_public_token')||localStorage.getItem('ith_token')||'';if(t)h['X-ITHAKI-TOKEN']=t}catch(e){}return h}
async function api(path,opt={}){const r=await fetch(base()+path,Object.assign({cache:'no-store'},opt,{headers:Object.assign(headers(!!opt.body),opt.headers||{})}));const txt=await r.text();let d={};try{d=txt?JSON.parse(txt):{}}catch(e){d={detail:txt}}if(!r.ok)throw Error(typeof d.detail==='string'?d.detail:(d.detail?.message||d.message||('HTTP '+r.status)));return d}
function toast(m,ms=6500){try{if(I().toast)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)}else alert(m)}
function addCss(){if($('ith521Css'))return;const st=document.createElement('style');st.id='ith521Css';st.textContent=`
/* V249521 app panels */
.ith521App{position:fixed;inset:0;z-index:100300;display:flex;flex-direction:column;background:radial-gradient(circle at 50% -10%,rgba(40,84,110,.40),transparent 42%),rgba(3,10,18,.97);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);color:#fff}.ith521AppHead{flex:0 0 auto;display:grid;grid-template-columns:46px minmax(0,1fr) 46px;align-items:center;gap:7px;padding:8px 9px;border-bottom:1px solid rgba(255,255,255,.12);background:rgba(4,16,27,.88)}.ith521AppHead button{width:42px;height:42px;border-radius:50%;border:1px solid rgba(255,255,255,.14);background:rgba(255,255,255,.07);color:#fff;font-size:23px}.ith521AppTitle{min-width:0}.ith521AppTitle b{display:block;color:#ffe08a;font-size:17px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ith521AppTitle small{display:block;color:rgba(238,247,255,.63);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ith521AppBody{flex:1;min-height:0;overflow-y:auto;padding:10px 10px calc(20px + env(safe-area-inset-bottom));-webkit-overflow-scrolling:touch}.ith521CreateCard,.ith521ContentCard{border:1px solid rgba(255,255,255,.12);background:linear-gradient(145deg,rgba(255,255,255,.075),rgba(255,255,255,.035));border-radius:20px;padding:12px;margin-bottom:11px;box-shadow:0 12px 30px rgba(0,0,0,.22)}.ith521CreateCard{border-color:rgba(255,216,110,.42);background:linear-gradient(145deg,rgba(255,216,110,.13),rgba(54,240,160,.055))}.ith521CreateCard h3,.ith521ContentCard h3{margin:0 0 9px;color:#ffe08a}.ith521Field{display:grid;gap:5px;margin:9px 0}.ith521Field label{font-size:12px;font-weight:900;color:rgba(243,248,255,.82)}.ith521Field input,.ith521Field textarea{width:100%;box-sizing:border-box;min-height:45px;border-radius:14px;border:1px solid rgba(255,255,255,.14);background:rgba(0,0,0,.25);color:#fff;padding:10px 11px;outline:none}.ith521Field textarea{min-height:96px;resize:vertical}.ith521Field input:focus,.ith521Field textarea:focus{border-color:rgba(54,240,160,.65);box-shadow:0 0 0 3px rgba(54,240,160,.08)}.ith521Primary{width:100%;min-height:52px;border-radius:16px;border:1px solid rgba(54,240,160,.55);background:linear-gradient(135deg,rgba(54,240,160,.22),rgba(45,126,180,.20));color:#fff;font-weight:950;font-size:15px}.ith521Gold{border-color:rgba(255,216,110,.58)!important;background:linear-gradient(135deg,rgba(255,216,110,.19),rgba(255,255,255,.055))!important}.ith521Row{display:flex;align-items:center;gap:8px}.ith521Row>*{min-width:0}.ith521Grow{flex:1}.ith521Mini{width:40px;height:40px;border-radius:13px;border:1px solid rgba(255,255,255,.13);background:rgba(255,255,255,.065);color:#fff;font-size:19px}.ith521Options{display:grid;gap:7px}.ith521Empty{padding:22px 12px;text-align:center;border-radius:17px;border:1px dashed rgba(255,255,255,.16);color:rgba(238,247,255,.62)}
/* Poll cards use the same visual language as the Feed */
.ith521PollCard.pollFeedCard{margin:0 0 12px!important;max-width:none!important;width:100%!important;box-sizing:border-box!important}.ith521PollCard .pollChoice{position:relative;overflow:hidden}.ith521PollCard .pollChoice em{position:absolute!important;left:0!important;top:0!important;bottom:0!important;height:auto!important;opacity:.18!important}.ith521PollCard .pollChoice span,.ith521PollCard .pollChoice b{position:relative;z-index:2}.ith521PollMeta{display:flex;justify-content:space-between;gap:8px;margin-top:8px;color:rgba(238,247,255,.62);font-size:11px}.ith521Announcement{border-color:rgba(255,216,110,.46);background:linear-gradient(145deg,rgba(255,216,110,.12),rgba(255,255,255,.045))}.ith521Announcement .mark{font-size:27px}.ith521Event{border-color:rgba(77,174,255,.35);background:linear-gradient(145deg,rgba(62,148,222,.12),rgba(255,255,255,.04))}.ith521EventTime{display:inline-flex;margin:7px 0;padding:5px 9px;border-radius:999px;background:rgba(54,240,160,.09);border:1px solid rgba(54,240,160,.25);color:#a8ffd1;font-size:12px}.ith521Rsvp{display:flex;gap:7px;margin-top:9px}.ith521Rsvp button{flex:1;min-height:40px;border-radius:13px;border:1px solid rgba(255,255,255,.13);background:rgba(255,255,255,.06);color:#fff}.ith521Rsvp button.on{border-color:rgba(54,240,160,.55);background:rgba(54,240,160,.12)}
/* Community video, feed-like and icon-only */
#spaceMsgs .ith518MediaWrap.ith521FeedVideo{position:relative!important;margin:8px 0 4px!important;border-radius:20px!important;overflow:hidden!important;background:#000!important;border:1px solid rgba(255,255,255,.13)!important;box-shadow:0 12px 34px rgba(0,0,0,.34)!important}#spaceMsgs .ith521FeedVideo .ith518MediaStage{height:min(68vh,690px)!important;min-height:300px!important;display:grid!important;place-items:center!important;background:#000!important;border-radius:20px 20px 0 0!important}#spaceMsgs .ith521FeedVideo .ith518MediaStage video{width:100%!important;height:100%!important;max-height:none!important;object-fit:contain!important;object-position:center!important;background:#000!important}#spaceMsgs .ith521FeedVideo .ith518Rail{right:8px!important;top:50%!important;gap:8px!important;padding:7px 5px!important;border-radius:24px!important;background:rgba(4,10,17,.48)!important}.ith521FeedVideo .ith518Rail button{width:42px!important;height:42px!important;font-size:19px!important;border-radius:50%!important;padding:0!important;color:#fff!important}.ith521RailAvatar{overflow:hidden!important;border:2px solid rgba(255,255,255,.92)!important;background:#12212d!important}.ith521RailAvatar img{width:100%;height:100%;object-fit:cover}.ith521RailAvatar .fallback{font-size:19px}.ith521VideoStrip{display:flex;gap:6px;overflow-x:auto;overflow-y:hidden;padding:7px 6px;background:rgba(0,0,0,.72);scrollbar-width:none}.ith521VideoStrip::-webkit-scrollbar{display:none}.ith521VideoThumb{flex:0 0 66px;width:66px;height:62px;border-radius:11px;border:2px solid rgba(255,255,255,.16);padding:0;overflow:hidden;background:#000}.ith521VideoThumb.on{border-color:#ffd86e}.ith521VideoThumb video,.ith521VideoThumb img{width:100%;height:100%;object-fit:cover;pointer-events:none}.ith521VideoThumb span,.ith521VideoStrip small,.ith521VideoStrip label{display:none!important}
/* One clean avatar system */
.storyItem .avatar,.storyItem .avatarDotWrap>.avatar,.ith477StoryRing,.ith481StoryAvatar{width:66px!important;height:66px!important;min-width:66px!important;min-height:66px!important;border-radius:50%!important;overflow:hidden!important;display:grid!important;place-items:center!important;background:rgba(255,255,255,.09)!important;border:2px solid rgba(255,255,255,.92)!important;box-shadow:0 5px 18px rgba(0,0,0,.30)!important;color:transparent!important;font-size:0!important}.storyItem .avatar img,.storyItem .avatarDotWrap>.avatar img,.ith477StoryRing img,.ith481StoryAvatar img{width:100%!important;height:100%!important;object-fit:cover!important;filter:none!important;opacity:1!important;mix-blend-mode:normal!important}.ith521StoryFallback{font-size:25px!important;color:#fff!important;line-height:1}.postHead .avatar,.feedAvatarOverlay .avatar{width:48px!important;height:48px!important;min-width:48px!important;border-radius:50%!important;overflow:hidden!important;border:2px solid rgba(255,255,255,.92)!important;background:rgba(255,255,255,.10)!important}.postHead .avatar img,.feedAvatarOverlay .avatar img{width:100%!important;height:100%!important;object-fit:cover!important;filter:none!important;opacity:1!important}.ith518Avatar,.ith517MemberAvatar{width:44px!important;height:44px!important;min-width:44px!important;border-radius:50%!important;border:2px solid rgba(255,255,255,.86)!important;background:rgba(255,255,255,.09)!important}.ith518Avatar img,.ith517MemberAvatar img{width:100%!important;height:100%!important;object-fit:cover!important;filter:none!important;opacity:1!important}.ith517MembersBar{min-height:56px!important}.ith517MemberChip{min-height:46px!important}.storyItem small{max-width:76px!important;margin-top:5px!important;white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important}
/* File share feedback */
.ith521ShareProgress{position:fixed;left:50%;bottom:calc(86px + env(safe-area-inset-bottom));transform:translateX(-50%);z-index:100400;max-width:88vw;padding:10px 14px;border-radius:999px;background:rgba(4,16,27,.94);border:1px solid rgba(54,240,160,.38);color:#fff;box-shadow:0 10px 32px rgba(0,0,0,.38);font-weight:850;text-align:center}
@media(max-width:680px){.ith521AppBody{padding:8px 8px calc(16px + env(safe-area-inset-bottom))}.ith521CreateCard,.ith521ContentCard{padding:10px;border-radius:17px}#spaceMsgs .ith521FeedVideo .ith518MediaStage{height:min(62vh,560px)!important;min-height:260px!important}.ith521FeedVideo .ith518Rail button{width:38px!important;height:38px!important}.storyItem .avatar,.storyItem .avatarDotWrap>.avatar,.ith477StoryRing,.ith481StoryAvatar{width:60px!important;height:60px!important;min-width:60px!important;min-height:60px!important}.postHead .avatar,.feedAvatarOverlay .avatar{width:44px!important;height:44px!important;min-width:44px!important}}
`;document.head.appendChild(st)}
function closeApp(){document.querySelectorAll('.ith521App').forEach(x=>x.remove())}
function app(title,subtitle,body){closeApp();const d=document.createElement('section');d.className='ith521App';d.innerHTML=`<header class="ith521AppHead"><button type="button" data-ith521-close>‹</button><div class="ith521AppTitle"><b>${esc(title)}</b><small>${esc(subtitle||String($('spaceTitle')?.textContent||'Κοινότητα'))}</small></div><button type="button" data-ith521-close>×</button></header><main class="ith521AppBody">${body}</main>`;document.body.appendChild(d);d.querySelectorAll('[data-ith521-close]').forEach(b=>b.addEventListener('click',closeApp));return d}
function logo(){return `<div class="pollLogoClean"><img src="ok_ithaki_ship_logo.png" onerror="this.style.display='none'"><div><b><span class="okRainbow">OK</span></b><small>ithaki</small></div></div>`}
function pollCard(p){const opts=Array.isArray(p.options)?p.options:[],total=opts.reduce((a,o)=>a+Number(o.votes||0),0);return `<article class="pollFeedCard professionalPollCard cleanPollV249233 ith521PollCard" data-ith521-poll="${esc(p.poll_id)}">${logo()}<div class="pollQuestion">${esc(p.question||'Ψηφοφορία')}</div><div class="pollVoteOptions">${opts.map(o=>{const n=Number(o.votes||0),pc=total?Math.round(n*100/total):0,on=String(p.my_option_id||'')===String(o.option_id||'');return `<button class="pollChoice ${on?'on':''}" data-ith521-vote="${esc(p.poll_id)}" data-opt="${esc(o.option_id)}"><span>${esc(o.label||'Επιλογή')}</span><em style="width:${pc}%"></em><b>${n} · ${pc}%${on?' ✓':''}</b></button>`}).join('')}</div><div class="ith521PollMeta"><span>Ψήφισαν ${total} μέλη</span><button type="button" class="ith521Mini" data-ith521-share-poll="${esc(p.poll_id)}" title="Κοινοποίηση">📤</button></div></article>`}
function pollCreateHtml(){return `<section class="ith521CreateCard"><h3>＋ Νέα ψηφοφορία</h3><div class="ith521Field"><label>Ερώτηση</label><textarea id="ith521PollQuestion" maxlength="500" placeholder="Γράψε την ερώτηση..."></textarea></div><div id="ith521PollOptions" class="ith521Options"><div class="ith521Row"><input class="ith521Grow" data-ith521-poll-option maxlength="180" placeholder="Επιλογή 1"><button class="ith521Mini" type="button" data-ith521-remove-option>−</button></div><div class="ith521Row"><input class="ith521Grow" data-ith521-poll-option maxlength="180" placeholder="Επιλογή 2"><button class="ith521Mini" type="button" data-ith521-remove-option>−</button></div></div><div class="ith521Row" style="margin-top:8px"><button class="ith521Mini" type="button" id="ith521AddPollOption">＋</button><button class="ith521Primary ith521Grow" type="button" id="ith521PublishPoll">Δημοσίευση ψηφοφορίας</button></div></section>`}
async function openPollApp(){let d;try{d=await api('/api/rooms/polls_v249516?room_id='+encodeURIComponent(room())+'&subroom_id='+encodeURIComponent(sid())+'&device_id='+encodeURIComponent(device()))}catch(e){return toast('Δεν φορτώθηκαν οι ψηφοφορίες: '+e.message)}const p=app('🗳️ Ψηφοφορίες','Ίδιες επαγγελματικές κάρτες με τη Ροή',pollCreateHtml()+((d.polls||[]).map(pollCard).join('')||'<div class="ith521Empty">Δεν υπάρχουν ακόμη ψηφοφορίες.</div>'));const opts=p.querySelector('#ith521PollOptions');const add=()=>{if(opts.querySelectorAll('[data-ith521-poll-option]').length>=9)return toast('Έως 9 επιλογές.');const r=document.createElement('div');r.className='ith521Row';r.innerHTML=`<input class="ith521Grow" data-ith521-poll-option maxlength="180" placeholder="Νέα επιλογή"><button class="ith521Mini" type="button" data-ith521-remove-option>−</button>`;opts.appendChild(r);r.querySelector('input').focus()};p.querySelector('#ith521AddPollOption').onclick=add;p.addEventListener('click',async e=>{const rm=e.target.closest('[data-ith521-remove-option]');if(rm){if(opts.querySelectorAll('[data-ith521-poll-option]').length<=2)return toast('Χρειάζονται τουλάχιστον δύο επιλογές.');rm.parentElement.remove();return}const v=e.target.closest('[data-ith521-vote]');if(v){try{await api('/api/rooms/polls/vote_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:sid(),device_id:device(),poll_id:v.dataset.ith521Vote,option_id:v.dataset.opt})});openPollApp()}catch(x){toast(x.message)}return}const sh=e.target.closest('[data-ith521-share-poll]');if(sh){const q=(d.polls||[]).find(x=>String(x.poll_id)===sh.dataset.ith521SharePoll);if(q)shareText([q.question,...(q.options||[]).map(o=>'• '+o.label+' — '+Number(o.votes||0))].join('\n'),'ITHAKI_poll_'+q.poll_id+'.txt')}});p.querySelector('#ith521PublishPoll').onclick=async()=>{const question=String(p.querySelector('#ith521PollQuestion').value||'').trim(),options=[...p.querySelectorAll('[data-ith521-poll-option]')].map(x=>x.value.trim()).filter(Boolean);if(!question)return toast('Γράψε την ερώτηση.');if(options.length<2)return toast('Χρειάζονται τουλάχιστον δύο επιλογές.');try{await api('/api/rooms/polls/create_v249518',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:sid(),device_id:device(),nickname:nickname(),question,options})});toast('Η ψηφοφορία δημοσιεύτηκε.');openPollApp()}catch(e){toast('Δεν δημοσιεύτηκε: '+e.message)}}}
function announcementCreateHtml(){return `<section class="ith521CreateCard ith521Gold"><h3>＋ Νέα ανακοίνωση</h3><div class="ith521Field"><label>Τίτλος</label><input id="ith521AnnTitle" maxlength="180" placeholder="Τίτλος ανακοίνωσης"></div><div class="ith521Field"><label>Κείμενο</label><textarea id="ith521AnnBody" maxlength="4000" placeholder="Γράψε την ανακοίνωση..."></textarea></div><button id="ith521PublishAnn" class="ith521Primary ith521Gold" type="button">Δημοσίευση και καρφίτσωμα</button></section>`}
function currentSpace(){return (S().spaces||[]).find(x=>String(x.subroom_id||'')===sid())||{subroom_id:sid(),role:'member',access_type:'public',owner_id:'ithaki-system'}}
function role(x=currentSpace()){return String(x.role||((x.is_owner||String(x.owner_id||'')===device())?'creator':'member'))}
function isFree(x=currentSpace()){const id=String(x.subroom_id||sid()),owner=String(x.owner_id||'').toLowerCase(),access=String(x.access_type||'public').toLowerCase();return access==='public'&&(owner==='system'||owner==='ithaki-system'||id.startsWith('default_')||id.startsWith('default_v249513_'))}
function staffCode(x=currentSpace()){if(isFree(x))return'';const r=role(x),key=r==='moderator'?'ith_space_moderator_code_v249516_'+sid():'ith_space_creator_code_v249510_'+sid();let c='';try{c=localStorage.getItem(key)||''}catch(e){}if(!c){c=prompt(r==='moderator'?'Κωδικός συντονιστή:':'Κωδικός δημιουργού:')||'';if(c)try{localStorage.setItem(key,c)}catch(e){}}return c}
function canOfficial(x=currentSpace()){return isFree(x)?role(x)!=='visitor':['creator','moderator'].includes(role(x))}
function parseBody(t){try{const o=JSON.parse(String(t||''));return String(o.body??o.text??t)}catch(e){return String(t||'')}}
async function openAnnouncementApp(){const x=currentSpace();let d;try{d=await api('/api/rooms/pins?room_id='+encodeURIComponent(room())+'&subroom_id='+encodeURIComponent(sid()))}catch(e){return toast('Δεν φορτώθηκαν οι ανακοινώσεις: '+e.message)}const create=canOfficial(x)?announcementCreateHtml():`<div class="ith521ContentCard">Οι επίσημες ανακοινώσεις αυτής της νέας κοινότητας γίνονται από δημιουργό ή συντονιστή.</div>`;const cards=(d.pins||[]).map(a=>`<article class="ith521ContentCard ith521Announcement"><div class="ith521Row"><span class="mark">📣</span><div class="ith521Grow"><h3>${esc(a.note||'Ανακοίνωση')}</h3><small>${esc(a.nickname||'Μέλος')} · ${new Date(Number(a.message_created_at||a.created_at||0)*1000).toLocaleString('el-GR')}</small></div><button class="ith521Mini" data-ith521-share-ann="${esc(a.message_id||'')}">📤</button></div><div style="white-space:pre-wrap;margin-top:9px;line-height:1.45">${esc(parseBody(a.text||''))}</div></article>`).join('')||'<div class="ith521Empty">Δεν υπάρχουν ακόμη ανακοινώσεις.</div>';const p=app('📣 Ανακοινώσεις','Επίσημες καρφιτσωμένες κάρτες',create+cards);p.querySelector('#ith521PublishAnn')?.addEventListener('click',async()=>{const title=p.querySelector('#ith521AnnTitle').value.trim(),body=p.querySelector('#ith521AnnBody').value.trim();if(!title||!body)return toast('Συμπλήρωσε τίτλο και κείμενο.');const code=staffCode(x);if(!isFree(x)&&!code)return;try{await api('/api/rooms/announcements/create_v249520',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:sid(),device_id:device(),nickname:nickname(),staff_code:code,title,body})});toast('Η ανακοίνωση δημοσιεύτηκε.');const f=I().loadSpaceMessagesV249518||I().loadSpaceMessages;if(typeof f==='function')await f();openAnnouncementApp()}catch(e){toast('Δεν δημοσιεύτηκε: '+e.message)}});p.querySelectorAll('[data-ith521-share-ann]').forEach(b=>b.onclick=()=>{const a=(d.pins||[]).find(x=>String(x.message_id||'')===b.dataset.ith521ShareAnn);if(a)shareText((a.note||'Ανακοίνωση')+'\n\n'+parseBody(a.text||''),'ITHAKI_announcement.txt')})}
function eventCreateHtml(){return `<section class="ith521CreateCard"><h3>＋ Νέα εκδήλωση</h3><div class="ith521Field"><label>Τίτλος</label><input id="ith521EventTitle" maxlength="180" placeholder="Τίτλος εκδήλωσης"></div><div class="ith521Field"><label>Ημερομηνία και ώρα</label><input id="ith521EventWhen" type="datetime-local"></div><div class="ith521Field"><label>Τοποθεσία ή σύνδεσμος</label><input id="ith521EventLocation" maxlength="240" placeholder="Τοποθεσία ή σύνδεσμος"></div><div class="ith521Field"><label>Περιγραφή</label><textarea id="ith521EventDescription" maxlength="1200" placeholder="Περιγραφή..."></textarea></div><button id="ith521PublishEvent" class="ith521Primary" type="button">Δημιουργία εκδήλωσης</button></section>`}
async function openEventApp(){const x=currentSpace();let d;try{d=await api('/api/rooms/events_v249516?room_id='+encodeURIComponent(room())+'&subroom_id='+encodeURIComponent(sid())+'&device_id='+encodeURIComponent(device()))}catch(e){return toast('Δεν φορτώθηκαν οι εκδηλώσεις: '+e.message)}const create=canOfficial(x)?eventCreateHtml():`<div class="ith521ContentCard">Οι επίσημες εκδηλώσεις αυτής της νέας κοινότητας γίνονται από δημιουργό ή συντονιστή.</div>`;const cards=(d.events||[]).map(ev=>`<article class="ith521ContentCard ith521Event"><div class="ith521Row"><span style="font-size:28px">📅</span><div class="ith521Grow"><h3>${esc(ev.title||'Εκδήλωση')}</h3><span class="ith521EventTime">${new Date(Number(ev.starts_at||0)*1000).toLocaleString('el-GR')}</span></div><button class="ith521Mini" data-ith521-share-event="${esc(ev.event_id)}">📤</button></div><div style="white-space:pre-wrap;line-height:1.45">${esc(ev.description||'')}</div>${ev.location?`<div style="margin-top:7px">📍 ${esc(ev.location)}</div>`:''}<div class="ith521Rsvp"><button class="${ev.my_response==='going'?'on':''}" data-event="${esc(ev.event_id)}" data-rsvp="going">Θα πάω · ${Number(ev.going_count||0)}</button><button class="${ev.my_response==='interested'?'on':''}" data-event="${esc(ev.event_id)}" data-rsvp="interested">Ενδιαφέρομαι</button></div></article>`).join('')||'<div class="ith521Empty">Δεν υπάρχουν ακόμη εκδηλώσεις.</div>';const p=app('📅 Εκδηλώσεις','Ημερομηνία, τοποθεσία και συμμετοχές',create+cards);p.querySelector('#ith521PublishEvent')?.addEventListener('click',async()=>{const title=p.querySelector('#ith521EventTitle').value.trim(),when=p.querySelector('#ith521EventWhen').value,starts=Date.parse(when),locationText=p.querySelector('#ith521EventLocation').value.trim(),description=p.querySelector('#ith521EventDescription').value.trim();if(!title||!Number.isFinite(starts)||starts<=Date.now())return toast('Βάλε τίτλο και σωστή μελλοντική ώρα.');const code=staffCode(x);if(!isFree(x)&&!code)return;try{await api('/api/rooms/events/create_v249520',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:sid(),device_id:device(),nickname:nickname(),staff_code:code,title,description,location:locationText,starts_at:starts/1000})});toast('Η εκδήλωση δημιουργήθηκε.');openEventApp()}catch(e){toast('Δεν δημιουργήθηκε: '+e.message)}});p.querySelectorAll('[data-event][data-rsvp]').forEach(b=>b.onclick=async()=>{try{await api('/api/rooms/events/rsvp_v249516',{method:'POST',body:JSON.stringify({room_id:room(),subroom_id:sid(),device_id:device(),nickname:nickname(),event_id:b.dataset.event,response:b.dataset.rsvp})});openEventApp()}catch(e){toast(e.message)}});p.querySelectorAll('[data-ith521-share-event]').forEach(b=>b.onclick=()=>{const ev=(d.events||[]).find(x=>String(x.event_id)===b.dataset.ith521ShareEvent);if(ev)shareText([ev.title,new Date(Number(ev.starts_at||0)*1000).toLocaleString('el-GR'),ev.location||'',ev.description||''].filter(Boolean).join('\n'),'ITHAKI_event_'+ev.event_id+'.txt')})}
function showShareProgress(text){let d=$('ith521ShareProgress');if(!d){d=document.createElement('div');d.id='ith521ShareProgress';d.className='ith521ShareProgress';document.body.appendChild(d)}d.textContent=text;clearTimeout(showShareProgress.t);showShareProgress.t=setTimeout(()=>d.remove(),7000)}
function fileName(url,fallback='OK_ITHAKI_file'){try{return decodeURIComponent(String(url).split('/').pop().split('?')[0])||fallback}catch(e){return fallback}}
function fullUrl(u){u=String(u||'');if(!u)return'';if(/^https?:|^blob:|^data:/i.test(u))return u;return base()+'/'+u.replace(/^\/+/, '')}
async function blobShare(blob,name,mime){if(window.__ITHAKI_V249523_SHARE_READY__&&I().shareBlobV249523)return I().shareBlobV249523(blob,name,mime);const br=window.AndroidBridge||window.OKITHAKI_ANDROID;mime=mime||blob.type||'application/octet-stream';if(br&&typeof br.shareBase64File==='function'&&blob.size<=18*1024*1024){const data=await new Promise((res,rej)=>{const fr=new FileReader();fr.onload=()=>res(String(fr.result||''));fr.onerror=()=>rej(fr.error);fr.readAsDataURL(blob)});const r=String(br.shareBase64File(name,mime,data)||'');if(/^ok/i.test(r))return true}const f=new File([blob],name,{type:mime});if(navigator.canShare&&navigator.canShare({files:[f]})&&navigator.share){await navigator.share({files:[f],title:'OK ITHAKI'});return true}const a=document.createElement('a');a.href=URL.createObjectURL(blob);a.download=name;document.body.appendChild(a);a.click();setTimeout(()=>{URL.revokeObjectURL(a.href);a.remove()},1600);return true}
async function shareUrlFile(url,name='',mime=''){const u=fullUrl(url),n=name||fileName(u);if(window.__ITHAKI_V249523_SHARE_READY__&&I().shareActualFileV249523)return I().shareActualFileV249523(u,n,mime);if(!u)throw Error('Δεν υπάρχει αρχείο για κοινοποίηση.');const br=window.AndroidBridge||window.OKITHAKI_ANDROID;if(br&&typeof br.shareRemoteFileV249521==='function'&&/^https?:/i.test(u)){showShareProgress('Προετοιμασία πραγματικού αρχείου…');const r=String(br.shareRemoteFileV249521(u,n,mime||'application/octet-stream')||'');if(/^(ok|queued)/i.test(r))return true;throw Error(r||'native share failed')}showShareProgress('Φόρτωση πραγματικού αρχείου…');const resp=await fetch(u,{cache:'no-store',headers:headers(false)});if(!resp.ok)throw Error('HTTP '+resp.status);const blob=await resp.blob();return blobShare(blob,n,mime||blob.type)}
async function shareText(text,name){return blobShare(new Blob([String(text||'')],{type:'text/plain;charset=utf-8'}),name||'ITHAKI_text.txt','text/plain')}
function installShareOverrides(){const o=I();o.shareActualUrlFileV249521=shareUrlFile;o.shareMediaFile=async(url,filename='',mime='')=>{try{await shareUrlFile(url,filename||fileName(url),mime);return false}catch(e){toast('Η κοινοποίηση απέτυχε: '+e.message);return false}};o.share=async(url,text)=>{try{const u=String(url||'');if(u&&(/\/api\/media\/file\/|\.(mp4|mov|webm|3gp|jpe?g|png|gif|webp|pdf|docx?|xlsx?|pptx?|zip|rar|7z|mp3|m4a|wav|ogg)(?:[?#]|$)/i.test(u)))return shareUrlFile(u,fileName(u),'');return shareText([text||'',u].filter(Boolean).join('\n'),'ITHAKI_share.txt')}catch(e){toast('Η κοινοποίηση απέτυχε: '+e.message);return false}}}
function cleanStoryAvatars(){document.querySelectorAll('.storyItem .avatar,.storyItem .avatarDotWrap>.avatar').forEach(a=>{const img=a.querySelector('img');if(img){[...a.childNodes].forEach(n=>{if(n.nodeType===3)n.remove()});return}a.innerHTML='<span class="ith521StoryFallback">👤</span>'});document.querySelectorAll('.ithakiOfficialStory .avatar').forEach(a=>{if(!a.querySelector('img'))a.innerHTML='<img src="ok_ithaki_ship_logo.png" alt="">'})}
function decorateVideos(){if(!active())return;const rows=[...document.querySelectorAll('#spaceMsgs .ith518Msg[data-mid]')],videos=[];rows.forEach(row=>{const wrap=row.querySelector('.ith518MediaWrap'),v=wrap?.querySelector('.ith518MediaStage video');if(!wrap||!v)return;wrap.classList.add('ith521FeedVideo');videos.push({mid:String(row.dataset.mid||''),src:v.currentSrc||v.src,row,v});const rail=wrap.querySelector('.ith518Rail');if(rail&&!rail.querySelector('.ith521RailAvatar')){const src=row.querySelector('.ith518Avatar img')?.src||'';const b=document.createElement('button');b.type='button';b.className='ith521RailAvatar';b.title='Μέλος';b.innerHTML=src?`<img src="${esc(src)}" alt="">`:'<span class="fallback">👤</span>';b.onclick=e=>{e.preventDefault();row.querySelector('.ith518Avatar')?.click()};rail.prepend(b)}});if(!videos.length)return;rows.forEach(row=>{const wrap=row.querySelector('.ith521FeedVideo');if(!wrap)return;let strip=wrap.querySelector('.ith521VideoStrip');const sig=videos.slice(-10).map(x=>x.mid).join('|');if(strip?.dataset.sig===sig)return;strip?.remove();strip=document.createElement('div');strip.className='ith521VideoStrip';strip.dataset.sig=sig;strip.innerHTML=videos.slice(-10).map(x=>`<button class="ith521VideoThumb ${x.mid===row.dataset.mid?'on':''}" data-mid="${esc(x.mid)}"><video muted playsinline preload="metadata" src="${esc(x.src)}"></video></button>`).join('');wrap.appendChild(strip);strip.querySelectorAll('video').forEach(v=>{v.addEventListener('loadedmetadata',()=>{try{v.currentTime=Math.min(.2,(v.duration||1)/10)}catch(e){}},{once:true});v.addEventListener('seeked',()=>v.pause(),{once:true})});strip.onclick=e=>{const b=e.target.closest('[data-mid]');if(!b)return;const target=document.querySelector('#spaceMsgs .ith518Msg[data-mid="'+CSS.escape(b.dataset.mid)+'"]');target?.scrollIntoView({behavior:'smooth',block:'center'});setTimeout(()=>target?.querySelector('.ith518MediaStage video')?.play().catch(()=>{}),350)}})}
function captureCommands(e){const b=e.target?.closest?.('#ith519CommunityCommandBar [data-ith519-cmd]');if(!b)return;const c=b.dataset.ith519Cmd;if(!['polls','announcements','events'].includes(c))return;e.preventDefault();e.stopPropagation();e.stopImmediatePropagation();if(c==='polls')openPollApp();else if(c==='announcements')openAnnouncementApp();else openEventApp()}
function canonical(){try{const u=new URL(location.href);if(u.searchParams.get('v')!=='249524'){u.searchParams.set('v',(window.ITHAKI_ACTIVE_VERSION||'249526r10f37f1f2'));history.replaceState(null,'',u.pathname+'?'+u.searchParams.toString()+u.hash)}}catch(e){}}
function audit(){addCss();cleanStoryAvatars();decorateVideos();installShareOverrides();document.querySelectorAll('#ith519CommunityCommandBar .ith519Cmd').forEach(b=>{b.style.pointerEvents='auto';b.style.touchAction='manipulation'});document.documentElement.setAttribute('data-ithaki-v249521','special-community-apps-video-share-avatars')}
function install(){addCss();canonical();installShareOverrides();document.addEventListener('click',captureCommands,true);window.addEventListener('ithaki:native-share-result',e=>{const d=e.detail||{};toast(d.ok?'Το πραγματικό αρχείο είναι έτοιμο για κοινοποίηση.':('Η κοινοποίηση απέτυχε: '+(d.message||'')))});Object.assign(I(),{openCommunityPollsV249521:openPollApp,openCommunityPollsV249518:openPollApp,openCommunityAnnouncementsV249521:openAnnouncementApp,openCommunityAnnouncementsV249520:openAnnouncementApp,openCommunityAnnouncementsV249519:openAnnouncementApp,openCommunityEventsV249521:openEventApp,openCommunityEventsV249520:openEventApp,openCommunityEventsV249516:openEventApp,shareActualUrlFileV249521:shareUrlFile,refreshV249521Special:audit});new MutationObserver(()=>{clearTimeout(install._m);install._m=setTimeout(audit,70)}).observe(document.body,{subtree:true,childList:true});window.addEventListener('ithaki:page-changed',()=>setTimeout(audit,80));window.addEventListener('pageshow',()=>setTimeout(audit,60));setInterval(()=>{canonical();audit()},1600);audit();try{localStorage.setItem('ith_frontend_build','V249521-special-community-apps-video-share-avatars')}catch(e){}}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',install,{once:true});else install();
})();
