'use client'; import { useState } from 'react'; import { FormModal } from '@/components/ui/form-modal'; import { Button } from '@/components/ui/button'; import { LeafletMap } from './leaflet-map'; interface LocationPickerModalProps { open: boolean; onClose: () => void; onConfirm: (latitude: number, longitude: number) => void; title?: string; description?: string; initialLatitude?: number | null; initialLongitude?: number | null; } export function LocationPickerModal({ open, onClose, onConfirm, title = 'Pin Client Location', description = 'Click on the map to pin the client location, or use your current location.', initialLatitude, initialLongitude, }: LocationPickerModalProps) { const [latitude, setLatitude] = useState(initialLatitude ?? null); const [longitude, setLongitude] = useState(initialLongitude ?? null); // Reset when modal opens const isOpen = open; if (isOpen && latitude === null && initialLatitude != null) { setLatitude(initialLatitude); setLongitude(initialLongitude ?? null); } function handleSelect(lat: number, lng: number) { setLatitude(lat); setLongitude(lng); } function handleConfirm() { if (latitude !== null && longitude !== null) { onConfirm(latitude, longitude); } } return (
{latitude !== null && longitude !== null ? (
Lat: {latitude.toFixed(6)},{' '} Lng: {longitude.toFixed(6)}
) : (

Click on the map to pin the location

)}
); }