import GoogleSuggestions from "../types/GoogleSuggestions";

export default async (query: string): Promise<GoogleSuggestions> => {
	const url = new URL(" http://suggestqueries.google.com/complete/search");
	const param = new URLSearchParams();
	param.append("q", query);
	param.append("client", "firefox"); // TODO check if the result are different on different clients
	url.search = param.toString();

	const response = await fetch(url.toString());
	const results = await response.json();

	return {
		query: results[0],
		suggestions: results[1]
	};
};
