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

// Notification settings. Access enforced by the family +layout.ts guard.
export async function load({ fetch }) {
  if (!hasStoredClientSession()) {
    return { settings: null as OrderingNotificationSettings | null };
  }

  try {
    const settings = await api.orderingAdmin.notificationSettings(fetch);
    return { settings };
  } catch {
    return { settings: null as OrderingNotificationSettings | null };
  }
}
