'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import Image from 'next/image'; import { agentsService, AgentType } from '@/services/agents.service'; export function HeroSection() { const router = useRouter(); const [agentTypes, setAgentTypes] = useState([]); const [searchParams, setSearchParams] = useState({ type: '', name: '', location: '', }); const [openDropdown, setOpenDropdown] = useState(null); const [validationError, setValidationError] = useState(null); // Fetch agent types on mount useEffect(() => { const fetchAgentTypes = async () => { try { const types = await agentsService.getAgentTypes(); setAgentTypes(types); } catch (error) { console.error('Failed to fetch agent types:', error); } }; fetchAgentTypes(); }, []); const handleSearch = () => { // Validate that at least one field has a value const hasType = searchParams.type.trim() !== ''; const hasName = searchParams.name.trim() !== ''; const hasLocation = searchParams.location.trim() !== ''; if (!hasType && !hasName && !hasLocation) { setValidationError('Please enter at least one search criteria (Type, Name/Keyword, or Location)'); return; } // Clear any previous validation error setValidationError(null); const params = new URLSearchParams(); if (searchParams.type) params.set('type', searchParams.type); if (searchParams.name) params.set('name', searchParams.name); if (searchParams.location) params.set('location', searchParams.location); router.push(`/user/profiles?${params.toString()}`); }; const handleSeeAllAgents = () => { router.push('/user/profiles'); }; const toggleDropdown = (dropdown: string) => { setOpenDropdown(openDropdown === dropdown ? null : dropdown); }; const selectType = (value: string) => { setSearchParams({ ...searchParams, type: value }); setOpenDropdown(null); setValidationError(null); // Clear error when user selects a type }; const handleInputChange = (field: 'name' | 'location', value: string) => { setSearchParams({ ...searchParams, [field]: value }); setValidationError(null); // Clear error when user starts typing }; const handleClearError = () => { setValidationError(null); }; return (
{/* Background Image */}
{/* Headline */}

“Discover verified, top-rated real estate professionals to guide your buying, selling, or investing journey.”

Discover verified, top-rated real estate professionals

{/* Search Form */}
{/* Type Select */}
{openDropdown === 'type' && (
{agentTypes.map((type, index, arr) => ( ))}
)}
{/* Name Input */}
handleInputChange('name', e.target.value)} className="w-full h-[42px] px-4 rounded-[7px] border border-[#00293d]/10 bg-white font-serif text-sm text-[#00293d] placeholder:text-[#00293d] focus:outline-none" />
{/* Location Input */}
handleInputChange('location', e.target.value)} className="w-full h-[42px] px-4 rounded-[7px] border border-[#00293d]/10 bg-white font-serif text-sm text-[#00293d] placeholder:text-[#00293d] focus:outline-none" />
{/* Search Button */}
{/* Validation Error Message */} {validationError && (
{validationError}
)}
{/* Bottom Section - pushed to bottom */}
{/* See All Agents Button */}
{/* Helper Text */}

Connect with trusted local agents to explore homes, compare options, and make smarter decisions.

); }