--- import Layout from '../layouts/Layout.astro'; import { formatImageUrl } from '../lib/api.js'; import { txasupabase } from '../lib/txasupabase.js'; // Lấy tất cả phim có lịch chiếu tập tiếp theo let scheduledMovies = []; try { const localMovies = await txasupabase.getLocalMovies().catch(() => ({})); scheduledMovies = Object.entries(localMovies) .map(([slug, m]) => { if (!m || !m.movie) return null; return { ...m.movie, slug }; }) .filter(Boolean) .filter(movie => movie.next_episode_time) .filter(movie => { const nextTime = new Date(movie.next_episode_time); const minTime = new Date(Date.now() - 7 * 86400000); return nextTime >= minTime; }) .sort((a, b) => new Date(a.next_episode_time).getTime() - new Date(b.next_episode_time).getTime()); } catch (e) { console.error('[lich-chieu] Error fetching schedule:', e); } // Nhóm phim theo ngày const getVietnamDateString = (date) => { return new Date(date).toLocaleDateString('en-CA', { timeZone: 'Asia/Ho_Chi_Minh' }); }; const today = new Date(new Date().toLocaleDateString('en-US', { timeZone: 'Asia/Ho_Chi_Minh' })); today.setHours(0, 0, 0, 0); // Tạo danh sách 7 ngày từ hôm nay const days = []; for (let i = 0; i < 7; i++) { const d = new Date(today); d.setDate(d.getDate() + i); days.push(d); } const dayNames = ['Chủ Nhật', 'Thứ Hai', 'Thứ Ba', 'Thứ Tư', 'Thứ Năm', 'Thứ Sáu', 'Thứ Bảy']; function getMoviesForDate(date: Date) { const targetStr = getVietnamDateString(date); return scheduledMovies.filter(m => { return getVietnamDateString(m.next_episode_time) === targetStr; }); } ---
Trang chủ Lịch chiếu

Lịch chiếu

{days.map((d, i) => { const dd = String(d.getDate()).padStart(2, '0'); const mm = String(d.getMonth() + 1).padStart(2, '0'); const dayName = dayNames[d.getDay()]; const isToday = i === 0; const count = getMoviesForDate(d).length; return ( ); })}
{days.map((d, i) => { const moviesForDay = getMoviesForDate(d); return (
{moviesForDay.length === 0 ? (

Không có phim nào dự kiến phát sóng vào ngày này.

Đón xem các cập nhật mới nhất từ ban quản trị hệ thống.

) : (
{moviesForDay.map(m => { const poster = formatImageUrl(m.poster_url || m.thumb_url); const epLabel = m.next_episode_name || m.episode_current || 'Tập mới'; const timeStr = new Date(m.next_episode_time).toLocaleTimeString('vi-VN', { hour: '2-digit', minute: '2-digit', hour12: false, timeZone: 'Asia/Ho_Chi_Minh' }); return (
{m.name}
Sắp phát sóng
{m.name}
{timeStr} {epLabel}
); })}
)}
); })}