import { hasStoredClientSession } from '$lib/session';
import { api } from '$lib/api';
import type { CatalogueProduct } from '$lib/types';

// Catalogue products. Access enforced by the family +layout.ts guard.
export async function load({ fetch }) {
  if (!hasStoredClientSession()) {
    return { products: [] as CatalogueProduct[] };
  }

  try {
    const products = await api.orderingAdmin.products(fetch);
    return { products };
  } catch {
    return { products: [] as CatalogueProduct[] };
  }
}
