{% set y1ncf = d.annuals[0].ncf if d.annuals else 0 %}
{% set y3ncf = d.annuals[2].ncf if d.annuals | length >= 3 else 0 %}
{% set payback_label = t.payback_not_reached if d.paybackIdx < 0 else ('Month ' ~ (d.paybackIdx + 1)) %}
{% set payback_sub = '' if d.paybackIdx < 0 else ('~' ~ ((d.paybackIdx + 1) / 12) | round(1) ~ ' years') %}

<div class="grid-4 mb-4">
  <div class="metric-card">
    <div class="metric-card__label">{{ t.card_y1_ncf }}</div>
    <div class="metric-card__value {{ 'c-green' if y1ncf >= 0 else 'c-red' }}">{{ y1ncf | int | fmt_currency }}</div>
  </div>
  <div class="metric-card">
    <div class="metric-card__label">{{ t.card_y3_ncf }}</div>
    <div class="metric-card__value {{ 'c-green' if y3ncf >= 0 else 'c-red' }}">{{ y3ncf | int | fmt_currency }}</div>
    <div class="metric-card__sub">{{ t.sub_stabilized }}</div>
  </div>
  <div class="metric-card">
    <div class="metric-card__label">{{ t.card_payback }} <span class="ti">i<span class="tp">{{ t.tip_result_payback }}</span></span></div>
    <div class="metric-card__value c-head">{{ payback_label }}</div>
    <div class="metric-card__sub">{{ payback_sub }}</div>
  </div>
  <div class="metric-card">
    <div class="metric-card__label">{{ t.card_initial_inv }}</div>
    <div class="metric-card__value c-red">{{ d.capex | fmt_currency }}</div>
  </div>
</div>

<div class="chart-container mb-4">
  <div class="chart-container__label">{{ t.planner_chart_cf }}</div>
  <div class="chart-h-56 chart-container__canvas"><canvas id="chartCF"></canvas></div>
</div>
<script type="application/json" id="chartCF-data">{{ d.cf_chart | tojson }}</script>

<div class="chart-container mb-4">
  <div class="chart-container__label">{{ t.planner_chart_cum }}</div>
  <div class="chart-h-48 chart-container__canvas"><canvas id="chartCum"></canvas></div>
</div>
<script type="application/json" id="chartCum-data">{{ d.cum_chart | tojson }}</script>

<div class="mb-section">
  <div class="section-header"><h3>{{ t.planner_section_annual }}</h3></div>
  <table class="data-table">
    <thead>
      <tr>
        <th>{{ t.th_year }}</th>
        <th class="right">{{ t.th_revenue }}</th>
        <th class="right">{{ t.th_ebitda }}</th>
        <th class="right">{{ t.th_debt_service }}</th>
        <th class="right">{{ t.th_net_cf }}</th>
        <th class="right">{{ t.th_dscr }}</th>
        <th class="right">{{ t.th_util }}</th>
      </tr>
    </thead>
    <tbody>
      {% for y in d.annuals %}
      {% set dscr = (y.ebitda / y.ds) if y.ds > 0 else 999 %}
      {% set util = ((y.booked / y.avail * 100) | int) if y.avail > 0 else 0 %}
      <tr>
        <td><b>Year {{ y.year }}</b></td>
        <td class="mono c-green">{{ y.revenue | int | fmt_currency }}</td>
        <td class="mono {{ 'c-green' if y.ebitda >= 0 else 'c-red' }}">{{ y.ebitda | int | fmt_currency }}</td>
        <td class="mono c-red">{{ y.ds | int | fmt_currency }}</td>
        <td class="mono" style="font-weight:700;{{ 'color:var(--gn)' if y.ncf >= 0 else 'color:var(--rd)' }}">{{ y.ncf | int | fmt_currency }}</td>
        <td class="mono">{{ '∞' if dscr > 99 else dscr | fmt_x }}</td>
        <td class="mono">{{ util }}%</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
</div>
