/** * TXA Comment Widget - TPHIMX Cinematic Platform * Tự động hóa khung bình luận cao cấp. */ class TxaComment { constructor(containerId) { this.container = document.getElementById(containerId); if (!this.container) return; this.movieSlug = this.container.getAttribute('data-movie-slug'); this.movieType = this.container.getAttribute('data-movie-type') || null; this.episodeName = this.container.getAttribute('data-episode-name') || null; this.serverName = this.container.getAttribute('data-server-name') || null; const userAttr = this.container.getAttribute('data-user'); this.user = userAttr ? JSON.parse(userAttr) : null; this.comments = []; this.bannedUsers = []; this.init(); } async init() { this.renderSkeleton(); await this.fetchComments(); this.renderCommentsList(); this.setupListeners(); } renderSkeleton() { const isLogged = !!this.user; this.container.innerHTML = `
${c.content}
`; // Episode Tag (If commented from watch page) const episodeTag = (c.episode_name && c.server_name) ? `${c.episode_name} - ${c.server_name}` : ''; // Likes/Dislikes Arrays const likes = c.likes || []; const dislikes = c.dislikes || []; const hasLiked = this.user && likes.includes(this.user.username); const hasDisliked = this.user && dislikes.includes(this.user.username); // Actions Check (Delete comment) const canDelete = this.user && (c.username === this.user.username || this.user.role === 'admin'); const deleteButton = canDelete ? `` : ''; // Ban Button (For Admin ONLY) const isBanned = this.bannedUsers.includes(c.username); const showBanBtn = this.user && this.user.role === 'admin' && c.username !== this.user.username; const banButton = showBanBtn ? (isBanned ? `` : `` ) : ''; // Lấy thông tin profile phục vụ cho hover popup const profile = (this.userProfiles && this.userProfiles[c.username]) || { commentsCount: 0, likesCount: 0, ward: '', province: '' }; let locationStr = 'Chưa cập nhật'; if (profile.ward || profile.province) { const parts = []; if (profile.ward) parts.push(`xã ${profile.ward}`); if (profile.province) parts.push(`tỉnh ${profile.province}`); locationStr = parts.join(', '); locationStr = locationStr.charAt(0).toUpperCase() + locationStr.slice(1); } const formattedComments = window.txaformat ? window.txaformat.twoDigits(profile.commentsCount) : (profile.commentsCount < 10 ? '0' + profile.commentsCount : profile.commentsCount); const formattedLikes = window.txaformat ? window.txaformat.twoDigits(profile.likesCount) : (profile.likesCount < 10 ? '0' + profile.likesCount : profile.likesCount); // Check if user has custom avatar URL const hasAvatar = profile && profile.avatar_url; const avatarInner = hasAvatar ? `