import { get } from "./serviceHelper";
export async function searchUsers(query, limit = 20) {
    const params = new URLSearchParams({
        query,
        limit: String(limit),
    });
    const result = await get(`/parhelia/users?${params.toString()}`);
    if (result.type !== "success") {
        throw new Error(`Failed to search users: ${result.summary || "Unknown error"} ${result.details || ""}`);
    }
    return result.data ?? [];
}
/**
 * Uploads the current user's avatar image. The global fetch wrapper attaches the Parhelia
 * CSRF header automatically. Returns the new version-stamped avatar URL on success.
 */
export async function uploadAvatar(file) {
    const formData = new FormData();
    formData.append("file", file);
    const response = await fetch("/parhelia/upload-avatar", {
        method: "POST",
        body: formData,
        credentials: "include",
    });
    if (!response.ok) {
        let message = `Upload failed (${response.status})`;
        try {
            const data = await response.json();
            if (data?.summary)
                message = data.summary;
        }
        catch {
            // keep the default message
        }
        throw new Error(message);
    }
    return (await response.json());
}
//# sourceMappingURL=userService.js.map