import axios from "axios";
import Head from "next/head";
import React, { useEffect } from "react";
import style from "./success.module.css";
import { CheckCircleRounded } from "@mui/icons-material";
import { useRouter } from "next/router";
import { useSelector } from "react-redux";
import { customerApi } from "@/api/api";
const SuccessPage = ({ metaData }) => {
  const router = useRouter();
  const account = useSelector((state) => state.accountStore);
  return (
    <React.Fragment>
      <Head>
        <title>
          {metaData.meta_title ? metaData.meta_title : "Order Success"}
        </title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      </Head>
      {account.loggedIn && (
        <div className={style.section}>
          <div className={style.icon}>
            <CheckCircleRounded />
          </div>
          <p className={style.order_success_text}>Order Successfully Placed</p>
          <button
            type="button"
            className="secondary-btn"
            onClick={() => router.push("/account/orders")}
          >
            My Orders
          </button>
        </div>
      )}
    </React.Fragment>
  );
};

export default SuccessPage;

export const getStaticProps = async (ctx) => {
  let metaData = {};
  await Promise.all([customerApi.get("/site/meta?path=/order/failed")]).then(
    (res) => {
      metaData = res[0].data.data;
    }
  );
  return {
    props: {
      metaData: metaData,
    },
    revalidate: 600,
  };
};
