import { useEffect, useRef } from 'react';
import { UserIcon, PhoneIcon, PlusIcon } from '@heroicons/react/24/outline';
import type { Appointment } from '../../types';
import AppointmentStatusDropdown from '../ui/AppointmentStatusDropdown';
import AppointmentActionsMenu from '../AppointmentActions';
import { turnStatusConfig, EMPTY_SLOT_CONFIG } from './turnStatus';
import type { TimelineSlot } from './types';
/**
* نمای زمانبندی (زمانبندی) — بازسازیِ `Timeline.jsx` طرح tauri: هر ردیف شامل یک
* «ریل مارکر» (نقطهٔ رنگی + ساعت شروع + خطچین اتصال) در راست و یک «کارت نوبت» در
* چپ است (RTL، row-reverse). اسلات خالی → «افزودن نوبت». اسکرول خودکار به اولین
* نوبتِ فعالِ امروز. رنگها عیناً از طرح مبدأ.
*/
// نقطهٔ رنگی + خطچین عمودی (ریل مارکر سمت راست).
function Marker({ color, time, showLine }: { color: string; time: string; showLine: boolean }) {
return (
);
}
function EmptyCard({ slot, onBook }: { slot: TimelineSlot; onBook: (s: TimelineSlot) => void }) {
const cfg = EMPTY_SLOT_CONFIG;
const isPast = slot.start < Math.floor(Date.now() / 1000);
return (
!isPast && onBook(slot)}
style={{
minHeight: 64, borderRadius: 8, padding: '12px 10px',
border: `1px dashed ${isPast ? 'var(--border-2)' : cfg.borderColor}`,
background: isPast ? 'var(--surface-2)' : cfg.bgColor,
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8,
cursor: isPast ? 'not-allowed' : 'pointer', opacity: isPast ? 0.7 : 1,
}}
>
{isPast ? 'گذشته' : 'افزودن نوبت'}
{!isPast &&
}
);
}
function OccupiedCard({
appointment: a, slot, queryKey, onView,
}: {
appointment: Appointment; slot: TimelineSlot; queryKey: unknown[]; onView: (a: Appointment) => void;
}) {
const cfg = turnStatusConfig(a.status);
return (
onView(a)}
style={{
background: cfg.bgColor, border: `1px solid ${cfg.borderColor}`, borderRadius: 8,
padding: '12px 10px', display: 'flex', alignItems: 'center', justifyContent: 'space-between',
gap: 10, cursor: 'pointer', minHeight: 64,
}}
>
{/* اطلاعات بیمار */}
{a.patient_name || '—'}
سرویس: {a.service_item?.name || '—'}
{/* وضعیت + عملیات (کلیک روی این ناحیه نباید کارت را باز کند) */}
e.stopPropagation()} style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-end', gap: 8, flexShrink: 0 }}>
);
}
export default function TurnsTimeline({
slots, loading, queryKey, onView, onBook,
}: {
slots: TimelineSlot[];
loading: boolean;
queryKey: unknown[];
onView: (a: Appointment) => void;
onBook: (s: TimelineSlot) => void;
}) {
const activeRef = useRef(null);
const now = Math.floor(Date.now() / 1000);
// اولین نوبتِ فعالِ آینده برای اسکرول خودکار.
const activeIndex = slots.findIndex(s => s.appointment && s.end >= now);
useEffect(() => {
if (!activeRef.current) return;
const el = activeRef.current;
const top = el.getBoundingClientRect().top + window.scrollY - window.innerHeight * 0.4;
window.scrollTo({ top: Math.max(0, top), behavior: 'smooth' });
}, [activeIndex]);
if (loading) return در حال بارگذاری...
;
if (!slots.length) return (
این روز تعطیل است
هیچ برنامه زمانبندی برای این روز تنظیم نشده است
);
return (
{slots.map((slot, i) => {
const color = slot.appointment ? turnStatusConfig(slot.appointment.status).dotColor : EMPTY_SLOT_CONFIG.dotColor;
return (
);
})}
);
}