'use client'; import { useState, useEffect } from 'react'; import SignOut from "@/app/components/sign-out"; import Link from "next/link"; import { fetchWithAuth } from '@/utils/api'; export default function Navbar() { const [versionInfo, setVersionInfo] = useState({ ab_version: 'Loading...', api_version: 'Loading...' }); const [uptime, setUptime] = useState('Loading...'); useEffect(() => { // Get the API URL const apiUrl = localStorage.getItem('apiUrl'); if (!apiUrl) return; // Fetch version information - no auth required fetch(`${apiUrl}/api/version`) .then(response => response.json()) .then(data => { setVersionInfo({ ab_version: data.ab_version, api_version: data.api_version }); }) .catch(error => { console.error('Failed to fetch version info:', error); setVersionInfo({ ab_version: 'Error', api_version: 'Error' }); }); // Fetch uptime information - no auth required fetch(`${apiUrl}/api/uptime`) .then(response => response.json()) .then(data => { // Convert milliseconds to a readable format const ms = data.uptime; const seconds = Math.floor(ms / 1000); const minutes = Math.floor(seconds / 60); const hours = Math.floor(minutes / 60); const days = Math.floor(hours / 24); let uptimeText = ''; if (days > 0) { uptimeText = `${days} day${days !== 1 ? 's' : ''}`; } else if (hours > 0) { uptimeText = `${hours} hour${hours !== 1 ? 's' : ''}`; } else if (minutes > 0) { uptimeText = `${minutes} minute${minutes !== 1 ? 's' : ''}`; } else { uptimeText = `${seconds} second${seconds !== 1 ? 's' : ''}`; } setUptime(uptimeText); }) .catch(error => { console.error('Failed to fetch uptime:', error); setUptime('Error'); }); }, []); return ( ); }