import { ref } from 'vue';
import laravelApiService from '@/services/laravelApiService';

export function useLaravelApi() {
    const data = ref(null);
    const error = ref(null);
    const loading = ref(false);

    const fetchData = async (endpoint, options = {}) => {
        loading.value = true;
        try {
            const response = await laravelApiService.fetchData(endpoint, options);
            data.value = response.data;
            error.value = null;
            return response;
        } catch (err) {
            error.value = err;
            throw err;
        } finally {
            loading.value = false;
        }
    };

    return { data, error, loading, fetchData };
}
