import { Button } from "antd"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { ProBottomSheet } from "../ProBottomSheet/ProBottomSheet"; import { GoogleMap } from "./GoogleMap"; import styles from "./MapBottomSheet.module.css"; import { MapFallback } from "./MapFallback"; interface MapBottomSheetProps { isOpen: boolean; onClose: () => void; initialValue: string; onSave: (value: string) => void; } interface LocationData { lat: number; lng: number; address: string; } export function MapBottomSheet({ isOpen, onClose, initialValue, onSave, }: MapBottomSheetProps) { const { t } = useTranslation(); const [value, setValue] = useState(initialValue); const [selectedLocation, setSelectedLocation] = useState( null ); const [useMapFallback, setUseMapFallback] = useState(false); useEffect(() => { setValue(initialValue); // Try to parse initialValue as JSON to set selectedLocation if (initialValue) { try { const parsed = JSON.parse(initialValue); if (parsed.lat && parsed.lng && parsed.address) { setSelectedLocation(parsed); } } catch { // If parsing fails, it's just a string value, not a location object setSelectedLocation(null); } } }, [initialValue]); const handleLocationSelect = (lat: number, lng: number, address: string) => { console.log('Location selected:', { lat, lng, address }); setSelectedLocation({ lat, lng, address }); setValue(address); }; const handleSave = () => { console.log('Save clicked, selectedLocation:', selectedLocation); if (selectedLocation) { onSave(JSON.stringify(selectedLocation)); } else { onSave(value); } onClose(); }; const handleCancel = () => { setValue(initialValue); setSelectedLocation(null); onClose(); }; return (
{useMapFallback ? ( ) : ( )}
{!useMapFallback && (
)}
); }