import dynamic from "next/dynamic";
import React from "react";
import SEO from "@/components/shared/SEO";
import { useHome } from "@/context/helpers/Home/HomeContext";
import { useRouter } from "next/router";
import { useTranslation } from "react-i18next";

// Dynamically import Checkout to avoid SSR issues
const Checkout = dynamic(() => import("@/features/checkout"), {
  ssr: false,
});

export default function CheckoutPage() {
  const { t } = useTranslation("checkout");
  const router = useRouter();
  const { companyData } = useHome();

  const baseUrl =
    typeof window !== "undefined"
      ? window.location.origin
      : companyData?.domain
        ? `https://${companyData.domain}`
        : "";
  const checkoutUrl = `${baseUrl}${router.asPath}`;

  return (
    <>
      <SEO
        title={t("seo.title", "Checkout")}
        description={t(
          "seo.description",
          "Complete your purchase and place your order"
        )}
        keywords={t("seo.keywords", "checkout, payment, order")}
        url={checkoutUrl}
        type="website"
        noindex={true}
      />

      <Checkout />
    </>
  );
}
