
import axios from "axios";
import { baseUrl } from "../../constants/urls";
export const socialLoginFetch = async (params:any) => {
  try {
    const url = `${baseUrl}/api/customer-social-login/google?token=true`;
    const config = {
        method: 'POST',
        url: url,
        data:params
      };
      return await axios(config);
  } catch (error:any) {
    console.log(error.response); 
    return error.response;
  }

}
export const loginFetch = async (params:any) => {
  try {
    const url = `${baseUrl}/api/customer/login?token=true`;
const config = {
    method: 'POST',
    url: url,
    data:{
        email:params.email,
        password:params.password
    }
  };

  const login_res =   await axios(config);

    
    
     return login_res.data;
  } catch (error:any) {
    // this is the main part. Use the response property from the error object

    return error.response;
  }

}

export const OtpVarify = async (params:any) => {
  
  try {
    const url = `${baseUrl}/api/get-otp`;
const config = {
    method: 'POST',
    url: url,
    data:{
      phone:params.finalValue
    }
  };

  const otp_res =   await axios(config);
 

    
     return otp_res.data;
  } catch (error:any) {
      // this is the main part. Use the response property from the error object

    return error.response.data;
  }

}




export const loginWithOTP = async (params:any) => {
  
  
  try {
    const url = `${baseUrl}/api/customer-otp-login?token=true`;
const config = {
    method: 'POST',
    url: url,
    data: params.data || {
      phone:params.finalValue,
        mobile_pin:params.otp
    }
  };

  const login_otp_res =   await axios(config);


    
     return login_otp_res.data;
  } catch (error:any) {
    //   // this is the main part. Use the response property from the error object

    return error.response;
  }

}

export const EmailSentOTP = async (params:any) => {
  
  try {
    const url = `${baseUrl}/api/customisation/login/send-otp`;
const config = {
    method: 'POST',
    url: url,
    data:{
      email:params.email
    }
  };
   
  

  const otp_res =   await axios(config);
 
    
    
     return otp_res.data;
  } catch (error:any) {
      // this is the main part. Use the response property from the error object

    return error.response.data;
  }

}


export const LoginEmailWithOTP = async (params:any) => {
  
  try {
    const url = `${baseUrl}/api/customisation/login/otp?token=true`;
const config = {
    method: 'POST',
    url: url,
    data:{
      email:params.email,
      otp:params.otp
    }
  };
   
  

  const login_res =   await axios(config);
 
    
    
     return login_res.data;
  } catch (error:any) {
      // this is the main part. Use the response property from the error object

    return error.response.data;
  }

}


