import React, { useEffect, useMemo, useState } from 'react'; import { mowingAPI } from '../../services/api'; import { PlayIcon, ArchiveBoxIcon, EyeIcon, MapPinIcon, WrenchScrewdriverIcon } from '@heroicons/react/24/outline'; import LoadingSpinner from '../../components/UI/LoadingSpinner'; import MowingPlanModal from '../../components/Mowing/MowingPlanModal'; import MowingExecutionModal from '../../components/Mowing/MowingExecutionModal'; import MowingSessionViewModal from '../../components/Mowing/MowingSessionViewModal'; import toast from 'react-hot-toast'; const Mowing = () => { const [plans, setPlans] = useState([]); const [loading, setLoading] = useState(true); const [showPlanModal, setShowPlanModal] = useState(false); const [execPlan, setExecPlan] = useState(null); const [viewSession, setViewSession] = useState(null); const [sessions, setSessions] = useState([]); const fetchPlans = async () => { try { setLoading(true); const r = await mowingAPI.getPlans(); setPlans(r.data.data.plans || []); // load recent sessions (not rendered as a list; used for View button) try { const s = await mowingAPI.getLogs(); setSessions(s.data?.data?.logs || []); } catch {} } catch (e) { toast.error('Failed to load mowing plans'); } finally { setLoading(false); } }; useEffect(() => { fetchPlans(); }, []); const filteredPlans = useMemo(() => { // Show all except archived by default, most recent first const list = (plans || []).filter(p => p.status !== 'archived'); return list.sort((a,b)=> new Date(b.planned_date) - new Date(a.planned_date)); }, [plans]); if (loading) return (
); return (

Mowing

{filteredPlans.length === 0 ? (
No mowing plans yet.
) : filteredPlans.map((p) => (

{p.property_name}

{p.status}

Areas: {p.section_names} ({Math.round(p.total_area || 0).toLocaleString()} sq ft)

{p.equipment_name || '—'} • Cut Height: {Number(p.cut_height_inches || 0).toFixed(2)}" • Direction: {p.direction || '—'}

{p.notes && (

"{p.notes}"

)}

{p.planned_date ? new Date(p.planned_date).toLocaleDateString() : 'No date'}

Last updated {new Date(p.updated_at || p.created_at).toLocaleDateString()}

{p.status === 'planned' && ( )} {p.status !== 'archived' && ( )}
))}
{showPlanModal && ( setShowPlanModal(false)} onCreated={fetchPlans} /> )} {execPlan && ( setExecPlan(null)} onComplete={fetchPlans} /> )} {/* Recent Sessions section removed as requested */} {viewSession && ( setViewSession(null)} /> )}
); }; export default Mowing;