import React from "react"; import { ArrowLeft } from "lucide-react"; interface NotesStepProps { notesForm: { shippingDate: Date | null; scheduleDelivery: boolean; shippingPriority: "B" | "M" | "A"; notesText1: string; notesText2: string; notesDeliveryText1: string; notesDeliveryText2: string; notesDeliveryText3: string; }; onFormChange: (field: string, value: any) => void; onPrevious: () => void; } const NotesStep: React.FC = ({ notesForm, onFormChange, onPrevious, }) => { // Função para formatar a data para o input type="date" (YYYY-MM-DD) const formatDateForInput = (date: Date | null): string => { if (!date) return ""; try { // Verificar se é uma data válida if (isNaN(date.getTime())) { console.warn("📅 [NOTES_STEP] Data inválida:", date); return ""; } // Formatar para YYYY-MM-DD const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, "0"); const day = String(date.getDate()).padStart(2, "0"); return `${year}-${month}-${day}`; } catch (error) { console.error("📅 [NOTES_STEP] Erro ao formatar data:", error, date); return ""; } }; // Log para debug React.useEffect(() => { console.log( "📅 [NOTES_STEP] shippingDate recebido:", notesForm.shippingDate ); console.log("📅 [NOTES_STEP] Tipo:", typeof notesForm.shippingDate); if (notesForm.shippingDate) { console.log( "📅 [NOTES_STEP] Data formatada:", formatDateForInput(notesForm.shippingDate) ); } }, [notesForm.shippingDate]); return (

Observações

{ // Calcular data mínima (D+3) const today = new Date(); today.setHours(0, 0, 0, 0); const minDate = new Date(today); minDate.setDate(today.getDate() + 3); // Formatar para YYYY-MM-DD const year = minDate.getFullYear(); const month = String(minDate.getMonth() + 1).padStart(2, "0"); const day = String(minDate.getDate()).padStart(2, "0"); return `${year}-${month}-${day}`; })()} value={formatDateForInput(notesForm.shippingDate)} onChange={(e) => { const dateValue = e.target.value; console.log( "📅 [NOTES_STEP] Valor do input alterado:", dateValue ); if (dateValue) { // Criar data a partir do valor do input (YYYY-MM-DD) // Usar data local para corresponder exatamente ao que o usuário selecionou const [year, month, day] = dateValue.split("-").map(Number); const date = new Date(year, month - 1, day); // Zerar horas para garantir que seja apenas a data, sem hora date.setHours(0, 0, 0, 0); console.log( "📅 [NOTES_STEP] Nova data criada (local):", date ); console.log( "📅 [NOTES_STEP] Data formatada de volta:", formatDateForInput(date) ); onFormChange("shippingDate", date); } else { console.log("📅 [NOTES_STEP] Data removida (null)"); onFormChange("shippingDate", null); } }} className="w-full px-4 py-3 bg-slate-50 rounded-xl font-bold text-[#002147] border border-slate-200 focus:outline-none focus:ring-2 focus:ring-orange-500/20" />
onFormChange("notesText1", e.target.value)} className="w-full px-4 py-3 bg-slate-50 rounded-xl font-bold text-[#002147] border border-slate-200 focus:outline-none focus:ring-2 focus:ring-orange-500/20 mb-2" placeholder="Observação 1" /> onFormChange("notesText2", e.target.value)} className="w-full px-4 py-3 bg-slate-50 rounded-xl font-bold text-[#002147] border border-slate-200 focus:outline-none focus:ring-2 focus:ring-orange-500/20" placeholder="Observação 2" />
onFormChange("notesDeliveryText1", e.target.value)} className="w-full px-4 py-3 bg-slate-50 rounded-xl font-bold text-[#002147] border border-slate-200 focus:outline-none focus:ring-2 focus:ring-orange-500/20 mb-2" placeholder="Observação de entrega 1" /> onFormChange("notesDeliveryText2", e.target.value)} className="w-full px-4 py-3 bg-slate-50 rounded-xl font-bold text-[#002147] border border-slate-200 focus:outline-none focus:ring-2 focus:ring-orange-500/20 mb-2" placeholder="Observação de entrega 2" /> onFormChange("notesDeliveryText3", e.target.value)} className="w-full px-4 py-3 bg-slate-50 rounded-xl font-bold text-[#002147] border border-slate-200 focus:outline-none focus:ring-2 focus:ring-orange-500/20" placeholder="Observação de entrega 3" />
); }; export default NotesStep;