"use client"; import { Card, CardContent, CardHeader, CardFooter } from "@/components/ui/card"; import { Calendar, ArrowRight, Layers } from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import type { Cropland } from "@/types"; // =================================================================== // Component Props: CropCard expects a cropland object and an optional click handler. // =================================================================== interface CropCardProps { crop: Cropland; // Crop data conforming to the Cropland type onClick?: () => void; } // =================================================================== // Component: CropCard // - Displays summary information about a crop, including status, // created date, and growth stage using an expressive card UI. // =================================================================== export function CropCard({ crop, onClick }: CropCardProps) { // --------------------------------------------------------------- // Status color mapping: Determines badge styling based on crop status. // Default colors provided for unknown statuses. // --------------------------------------------------------------- const statusColors: Record = { growing: { bg: "bg-green-50 dark:bg-green-900", text: "text-green-600 dark:text-green-300", border: "border-green-200", }, harvested: { bg: "bg-yellow-50 dark:bg-yellow-900", text: "text-yellow-600 dark:text-yellow-300", border: "border-yellow-200", }, planned: { bg: "bg-blue-50 dark:bg-blue-900", text: "text-blue-600 dark:text-blue-300", border: "border-blue-200", }, fallow: { bg: "bg-gray-50 dark:bg-gray-900", text: "text-gray-600 dark:text-gray-400", border: "border-gray-200", }, default: { bg: "bg-gray-100 dark:bg-gray-700", text: "text-gray-800 dark:text-gray-200", border: "border-gray-300", }, }; // --------------------------------------------------------------- // Derive styling based on crop status (ignoring case). // --------------------------------------------------------------- const statusKey = crop.status?.toLowerCase() || "default"; // Use camelCase status const statusColor = statusColors[statusKey] || statusColors.default; // --------------------------------------------------------------- // Format metadata for display: creation date and area. // --------------------------------------------------------------- const displayDate = crop.createdAt ? new Date(crop.createdAt).toLocaleDateString() : "N/A"; // Use camelCase createdAt const displayArea = typeof crop.landSize === "number" ? `${crop.landSize} ha` : "N/A"; // Use camelCase landSize // =================================================================== // Render: Crop information card with clickable behavior. // =================================================================== return (
{crop.status || "Unknown"}
{displayDate}
{/* ... icon ... */}

{crop.name}

{/* Use camelCase name */}

{crop.growthStage || "N/A"} • {displayArea} {/* Use camelCase growthStage */}

{crop.growthStage && (
{/* Use camelCase growthStage */} Stage: {crop.growthStage}
)}
); }