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

export async function load({ cookies }) {
    const regionId = cookies.get('selectedRegion');

    const res = await fetch(
        `http://localhost:9000/store/products?region_id=${regionId}`,
        {
            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 };
} 