import React from 'react';
import { format, differenceInMinutes, parseISO } from 'date-fns';
import { CheckCircle2, Circle, Clock, MapPin, AlertCircle } from 'lucide-react';
import { useTourStore } from './useTourStore';
const TimeVariance = ({ planned, actual }: { planned: string, actual: string | null }) => {
if (!actual) return null;
const diff = differenceInMinutes(parseISO(actual), parseISO(planned));
const isLate = diff > 0;
return (
{isLate ?
:
}
{isLate ? `Trễ ${diff} phút` : diff === 0 ? 'Đúng giờ' : `Sớm ${Math.abs(diff)} phút`}
);
};
export const ItineraryTimeline = () => {
const { legs } = useTourStore();
const toggleComplete = async (placeId: number) => {
// Gọi API PATCH /api/v1/places/:id để cập nhật trạng thái
console.log("Toggle status for place:", placeId);
};
return (
Lộ trình chuyến đi
{legs.map((leg, legIdx) => (
{/* Leg Header */}
Chặng {leg.sequenceNumber}
{/* Vertical Line for the whole leg */}
{leg.places.map((place) => (
{/* Timeline Node */}
{/* Card Content */}
{place.name}
{place.address}
{format(parseISO(place.arrivalTime), 'HH:mm')}
{place.isCompleted && place.completedAt && (
Thực tế: {format(parseISO(place.completedAt), 'HH:mm')}
)}
{/* Logic tính toán độ lệch thời gian */}
))}
{leg.notes && (
* {leg.notes}
)}
))}
);
};