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

export async function load({ params, fetch }) {
  if (!hasStoredClientSession()) {
    return {
      session: null
    };
  }

  const session = getStoredClientSession();

  if (!hasModuleAccess(session, 'mix_calculator')) {
    return {
      session: null
    };
  }

  try {
    return {
      session: await api.mixCalculatorSession(Number(params.id), fetch)
    };
  } catch {
    return {
      session: null
    };
  }
}
