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://51.20.250.24/jobs/itjobbank");
  if (!response.ok) {
    throw new Error("Failed to fetch jobs");
  }

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

export default async function ITJobbank() {
  const jobs = await fetchJobs();
  return (
    <>
      <h1 className="text-4xl my-4">IT Jobbank</h1>
      {jobs.map((job, i) => (
        <JobCard key={i} job={job} />
      ))}
    </>
  );
}
