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

// Orders queue. Access is already enforced by the family +layout.ts guard.
export async function load({ fetch }) {
  if (!hasStoredClientSession()) {
    return { orders: [] as Order[] };
  }

  try {
    const orders = await api.orderingAdmin.orders(undefined, fetch);
    return { orders };
  } catch {
    return { orders: [] as Order[] };
  }
}
