"use client"; import { useAuth } from "@/lib/auth-context"; import { DEPARTMENTS } from "@/lib/constants"; import { useShift } from "@/lib/shift-context"; import { useState } from "react"; import type { ShiftDetailModalProps } from "./ShiftSchedule.types"; export default function ShiftDetailModal({ shift, isOpen, onClose, }: ShiftDetailModalProps) { const { user } = useAuth(); const { registerShift, unregisterShift, deleteShift } = useShift(); const [error, setError] = useState(null); const [success, setSuccess] = useState(null); if (!isOpen || !shift) return null; // const dept = DEPARTMENTS.find((d) => d.id === shift.department); const isManager = user?.role === "manager"; const isRegistered = user ? shift.registeredStaff!.some((s) => s.id === user.id) : false; const isFull = shift.registeredStaff!.length >= shift.maxStaff; const handleRegister = () => { if (!user) return; setError(null); setSuccess(null); const result = registerShift(shift.id, user.id, user.name); if (result.success) { setSuccess("Đăng ký ca thành công!"); setTimeout(onClose, 1200); } else { setError(result.error ?? "Có lỗi xảy ra."); } }; const handleUnregister = () => { if (!user) return; setError(null); unregisterShift(shift.id, user.id); setSuccess("Đã hủy đăng ký ca."); setTimeout(onClose, 1200); }; const handleManagerUnregister = (staffId: string) => { unregisterShift(shift.id, staffId); setSuccess("Đã xóa nhân viên khỏi ca."); }; const handleDelete = () => { deleteShift(shift.id); onClose(); }; const statusLabel = { available: "Còn trống", registered: "Đã đăng ký", approved_leave: "Nghỉ phép", absent: "Vắng mặt", }; const statusColor = { available: "bg-blue-100 text-blue-700", registered: "bg-blue-200 text-blue-900", approved_leave: "bg-purple-100 text-purple-700", absent: "bg-red-100 text-red-700", }; return (
{/* Backdrop */}
{/* Modal */}
{/* Header */}
{/* {dept && } */}

Chi tiết ca làm

{/*

{dept?.name}

*/}
{/* Body */}
{/* Status badge */} {/*
{statusLabel[shift.status]}
*/} {/* Shift info grid */}

Ngày

{new Date(shift.date + "T00:00:00").toLocaleDateString( "vi-VN", { weekday: "long", day: "2-digit", month: "2-digit", year: "numeric", }, )}

Giờ làm

{shift.startTime} – {shift.endTime}

Thời lượng

{""} giờ

Lương ca

{shift.wage.toLocaleString("vi-VN")} VND

{/* Registered staff */}

Nhân viên đã đăng ký ({shift.registeredStaff!.length}/ {shift.maxStaff})

{shift.registeredStaff && shift.registeredStaff.length === 0 ? (

Chưa có ai đăng ký

) : (
{shift.registeredStaff!.map((staff) => (
{staff.staffId}
{isManager && ( )}
))}
)}
{/* Feedback messages */} {error && (
{error}
)} {success && (
{success}
)}
{/* Footer actions */}
{/* {!isRegistered && !isFull && shift.status !== "approved_leave" && shift.status !== "absent" && ( )} */} {isRegistered && ( )} {isManager && ( )}
); }