// PropertyDetailScreen — gallery, key facts, description, consultant contact panel. function PropertyDetailScreen({ propertyId, onBack }) { const { Button, Badge, IconButton, Avatar } = window.SBLImVeisDesignSystem_08a506; const { isMobile } = window.useResponsive(); const { t, field } = window.useLang(); const p = window.SBL_DATA.properties.find((x) => x.id === propertyId) || window.SBL_DATA.properties[0]; const [active, setActive] = React.useState(0); const kindLabel = { sale: 'Venda', rent: 'Aluguel', season: 'Temporada' }[p.kind]; // ── Favorites ────────────────────────────────────────────────────────────── function loadFavs() { try { return JSON.parse(localStorage.getItem('sbl_favorites') || '[]'); } catch { return []; } } const [fav, setFav] = React.useState(() => loadFavs().includes(p.id)); const [favToast, setFavToast] = React.useState(null); const favTimerRef = React.useRef(null); function toggleFav() { const favs = loadFavs(); const isNowFav = !favs.includes(p.id); const next = isNowFav ? [...favs, p.id] : favs.filter(id => id !== p.id); localStorage.setItem('sbl_favorites', JSON.stringify(next)); setFav(isNowFav); window.dispatchEvent(new CustomEvent('sbl:favorites-changed')); clearTimeout(favTimerRef.current); setFavToast(isNowFav ? 'added' : 'removed'); favTimerRef.current = setTimeout(() => setFavToast(null), 3000); } React.useEffect(() => () => clearTimeout(favTimerRef.current), []); function handleShare() { const siteUrl = window.location.origin + (window.location.pathname.replace(/\/[^/]*$/, '/') || '/'); const text = t('Veja esse imóvel incrível que encontrei no site da SBL:') + ' ' + p.title + ' — ' + siteUrl; window.open('https://wa.me/?text=' + encodeURIComponent(text), '_blank', 'noopener'); } const gallery = p.gallery || []; const thumbRef = React.useRef(null); function prev() { setActive(i => (i - 1 + gallery.length) % gallery.length); } function next() { setActive(i => (i + 1) % gallery.length); } // Scroll active thumbnail into view React.useEffect(() => { if (!thumbRef.current) return; const el = thumbRef.current.children[active]; if (el) el.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' }); }, [active]); // Keyboard navigation React.useEffect(() => { function onKey(e) { if (e.key === 'ArrowLeft') prev(); else if (e.key === 'ArrowRight') next(); } window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [gallery.length]); const facts = [ { icon: 'bed-double', v: p.beds, l: t('Quartos') }, { icon: 'bath', v: p.baths, l: t('Banheiros') }, { icon: 'car', v: p.parking, l: t('Vagas') }, { icon: 'maximize', v: p.area + ' m²', l: t('Área útil') }, ]; const arrowBtn = (onClick, icon, side) => ( ); return (
{field(p, 'desc')}
{p.amenities && p.amenities.length > 0 && ( <>