import React from 'react';
import { format, differenceInMinutes, parseISO } from 'date-fns';
import { CheckCircle2, Circle, Clock, MapPin, AlertCircle } from 'lucide-react';
import { useTourStore } from './useTourStore.js';
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 (locationId: string) => {
// Gọi API PATCH /api/v1/locations/:id để cập nhật trạng thái
console.log("Toggle status for location:", locationId);
};
return (
Lộ trình chuyến đi
{legs.map((leg, legIdx) => (
{/* Leg Header */}
{/* Vertical Line for the whole leg */}
{leg.locations.map((location) => (
{/* Timeline Node */}
{/* Card Content */}
{location.name}
{location.address}
{location.plannedStart ? format(parseISO(location.plannedStart), 'HH:mm') : '--:--'}
{location.status === 'COMPLETED' && location.actualStart && (
Thực tế: {format(parseISO(location.actualStart), 'HH:mm')}
)}
{/* Logic tính toán độ lệch thời gian */}
))}
{leg.notes && (
* {leg.notes}
)}
))}
);
};