import { fail } from '@sveltejs/kit';
import type { Actions } from './$types';
import { createApiClient } from '$lib/shared/api.server';

export const actions = {
	default: async ({ request, fetch }) => {
		const formData = await request.formData();
		const email = formData.get('email') as string;

		if (!email) {
			return fail(400, { error: 'Email is required' });
		}

		const api = createApiClient(fetch);
		await api.POST('/api/auth/forgot-password', { body: { email } });

		// Always return success — never disclose whether the email exists
		return { success: true };
	}
} satisfies Actions;
