import { useState, useEffect } from 'react' import { Link } from 'react-router-dom' import Navbar from '../components/Navbar' import Footer from '../components/Footer' import ProductCard from '../components/ProductCard' import { API_BASE, getCategoryImage, type Category, type Product, type Hero } from '../types' export default function HomePage() { const [categories, setCategories] = useState([]) const [featuredProducts, setFeaturedProducts] = useState([]) const [hero, setHero] = useState(null) const [loading, setLoading] = useState(true) useEffect(() => { const fetchData = async () => { try { const [catRes, prodRes, heroRes] = await Promise.all([ fetch(`${API_BASE}/categories`), fetch(`${API_BASE}/products?categoryId=1`), fetch(`${API_BASE}/hero`), ]) const cats: Category[] = await catRes.json() const prodsJson = await prodRes.json() const heroText = await heroRes.text() const heroData: Hero | null = heroText ? JSON.parse(heroText) : null const prods: Product[] = prodsJson.data || [] setCategories(cats) setFeaturedProducts(prods.slice(0, 3)) setHero(heroData) } catch (err) { console.error('API error:', err) } finally { setLoading(false) } } fetchData() }, []) return (
{/* Hero Section */}
Hero Background { (e.target as HTMLImageElement).style.display = 'none' }} /> {/* Dark gradient overlay for premium vibe */}

{hero?.tagline || "Vibrant Elegance Collection"}

{hero ? ( hero.title.split('[').map((part, i) => { if (part.includes(']')) { const [accent, rest] = part.split(']') return ( {accent} {rest} ) } return {part} }) ) : ( <> Inhale Serenity )}

{hero?.description || "Crafting premium sensory experiences that transform your space into a sanctuary of peace."}

{/* White solid primary button */} {hero?.buttonText || "Explore Collection"} {/* Outline secondary link */} Learn More →
{/* Categories Showcase */}

Our Collections

Discover the perfect scent for every moment

{loading ? (
{Array.from({ length: 5 }).map((_, i) => (
))}
) : (
{categories.map((cat) => (
{cat.name} { (e.target as HTMLImageElement).style.display = 'none' }} />
{cat.name} {cat._count && ( {cat._count.products} Products )}
))}
)}
{/* Featured Products */}

Featured Picks

View All Collection →
{loading ? (
{Array.from({ length: 3 }).map((_, i) => (
))}
) : (
{featuredProducts.map((p) => (
))}
)}
) }