import { useState } from 'react' import { ColorDot } from '@/components/plants/Monogram' import { Button, IconButton } from '@/components/ui/Button' import { cn } from '@/lib/cn' import type { FillLayout } from '@/lib/objects' import type { Plant } from '@/lib/plants' import type { EditorPlanting } from '@/lib/plantings' import { formatQuantity, type SeedLot } from '@/lib/seedLots' import { formatSize, formatSpacing, type UnitPref } from '@/lib/units' import { lotChoices, orderedPlants, toggleArmedKind, toggleArmedPlant } from './arming' import { KindSwatch } from './KindSwatch' import { OBJECT_KINDS } from './kinds' import { useEditorStore } from './store' import type { EditorObject } from './types' /** * The desktop editor's toolkit, the rail's first tab. Out of focus: the seven * object kinds as pill rows — click to arm (then click the plan), or drag one * straight onto it. In a focused bed it swaps to the plant list with a search, * same arm/drag behavior, plus the bed's bulk tools (fill, clear, scan a * packet). * * It started life as the workspace's left card (the handoff's layout) and * moved into the rail so the plan and the rail get the width the card took; * the rail's tab body provides the card chrome and the scrolling, and the tab * is the heading. */ export function Toolkit({ unit, plants, plantings, lotsByPlant, canEdit, focused, focusedPlopCount, canScan, filling, onBack, onFill, onClear, onScan, }: { unit: UnitPref plants: Plant[] plantings: EditorPlanting[] lotsByPlant: Map canEdit: boolean focused: EditorObject | null focusedPlopCount: number canScan: boolean filling: boolean onBack: () => void onFill: (layout: FillLayout) => void onClear: () => void onScan: () => void }) { const armedKind = useEditorStore((s) => s.armedKind) const armedPlant = useEditorStore((s) => s.armedPlant) const armedLotId = useEditorStore((s) => s.armedLotId) const setArmedLotId = useEditorStore((s) => s.setArmedLotId) const [query, setQuery] = useState('') return (
{!focused ? ( <> {OBJECT_KINDS.map((k) => { const armed = armedKind === k.kind return ( ) })}
{canEdit ? 'Drag a shape onto the plan. Double-click any bed to plant it.' : 'You can look but not change this garden.'}
) : ( <>
{focused.name}
{canEdit && focused.plantable ? ( <> setQuery(e.target.value)} /> {orderedPlants(plants, plantings, query).map((p) => { const armed = armedPlant?.id === p.id const choices = armed ? lotChoices(armedPlant, lotsByPlant) : [] return (
{choices.length > 0 && }
) })} {plants.length === 0 &&

No plants in the catalog yet.

}
{armedPlant && }
{focusedPlopCount > 0 && ( )} {canScan && ( )}
) : (

{!canEdit ? 'You can look but not change this garden.' : `${focused.name} isn't plantable — turn that on in the inspector's details.`}

)} )}
) } /** Which packet a planting comes out of, when a plant has more than one. */ export function LotChooser({ lots, value, onChange, compact = false, }: { lots: SeedLot[] value: number | null onChange: (lotId: number | null) => void compact?: boolean }) { return (
Which packet? {lots.map((lot) => ( ))}
) } /** Fill the whole bed with the armed plant — rows you could plant from, or * clumps for a quick sketch (#77). */ export function FillRow({ plant, busy, onFill }: { plant: Plant; busy: boolean; onFill: (layout: FillLayout) => void }) { return (
Fill the bed with {plant.name.toLowerCase()}: {busy && filling…}
) }