import React from "react";
import { NextPage, GetStaticProps } from "next";
import Head from "next/head";
import useSWR from "swr";
import JobAd from "@models/JobAd";
import CorporatePageView from "@views/CorporatePage/CorporatePageView";
import PageWrapper from "@views/common/PageWrapper";
import { API, APIPath, fetcher } from "@api/backend";

interface InitialProps {
  initialJobAds: JobAd[];
}

const jobAdApi: API = {
  path: APIPath.JOBADS,
};

const CorporatePage: NextPage<InitialProps> = ({ initialJobAds }) => {
  const { data: jobAds } = useSWR<JobAd[]>(jobAdApi, fetcher, { fallbackData: initialJobAds });
  return (
    <>
      <Head>
        <link rel="canonical" href={`${process.env.NEXT_PUBLIC_SITE_URL}/yritysyhteistyo`} />
      </Head>
      <PageWrapper>
        <CorporatePageView jobAds={jobAds} />
      </PageWrapper>
    </>
  );
};

export const getStaticProps: GetStaticProps<InitialProps> = async () => {
  const initialJobAds = await fetcher<JobAd[]>(jobAdApi);
  return {
    props: {
      initialJobAds,
    },
    revalidate: 10,
  };
};

export default CorporatePage;
