File size: 3,041 Bytes
c993983
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/** HeatPumpTable β€” shows available/excluded heat pumps with comparison data. */

import { useState } from 'react';
import { useAnalysisStore } from '../../store/analysisStore';

export default function HeatPumpTable() {
  const hpiResult = useAnalysisStore((s) => s.hpiResult);
  const [isExcludedOpen, setIsExcludedOpen] = useState(false);

  if (!hpiResult) return null;

  const available = hpiResult.heat_pumps.filter((hp) => hp.available);
  const excluded = hpiResult.excluded_heat_pumps;

  if (available.length === 0 && excluded.length === 0) return null;

  return (
    <div className="pa-hp-table-wrap">
      {/* ── Available heat pumps ── */}
      {available.length > 0 && (
        <>
          <p className="pa-hp-section-label"> Integrable heat pumps</p>
          <table className="pa-table pa-hp-table">
            <thead>
              <tr>
                <th>Heat Pump</th>
                <th>COP</th>
                <th>T_source (Β°C)</th>
                <th>T_sink (Β°C)</th>
                <th>Q_source (kW)</th>
                <th>Q_sink (kW)</th>
              </tr>
            </thead>
            <tbody>
              {available
                .sort((a, b) => (b.cop ?? 0) - (a.cop ?? 0))
                .map((hp) => (
                  <tr key={hp.name}>
                    <td>{hp.name}</td>
                    <td>{hp.cop?.toFixed(2) ?? 'β€”'}</td>
                    <td>{hp.t_source?.toFixed(1) ?? 'β€”'}</td>
                    <td>{hp.t_sink?.toFixed(1) ?? 'β€”'}</td>
                    <td>{hp.q_source?.toFixed(1) ?? 'β€”'}</td>
                    <td>{hp.q_sink?.toFixed(1) ?? 'β€”'}</td>
                  </tr>
                ))}
            </tbody>
          </table>
        </>
      )}

      {/* ── Excluded heat pumps β€” collapsible, closed by default ── */}
      {excluded.length > 0 && (
        <div className="pa-excluded-hp">
          <p
            className="pa-hp-section-label pa-panel-toggle"
            onClick={() => setIsExcludedOpen(!isExcludedOpen)}
            style={{ cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}
          >
            <span> Heat pumps that cannot be integrated</span>
            <span style={{ transform: isExcludedOpen ? 'rotate(0deg)' : 'rotate(-90deg)', transition: 'transform 0.2s' }}>β–Ό</span>
          </p>

          {isExcludedOpen && (
            <div className="pa-excluded-list">
              {excluded.map((hp) => (
                <div key={hp.name} className="pa-excluded-card">
                  <div className="pa-excluded-card-header">
                    <span className="pa-excluded-name">{hp.name}</span>
                    <span className="pa-excluded-badge">Cannot be integrated</span>
                  </div>
                  <div className="pa-excluded-reason">
                    {hp.reason}
                  </div>
                </div>
              ))}
            </div>
          )}
        </div>
      )}
    </div>
  );
}