import React, { useState, useEffect } from 'react'; import { Link } from 'react-router-dom'; import axios from 'axios'; import { ArrowRight, Truck, Shield, Headphones, Wrench, Laptop, Smartphone, Watch } from 'lucide-react'; import { Button } from '../components/ui/button'; import { Badge } from '../components/ui/badge'; import ProductCard from '../components/cards/ProductCard'; import ServiceCard from '../components/cards/ServiceCard'; const API = `${process.env.REACT_APP_BACKEND_URL}/api`; const Home = () => { const [featuredProducts, setFeaturedProducts] = useState([]); const [featuredServices, setFeaturedServices] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const fetchData = async () => { try { // Seed data first await axios.post(`${API}/seed`); const [productsRes, servicesRes] = await Promise.all([ axios.get(`${API}/products`), axios.get(`${API}/services`) ]); setFeaturedProducts(productsRes.data.slice(0, 4)); setFeaturedServices(servicesRes.data.slice(0, 3)); } catch (error) { console.error('Failed to fetch data:', error); } finally { setLoading(false); } }; fetchData(); }, []); const features = [ { icon: Truck, title: 'Free Shipping', desc: 'On orders over $100' }, { icon: Shield, title: 'Warranty', desc: '1 Year manufacturer warranty' }, { icon: Headphones, title: '24/7 Support', desc: 'Expert assistance anytime' }, { icon: Wrench, title: 'Expert Repair', desc: 'Certified technicians' }, ]; const categories = [ { icon: Smartphone, name: 'Phones', link: '/products?category=phones' }, { icon: Laptop, name: 'Laptops', link: '/products?category=laptops' }, { icon: Watch, name: 'Wearables', link: '/products?category=wearables' }, ]; return (
{/* Hero Section */}
{/* Content */}
New Arrivals Available

Premium Tech,
Expert Service

Discover the latest electronics and get professional repair services. Quality products, trusted solutions for all your tech needs.

{/* Hero Image */}
Premium Electronics {/* Floating Card */}

Starting from

$99.99

{/* Features Bar */}
{features.map((feature, idx) => { const Icon = feature.icon; return (

{feature.title}

{feature.desc}

); })}
{/* Categories */}

Shop by Category

Browse our wide selection of premium electronics

{categories.map((cat, idx) => { const Icon = cat.icon; return (

{cat.name}

); })}
{/* Featured Products */}

Featured Products

Handpicked selection of our best-selling items

{loading ? (
{[...Array(4)].map((_, i) => (
))}
) : (
{featuredProducts.map((product) => ( ))}
)}
{/* Services Section */}

Our Services

Professional tech support and repair services

{loading ? (
{[...Array(3)].map((_, i) => (
))}
) : (
{featuredServices.map((service) => ( ))}
)}
{/* CTA Section */}

Need Expert Help?

Our certified technicians are ready to help you with any tech problem. From repairs to upgrades, we've got you covered.

); }; export default Home;