import { PUBLIC_MEDUSA_KEY } from '$env/static/public';

export async function load() {
    const res = await fetch(
        `http://localhost:9000/store/products?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 products');
    }

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

    return { products };
} 