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

export async function load({ fetch }) {
  if (!hasStoredClientSession()) {
    return {
      rawMaterials: []
    };
  }

  const session = getStoredClientSession();

  try {
    return {
      rawMaterials: hasModuleAccess(session, 'mix_master') && hasModuleAccess(session, 'raw_materials') ? await api.rawMaterials(fetch) : []
    };
  } catch {
    return {
      rawMaterials: []
    };
  }
}
