import * as Yup from "yup";
import { ReSeller, ReSellerInitialValues } from "../../../types/ReSeller";

export const getInitialValues = (
  objectToEdit: Partial<ReSeller>,
): ReSellerInitialValues => {
  console.log(objectToEdit,"objectToEdit");
  
  return {
 
    id: objectToEdit?.id,
    first_name: objectToEdit?.first_name ?? "",
    last_name: objectToEdit?.last_name ?? "",
    lat: objectToEdit?.location?.lat ?? 33.5138,
    lng: objectToEdit?.location?.lng ?? 36.2765,
    contact_number1:objectToEdit?.contact_number1  ?? null,
    contact_number2:objectToEdit?.contact_number2  ?? null ,
    username: objectToEdit?.user?.username  ?? null ,
  };
};

export const getValidationSchema = () => {
  // validate input
  return Yup.object().shape({
    first_name: Yup.string().required("validation.required"),
    last_name: Yup.string().required("validation.required"),
    contact_number1: Yup.string()
    .matches(/^([0-9\s\-\+\(\)]*)$/, 'validation.Please enter a valid phone number (e.g., +1 123-456-7890)') // Regex for phone number
    .min(10, "validation.must_be_at_least_10_characters_long") // Minimum length
    .max(15, "validation.must_not_exceed_15_characters_long") // Maximum length
    .required("validation.required"), // Required field

contact_number2: Yup.string()
    .matches(/^([0-9\s\-\+\(\)]*)$/, 'validation.Please enter a valid phone number (e.g., +1 123-456-7890)') // Regex for phone number
    .min(10, "validation.must_be_at_least_10_characters_long") // Minimum length
    .max(15, "validation.must_not_exceed_15_characters_long") // Maximum length
    .required("validation.required"), // Required field
    
    password: Yup.string().min(8,"validation.Password_must_be_at_least_8_characters_long").required("validation.required"),
    username: Yup.string().required("validation.required"),
    lat: Yup.string().required("validation.required"),
    lng: Yup.string().required("validation.required"),
  });
};

export const getValidationSchemaEdit = () => {
  // validate input
  return Yup.object().shape({
    first_name: Yup.string().required("validation.required"),
    last_name: Yup.string().required("validation.required"),
    contact_number1: Yup.string()
    .matches(/^([0-9\s\-\+\(\)]*)$/, 'validation.Please enter a valid phone number (e.g., +1 123-456-7890)') // Regex for phone number
    .min(10, "validation.must_be_at_least_10_characters_long") // Minimum length
    .max(15, "validation.must_not_exceed_15_characters_long") // Maximum length
    .required("validation.required"), // Required field

contact_number2: Yup.string()
    .matches(/^([0-9\s\-\+\(\)]*)$/, 'validation.Please enter a valid phone number (e.g., +1 123-456-7890)') // Regex for phone number
    .min(10, "validation.must_be_at_least_10_characters_long") // Minimum length
    .max(15, "validation.must_not_exceed_15_characters_long") // Maximum length
    .required("validation.required"), // Required field
    username: Yup.string().required("validation.required"),
    lat: Yup.string().required("validation.required"),
    lng: Yup.string().required("validation.required"),
  });
};

