'use client';
import { useState, useEffect } from 'react';
import Image from 'next/image';
import type { FeaturesContent, FeaturedAgentItem } from '@/types/cms';
import { resolveImageUrl } from '@/services/cms.service';
function AgentCard({ agent, className = '' }: { agent: FeaturedAgentItem; className?: string }) {
const [imgLoaded, setImgLoaded] = useState(false);
const [imgSrc, setImgSrc] = useState(agent.imageUrl);
useEffect(() => {
// Only resolve if it's an S3 key (not a URL or local path)
if (agent.imageUrl && !agent.imageUrl.startsWith('http') && !agent.imageUrl.startsWith('/')) {
resolveImageUrl(agent.imageUrl).then((url) => {
if (url) setImgSrc(url);
});
} else {
setImgSrc(agent.imageUrl);
}
}, [agent.imageUrl]);
return (
{imgSrc && (
![]()
{ if (el?.complete && el.naturalWidth > 0) setImgLoaded(true); }}
src={imgSrc}
alt={agent.name}
className={`w-full h-full object-cover transition-opacity duration-300 ${imgLoaded ? 'opacity-100' : 'opacity-0'}`}
onLoad={() => setImgLoaded(true)}
onError={() => setImgLoaded(true)}
/>
)}
{!imgLoaded &&
}
{agent.name}
{agent.role}
Verified Agent
{agent.rating && (
{agent.rating} Rating
)}
{agent.location && (
{agent.location}
)}
{agent.experience && (
Experience:
{agent.experience}
)}
);
}
export function FeaturesSection({ content }: { content?: FeaturesContent }) {
if (!content) return null;
const data = content;
const agents = data.featuredAgents || [];
const [activeCard, setActiveCard] = useState(0);
return (
{/* Left Side - Title & Features */}
{data.title}
{data.subtitle}
{data.features.map((feature, index) => (
{feature.title}
{feature.description}
))}
{/* Right Side - Agent Cards (Desktop) */}
{agents.length > 0 && (
{agents[0] &&
}
{agents[1] &&
}
{agents[2] &&
}
)}
{/* Mobile Agent Cards - Horizontal swipe carousel */}
{agents.length > 0 && (
{
const el = e.currentTarget;
const cardWidth = el.children[0]?.clientWidth || 254;
const gap = 16;
const idx = Math.round(el.scrollLeft / (cardWidth + gap));
if (idx !== activeCard) setActiveCard(idx);
}}
>
{agents.map((agent, index) => (
))}
{/* Dot indicators (visual only — swipe to change) */}
{agents.map((_, index) => (
))}
)}
);
}