'use client';

import JobsTable from '@/components/JobsTable';
import { TopBar, MainContent } from '@/components/layout';
import Link from 'next/link';
import { useAuth } from '@/contexts/AuthContext';
import HFLoginButton from '@/components/HFLoginButton';

export default function Dashboard() {
  const { status: authStatus } = useAuth();
  const isAuthenticated = authStatus === 'authenticated';

  return (
    <>
      <TopBar>
        <div>
          <h1 className="text-lg">Training Jobs</h1>
        </div>
        <div className="flex-1"></div>
        <div>
          {isAuthenticated ? (
            <Link href="/jobs/new" className="text-gray-200 bg-slate-600 px-3 py-1 rounded-md">
              New Training Job
            </Link>
          ) : (
            <span className="text-gray-600 bg-gray-900 px-3 py-1 rounded-md border border-gray-800">
              Sign in to create jobs
            </span>
          )}
        </div>
      </TopBar>
      <MainContent>
        {isAuthenticated ? (
          <JobsTable />
        ) : (
          <div className="border border-gray-800 rounded-lg p-6 bg-gray-900 text-gray-400 text-sm flex flex-col gap-4">
            <p>Sign in with Hugging Face or add a personal access token to view and manage training jobs.</p>
            <div className="flex items-center gap-3">
              <HFLoginButton size="sm" />
              <Link href="/settings" className="text-xs text-blue-400 hover:text-blue-300">
                Manage tokens in Settings
              </Link>
            </div>
          </div>
        )}
      </MainContent>
    </>
  );
}
