import { useJobs, useToggleJob, useTriggerJob } from '../../hooks/useAdmin';
import { SkeletonTable } from '../ui/Skeleton';
function formatNextRun(iso: string | null): string {
if (!iso) return '—';
const d = new Date(iso);
const now = new Date();
const diffMs = d.getTime() - now.getTime();
if (diffMs < 0) return 'imminent';
const mins = Math.round(diffMs / 60_000);
if (mins < 60) return `in ${mins}m`;
const hrs = Math.round(mins / 60);
return `in ${hrs}h`;
}
function formatAgo(iso: string | null | undefined): string {
if (!iso) return '';
const mins = Math.floor((Date.now() - new Date(iso).getTime()) / 60_000);
if (mins < 1) return 'just now';
if (mins < 60) return `${mins}m ago`;
const hrs = Math.floor(mins / 60);
if (hrs < 24) return `${hrs}h ago`;
return `${Math.floor(hrs / 24)}d ago`;
}
function lastRunColor(status: string | null | undefined): string {
if (status === 'error') return 'text-red-300';
if (status === 'rate_limited') return 'text-amber-300';
return 'text-gray-500';
}
export function JobControls() {
const { data: jobs, isLoading } = useJobs();
const toggleJob = useToggleJob();
const triggerJob = useTriggerJob();
const anyJobRunning = (jobs ?? []).some((job) => job.running);
const runningJob = jobs?.find((job) => job.running);
const pausedJob = jobs?.find((job) => !job.running && job.runtime_status === 'rate_limited');
const runningJobLabel = runningJob?.label;
if (isLoading) return