import { useMemo } from 'react'; import { getDigiPin, isWithinIndia } from '../core/digipin'; /** * Compute a DigiPin code from lat/lng entirely offline (no API call). * Returns null if coordinates are outside India's bounds. * * The calculation is pure math (~0.1ms), so no debouncing is needed * even when called on every marker drag event. */ export function useDigiPin(lat: number, lng: number): string | null { return useMemo(() => { if (!isWithinIndia(lat, lng)) return null; try { return getDigiPin(lat, lng); } catch { return null; } }, [lat, lng]); }