export default async function searchUsers(query) {
    try {
        const encodedQuery = encodeURIComponent(query);
        const response = await fetch(
            `${import.meta.env.VITE_API_URL}/api/users/search?query=${encodedQuery}`,
            {
                method: 'GET',
                credentials: 'include',
                headers: {
                    'Content-Type': 'application/json',
                    'Accept': 'application/json'
                }
            }
        );
        const data = await response.json();
        return data.hits.map(hit => hit.document);

    } catch (err) {
        console.error("Erreur :", err);
        return null;
    }
}
