import React, { useEffect, useState } from 'react'; import { ChevronLeft, ChevronRight, Play, Sparkles } from 'lucide-react'; import { Course } from '../types'; import { getCourses, getHomeBanners, PublicHomeBanner } from '../services/db'; import { CourseCoverImage } from './CourseCoverImage'; interface HeroProps { onPlay?: (course: Course) => void; } export const Hero: React.FC = ({ onPlay }) => { const [banners, setBanners] = useState([]); const [courses, setCourses] = useState([]); const [index, setIndex] = useState(0); useEffect(() => { Promise.all([getHomeBanners(), getCourses()]).then(([loadedBanners, loadedCourses]) => { setBanners(loadedBanners); setCourses(loadedCourses); }).catch(() => setBanners([])); }, []); useEffect(() => { if (banners.length < 2) return; const timer = window.setInterval(() => setIndex((current) => (current + 1) % banners.length), 7000); return () => window.clearInterval(timer); }, [banners.length]); const fallback = courses[0]; const banner = banners[index]; const course = banner?.courseId ? courses.find((item) => item.id === banner.courseId) : fallback; if (!banner && !fallback) return null; const title = banner ? (banner.kind === 'course' ? banner.courseTitle || banner.title : banner.title) : fallback.title; const description = banner ? (banner.kind === 'course' ? banner.courseDescription || banner.description : banner.description) : fallback.description; const image = banner ? (banner.kind === 'course' ? banner.courseImageUrl : banner.imageUrl) : fallback.thumbnail; const canPlay = Boolean(course && (banner?.kind !== 'custom' || banner.courseId)); return
{image && }
Destaque{banner?.kind === 'course' && {course?.category}}

{title}

{description &&

{description}

}{canPlay && }
{banners.length > 1 &&
{banners.map((item, itemIndex) =>
}
; };