'use client';
import React from "react";
import { useFormik } from "formik";
import { useRouter } from "next/navigation";

export function Form({jamID}:{jamID:string}) {
  const router = useRouter();
  const formik = useFormik({
    initialValues: {},
    onSubmit: async (values) => {
      const submitRequest = await fetch(`/jams/api/jams/${jamID}`, {
        method: "DELETE"
      });

      if (submitRequest.ok) {
        router.push(`/jams/`);
      } else {
        formik.setSubmitting(false);
      }
    },
  });

  return (
    <form onSubmit={formik.handleSubmit}>
      <div>
        <p><label htmlFor="submit">Are you sure?</label></p>
        <input id="submit" name="submit" type="submit" value="Delete" />
      </div>
     </form>
  );
}