import React from 'react'; import { useDraggable } from '@dnd-kit/core'; import { CSS } from '@dnd-kit/utilities'; import { clsx } from 'clsx'; import { Clock, DollarSign } from 'lucide-react'; // Import from types.ts for consistency import type { AppointmentStatus } from '../../types'; export type { AppointmentStatus }; export interface DraggableEventProps { id: number; title: string; serviceName?: string; start: Date; end: Date; status?: AppointmentStatus; isPaid?: boolean; height: number; left: number; width: number; top: number; onResizeStart: (e: React.MouseEvent, direction: 'left' | 'right', id: number) => void; } export const DraggableEvent: React.FC = ({ id, title, serviceName, start, end, status = 'CONFIRMED', isPaid = false, height, left, width, top, onResizeStart, }) => { const { attributes, listeners, setNodeRef, transform, isDragging } = useDraggable({ id: `event-${id}`, data: { type: 'event', title, duration: (end.getTime() - start.getTime()) / 60000 }, }); const style: React.CSSProperties = { transform: CSS.Translate.toString(transform), left, width, top, height, position: 'absolute', zIndex: isDragging ? 50 : 10, }; // Status Logic matching legacy OwnerScheduler.tsx exactly const getStatusStyles = () => { const now = new Date(); // Legacy: if (status === 'COMPLETED' || status === 'NO_SHOW') if (status === 'COMPLETED' || status === 'NO_SHOW') { return { container: 'bg-gray-100 border-gray-400 text-gray-600 dark:bg-gray-800 dark:border-gray-600 dark:text-gray-400', accent: 'bg-gray-400' }; } // Legacy: if (status === 'CANCELLED') if (status === 'CANCELLED') { return { container: 'bg-gray-100 border-gray-400 text-gray-500 opacity-75 dark:bg-gray-800 dark:border-gray-600 dark:text-gray-400', accent: 'bg-gray-400' }; } // Legacy: if (now > endTime) (Overdue) if (now > end) { return { container: 'bg-red-100 border-red-500 text-red-900 dark:bg-red-900/50 dark:border-red-500 dark:text-red-200', accent: 'bg-red-500' }; } // Legacy: if (now >= startTime && now <= endTime) (In Progress) if (now >= start && now <= end) { return { container: 'bg-yellow-100 border-yellow-500 text-yellow-900 dark:bg-yellow-900/50 dark:border-yellow-500 dark:text-yellow-200', accent: 'bg-yellow-500 animate-pulse' }; } // Legacy: Default (Future) return { container: 'bg-blue-100 border-blue-500 text-blue-900 dark:bg-blue-900/50 dark:border-blue-500 dark:text-blue-200', accent: 'bg-blue-500' }; }; const styles = getStatusStyles(); return (
{/* Colored Status Strip */}
{/* Content */}
{title} {isPaid && ( )}
{serviceName && width > 100 && (
{serviceName}
)} {/* Time (only show if wide enough) */} {width > 60 && (
{start.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })}
)}
{/* Resize Handles */}
{ e.stopPropagation(); onResizeStart(e, 'left', id); }} />
{ e.stopPropagation(); onResizeStart(e, 'right', id); }} />
); };