';
},
bindCards: function(container, items, isLive) {
var self = this;
var cards = container.querySelectorAll('.aky-card');
for (var i = 0; i < cards.length; i++) {
(function(card, item) {
card.onclick = function() {
if (isLive) self.openQr(item.hostId, item.hostName, item.avatar, true);
else self.openMedia(item);
};
var av = card.querySelector('.aky-avatar-btn');
if (av) av.onclick = function(e) {
e.stopPropagation();
self.openQr(isLive ? item.hostId : item.userId,
isLive ? item.hostName : item.userName,
item.avatar, isLive);
};
})(cards[i], items[i]);
}
},
renderMundo: function() {
var grid = document.getElementById('aky-grid-mundo');
if (!this.videos.length) {
grid.innerHTML = this.emptyGrid('video_library', 'Sin videos', 'Aun no hay contenido en Mundo');
return;
}
var html = '';
for (var i = 0; i < this.videos.length; i++) html += this.cardHTML(this.videos[i]);
grid.innerHTML = html;
this.bindCards(grid, this.videos);
},
renderRecuerdos: function() {
var grid = document.getElementById('aky-grid-recuerdos');
if (!this.images.length) {
grid.innerHTML = this.emptyGrid('photo_library', 'Sin recuerdos', 'Aun no hay imagenes');
return;
}
var html = '';
for (var i = 0; i < this.images.length; i++) html += this.cardHTML(this.images[i]);
grid.innerHTML = html;
this.bindCards(grid, this.images);
},
renderLives: function() {
var grid = document.getElementById('aky-grid-live');
if (!this.lives.length) {
grid.innerHTML = this.emptyGrid('sensors_off', 'Sin transmisiones', 'No hay lives activos ahora');
return;
}
var html = '';
for (var i = 0; i < this.lives.length; i++) html += this.cardHTML(this.lives[i], true);
grid.innerHTML = html;
this.bindCards(grid, this.lives, true);
},
updateLiveBadge: function() {
var n = this.lives.length;
var pill = document.getElementById('aky-live-pill');
var badge = document.getElementById('aky-live-badge');
document.getElementById('aky-live-count').textContent = n;
pill.style.display = n > 0 ? 'flex' : 'none';
badge.style.display = n > 0 ? 'inline-block' : 'none';
badge.textContent = n;
},
stars: function(rating) {
var r = Math.round(Number(rating) || 0);
var s = '';
for (var i = 1; i <= 5; i++) s += i <= r ? '★' : '☆';
return s;
},
renderComunidad: function() {
var self = this;
var list = document.getElementById('aky-posts-list');
if (!this.posts.length) {
list.innerHTML = this.emptyGrid('forum', 'Sin posts', 'La comunidad aun no publica');
return;
}
var html = '';
for (var i = 0; i < this.posts.length; i++) {
var p = this.posts[i];
var flag = this.flag(p.country);
var media = '';
if (p.videoUrl) {
media = '
' +
'
play_arrow
';
} else if (p.photo) {
media = '
';
}
var links = '';
if (p.webReferences.length) {
links = '
';
for (var w = 0; w < p.webReferences.length; w++) {
var ref = p.webReferences[w];
if (!/^https?:\/\//i.test(ref)) continue;
links += '' +
'link' + this.esc(this.shortUrl(ref)) + '';
}
links += '
';
document.getElementById('aky-media-modal').classList.add('active');
document.body.style.overflow = 'hidden';
var likeBtn = document.getElementById('aky-like-btn');
if (likeBtn) likeBtn.onclick = function() { self.toggleLike(m); };
var av = document.getElementById('aky-player-avatar');
if (av) av.onclick = function() { self.openQr(m.userId, m.userName, m.avatar); };
var openApp = document.getElementById('aky-open-app');
if (openApp) openApp.onclick = function() { self.openQr(m.userId, m.userName, m.avatar); };
/* stats del canal */
this.getUser(m.userId).then(function(u) {
var el = document.getElementById('aky-channel-stats');
if (el && u) el.textContent = self.fmtCount(u.followersCount) + ' seguidores';
else if (el) el.textContent = '';
});
this.loadComments(m);
},
/* Likes: misma ruta de la app {coll}/{id} -> likeCount + likedBy[] */
toggleLike: function(m) {
var key = 'aky_like_' + m.coll + '_' + m.id;
var btn = document.getElementById('aky-like-btn');
var num = document.getElementById('aky-like-n');
if (!btn) return;
var self = this;
var likedNow = localStorage.getItem(key) === '1';
var delta = likedNow ? -1 : 1;
var update = {
likeCount: firebase.firestore.FieldValue.increment(delta)
};
if (this.uid) {
update.likedBy = likedNow
? firebase.firestore.FieldValue.arrayRemove(this.uid)
: firebase.firestore.FieldValue.arrayUnion(this.uid);
}
this.db.collection(m.coll).doc(m.id).update(update)
.then(function() {
m.likes = Math.max(0, (m.likes || 0) + delta);
if (likedNow) localStorage.removeItem(key);
else localStorage.setItem(key, '1');
btn.classList.toggle('liked', !likedNow);
if (num) num.textContent = self.fmtCount(m.likes);
})
.catch(function(e) { console.warn('[AKY] like:', e); });
},
/* {coll}/{id}/comments -> misma subcoleccion que la app (solo lectura) */
loadComments: function(m) {
var self = this;
var box = document.getElementById('aky-comments');
box.innerHTML = '
chat_bubbleComentarios
' +
'
';
this.db.collection(m.coll).doc(m.id).collection('comments')
.orderBy('timestamp', 'desc').limit(50).get()
.then(function(snap) {
var html = '
chat_bubbleComentarios (' + snap.size + ')
';
if (!snap.size) {
html += '
Sin comentarios aun
';
} else {
snap.forEach(function(doc) {
var c = doc.data();
var color = '';
if (typeof c.commentColor === 'number') {
var hex = (c.commentColor >>> 0).toString(16).padStart(8, '0').slice(2);
color = ' style="color:#' + hex + '"';
}
html += '
';
});
}
box.innerHTML = html;
})
.catch(function() {
/* fallback sin orden si falta indice */
self.db.collection(m.coll).doc(m.id).collection('comments').limit(50).get()
.then(function(snap) {
var html = '
chat_bubbleComentarios (' + snap.size + ')
';
if (!snap.size) html += '
Sin comentarios aun
';
snap.forEach(function(doc) {
var c = doc.data();
html += '