import axios from "axios";
import Head from "next/head";
import React from "react";
import ReactHtmlParser from "react-html-parser";
import { customerApi } from "@/api/api";
import FadeInContainer from "@/components/utils/animation/fadeInContainer";
export default function Home({ metaData, siteText }) {
  return (
    <>
      <Head>
        <title>
          {metaData.meta_title
            ? metaData.meta_title
            : "Shipping Policy - " + 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>
      <FadeInContainer loadVisibile={true}>
        <div className="page_section">
          {siteText.shipping_policy_page && (
            <h1 className="my-3 primary-heading">
              {siteText.shipping_policy_page.title}
            </h1>
          )}
          {siteText.shipping_policy_page &&
            siteText.shipping_policy_page.content &&
            siteText.shipping_policy_page.content.length > 0 && (
              <div className="my-3  ql-editor">
                {ReactHtmlParser(siteText.shipping_policy_page.content[0])}
              </div>
            )}
        </div>
      </FadeInContainer>
    </>
  );
}

export const getStaticProps = async (ctx) => {
  let siteText = {};
  let metaData = {};
  await Promise.all([
    customerApi.get("/site/contents?group_code=shipping_policy_section"),
    customerApi.get("/site/meta?path=/shipping-policy"),
  ]).then((res) => {
    console.log("res.data, ", res[0].data);
    let newArray = { ...res[0].data.result };
    siteText = newArray;
    metaData = res[1].data.data;
  });
  return {
    props: {
      siteText: siteText,
      metaData: metaData,
    },
    revalidate: 600,
  };
};
