Source: data/addnewpoi.js

import { getDatabase, ref, push, set } from "firebase/database";
import { useAuth } from "../context/AuthContext";

// Function to add a new point of interest (POI) with user's UUID and email
/**
 * The function `addNewPOI` adds a new point of interest (POI) to a database under a specific category
 * and displays a success message or an error message accordingly.
 * @param poiType - poiType is a string that represents the type of point of interest (POI) being
 * added. It could be something like "restaurant", "park", "museum", etc.
 * @param poiData - The `poiData` parameter in the `addNewPOI` function represents the data of the
 * Point of Interest (POI) being added. It could include information such as the name of the POI, its
 * location coordinates, description, category, and any other relevant details that describe the PO
 */
export async function addNewPOI(poiType, poiData) {
  const database = getDatabase();

  try {
    // Push the new POI to newsuggestions based on the poiType
    const newPOIRef = push(ref(database, `newsuggestions/${poiType}`));
    await set(newPOIRef, {
      ...poiData, // Spread POI data
    });

    alert(`New ${poiType} suggested successfully!`);
  } catch (error) {
    alert(`Error suggesting new ${poiType}: ${error}`);
    throw error;
  }
}