"use client";

import type { ParcelAnalysis } from "@/types/site-finder";
import { SectionLabel } from "@/components/ui/SectionLabel";
import { EmptyState } from "@/components/ui/EmptyState";
import { GeologyBlock } from "./GeologyBlock";
import { GeometrySuitabilityBlock } from "./GeometrySuitabilityBlock";
import { GeotechRiskBlock } from "./GeotechRiskBlock";
import { NeighborsBlock } from "./NeighborsBlock";

interface Props {
  data: ParcelAnalysis;
}

export function LandTab({ data }: Props) {
  const hasAny =
    data.geotech_risk !== undefined ||
    data.geology !== undefined ||
    data.geometry_suitability !== undefined ||
    data.neighbors_summary !== undefined;

  return (
    <div style={{ display: "flex", flexDirection: "column", gap: 20 }}>
      {/* P2 (#46) — Соседи + overlap warning (hard warn если overlap) */}
      {data.neighbors_summary && (
        <NeighborsBlock data={data.neighbors_summary} />
      )}

      {/* P1 (#45) — Geometry suitability */}
      {data.geometry_suitability !== undefined && (
        <GeometrySuitabilityBlock data={data.geometry_suitability} />
      )}

      {/* Zoning note */}
      <div
        style={{
          background: "#f9fafb",
          border: "1px solid #e5e7eb",
          borderRadius: 10,
          padding: "14px 18px",
        }}
      >
        <SectionLabel style={{ marginBottom: 8 }}>
          Зонирование (ПЗЗ)
        </SectionLabel>
        <div style={{ fontSize: 13, color: "#6b7280" }}>
          Данные ПЗЗ доступны через{" "}
          <a
            href="https://pkk.rosreestr.ru/"
            target="_blank"
            rel="noopener noreferrer"
            style={{ color: "#1d4ed8", textDecoration: "none" }}
          >
            Публичную кадастровую карту
          </a>
          . API Росреестра закрыт в 2024 — используйте deep-link для кад. номера{" "}
          <strong style={{ color: "#374151" }}>{data.cad_num}</strong>.
        </div>
        <a
          href={`https://pkk.rosreestr.ru/#/search/${encodeURIComponent(data.cad_num)}`}
          target="_blank"
          rel="noopener noreferrer"
          style={{
            display: "inline-block",
            marginTop: 10,
            padding: "6px 14px",
            background: "#1d4ed8",
            color: "#fff",
            borderRadius: 6,
            fontSize: 13,
            fontWeight: 500,
            textDecoration: "none",
          }}
        >
          Открыть в ПКК
        </a>
      </div>

      {/* Geotech risk */}
      {data.geotech_risk !== undefined && (
        <div>
          <SectionLabel style={{ marginBottom: 12 }}>
            Геотехнический риск
          </SectionLabel>
          <GeotechRiskBlock risk={data.geotech_risk} />
        </div>
      )}

      {/* Geology */}
      {data.geology !== undefined && (
        <div>
          <SectionLabel style={{ marginBottom: 12 }}>Геология</SectionLabel>
          <GeologyBlock geology={data.geology} />
        </div>
      )}

      {!hasAny && <EmptyState message="Данные о земле и геологии недоступны" />}
    </div>
  );
}
