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 getPrograms = () => 
{
	return new Promise((resolve, reject) => 
	{
		axios.get(`${ process.env.NEXT_PUBLIC_API_HOST }/api/programs/`)
		.then((response) => 
		{
			resolve(response.data.programs);
		})
		.catch((error) => 
		{
			console.error(error);
		});		
	});
}