import React from "react";
import axios from "axios";

const GenerateCSV = () => {
  const handleGenerateCSV = async () => {
    try {
      const response = await axios.get("http://localhost:8080/api/csv/generate");
      if (response.status === 200) {
        alert("CSV generated successfully. Check the generated_csv folder in the server.");
      }
    } catch (error) {
      console.error("Error generating CSV:", error);
      alert("Failed to generate CSV");
    }
  };

  return (
    <div>
      <button onClick={handleGenerateCSV} style={{ padding: "10px 20px", fontSize: "16px" }}>
        Generate CSV
      </button>
    </div>
  );
};

export default GenerateCSV;
