import React, { useState } from 'react'; interface CycleCreateModalProps { isOpen: boolean; onClose: () => void; onSave: (startDate: Date, docInCount?: number, chickInWeight?: number) => void; } const CycleCreateModal: React.FC = ({ isOpen, onClose, onSave }) => { const [startDate, setStartDate] = useState(new Date().toISOString().split('T')[0] ?? ''); const [docInCount, setDocInCount] = useState('20000'); const [chickInWeight, setChickInWeight] = useState(''); const [error, setError] = useState(''); const generatedId = `CYCLE-JBW-${startDate}`; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); const start = new Date(startDate); const docCount = docInCount ? parseInt(docInCount, 10) : undefined; const weight = chickInWeight ? parseInt(chickInWeight, 10) : undefined; if (isNaN(start.getTime())) { setError('Tanggal mulai tidak valid'); return; } if (docInCount && (isNaN(docCount!) || docCount! <= 0)) { setError('Jumlah DOC harus berupa angka positif'); return; } if (chickInWeight && (isNaN(weight!) || weight! <= 0)) { setError('Berat DOC harus berupa angka positif'); return; } onSave(start, docCount, weight); onClose(); }; if (!isOpen) return null; return (
e.stopPropagation()} >

Siklus Produksi Baru

{error &&

{error}

}

ID Siklus (otomatis)

{generatedId}

{ setStartDate(e.target.value); setError(''); }} className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-red-500 focus:border-red-500" required />
{ setDocInCount(e.target.value); setError(''); }} placeholder="Contoh: 20000" className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-red-500 focus:border-red-500" />
{ setChickInWeight(e.target.value); setError(''); }} placeholder="Contoh: 40" className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-red-500 focus:border-red-500" />
Durasi siklus: 42 hari (standar broiler). Siklus aktif sebelumnya akan otomatis ditandai selesai.
); }; export default CycleCreateModal;