import { validatePhone } from "../../utlits/validation";

/* eslint-disable @typescript-eslint/no-explicit-any */
export const validateForm = (formData: any) => {
  const newErrors: { [key: string]: string } = {};

  if (!formData.name.trim()) {
    newErrors.name = "Name is required.";
  } else if (formData.name.trim().length < 2) {
    newErrors.name = "Name must be at least 2 characters long.";
  }
  if (!formData.blockNo) newErrors.blockNo = "Block is required.";
  if (!formData.roadNo) newErrors.roadNo = "Road is required.";
  if (!formData.buildingNo) newErrors.buildingNo = "Building is required.";
  if (!formData.flatNo.trim()) newErrors.flatNo = "Flat/Office No is required.";
  if (!formData.latitude) newErrors.latitude = "Latitude is required.";
  if (!formData.longitude) newErrors.longitude = "Longitude is required.";
  const phoneError = validatePhone(formData.phone);
  if (phoneError) newErrors.phone = phoneError;
  return newErrors;
};
