summaryrefslogtreecommitdiff
path: root/frontend/components/prism/ValuationCard.tsx
blob: 7329ff592c986f1e0f0fa472e1605f48f6d563db (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
"use client";
import type { ValuationResponse } from "@/types/api";
import { deltaClass, fmtCurrency, fmtLarge, fmtPct } from "@/lib/format";

type Props = { data: ValuationResponse };

function pctVsCurrent(implied?: number | null, current?: number | null): number | null {
  if (implied == null || current == null || current === 0) return null;
  return (implied - current) / current;
}

function SummaryChip({
  label,
  price,
  current,
  accent = false,
}: {
  label: string;
  price?: number | null;
  current?: number | null;
  accent?: boolean;
}) {
  const pct = pctVsCurrent(price, current);
  return (
    <div className={`psm-val-chip${accent ? " accent" : ""}`}>
      <span className="psm-val-chip-label">{label}</span>
      <span className="psm-val-chip-price">{price != null ? fmtCurrency(price) : "—"}</span>
      {pct != null && (
        <span className={`psm-val-chip-pct ${deltaClass(pct)}`}>{fmtPct(pct, 1, true)}</span>
      )}
    </div>
  );
}

function MultipleRow({
  label,
  multiple,
  price,
  current,
}: {
  label: string;
  multiple?: number | null;
  price?: number | null;
  current?: number | null;
}) {
  const pct = pctVsCurrent(price, current);
  return (
    <div className="psm-val-mult-row">
      <span className="psm-val-mult-label">{label}</span>
      <span className="psm-val-mult-x">{multiple != null ? `${multiple.toFixed(1)}×` : "—"}</span>
      <span className="psm-val-mult-price">{price != null ? fmtCurrency(price) : "—"}</span>
      <span className={`psm-val-mult-pct ${pct != null ? deltaClass(pct) : "neutral"}`}>
        {pct != null ? fmtPct(pct, 1, true) : "—"}
      </span>
    </div>
  );
}

export function ValuationCard({ data }: Props) {
  const { dcf, ev_ebitda, ev_revenue, price_to_book, current_price } = data;
  const dcfPrice = dcf.available && !dcf.error ? dcf.intrinsic_value_per_share : null;
  const hasMultiples = ev_ebitda.available || ev_revenue.available || price_to_book.available;

  return (
    <section className="psm-card psm-val-card">
      {/* Summary strip */}
      <div className="psm-val-strip">
        <div className="psm-val-chip accent">
          <span className="psm-val-chip-label">Market Price</span>
          <span className="psm-val-chip-price">
            {current_price != null ? fmtCurrency(current_price) : "—"}
          </span>
        </div>
        <SummaryChip label="DCF" price={dcfPrice} current={current_price} />
        <SummaryChip
          label="EV / EBITDA"
          price={ev_ebitda.available ? ev_ebitda.implied_price_per_share : null}
          current={current_price}
        />
        <SummaryChip
          label="EV / Revenue"
          price={ev_revenue.available ? ev_revenue.implied_price_per_share : null}
          current={current_price}
        />
        <SummaryChip
          label="P / Book"
          price={price_to_book.available ? price_to_book.implied_price_per_share : null}
          current={current_price}
        />
      </div>

      {/* DCF detail */}
      <div className="psm-val-section">
        <div className="psm-val-section-head">
          <span className="psm-eyebrow">Discounted Cash Flow</span>
          <span className="psm-val-wacc-note">
            WACC {(dcf.wacc * 100).toFixed(1)}% · Terminal {(dcf.terminal_growth * 100).toFixed(1)}%
          </span>
        </div>

        {!dcf.available && (
          <p className="psm-muted-copy">Insufficient free cash flow history for DCF.</p>
        )}
        {dcf.available && dcf.error && (
          <p className="psm-val-dcf-error">{dcf.error}</p>
        )}
        {dcf.available && !dcf.error && (
          <div className="psm-val-dcf-body">
            <div className="psm-val-kv-list">
              <div className="psm-val-kv-row">
                <span className="psm-val-kv-label">Base FCF (TTM)</span>
                <span className="psm-val-kv-val">{dcf.base_fcf != null ? fmtLarge(dcf.base_fcf) : "—"}</span>
              </div>
              <div className="psm-val-kv-row">
                <span className="psm-val-kv-label">Historical growth</span>
                <span className="psm-val-kv-val">
                  {dcf.growth_rate_used != null ? fmtPct(dcf.growth_rate_used) : "—"}
                </span>
              </div>
              <div className="psm-val-kv-row is-divider">
                <span className="psm-val-kv-label">Enterprise Value</span>
                <span className="psm-val-kv-val">
                  {dcf.enterprise_value != null ? fmtLarge(dcf.enterprise_value) : "—"}
                </span>
              </div>
              <div className="psm-val-kv-row">
                <span className="psm-val-kv-label">Net Debt</span>
                <span className="psm-val-kv-val">
                  {dcf.net_debt != null ? fmtLarge(dcf.net_debt) : "—"}
                </span>
              </div>
              <div className="psm-val-kv-row is-total">
                <span className="psm-val-kv-label">Equity Value</span>
                <span className="psm-val-kv-val">
                  {dcf.equity_value != null ? fmtLarge(dcf.equity_value) : "—"}
                </span>
              </div>
            </div>
            <div className="psm-val-intrinsic">
              <span className="psm-val-intrinsic-label">Intrinsic Value</span>
              <span className="psm-val-intrinsic-price">
                {dcf.intrinsic_value_per_share != null ? fmtCurrency(dcf.intrinsic_value_per_share) : "—"}
              </span>
              {data.shares_outstanding != null && (
                <span className="psm-val-intrinsic-shares">
                  {fmtLarge(data.shares_outstanding)} shares
                </span>
              )}
            </div>
          </div>
        )}
      </div>

      {/* Multiples */}
      {hasMultiples && (
        <div className="psm-val-section">
          <div className="psm-val-section-head">
            <span className="psm-eyebrow">Multiples — at current market multiple</span>
          </div>
          <div className="psm-val-mult-list">
            {ev_ebitda.available && (
              <MultipleRow
                label="EV / EBITDA"
                multiple={ev_ebitda.multiple_used}
                price={ev_ebitda.implied_price_per_share}
                current={current_price}
              />
            )}
            {ev_revenue.available && (
              <MultipleRow
                label="EV / Revenue"
                multiple={ev_revenue.multiple_used}
                price={ev_revenue.implied_price_per_share}
                current={current_price}
              />
            )}
            {price_to_book.available && (
              <MultipleRow
                label="P / Book"
                multiple={price_to_book.multiple_used}
                price={price_to_book.implied_price_per_share}
                current={current_price}
              />
            )}
          </div>
        </div>
      )}
    </section>
  );
}