import {useEffect, useState} from 'react'; import {HeroCatchphrase} from '@site/sections/HeroCatchphrase'; import {useSite} from '@site/lib/site-context'; import {bookingActionLabel, bookingLinks, isSectionEnabled, stayBookingView} from '@site/lib/derive'; import {PlaceCategory} from '@o2o/shared'; import {heroSub} from '../kit/heroSub'; import {BOOK_EVENT} from '../paper/Rooms'; import {pad2} from './ui'; import {Weather} from './Weather'; const MAX_SLIDES = 5; export function Hero() { const payload = useSite(); const {place, narrative} = payload; const slides = [...payload.media] .filter((image) => image.alt?.trim()) .sort((a, b) => Number(b.isPrimary) - Number(a.isPrimary)) .slice(0, MAX_SLIDES); const [index, setIndex] = useState(0); const total = slides.length; useEffect(() => { if (total < 2) return; const motion = window.matchMedia('(prefers-reduced-motion: reduce)'); const timer = window.setInterval(() => { if (!document.hidden && !motion.matches) setIndex((was) => (was + 1) % total); }, 5000); return () => window.clearInterval(timer); }, [total]); const sub = heroSub(payload); const english = place.englishName?.trim(); const locality = [place.addressLocality, place.addressRegion].find(Boolean); const stayBooking = place.category === PlaceCategory.LODGING ? stayBookingView(payload) : null; const booking = bookingLinks(payload)[0]; return ( <>
0 ? 'b-hero' : 'b-hero b-hero--plain'} id="top" data-pg="home" role="region" aria-roledescription="carousel" aria-label={`${place.name} 사진`} > {slides.map((image, i) => (
{image.alt}
))}
{english &&

{english}

}

{place.name}

{locality &&

{locality}

}

{sub &&

{sub}

}
{stayBooking ? ( ) : ( booking && ( {bookingActionLabel(booking)} ) )} 이용안내 보기
{total > 1 && (

{pad2(index + 1)}  /  {pad2(total)}

)}
{isSectionEnabled(payload, 'weather') && (
)} ); }