import React from "react";
import { NextPage, GetStaticProps } from "next";
import Head from "next/head";
import Event from "@models/Event";
import EventApi from "@api/eventApi";
import useFetchEvents from "@hooks/useFetchEvents";
import Post from "@models/Feed";
import FeedApi from "@api/feedApi";
import useFetchFeed from "@hooks/useFetchFeed";
import InEnglishPageView from "@views/InEnglishPage/InEnglishPageView";
import PageWrapper from "@views/common/PageWrapper";

const eventOptions = {
  onlyNonPast: true,
  limit: 4,
};

interface InitialProps {
  initialEvents: Event[];
  initialFeed: Post[];
}

const InEnglishPage: NextPage<InitialProps> = ({ initialEvents, initialFeed }) => {
  const eventResult = useFetchEvents({ initialData: initialEvents, options: eventOptions });
  const feedResult = useFetchFeed({ initialData: initialFeed });

  return (
    <>
      <Head>
        <link rel="canonical" href={`${process.env.NEXT_PUBLIC_SITE_URL}/in_english`} />
      </Head>
      <PageWrapper>
        <InEnglishPageView events={eventResult.data as Event[]} feed={feedResult.data} />
      </PageWrapper>
    </>
  );
};

export const getStaticProps: GetStaticProps<InitialProps> = async () => {
  const initialEvents = await EventApi.getEvents(eventOptions);
  const initialFeed = await FeedApi.getFeed();
  return {
    props: {
      initialEvents,
      initialFeed,
    },
    revalidate: 10,
  };
};

export default InEnglishPage;
