<script lang="ts">
  import { A12BerechnungNutzenergiebedarfHeizung } from "#lib/Berechnungen/BedarfsausweisWohnen/A12BerechnungNutzenergiebedarfHeizung.js";

$: result = A12BerechnungNutzenergiebedarfHeizung();

</script>

<div class="overflow-x-auto mt-16">
    <table class="table-auto border-collapse border border-gray-300 w-full text-left">
      <thead>
        <tr class="bg-gray-200 text-left">
          <th colspan="12" class="border border-gray-300 p-2">
            <h2>Tabelle A.12 — Heizung – Berechnung des Nutzenergiebedarfs</h2>
          </th>
        </tr>  
        
          <tr class="bg-gray-200 text-left">
            <th colspan="12" class="border border-gray-300 p-2 text-xl">
              Heizbedarf des Wohngebäudes
            </th>
          </tr> 

          <tr class="text-center h-10">
          <th colspan="1" class="border border-gray-300 p-2">min. Außen-<br>temperatur<br>&#952;<sub>e,min</sub> [°C]</th>
          <th colspan="1" class="border border-gray-300 p-2">Innen-<br>temperatur<br>&#952;<sub>i,h,soll</sub> [°C]</th>
          <th colspan="2" class="border border-gray-300 p-2">maximaler Wärmestrom<br>Q̇<sub>ges</sub> [W]<br>aus Tabelle A.6 (1)</th>
          <th colspan="8" class="border border-gray-300 p-2"></th>
        </tr>
          
          <tr class="text-center h-10">
            <th colspan="1" class="border border-gray-300 p-2  bg-gray-100">{result.minimaleAussentemperatur}</th>
            <th colspan="1" class="border border-gray-300 p-2  bg-gray-100">{result.innenTemperatur}</th>
            <th colspan="2" class="border border-gray-300 p-2  bg-yellow-100">{Math.round(result.maximalerWaermestromGesamt)}</th>
            <th colspan="8" class="border border-gray-300 p-2"></th>
          </tr>
    
      <tr>
      <th class="border border-gray-300 px-2 py-1">Tage im Monat<br>d<sub>mth</sub> [d]</th>
       <th class="border border-gray-300 px-2 py-1">Bilanzinnen-<br>temperatur<br>&#952;<sub>i,h</sub> [°C]<br>aus Tabelle 8 (EFH) bzw. 10 (MFH)</th>
       <th class="border border-gray-300 px-2 py-1">mittlere Außen-<br>temp.<br>&#952;<sub>e,m</sub> [°C]</th>
       <th class="border border-gray-300 px-2 py-1">Mittlere Belastung<br>&#946;<sub>e,m</sub><br>aus Tabelle 9 bzw. 11 (2)</th>
       <th class="border border-gray-300 px-2 py-1">P<sub>h,sink</sub> = Q̇<sub>ges</sub> · (&#952;<sub>i,h</sub> - &#952;<sub>e,min</sub>) / (&#952;<sub>i,h,soll</sub> - &#952;<sub>e,min</sub>) · &#946;<sub>e,m</sub> [W] (3)</th>
       <th class="border border-gray-300 px-2 py-1">P<sub>h,source</sub> = P<sub>i,ges</sub><br>aus Tabelle A.11 (4)</th>
       <th class="border border-gray-300 px-2 py-1">&#947;<sub>m</sub> = P<sub>h,source</sub> / P<sub>h,sink</sub><br>(5) = (4) / (3)</th>
       <th class="border border-gray-300 px-2 py-1">&#951;<sub>m</sub> = f(γ) aus Tabelle 18<br>(6)</th>
       <th class="border border-gray-300 px-2 py-1">(7) = max[1 - (5) · (6);0]</th>
       <th class="border border-gray-300 px-2 py-1">&#946;<sub>m</sub><br>(8) = (2) · (7)</th>
       <th class="border border-gray-300 px-2 py-1">t<sub>h,m</sub> [h] (9)</th>
       <th class="border border-gray-300 px-2 py-1">Q<sub>h,b</sub> [kWh] (10)</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">31</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.bilanzInnenTemperaturen.Januar*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">1,0</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.belastungsgrade.Januar*1000)/1000}
        </td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermeSenken.Januar)}</td>
        <td class="border border-gray-300 px-2 py-1 bg-yellow-100">{Math.round(result.waermeQuellen.Januar)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermequellensenkenverhaeltnisJanuar*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.ausnutzungsgradJanuar*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.faktorBelastungJanuar*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.monatlicheBelastungJanuar*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.heizstundenJanuar)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.nutzenergieHeizungJanuar)}</td>
      </tr>
      <tr>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">28</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.bilanzInnenTemperaturen.Februar*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">1,9</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.belastungsgrade.Februar*1000)/1000}
        
        </td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermeSenken.Februar)}</td>
        <td class="border border-gray-300 px-2 py-1 bg-yellow-100">{Math.round(result.waermeQuellen.Februar)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermequellensenkenverhaeltnisFebruar*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.ausnutzungsgradFebruar*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.faktorBelastungFebruar*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.monatlicheBelastungFebruar*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.heizstundenFebruar)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.nutzenergieHeizungFebruar)}</td>
      </tr>
      <tr>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">31</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.bilanzInnenTemperaturen.März*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">4,7</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.belastungsgrade.März*1000)/1000}
         
        </td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermeSenken.März)}</td>
        <td class="border border-gray-300 px-2 py-1 bg-yellow-100">{Math.round(result.waermeQuellen.Maerz)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermequellensenkenverhaeltnisMärz*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.ausnutzungsgradMärz*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.faktorBelastungMärz*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.monatlicheBelastungMärz*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.heizstundenMärz)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.nutzenergieHeizungMärz)}</td>
      </tr>
      <tr>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">30</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.bilanzInnenTemperaturen.April*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">9,2</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.belastungsgrade.April*1000)/1000}
         
        </td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermeSenken.April)}</td>
        <td class="border border-gray-300 px-2 py-1 bg-yellow-100">{Math.round(result.waermeQuellen.April)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermequellensenkenverhaeltnisApril*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.ausnutzungsgradApril*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.faktorBelastungApril*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.monatlicheBelastungApril*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.heizstundenApril)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.nutzenergieHeizungApril)}</td>
      </tr>
      <tr>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">31</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.bilanzInnenTemperaturen.Mai*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">14,1</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.belastungsgrade.Mai*1000)/1000}
         
        </td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermeSenken.Mai)}</td>
        <td class="border border-gray-300 px-2 py-1 bg-yellow-100">{Math.round(result.waermeQuellen.Mai)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermequellensenkenverhaeltnisMai*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.ausnutzungsgradMai*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.faktorBelastungMai*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.monatlicheBelastungMai*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.heizstundenMai)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.nutzenergieHeizungMai)}</td>
      </tr>
      <tr>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">30</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.bilanzInnenTemperaturen.Juni*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">16,7</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.belastungsgrade.Juni*1000)/1000}
         
        </td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermeSenken.Juni)}</td>
        <td class="border border-gray-300 px-2 py-1 bg-yellow-100">{Math.round(result.waermeQuellen.Juni)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermequellensenkenverhaeltnisJuni*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.ausnutzungsgradJuni*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.faktorBelastungJuni*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.monatlicheBelastungJuni*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.heizstundenJuni)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.nutzenergieHeizungJuni)}</td>
      </tr>
      <tr>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">31</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.bilanzInnenTemperaturen.Juli*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">19,0</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.belastungsgrade.Juli*1000)/1000}
         
        </td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermeSenken.Juli)}</td>
        <td class="border border-gray-300 px-2 py-1 bg-yellow-100">{Math.round(result.waermeQuellen.Juli)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermequellensenkenverhaeltnisJuli*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.ausnutzungsgradJuli*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.faktorBelastungJuli*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.monatlicheBelastungJuli*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.heizstundenJuli)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.nutzenergieHeizungJuli)}</td>
      </tr>
      <tr>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">31</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.bilanzInnenTemperaturen.August*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">18,6</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.belastungsgrade.August*1000)/1000}
          
        </td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermeSenken.August)}</td>
        <td class="border border-gray-300 px-2 py-1 bg-yellow-100">{Math.round(result.waermeQuellen.August)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermequellensenkenverhaeltnisAugust*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.ausnutzungsgradAugust*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.faktorBelastungAugust*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.monatlicheBelastungAugust*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.heizstundenAugust)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.nutzenergieHeizungAugust)}</td>
      </tr>
      <tr>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">30</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.bilanzInnenTemperaturen.September*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">14,3</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.belastungsgrade.September*1000)/1000}
         
        </td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermeSenken.September)}</td>
        <td class="border border-gray-300 px-2 py-1 bg-yellow-100">{Math.round(result.waermeQuellen.September)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermequellensenkenverhaeltnisSeptember*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.ausnutzungsgradSeptember*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.faktorBelastungSeptember*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.monatlicheBelastungSeptember*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.heizstundenSeptember)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.nutzenergieHeizungSeptember)}</td>
      </tr>
      <tr>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">31</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.bilanzInnenTemperaturen.Oktober*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">9,4</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.belastungsgrade.Oktober*1000)/1000}
         
        </td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermeSenken.Oktober)}</td>
        <td class="border border-gray-300 px-2 py-1 bg-yellow-100">{Math.round(result.waermeQuellen.Oktober)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermequellensenkenverhaeltnisOktober*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.ausnutzungsgradOktober*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.faktorBelastungOktober*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.monatlicheBelastungOktober*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.heizstundenOktober)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.nutzenergieHeizungOktober)}</td>
      </tr>
      <tr>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">30</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.bilanzInnenTemperaturen.November*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">4,1</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.belastungsgrade.November*1000)/1000}
         
        </td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermeSenken.November)}</td>
        <td class="border border-gray-300 px-2 py-1 bg-yellow-100">{Math.round(result.waermeQuellen.November)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermequellensenkenverhaeltnisNovember*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.ausnutzungsgradNovember*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.faktorBelastungNovember*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.monatlicheBelastungNovember*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.heizstundenNovember)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.nutzenergieHeizungNovember)}</td>
      </tr>
      <tr>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">31</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.bilanzInnenTemperaturen.Dezember*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-gray-100">0,9</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.belastungsgrade.Dezember*1000)/1000}
         
        </td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermeSenken.Dezember)}</td>
        <td class="border border-gray-300 px-2 py-1 bg-yellow-100">{Math.round(result.waermeQuellen.Dezember)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.waermequellensenkenverhaeltnisDezember*1000)/1000}</td>
        <td class="border border-gray-300 px-2 py-1 bg-blue-100">{Math.round(result.ausnutzungsgradDezember*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.faktorBelastungDezember*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.monatlicheBelastungDezember*1000)/1000}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.heizstundenDezember)}</td>
        <td class="border-2 border-gray-600 px-2 py-1">{Math.round(result.nutzenergieHeizungDezember)}</td>
      </tr>
      <tr class="text-center h-10">
        <th colspan="9" class="border border-gray-300 p-2 text-left">Spalte 9:&nbsp;&nbsp;(8) &gt; 0,05 → (9) = d<sub>mth</sub> · 24 &nbsp;&nbsp;&nbsp;
          (8) &leq; 0,05 → (9) = (8) / 0,05 · d<sub>mth</sub> · 24</th>
        <th colspan="1" class="border border-gray-300 p-2">Summe</th> 
        <th colspan="1" class="border-2 border-gray-600 p-2">{Math.round(result.gesamtHeizstunden)}</th>
        <th colspan="1" class="border-2 border-gray-600 p-2">{Math.round(result.gesamtNutzenergieHeizung)}</th>
      </tr>
      <tr class="text-center h-10">
        <th colspan="10" class="border border-gray-300 p-2 text-left">Spalte 10:&nbsp;&nbsp;(10) = (3) · (7) · (9) / 1000</th>
        <th colspan="1" class="border border-gray-300 p-2"></th>
        <th colspan="1" class="border border-gray-300 p-2"></th>
      </tr>
    </tbody>
  </table>
</div>