import React, { useState } from 'react'; import { Plant, Language } from '../types'; import { Droplets, Sun, Thermometer, ArrowLeft, Calendar, Trash2, Share2, Edit2, AlertCircle, Check, Clock, Bell, BellOff } from 'lucide-react'; interface PlantDetailProps { plant: Plant; onClose: () => void; onDelete: (id: string) => void; onUpdate: (plant: Plant) => void; t: any; language: Language; } export const PlantDetail: React.FC = ({ plant, onClose, onDelete, onUpdate, t, language }) => { const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); // Map internal language codes to locale strings for Date const localeMap: Record = { de: 'de-DE', en: 'en-US', es: 'es-ES' }; const formattedAddedDate = new Date(plant.dateAdded).toLocaleDateString(localeMap[language] || 'de-DE'); const formattedWateredDate = new Date(plant.lastWatered).toLocaleDateString(localeMap[language] || 'de-DE'); // Calculate next watering date const lastWateredObj = new Date(plant.lastWatered); const nextWateringDate = new Date(lastWateredObj); nextWateringDate.setDate(lastWateredObj.getDate() + plant.careInfo.waterIntervalDays); const formattedNextWatering = nextWateringDate.toLocaleDateString(localeMap[language] || 'de-DE', { weekday: 'long', day: 'numeric', month: 'numeric' }); const nextWateringText = t.nextWatering.replace('{0}', formattedNextWatering); const lastWateredText = t.lastWateredDate.replace('{0}', formattedWateredDate); // Check if watered today const isWateredToday = new Date(plant.lastWatered).toDateString() === new Date().toDateString(); const handleWaterPlant = () => { const now = new Date().toISOString(); // Update history: add new date to the beginning, keep last 10 entries max const currentHistory = plant.wateringHistory || []; const newHistory = [now, ...currentHistory].slice(0, 10); const updatedPlant = { ...plant, lastWatered: now, wateringHistory: newHistory }; onUpdate(updatedPlant); }; const toggleReminder = async () => { const newValue = !plant.notificationsEnabled; if (newValue) { // Request permission if enabling if (!('Notification' in window)) { alert("Notifications are not supported by this browser."); return; } if (Notification.permission === 'granted') { onUpdate({ ...plant, notificationsEnabled: true }); } else if (Notification.permission !== 'denied') { const permission = await Notification.requestPermission(); if (permission === 'granted') { onUpdate({ ...plant, notificationsEnabled: true }); } } else { alert(t.reminderPermissionNeeded); } } else { // Disabling onUpdate({ ...plant, notificationsEnabled: false }); } }; const handleDeleteClick = () => { setShowDeleteConfirm(true); }; const handleConfirmDelete = () => { onDelete(plant.id); }; const handleCancelDelete = () => { setShowDeleteConfirm(false); }; return (
{/* Header */}
{/* Hero Image */}
{plant.name}

{plant.name}

{plant.botanicalName}

{/* Content Container */}
{/* Added Date Info */}
{t.addedOn} {formattedAddedDate}
{/* Main Action: Water */}
{lastWateredText} {nextWateringText}
{/* Reminder Toggle */}
{plant.notificationsEnabled ? : }
{t.reminder} {plant.notificationsEnabled ? t.reminderOn : t.reminderOff}

{t.aboutPlant}

{plant.description || t.noDescription}

{/* Care Info */}

{t.careTips}

{t.water} {plant.careInfo.waterIntervalDays} {t.days || 'Tage'}
{t.light} {plant.careInfo.light}
{t.temp} {plant.careInfo.temp}
{/* Watering History Section */}

{t.wateringHistory}

{(!plant.wateringHistory || plant.wateringHistory.length === 0) ? (
{t.noHistory}
) : (
    {plant.wateringHistory.slice(0, 5).map((dateStr, index) => (
  • {new Date(dateStr).toLocaleDateString(localeMap[language] || 'de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' })}
    {new Date(dateStr).toLocaleTimeString(localeMap[language] || 'de-DE', { hour: '2-digit', minute: '2-digit' })}
  • ))}
)}
{/* Danger Zone */}
{/* Delete Confirmation Modal */} {showDeleteConfirm && (

{t.deleteConfirmTitle}

{t.deleteConfirmMessage}

)}
); };