import React from "react"; import { Panel } from "../UI/Panel"; import { Button } from "../UI/Button"; import { Bell, Check, CheckCheck, Settings, X } from "../UI/Icons"; const TYPE_ICONS = { driver_assigned: "🚚", driver_unassigned: "📤", order_status_change: "📦", delivery_problem: "⚠️", }; const TYPE_LABELS = { driver_assigned: "Назначение водителя", driver_unassigned: "Снятие водителя", order_status_change: "Изменение статуса", delivery_problem: "Проблема доставки", }; function formatTimeAgo(dateStr) { const date = new Date(dateStr); const now = new Date(); const diffMs = now - date; const diffMin = Math.floor(diffMs / 60000); if (diffMin < 1) return "сейчас"; if (diffMin < 60) return `${diffMin} мин`; const diffH = Math.floor(diffMin / 60); if (diffH < 24) return `${diffH} ч`; const diffD = Math.floor(diffH / 24); return `${diffD} д`; } export function NotificationBell({ notifications, unreadCount, onMarkAsRead, onMarkAllAsRead, onOpenSettings }) { const [isOpen, setIsOpen] = React.useState(false); const bellRef = React.useRef(null); React.useEffect(() => { if (!isOpen) return; const handleClickOutside = (e) => { if (bellRef.current && !bellRef.current.contains(e.target)) { setIsOpen(false); } }; document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, [isOpen]); return (
{notif.title}
{formatTimeAgo(notif.created_at)}{notif.body}
)}