"use client"; import React, { useEffect, useMemo, useState } from 'react'; import Link from 'next/link'; import { useParams } from 'next/navigation'; import { ArrowLeft, MapPin, Globe, Mail, Phone, CheckCircle, Star, Facebook, Linkedin, Instagram, Play, Share2, Send, Award, Quote } from 'lucide-react'; import { MOCK_BUSINESSES, MOCK_OFFERS } from '../../../lib/mockData'; import { Business, OfferType } from '../../../types'; import { toast } from 'react-hot-toast'; const BusinessDetailPage = () => { const { id } = useParams(); const [business, setBusiness] = useState(null); const [loading, setLoading] = useState(true); const [contactForm, setContactForm] = useState({ name: '', email: '', message: '' }); const [formStatus, setFormStatus] = useState<'idle' | 'sending' | 'success'>('idle'); const businessOffers = useMemo(() => { if (!business) return []; // If the business has its own offers (from DB), use them if (business.offers && business.offers.length > 0) return business.offers; // Otherwise fallback to mock offers for mock businesses return MOCK_OFFERS.filter(o => o.businessId === id && o.active); }, [business, id]); useEffect(() => { window.scrollTo(0, 0); const loadBusiness = async () => { setLoading(true); // 1. Try Mock Data First (Instant) const mock = MOCK_BUSINESSES.find(b => b.id === id); if (mock) { setBusiness(mock); setLoading(false); return; } // 2. Try API (Database) try { const res = await fetch(`/api/businesses/${id}`); if (res.ok) { const data = await res.json(); setBusiness(data); // 3. Increment views silently fetch(`/api/businesses/${id}/view`, { method: 'POST' }).catch(console.error); } else { setBusiness(null); } } catch (err) { console.error("Error fetching business:", err); setBusiness(null); } finally { setLoading(false); } }; if (id) loadBusiness(); }, [id]); if (loading) { return (

Chargement du profil...

); } if (!business) { return (

Entreprise introuvable

Retour à l'annuaire
); } // Helper to get YouTube embed URL const getEmbedUrl = (url: string) => { const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/; const match = url.match(regExp); return (match && match[2].length === 11) ? `https://www.youtube.com/embed/${match[2]}` : null; }; const videoEmbedUrl = business.videoUrl ? getEmbedUrl(business.videoUrl) : null; const handleContactSubmit = (e: React.FormEvent) => { e.preventDefault(); setFormStatus('sending'); // Simulate API call setTimeout(() => { setFormStatus('success'); setContactForm({ name: '', email: '', message: '' }); // Reset status after 3 seconds setTimeout(() => setFormStatus('idle'), 3000); }, 1500); }; return (
{/* Header Banner */}
Retour
{/* Profile Header */}
{business.name} {business.isFeatured && (
)}

{business.name}

{business.verified && }
{business.category}
{business.isFeatured && (
ENTREPRENEUR DU MOIS
)}
Contacter
{business.location}
{business.rating} ({business.viewCount} vues)
{business.tags.map(tag => ( #{tag} ))}
{/* Left Column: Main Content */}
{/* Presentation */}

À propos

{business.description}

{/* Founder Section (Specifically for Featured or if data exists) */} {(business.founderName || business.founderImageUrl) && (

Le Fondateur

{business.founderImageUrl && ( {business.founderName} )}

{business.founderName}

CEO & Fondateur

"Notre mission est d'apporter des solutions concrètes et adaptées aux réalités locales, tout en visant l'excellence internationale."

{business.keyMetric && (
🚀 {business.keyMetric}
)}
)} {/* Video */} {videoEmbedUrl && (

Présentation Vidéo

)} {/* Offers */} {businessOffers.length > 0 && (

Produits & Services

{businessOffers.map(offer => (
{offer.title} {offer.type === OfferType.PRODUCT ? 'Produit' : 'Service'}

{offer.title}

{new Intl.NumberFormat('fr-FR').format(offer.price)} {offer.currency}

))}
)}
{/* Right Column: Sidebar */}
{/* Contact Card */}

Contact

{/* Direct Info */}
{business.contactEmail}
{business.contactPhone && (
{business.contactPhone}
)} {business.socialLinks?.website && (
Site Web
)}
{/* Contact Form */}

Envoyer un message

{formStatus === 'success' ? (
Message envoyé avec succès !
) : (
setContactForm({ ...contactForm, name: e.target.value })} />
setContactForm({ ...contactForm, email: e.target.value })} />