import React, { useEffect, useState } from 'react'; import { propertiesAPI, equipmentAPI, mowingAPI } from '../../services/api'; import toast from 'react-hot-toast'; const directionOptions = [ { value: 'N_S', label: 'North to South' }, { value: 'E_W', label: 'East to West' }, { value: 'NE_SW', label: 'NE to SW' }, { value: 'NW_SE', label: 'NW to SE' }, { value: 'CIRCULAR', label: 'Circular' }, ]; const MowingPlanModal = ({ onClose, onCreated }) => { const [properties, setProperties] = useState([]); const [mowers, setMowers] = useState([]); const [sections, setSections] = useState([]); const [propertyId, setPropertyId] = useState(''); const [lawnSectionIds, setLawnSectionIds] = useState([]); const [equipmentId, setEquipmentId] = useState(''); const [plannedDate, setPlannedDate] = useState(new Date().toISOString().slice(0,10)); const [cutHeightInches, setCutHeightInches] = useState(3.0); const [direction, setDirection] = useState('N_S'); const [notes, setNotes] = useState(''); useEffect(() => { const load = async () => { try { const [props, eq] = await Promise.all([propertiesAPI.getAll(), equipmentAPI.getAll()]); setProperties(props.data.data.properties || []); const m = (eq.data.data.equipment || []).filter(e => (e.categoryName || '').toLowerCase().includes('mower')); setMowers(m); } catch (e) { toast.error('Failed to load data'); } }; load(); }, []); useEffect(() => { const loadSections = async () => { if (!propertyId) { setSections([]); return; } try { const r = await propertiesAPI.getById(propertyId); setSections(r.data.data.property.sections || []);} catch { setSections([]); } }; loadSections(); }, [propertyId]); const create = async () => { try { if (!propertyId || lawnSectionIds.length === 0 || !equipmentId) { toast.error('Missing fields'); return; } await mowingAPI.createPlan({ propertyId: Number(propertyId), lawnSectionIds: lawnSectionIds.map(Number), equipmentId: Number(equipmentId), plannedDate, cutHeightInches: Number(cutHeightInches), direction, notes }); toast.success('Mowing plan created'); onCreated?.(); onClose(); } catch (e) { toast.error(e.response?.data?.message || 'Failed to create plan'); } }; return (

New Mowing Plan

setPlannedDate(e.target.value)} className="w-full border rounded px-2 py-2" />
setCutHeightInches(e.target.value)} />