"use client"; import { X, ExternalLink, Clock, Zap, MapPin, Building2, Truck } from "lucide-react"; import type { ChargeFeature, EnrichedConnector, EnrichedLocation } from "@/types/charging"; import { formatConnectorStandard, formatPowerType, statusColorClass, statusLabel } from "@/lib/connectorLabels"; import UsageChart from "@/components/UsageChart"; const fmtPrice = (v: number) => v.toLocaleString("nl-NL", { style: "currency", currency: "EUR", minimumFractionDigits: 2, maximumFractionDigits: 3 }); // Prefer the price baked by the pipeline; fall back to a best-effort parse of the // raw tariff (for data generated before the price field existed). // Best-effort connector kW mirroring the pipeline: plausible declared power, // else derived from V×A (×3 for three-phase AC). Filters out garbage values // like 7,360,000 W on a 230 V/32 A AC post. function connectorKw(c: EnrichedConnector): number | null { const declared = c.max_electric_power ?? 0; if (declared > 0 && declared <= 1_500_000) return declared / 1000; const v = c.max_voltage ?? 0; const a = c.max_amperage ?? 0; if (v <= 0 || a <= 0) return null; const phases = (c.power_type ?? "").toUpperCase() === "AC_3_PHASE" ? 3 : 1; return (v * a * phases) / 1000; } const FREIGHT_REASON_LABEL: Record = { operator: "truck-exploitant", "truck-name": "“truck” in de naam", mcs: "MCS-aansluiting", "depot-name": "logistiek depot", motorway: "snelweglocatie ≥350 kW", power: "alleen op vermogen (≥350 kW DC)", curated: "handmatig toegevoegde hub", }; function connectorPriceKwh(c: EnrichedConnector): number | null { if (typeof c.priceKwh === "number") return c.priceKwh; for (const t of c.tariffs ?? []) { for (const el of t.elements ?? []) { const energy = el.price_components?.find((pc) => pc.type === "ENERGY"); if (energy && typeof energy.price === "number") return energy.price; } } return null; } interface Props { selected: ChargeFeature | null; detail: EnrichedLocation | null; loading: boolean; slug?: string; // gemeente slug for usage history (undefined / 'nederland' = no chart) onClose: () => void; onJumpToGemeente?: () => void; } export default function LocationDetailPanel({ selected, detail, loading, slug, onClose, onJumpToGemeente }: Props) { if (!selected) return null; const p = selected.properties; const isFreight = p.layer === "freight"; return (
{isFreight ? : } {isFreight ? (p.freightKind === "hpc" ? "Truck-capable" : "Truck") : "Personenauto"} {p.isMegawatt && ( Megawatt )}
{isFreight && p.freightReason && FREIGHT_REASON_LABEL[p.freightReason] && (
Classificatie: {FREIGHT_REASON_LABEL[p.freightReason]}
)}

{p.name}

{p.address && (
{p.address} {p.city ? `, ${p.city}` : ""}
)}
{/* Operator */}

Exploitant

{p.operatorName || "Onbekend"}
{detail?.operatorWebsite && ( {detail.operatorWebsite} )}
Bron: {p.source.toUpperCase()}
{/* Usage over time (gemeente view only; per-gemeente snapshot history) */} {slug && slug !== "nederland" && } {loading && (
Details laden…
)} {!loading && detail && ( <> {/* General */}

Gegevens

{detail.twentyFourSeven ? "Ja" : "Nee"} {detail.maxPowerKw > 0 && {detail.maxPowerKw} kW} {detail.parkingType && ( {detail.parkingType.replace(/_/g, " ")} )} {detail.ocpiId} {new Date(detail.lastUpdated).toLocaleString("nl-NL")}
{/* EVSEs */} {detail.evses.length > 0 && (

Laadpunten ({detail.evses.length})

{detail.evses.map((evse) => (
{evse.evse_id} {statusLabel(evse.status)}
{evse.connectors.length > 0 && (
{evse.connectors.map((c) => (
{formatConnectorStandard(c.standard)} {c.format}
{formatPowerType(c.power_type)} {(() => { const kw = connectorKw(c); return kw ? {kw.toFixed(1)} kW : null; })()}
{(() => { const price = connectorPriceKwh(c); if (price === null) return null; return (
Tarief: {fmtPrice(price)} / kWh {typeof c.priceVat === "number" ? ` (excl. ${c.priceVat}% btw)` : ""}
); })()}
))}
)}
))}
)} )} {!loading && !detail && (

Geen gedetailleerde informatie geladen voor deze locatie {p.maxPowerKw > 0 ? ` (max. ${p.maxPowerKw} kW).` : "."}

{onJumpToGemeente && ( )}
)}
); } function Row({ label, children }: { label: string; children: React.ReactNode }) { return (
{label}: {children}
); }