import React from 'react';
import {formatDate} from '../dates';
import PlantedDate from './PlantedDate';
import PlantingChip from './PlantingChip';
// One annual planting as a row of two aligned columns: the crop, which is also
// the planting's menu (and when it was planted), and how it is getting on
// (badges, then a progress bar or a note when there is nothing to predict from).
// `handlers` is what the menu's items open (see selectPlantingAction).
export default function PlantingRow({planting, defaultIconUrl, highlighted, highlightKind = 'added', onUpdated, handlers}) {
const {badges} = planting;
return (
{highlighted && highlightKind === 'harvested' && (
Harvest recorded
)}
{badges.length > 0 && (
{badges.map((badge) => (
{badge.label}
))}
)}
{planting.progress_note ? (
{planting.progress_note}
) : (
)}
);
}
// The bar, with a tick at the date of each harvest, on the bar's own scale.
// The ticks are for the eye; the hidden sentence is for everything else.
function Progress({percentage, state, finishLabel, harvests = []}) {
if (percentage === null || percentage === undefined) return null;
const last = harvests[harvests.length - 1];
return (
{harvests.map((harvest, index) => (
))}
{last && (
{harvests.length} {harvests.length === 1 ? 'harvest' : 'harvests'}, the latest on {formatDate(last.date)}
)}
{Math.round(percentage)}%
{finishLabel && {finishLabel}}
);
}