"use client";

/**
 * DevelopmentScan — "Development Scan" section: a 7-card grid of ScanCards
 * (Градостроительство / Ограничения / Инженерия / Рынок / Экономика / Риски /
 * Среда), matching the prototype scan-grid. ОКС and Инсоляция live in the
 * lower-grid (PticaLowerGrid). Every card's real-vs-placeholder content comes
 * from the adapter.
 *
 * Each card maps to its drawer key and opens the matching detail drawer via the
 * `onOpenDrawer` callback threaded down from PticaPageContent.
 */

import styles from "@/app/site-finder/analysis/[cad]/ptica/ptica.module.css";
import type { ParcelAnalysis } from "@/types/site-finder";
import { ScanCard } from "@/components/site-finder/ptica/ScanCard";
import { BuildabilityGauge } from "@/components/site-finder/ptica/BuildabilityGauge";
import {
  adaptUrbanCard,
  adaptRestrictionsCard,
  adaptEngineeringCard,
  adaptMarketCard,
  adaptEconomyCard,
  adaptEnvironmentCard,
  adaptRiskGauge,
} from "@/components/site-finder/ptica/ptica-adapt";
import type { DrawerKey } from "@/components/site-finder/ptica/drawers/drawer-keys";

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

export function DevelopmentScan({ analysis, onOpenDrawer }: Props) {
  const riskGauge = adaptRiskGauge(analysis);

  return (
    <>
      <div className={styles.sectionLabel}>
        Development Scan · <b>градостроительный анализ</b>
      </div>
      <section className={styles.scanGrid}>
        <ScanCard
          card={adaptUrbanCard(analysis)}
          drawerKey="urban"
          onOpen={onOpenDrawer}
        />
        <ScanCard
          card={adaptRestrictionsCard(analysis)}
          drawerKey="restrictions"
          onOpen={onOpenDrawer}
        />
        <ScanCard
          card={adaptEngineeringCard(analysis)}
          drawerKey="engineering"
          onOpen={onOpenDrawer}
        />
        <ScanCard
          card={adaptMarketCard(analysis)}
          drawerKey="market"
          onOpen={onOpenDrawer}
        />
        <ScanCard
          card={adaptEconomyCard(analysis.financial_estimate)}
          drawerKey="economy"
          onOpen={onOpenDrawer}
        />

        <div
          id="ptica-risks"
          className={`${styles.card} ${styles.scanCard} ${styles.scanCardCentered}`}
        >
          <h3 className={styles.cardTitle}>Риски</h3>
          <BuildabilityGauge gauge={riskGauge} title="Сводный риск" />
          <button
            type="button"
            className={`${styles.detailBtn} ${styles.detailBtnScan}`}
            onClick={() => onOpenDrawer("risks")}
            title="Открыть детализацию"
          >
            Подробнее
          </button>
        </div>

        <ScanCard
          card={adaptEnvironmentCard(analysis)}
          drawerKey="environment"
          onOpen={onOpenDrawer}
        />
        {/* ОКС and Инсоляция · 3D-масса live in the lower-grid (PticaLowerGrid)
            per the prototype, keeping the scan at 7 cards. */}
      </section>
    </>
  );
}
