import React, { useState } from 'react'; const LocationSelector = ({ onLocationChange, currentLocation, isLoading, isNight }) => { const [searchQuery, setSearchQuery] = useState(''); const [isSearching, setIsSearching] = useState(false); const handleSearch = async (e) => { e.preventDefault(); if (searchQuery.trim() && !isLoading) { setIsSearching(true); await onLocationChange(searchQuery.trim()); setIsSearching(false); setSearchQuery(''); } }; const handleCurrentLocation = async () => { if (!isLoading) { setIsSearching(true); try { const position = await new Promise((resolve, reject) => { navigator.geolocation.getCurrentPosition(resolve, reject, { enableHighAccuracy: true, timeout: 10000, maximumAge: 600000 }); }); const { latitude, longitude } = position.coords; await onLocationChange(`${latitude},${longitude}`); } catch (error) { console.error('Error getting current location:', error); alert('Unable to get your current location. Please enter a city name manually.'); } setIsSearching(false); } }; return (