// hooks/useReport.js
import { useState } from 'react';
import { submitReport } from '../services/ReportService';

const useReports = () => {
    const [report, setReport] = useState(''); 
    const [loading, setLoading] = useState(false); 
    const [error, setError] = useState(null); 
    const [successReport, setSuccess] = useState(false); 

    const handleSubmit = async (e) => {
        e.preventDefault();
        setLoading(true);
        setError(null);
        setSuccess(false);
        try {
            await submitReport(report);
            setSuccess(true); 
            setReport(''); 
        } catch (err) {
            setError(err.message); 
        } finally {
            setLoading(false); 
        }
    };

    return {
        report,
        setReport,
        loading,
        error,
        successReport,
        handleSubmit,
    };
};

export default useReports;
