import { CenterLayout, FullPageLayout, useConfig } from "@witel/webapp-builder";
import moment from "jalali-moment";
import SvgMaintenance from "@/core/components/svgs/SvgMaintenance";
import { Typography } from "@mui/material";
import { useTranslations } from "next-intl";

const RegisterDeadlineMiddleware = ({ children, serverToday }) => {
    const { config } = useConfig();
    const t = useTranslations();

    const fromDate = moment(config.navgan_registration_start_date, "YYYY/MM/DD HH:mm:ss");
    const toDate = moment(config.navgan_registration_end_date, "YYYY/MM/DD HH:mm:ss");
    const today = moment(serverToday);

    console.log(config.navgan_registration_status);

    if (config.navgan_registration_status) {
        if (today.isBetween(fromDate, toDate, null, "[]")) {
            return children;
        } else if (today.isAfter(toDate, null)) {
            return (
                <FullPageLayout>
                    <CenterLayout spacing={3}>
                        <SvgMaintenance height={200} width={200} />
                        <Typography>{t("RegisterDeadline.after")}</Typography>
                    </CenterLayout>
                </FullPageLayout>
            );
        } else if (today.isBefore(fromDate, null)) {
            return (
                <FullPageLayout>
                    <CenterLayout spacing={3}>
                        <SvgMaintenance height={200} width={200} />
                        <Typography>{t("RegisterDeadline.before")}</Typography>
                    </CenterLayout>
                </FullPageLayout>
            );
        }
    } else {
        return (
            <FullPageLayout>
                <CenterLayout spacing={3}>
                    <SvgMaintenance height={200} width={200} />
                    <Typography>{t("RegisterDeadline.soon")}</Typography>
                </CenterLayout>
            </FullPageLayout>
        );
    }
};

export default RegisterDeadlineMiddleware;
