'use client';

import { useRouter } from 'next/navigation';
import { useState } from 'react';
import JobsView from '@/components/JobsView';
import { useJobs } from '@/contexts/JobsContext';
import { JobStatus } from '@/components/ScraperTest';

export default function JobsPage() {
  const router = useRouter();
  const { jobs, refreshJobs } = useJobs();
  const [isLoadingJob, setIsLoadingJob] = useState<string | null>(null);

  const handleSelectJob = async (job: JobStatus, previousJob?: JobStatus) => {
    // Navigate to analytics page for this job
    const url = previousJob
      ? `/analytics/${job.job_id}?compare=${previousJob.job_id}`
      : `/analytics/${job.job_id}`;
    router.push(url);
  };

  return (
    <JobsView
      jobs={jobs}
      onSelectJob={handleSelectJob}
      isLoadingJob={isLoadingJob}
      onRefresh={refreshJobs}
    />
  );
}
