class HeroSection extends HTMLElement { connectedCallback() { this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = `

Unlimited movies, TV shows, and more.

Watch anywhere. Cancel anytime.

`; // Random hero image from TMDB API this.fetchHeroImage(); } async fetchHeroImage() { try { const response = await fetch(`https://api.themoviedb.org/3/movie/popular?api_key=8f2b224acadeeebc64ef32b4c04919de&language=en-US&page=1`); const data = await response.json(); const randomMovie = data.results[Math.floor(Math.random() * data.results.length)]; this.shadowRoot.querySelector('.hero').style.backgroundImage = `url(https://image.tmdb.org/t/p/original${randomMovie.backdrop_path})`; this.shadowRoot.querySelector('.hero-title').textContent = randomMovie.title; this.shadowRoot.querySelector('.hero-desc').textContent = randomMovie.overview; } catch (error) { console.error('Error fetching hero image:', error); this.shadowRoot.querySelector('.hero').style.backgroundImage = `url(http://static.photos/movie/1200x630/1)`; } } } customElements.define('hero-section', HeroSection);