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

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

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