import { api } from '$lib/api';
import { getStoredClientSession, hasModuleAccess, hasStoredClientSession } from '$lib/session';

export async function load({ fetch }) {
  if (!hasStoredClientSession()) {
    return {
      options: { clients: [], products: [] }
    };
  }

  const session = getStoredClientSession();

  try {
    return {
      options: hasModuleAccess(session, 'mix_calculator', 'edit')
        ? await api.mixCalculatorOptions(fetch)
        : { clients: [], products: [] }
    };
  } catch {
    return {
      options: { clients: [], products: [] }
    };
  }
}
