import React, {useState} from 'react'; // A list of your seed packets to search and choose from, each with its photo // (what tells two packets of the same crop apart), what kind it is, and how many // seeds it has. `sownOn` is the day being sown, for saying a packet had expired. export default function SeedPacketList({packets, search, onSearch, selected, onChoose, sownOn}) { const expired = (packet) => Boolean(packet.plant_before) && packet.plant_before < sownOn; // Expired packets are left out unless asked for, or one of them is already chosen. const [includeExpired, setIncludeExpired] = useState(Boolean(selected && expired(selected))); const named = packets.filter((packet) => packet.name.toLowerCase().includes(search.trim().toLowerCase())); const matching = includeExpired ? named : named.filter((packet) => !expired(packet)); const hidden = named.length - matching.length; return (