import { error } from "@sveltejs/kit";
import { n as newSimulationCommunaute } from "../../../../../chunks/grain-types.js";
import { readFileSync } from "node:fs";
import { P as PROJETS_DIR } from "../../../../../chunks/private.js";
const load = async ({ params }) => {
  console.log("LOAD");
  if (params["id"] == "nouveau") {
    const sim = newSimulationCommunaute();
    console.log(JSON.stringify(sim));
    return {
      nom: "",
      id: "nouveau",
      porteur: "",
      tel: "",
      adresse: "",
      simulation: { ...sim },
      email: "grain@coturnix.fr",
      prms: [],
      profils: [],
      N: 30,
      expert: false
    };
  }
  try {
    const result = JSON.parse(
      readFileSync(
        PROJETS_DIR + "/" + fixNom(params.id) + ".json",
        "utf8"
      )
    );
    console.log(result);
    return result;
  } catch (err) {
    console.error(err);
    return error(500, `${err}`);
  }
};
function fixNom(nom) {
  return nom.replaceAll("/", "_");
}
export {
  load
};
