import { api, APIResponse } from "../API/API";

/**
 * Use to delete a project from the system
 * @param {string} props.projectToDelete - The projectname of project to delete
 * @returns {void} Nothing
 * @example
 * const exampleProjectName = "project";
 * DeleteProject({ projectToDelete: exampleProjectName });
 */

function DeleteProject(props: { projectToDelete: string }): void {
  api
    .removeProject(
      props.projectToDelete,
      localStorage.getItem("accessToken") ?? "",
    )
    .then((response: APIResponse<string>) => {
      if (response.success) {
        alert("Project has been deleted!");
        location.reload();
      } else {
        alert("Project has not been deleted");
        console.error(response.message);
      }
    })
    .catch((error) => {
      alert("project has not been deleted");
      console.error("An error occurred during deletion:", error);
    });
}

export default DeleteProject;
