import React from "react"; import { Clock, TimerOff } from "lucide-react"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; interface LastCheckedTimeProps { lastCheckedTime: string; status?: string; interval?: number; } export const LastCheckedTime = ({ lastCheckedTime, status, interval }: LastCheckedTimeProps) => { // Format the time without seconds to display a static time const formatTimeWithoutSeconds = (timeString: string) => { try { const date = new Date(timeString); // Check if it's a valid date if (isNaN(date.getTime())) { // If it's already in HH:MM format, just return it if (timeString.includes(':') && !timeString.includes(':00:')) { return timeString; } return timeString; } // Format to only show hours and minutes (HH:MM) return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); } catch (e) { return timeString; } }; // Get the formatted time without creating a new Date for paused services const formattedTime = formatTimeWithoutSeconds(lastCheckedTime); // Explicitly prevent real-time updates for paused services const isPaused = status === "paused"; // Format the interval for display const formatInterval = (seconds: number) => { if (seconds < 60) return `${seconds}s`; const minutes = Math.round(seconds / 60); return `${minutes}min`; }; return (
{isPaused ? ( ) : ( )} {isPaused ? "Paused at " : ""} {formattedTime}
{isPaused ? "Monitoring Paused" : "Last Check Details"}
{isPaused ? "No automatic checks" : `Checked at ${formattedTime}`}
{interval && !isPaused && (
Check interval: {formatInterval(interval)}
)}
{new Date(lastCheckedTime).toLocaleString()}
); };