const fetchPostData = async (query, data) => {
	const baseUrl = window.ssasBookingRest?.root || `${window.location.protocol}//${window.location.host}/wp-json/`;
	const nonce = window.ssasBookingRest?.nonce;

	try {
		const response = await fetch(`${baseUrl}${query}`, {
			method: 'POST',
			headers: {
				'Content-Type': 'application/json',
				...(nonce ? { 'X-WP-Nonce': nonce } : {}),
			},
			body: JSON.stringify(data),
		});
		const responseData = await response.json(); // Parse the JSON response

		if (response.ok) {
			return responseData;
		} else {
			return "failed";
		}
	} catch (error) {
		return "failed";
	}
};

export default fetchPostData;
