export const formatTimestamp = (isoString: string) => {
  const date = new Date(isoString);
  return (
    date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) +
    ' ' +
    date.toLocaleDateString([], { month: 'short', day: 'numeric' })
  );
};

export function extractLatLon(pointString: string): { latitude: number; longitude: number } {
  // Regular expression to match the numbers within the parentheses
  const regex = /POINT\(([-+]?\d+\.?\d*)\s+([-+]?\d+\.?\d*)\)/;
  const match = pointString.match(regex);

  if (match && match.length === 3) {
    // The first captured group is the longitude, the second is the latitude
    const longitude = parseFloat(match[1]);
    const latitude = parseFloat(match[2]);

    // Check if parsing was successful and resulted in valid numbers
    if (!isNaN(longitude) && !isNaN(latitude)) {
      return { latitude, longitude };
    }
  }
  return { latitude: 0, longitude: 0 }; // Return null if the string format is not as expected or parsing fails
}

/**
 * Formats a number as a currency string using US dollar locale.
 *
 * @param value The number to format.
 * @returns A string representing the formatted currency value (e.g., "$1,234.56").
 */
export const formatCurrency = (value: number): string => {
  return new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: 'USD',
  }).format(value);
};
