import { SERVER_IP, PROXY_PORT } from '../../../../config.ts'; const BASE_URL = typeof window === 'undefined' ? `http://${SERVER_IP}:${PROXY_PORT}` : ''; async function memberFetch( method: string, path: string, token: string, famId: string, body?: unknown, ): Promise { const headers: Record = { 'x-device-token': token, 'x-device-famid': famId, }; if (body !== undefined) headers['Content-Type'] = 'application/json'; const res = await fetch(`${BASE_URL}${path}`, { method, headers, body: body !== undefined ? JSON.stringify(body) : undefined, }); const data = await res.json(); if (!res.ok) throw new Error(data.error || `${method} ${path} failed`); return data as T; } export const memberApi = { async toggleCompletion(token: string, famId: string, assignedChoreId: string, date: string) { return memberFetch('POST', '/api/completions/toggle', token, famId, { assignedChoreId, date }); }, async myChores(token: string, famId: string) { return memberFetch('POST', '/api/members/my-chores', token, famId); }, async claimReward(token: string, famId: string, rewardId: string) { return memberFetch('POST', `/api/members/rewards/${rewardId}/claim`, token, famId); }, };