// app/api/update/route.js

export async function PUT(req) {
    try {
        const body = await req.json();

        const res = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/profiles/me`, {
            method: 'PUT',
            headers: {
                'Content-Type': 'application/json',
                cookie: req.headers.get('cookie') || '',
            },
            credentials: 'include',
            body: JSON.stringify(body),
        });
        //   console.log("Submitting data:", body);

        //   console.log("Update profile response:", res);
        // Check if the response is ok
        if (!res.ok) {
            const errorData = await res.json();
            return new Response(JSON.stringify({ error: errorData.error || 'Failed to update profile' }), {
                status: res.status,
            });
        }

        const data = await res.json();
        return new Response(JSON.stringify(data), { status: 200 });
    } catch (error) {
        console.error('Update profile error:', error);
        return new Response(JSON.stringify({ error: error.message }), { status: 500 });
    }
}
