import axios from 'axios';

if(process.browser)
{
	FormData.prototype.appendObject = function(obj, namespace) 
	{
		let keyName;
		for (var key in obj) 
		{
			if (obj.hasOwnProperty(key)) 
			{
				keyName = [namespace, '[', key, ']'].join('');
				this.append(keyName, obj[key]);
			}
		}
	};	
}

export const sendFeedback = (feedback) => 
{
	//{ name, phone, email, company, recaptcha_token }
	return new Promise((resolve, reject) => 
	{
		axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/feedbacks/add`, feedback, 
		{
			withCredentials: true, 
		})
		.then((response) => 
		{
			if(response.data.status === "success")
			{
				resolve();
			}
			else
			{
				reject(response.data);
			}
		})
		.catch((error) => 
		{
			console.error(error);
			reject();
		});		
	});
}