import type { PageServerLoad } from './$types';
import { PUBLIC_MEDUSA_KEY } from '$env/static/public';

export const load = (async ({ params }) => {
	const res = await fetch(
		`http://localhost:9000/store/products/${params.id}?region_id=reg_01JXB17SNW6VA5WJVV8QPHKAY3`,
		{
			headers: {
				'x-publishable-api-key': PUBLIC_MEDUSA_KEY,
			},
		}
	);

	if (!res.ok) {
		console.error(await res.text());
		throw new Error('Failed to fetch product');
	}

	const { product } = await res.json();

	return {
		product
	};
}) satisfies PageServerLoad;

