"use client";

/**
 * ScanCard — generic dark cockpit card: title (+ optional badge), metric rows,
 * and a "Подробнее" button that is RENDERED but disabled in INCREMENT 1 (drill-
 * down detail ships in a later release).
 *
 * Each row's value flows from a {value, isReal, caption} view-model: placeholder
 * fields are rendered muted with their caption so they never read as live data.
 */

import styles from "@/app/site-finder/analysis/[cad]/ptica/ptica.module.css";
import type { PticaScanCard } from "@/components/site-finder/ptica/ptica-adapt";

interface Props {
  card: PticaScanCard;
}

export function ScanCard({ card }: Props) {
  const { title, badge, rows, emptyState } = card;

  return (
    <div className={`${styles.card} ${styles.scanCard}`}>
      <h3 className={styles.cardTitle}>
        {title}
        {badge && <span className={styles.cardTitleSub}>{badge}</span>}
      </h3>

      {emptyState ? (
        <div className={styles.emptyState}>{emptyState}</div>
      ) : (
        rows.map((row) => {
          const placeholder = !row.field.isReal;
          return (
            <div
              key={row.key}
              className={`${styles.kvrow} ${
                placeholder ? styles.kvrowPlaceholder : ""
              }`}
            >
              <span className={styles.k}>{row.key}</span>
              <span className={styles.v} title={row.field.caption}>
                {row.field.value}
              </span>
            </div>
          );
        })
      )}

      <button
        type="button"
        className={styles.detailBtn}
        disabled
        aria-disabled="true"
        title="Детализация — в следующем релизе"
      >
        Подробнее
      </button>
    </div>
  );
}
