import axios from "axios";
import Head from "next/head";
import CategorySelection from "@/components/index/categorySelection";
import React from "react";
import { customerApi } from "../api/api";

export default function Home({ metaData }) {
  return (
    <React.Fragment>
      <Head>
        <title>
          {metaData.meta_title
            ? metaData.meta_title
            : "Category List - " + process.env.NEXT_PUBLIC_COMPANY_NAME}
        </title>
        <meta charset="UTF-8" />
        <meta name="description" content={metaData.meta_description} />
        <meta
          name="keywords"
          content={
            metaData.meta_keywords && metaData.meta_keywords.length > 0
              ? metaData.meta_keywords.join(",")
              : ""
          }
        />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      </Head>
      <CategorySelection heading="Category" column={4} row={100} />
    </React.Fragment>
  );
}

export const getStaticProps = async (ctx) => {
  let metaData = {};
  await Promise.all([customerApi.get("/site/meta?path=/category-list")])
    .then((res) => {
      if (res[0] && res[0].data) metaData = res[0].data.data;
    })
    .catch((err) => {
      console.log("err:", err);
    });
  return {
    props: {
      metaData: metaData,
    },
    revalidate: 600,
  };
};
