function ValuationCalc() {
  const [pre, setPre] = React.useState("");
  const [sh, setSh] = React.useState("");
  const [cap, setCap] = React.useState("");
  const p = parseNum(pre), s = parseNum(sh), c = parseNum(cap);
  const ok = p > 0 && s > 0 && c > 0;
  const r = React.useMemo(() => {
    if (!ok) return null;
    const post = p + c, price = p / s, ns = c / price, tot = s + ns, eo = s / tot, io = ns / tot;
    return { post, price, s, ns, tot, eo, io, ev: eo * post, iv: io * post };
  }, [p, s, c, ok]);
  return (
    <div className="cx-split">
      <Box title="Inputs" sub="Enter your round details. Results update as you type.">
        <NumIn id="pre" label="Pre-Money Valuation" pre="$" ph="7,000,000" value={pre} set={setPre} />
        <Cells cols={2}>
          <NumIn id="shares" label="Shares Outstanding" ph="1,000,000" value={sh} set={setSh} />
          <NumIn id="capital" label="Capital Raised" pre="$" ph="2,000,000" value={cap} set={setCap} />
        </Cells>
      </Box>
      <div className="cx-stick">
        <Box title="Results" right={<PdfButton ready={ok} />}>
          {!r ? <Empty>Enter all three values above to see the calculated results.</Empty> : <>
            <Cells cols={2}><Res hi label="Post-Money Valuation" value={fmtD(r.post)} /><Res hi label="Share Price" value={fmtD(r.price)} /></Cells>
            <Cells cols={3}><Res label="Existing Shares" value={fmtN(r.s)} /><Res label="New Shares Issued" value={fmtN(r.ns)} /><Res label="Total Shares" value={fmtN(r.tot)} /></Cells>
            <Cells cols={2}><Res label="Existing Ownership" value={fmtP(r.eo)} /><Res label="Investor Ownership" value={fmtP(r.io)} /></Cells>
            <Cells cols={2}><Res label="Existing Equity Value" value={fmtD(r.ev)} /><Res label="Investor Equity Value" value={fmtD(r.iv)} /></Cells>
            <Bar parts={[["Existing shareholders", r.eo, CX_COL[0]], ["New investors", r.io, CX_COL[1]]]} />
          </>}
        </Box>
      </div>
    </div>
  );
}

mountCalc(
  <CalcPage slug="valuation-calculator" title="Pre-Money & Post-Money" hl="Valuation Calculator"
    lead={<><strong>Pre-money valuation</strong> is what your company is worth before receiving new investment. <strong>Post-money valuation</strong> is the pre-money valuation plus the capital raised in the round. Together, they determine how much equity investors receive and what existing shareholders retain.</>}
    how={<>
      <h2>How the Calculation Works</h2>
      <p>The <strong>share price</strong> is determined by dividing the pre-money valuation by the number of shares outstanding before the round. This price applies to both existing shares and the new shares issued to investors.</p>
      <p>The number of <strong>new shares issued</strong> equals the capital raised divided by the share price. After the round closes, the total share count is the sum of existing shares and newly issued shares.</p>
      <p><strong>Ownership percentages</strong> are simply each party's shares divided by the total. Equity values are calculated by multiplying each ownership percentage by the post-money valuation.</p>
    </>}>
    <ValuationCalc />
  </CalcPage>
);
