"use client";

/**
 * InvestmentClearance — bottom-grid «Investment Clearance» card. When the backend
 * supplies `analysis.financial_estimate` (#1881) the bignums (GDV / Cost / Profit /
 * ROI / IRR / NPV / срок окуп.) carry REAL numbers по макс. застройке НСПД; the
 * caption stays honest that it's ориентировочно. Otherwise every value is an
 * honest «—» placeholder with a «после финмодели (§23)» caption — NO fabricated
 * numbers. "Подробнее" opens the finance drawer.
 */

import styles from "@/app/site-finder/analysis/[cad]/ptica/ptica.module.css";
import { adaptInvestmentClearance } from "@/components/site-finder/ptica/ptica-adapt";
import type { ParcelAnalysis } from "@/types/site-finder";
import type { DrawerKey } from "@/components/site-finder/ptica/drawers/drawer-keys";

interface Props {
  analysis?: ParcelAnalysis;
  onOpenDrawer: (key: DrawerKey) => void;
}

export function InvestmentClearance({ analysis, onOpenDrawer }: Props) {
  const { bignums, caption } = adaptInvestmentClearance(
    analysis?.financial_estimate,
  );

  return (
    <div className={styles.card}>
      <div className={styles.cardHead}>
        <h3 className={styles.cardTitle}>
          Investment Clearance
          <span className={styles.cardTitleSub}>финансовая модель</span>
        </h3>
        <button
          type="button"
          className={styles.detailBtn}
          onClick={() => onOpenDrawer("finance")}
          title="Открыть финансовую модель"
        >
          Подробнее
        </button>
      </div>

      <div className={styles.bignumRow}>
        {bignums.map((b) => (
          <div key={b.label} className={styles.bignum}>
            <div className={styles.bignumLabel}>{b.label}</div>
            <div
              className={`${styles.bignumValue} ${
                b.isReal ? "" : styles.bignumValuePlaceholder
              }`}
              title={b.caption}
            >
              {b.value}
            </div>
            {b.unit && <span className={styles.bignumUnit}>{b.unit}</span>}
          </div>
        ))}
      </div>

      <p className={styles.bignumCaption}>{caption}</p>
    </div>
  );
}
