"use client";

/**
 * LegalStatus — bottom-grid «Legal Status» card. Renders ОКН / сервитуты /
 * красные линии / аренда / ЗОУИТ / ограничения оборота as Нет/значение rows from
 * `adaptLegalStatus`: REAL where /analyze provides it (ЗОУИТ count, красные
 * линии, gate blockers), honest «—» for the rest. "Подробнее" opens the legal
 * drawer.
 */

import styles from "@/app/site-finder/analysis/[cad]/ptica/ptica.module.css";
import type { ParcelAnalysis } from "@/types/site-finder";
import { adaptLegalStatus } 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 LegalStatus({ analysis, onOpenDrawer }: Props) {
  const { rows } = adaptLegalStatus(analysis);

  return (
    <div className={styles.card}>
      <div className={styles.cardHead}>
        <h3 className={styles.cardTitle}>Legal Status</h3>
        <button
          type="button"
          className={styles.detailBtn}
          onClick={() => onOpenDrawer("legal")}
          title="Открыть правовой статус"
        >
          Подробнее
        </button>
      </div>

      <div className={styles.legalGrid}>
        {rows.map((row) => (
          <div key={row.k} className={styles.legalCell}>
            <span className={styles.legalKey}>{row.k}</span>
            <span
              className={`${styles.legalValue} ${
                row.field.isReal ? "" : styles.legalValuePlaceholder
              }`}
              title={row.field.caption}
            >
              {row.field.value}
            </span>
          </div>
        ))}
      </div>
    </div>
  );
}
