import { k as setContext, e as escape_html, b as attr, f as store_get, l as attr_class, u as unsubscribe_stores, p as pop, a as push } from "../../../../../chunks/index.js";
import { w as writable, d as derived } from "../../../../../chunks/index4.js";
import { D as Derived } from "../../../../../chunks/calcul.js";
import { p as page } from "../../../../../chunks/index2.js";
import { r as resolve } from "../../../../../chunks/index3.js";
import { Q as Question } from "../../../../../chunks/Question.js";
import "@sveltejs/kit/internal";
import "../../../../../chunks/exports.js";
import "../../../../../chunks/utils.js";
function ExclamationTriangle($$payload) {
  $$payload.out.push(`<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="var(--color-warning)" class="size-6 inline"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z"></path></svg>`);
}
function _layout($$payload, $$props) {
  push();
  var $$store_subs;
  let { $$slots, $$events, ...props } = $$props;
  let data = props.data;
  let simulation = new Derived(data.simulation);
  let profils_modified = writable(false);
  let prms_modified = writable(false);
  let expert = writable(data.expert);
  let needsSaving = derived([simulation.modified, profils_modified, prms_modified], ([$mod, $profils, $prms]) => {
    console.log("derived", $mod);
    return $mod || $profils || $prms;
  });
  setContext("simulation", simulation);
  setContext("profils", writable(data.profils || []));
  setContext("prms", writable(data.prms || []));
  setContext("profils_modified", profils_modified);
  setContext("prms_modified", writable(data.prms || []));
  let communaute = writable(data.communaute);
  setContext("communaute", communaute);
  setContext("expert", expert);
  setContext("pvgis", writable({ pvgis: null, loading: false }));
  setContext("soleil", writable({
    hourly: { x: [], y: [] },
    daily: { x: [], y: [] },
    weekly: { x: [], y: [] },
    x: [],
    y: [],
    type: "bar",
    line: { color: "#ffbf00", width: 1 },
    marker: { color: "#ffbf00", width: 1 },
    name: "Production solaire",
    bucket: 1
  }));
  const compteActive = page.route.id?.endsWith("/finances") ?? false;
  const descriptionActive = page.route.id?.endsWith("/description") ?? false;
  const banqueActive = page.route.id?.endsWith("/banque") ?? false;
  const expertActive = page.route.id?.endsWith("/expert") ?? false;
  const simuActive = page.route.id?.endsWith("/simulation") ?? false;
  const syntheseActive = !compteActive && !descriptionActive && !banqueActive && !expertActive && !simuActive;
  const surface_kwc = 4.5;
  let surface = surface_kwc * data.simulation.puissance;
  const puissance = simulation?.p.puissance;
  const autoconso = simulation?.p.autoconso;
  const autoprod = simulation?.p.autoprod;
  const cout = simulation?.p.cout_elec;
  const prix = simulation.p.prix;
  const apport = simulation.p.apport;
  const interet = simulation.p.interet;
  const echeances = simulation.p.echeances;
  const N = simulation.N;
  $$payload.out.push(`<div class="w-full"><div class="drawer lg:drawer-open flex-1"><input id="grain-menu" type="checkbox" class="drawer-toggle"/> <div class="drawer-side shadow-xl z-100 lg:z-0 overflow-y-auto drawer-side- svelte-1hxchzm"><label for="grain-menu" aria-label="close sidebar" class="drawer-overlay"></label> <div class="pt-10 px-5 bg-base-100"><div class="lg:hidden ms-3 me-auto"><h1 class="text-4xl">${escape_html(data.nom)}</h1></div> <input type="text" class="input input-lg"${attr("value", data.nom)} placeholder="Nouveau projet"/> <form><button class="my-2 btn btn-sm btn-primary"${attr("disabled", !store_get($$store_subs ??= {}, "$needsSaving", needsSaving), true)}>Sauvegarder</button></form> `);
  if (data.email) {
    $$payload.out.push("<!--[-->");
    $$payload.out.push(`<div class="flex gap-2 my-5"><input class="checkbox" type="checkbox" role="switch" id="expertsw"${attr("checked", store_get($$store_subs ??= {}, "$expert", expert), true)}/> <label class="label ms" for="expertsw">Niveau expert</label></div>`);
  } else {
    $$payload.out.push("<!--[!-->");
  }
  $$payload.out.push(`<!--]--> <h2 class="mt-5">Communauté</h2> <div class="my-3 flex flex-col gap-1"><label class="label" for="puissance">Puissance totale (kWc)</label> <input class="input input-sm" type="number" id="puissance" min="1" max="3000"${attr("value", store_get($$store_subs ??= {}, "$puissance", puissance))}/> `);
  if (data.simulation.puissance > 3e3) {
    $$payload.out.push("<!--[-->");
    $$payload.out.push(`<div class="text-warning my-5 max-w-82">`);
    ExclamationTriangle($$payload);
    $$payload.out.push(`<!----> Une communauté
                            d'autoconsommation ne peut dépasser plus de 3MWc.
                            Les résultats obtenus seront donc purement
                            hypothétiques.</div>`);
  } else {
    $$payload.out.push("<!--[!-->");
  }
  $$payload.out.push(`<!--]--></div> <div class="my-3 flex flex-col gap-1"><label class="label" for="surface">Surface totale (m²)`);
  Question($$payload, {
    datatip: "Estimation de la surface de modules photovoltaïques en fonction de la puissance et du ratio (configurable en mode expert)."
  });
  $$payload.out.push(`<!----></label> <input class="input input-sm" type="number" id="surface" min="1"${attr("value", surface)}/></div> <div class="mb-3 flex flex-col"><label class="label" for="autoconso">Taux d'autoconsommation (%)`);
  Question($$payload, {
    datatip: "Pourcentage de la production consommée localement, à valider plus finement dans l'onglet Simulation. C'est la valeur que l'application Coturnix optimise."
  });
  $$payload.out.push(`<!----></label> <div><input class="range range-sm me-4 my-3 max-w-64" type="range" id="autoconso"${attr("value", store_get($$store_subs ??= {}, "$autoconso", autoconso))}/>${escape_html(store_get($$store_subs ??= {}, "$autoconso", autoconso))}%</div></div> <div class="mb-3 flex flex-col gap-1"><label class="label" for="autoprod">Taux d'autoproduction (%) `);
  Question($$payload, {
    datatip: "Pourcentage des consommations venant de sources locales, à valider plus finement dans l'onglet Simulation."
  });
  $$payload.out.push(`<!----></label> <div class="d-flex"><input class="range range-sm me-4 my-3 max-w-64" type="range" id="autoprod"${attr("value", store_get($$store_subs ??= {}, "$autoprod", autoprod))}/>${escape_html(store_get($$store_subs ??= {}, "$autoprod", autoprod))}%</div></div> <div class="mb-3 flex flex-col gap-1"><label class="label" for="prix">Prix d'achat fournisseur (€/kWh)`);
  Question($$payload, {
    datatip: "Prix d'achat moyen des consommateurs de la communauté à leur fournisseur d'électricité habituel (par exemple EDF)."
  });
  $$payload.out.push(`<!----></label> <input class="input input-sm" type="number" step="0.01" min="0" id="coutElec"${attr("value", store_get($$store_subs ??= {}, "$cout", cout))}/></div> <div class="mb-3 flex flex-col gap-1"><label class="label" for="prix">Prix de vente local (€/kWh)`);
  Question($$payload, {
    datatip: "Hypothèse sur le prix de vente moyen. Dans Coturnix, les producteurs et les consommateurs choisissent leurs prix acceptables, et Coturnix calcule à chaque instant le prix qui maximise la valeur totale créée par la communauté."
  });
  $$payload.out.push(`<!----></label> <input class="input input-sm" type="number" step="0.01" min="0" id="prix"${attr("value", store_get($$store_subs ??= {}, "$prix", prix))}/></div> <div class="mb-3 flex flex-col gap-1"><label class="label" for="echeances">Durée d'analyse (an)</label> <input class="input input-sm" type="number" id="echeances" min="0"${attr("value", store_get($$store_subs ??= {}, "$N", N))}/></div> <h2 class="mt-5 text-2xl">Financement</h2> <div class="my-3 flex flex-col gap-1"><label class="label" for="apport">Apport initial (€)</label> <input class="input input-sm" type="number" id="apport" min="0" step="1000"${attr("value", store_get($$store_subs ??= {}, "$apport", apport))}/></div> <div class="mb-3 flex flex-col gap-1"><label class="label" for="interet">Taux d'intérêt(%)</label> <input class="input input-sm" type="number" step="0.1" id="interet" min="0" max="100"${attr("value", store_get($$store_subs ??= {}, "$interet", interet))}/></div> <div class="mb-3 flex flex-col gap-1"><label class="label" for="echeances">Nombre d'échéances (en mois)</label> <input class="input input-sm" type="number" id="echeances" min="0"${attr("value", store_get($$store_subs ??= {}, "$echeances", echeances))}/></div> `);
  if (data.id) {
    $$payload.out.push("<!--[-->");
    $$payload.out.push(`<form method="POST" action="?/del"><button class="my-2 btn btn-outline btn-primary">Supprimer</button></form>`);
  } else {
    $$payload.out.push("<!--[!-->");
  }
  $$payload.out.push(`<!--]--></div></div> <div class="drawer-content flex flex-col p-5 overflow-y-auto drawer-side- svelte-1hxchzm"><div class="flex"><label for="grain-menu" class="btn drawer-button lg:hidden"><div tabindex="0" role="button" class="btn btn-ghost btn-circle"><svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h7"></path></svg></div></label> <div><div role="tablist" class="tabs tabs-border"><a${attr("href", resolve("/grain/projet/[id]", { id: data.id || "nouveau" }))}${attr_class("tab", void 0, { "tab-active": syntheseActive })} id="synthese-tab" type="button" role="tab">Synthèse</a> <a${attr("href", resolve("/grain/projet/[id]/finances", { id: data.id || "nouveau" }))}${attr_class("tab", void 0, { "tab-active": compteActive })} id="profile-tab" type="button" role="tab">Détails financiers</a> <a${attr("href", resolve("/grain/projet/[id]/description", { id: data.id || "nouveau" }))}${attr_class("tab", void 0, { "tab-active": descriptionActive })} id="profile-tab" type="button" role="tab">Description</a> <a${attr("href", resolve("/grain/projet/[id]/banque", { id: data.id || "nouveau" }))}${attr_class("tab", void 0, { "tab-active": banqueActive })} id="banque-tab" type="button" role="tab">Emprunt</a> `);
  if (store_get($$store_subs ??= {}, "$expert", expert)) {
    $$payload.out.push("<!--[-->");
    $$payload.out.push(`<a${attr("href", resolve("/grain/projet/[id]/expert", { id: data.id || "nouveau" }))}${attr_class("tab", void 0, { "tab-active": expertActive })} id="expert-tab" type="button" role="tab">Mode expert</a>`);
  } else {
    $$payload.out.push("<!--[!-->");
  }
  $$payload.out.push(`<!--]--> <a${attr("href", resolve("/grain/projet/[id]/simulation", { id: data.id || "nouveau" }))}${attr_class("tab", void 0, { "tab-active": simuActive })} id="prm-tab" type="button" role="tab">Simulation</a></div></div></div> `);
  props.children($$payload);
  $$payload.out.push(`<!----></div></div></div>`);
  if ($$store_subs) unsubscribe_stores($$store_subs);
  pop();
}
export {
  _layout as default
};
