/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable react/destructuring-assignment */
import axios from 'axios';
import type { ReactNode } from 'react';
import type React from 'react';
import { createContext, useState } from 'react';

import environment from '../../Environments/environment';

export interface AcceptInviteeContextModel {
	whatIsChecked: number;
	acceptInviteHandler: (event: string) => void;
}

export const AcceptInviteeContext: React.Context<AcceptInviteeContextModel> =
	createContext<AcceptInviteeContextModel>({
		whatIsChecked: 0,
		acceptInviteHandler: (): void => {}
	});

const AcceptInviteeContextProvider: React.FC<{ children: ReactNode }> = (props: {
	children: ReactNode;
}) => {
	const { apiUrl, backendRoutes } = environment;
	const [whatIsChecked, setWhatIsChecked] = useState<number>(0);

	function acceptInviteHandler(event: string): void {
		axios
			.post(apiUrl + backendRoutes.account.acceptInvitee, {
				inviteUuid: event
			})
			.then((result) => {
				console.log(result);
				return result.data;
			})
			.catch((error) => console.log(error.message));
	}

	// eslint-disable-next-line react/jsx-no-constructed-context-values
	const contextValue = {
		whatIsChecked,
		acceptInviteHandler
	};

	return (
		<AcceptInviteeContext.Provider value={contextValue}>
			{props.children}
		</AcceptInviteeContext.Provider>
	);
};

export default AcceptInviteeContextProvider;
