import { revalidatePath } from "next/cache";
import JobCard from "./_jobcard/JobCard";

interface JobPosting {
  title: string;
  logo: string;
  company: string;
  location: string;
  type: string;
  description: string;
  link: string;
  skills: {
    react: boolean;
    python: boolean;
    golang: boolean;
    svelte: boolean;
    nextjs: boolean;
    typescript: boolean;
    tailwind: boolean;
  };
}

async function fetchJobs(): Promise<JobPosting[]> {
  const response = await fetch("http://16.16.63.237/jobs/thehub", {
    cache: "no-store",
  });
  if (!response.ok) {
    throw new Error("Failed to fetch jobs");
  }

  revalidatePath("/");
  return response.json();
}

export default async function TheHub() {
  const jobs = await fetchJobs();
  return (
    <div className="transition ease-in-out transform -translate-y-1">
      <h1 className="text-4xl my-4">The Hub</h1>
      {jobs.map((job, i) => (
        <JobCard key={i} job={job} />
      ))}
    </div>
  );
}
