import React from 'react';
import axios from 'axios';

interface ButtonProps {
	classes: string;
	to: string;
	method: 'GET' | 'POST' | 'PUT' | 'DELETE';
	text: string;
}

/* eslint-disable */
/**
 * @return {jsx} The root component
 */
export default function Button({classes, to, method, text}: ButtonProps) {
	async function buttonFetch() {
		console.log('buttonFetch');
		console.log(to);
		console.log(method);
		axios({
			method: method,
			url: to,
			withCredentials: true,
		}).then((_res: any) => {
			window.location.replace('/');
		}).catch((_err: any) => {
		});
	}

	return (
		<button className={'btn mx-2 ' + classes} onClick={buttonFetch}>
			{text}</button>
	);
}
/* eslint-enable */
