// material-ui
import {
    Dialog, DialogTitle, DialogContent, DialogActions,
    Typography,
    Grid,
    Stack,
    TextField,
    FormLabel,
    Button,
    Checkbox,
    RadioGroup, Radio,
    FormControlLabel
} from '@mui/material';
import * as UrlUtils from "utils/ApiPathConst";
import * as HttpUtils from "utils/HttpUtils";
import FileList from "components/FileList"
import MainCard from "components/MainCard";
import * as React from "react";
import * as yup from 'yup';
import { useParams } from "react-router-dom";
import { useFormik } from 'formik';
import { useNavigate } from "react-router-dom";
import * as DateUtils from "utils/DateUtils"
import Loadable from 'components/Loadable';
import { notifyActionSuccess } from 'utils/CommonFunction';
import { PNSPS_BUTTON_THEME } from "themes/buttonConst";
import { ThemeProvider } from "@emotion/react";
import { FormattedMessage, useIntl } from "react-intl";
import { 
    isDummyLoggedIn,
    checkIsOnlyOnlinePayment,
    checkPaymentSuspension,
    checkIsNoPaymentByCreateDate,
 } from "utils/Utils"

const UploadFileTable = Loadable(React.lazy(() => import('./UploadFileTable')));
//import * as ProofStatus from "utils/statusUtils/ProofStatus";

// ==============================|| DASHBOARD - DEFAULT ||============================== //


const FormPanel = ({ formData }) => {
    const intl = useIntl();
    const { locale } = intl;
    const [data, setData] = React.useState({});
    const [paymentMethod, set_paymentMethod] = React.useState("");
    const [attachments, setAttachments] = React.useState([]);

    const [actionValue, setActionValue] = React.useState(true);

    const [warningTitle, setWarningTitle] = React.useState("");
    const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
    const [warningText, setWarningText] = React.useState("");
    const [isSubmitting, setIsSubmitting] = React.useState(false);
    const [isOnlyOnlinePayment, setOnlyOnlinePayment] = React.useState();
    const [isNoPayment, setNoPayment] = React.useState();
    const fileInputRef = React.useRef(null);
    
    const navigate = useNavigate()
    const params = useParams();
    // const dft = locale === 'en' ? "DD MMMM YYYY" : "YYYY年MM月DD日";

    const tabelStyle = {
        border: "2px solid gray",
        borderCollapse: "collapse",
        padding: "right"
    }

    React.useEffect(() => {
        if (formData) {
            // console.log("formData", formData)
            setData(formData);
            setOnlyOnlinePayment(checkIsOnlyOnlinePayment())
            setNoPayment(checkIsNoPaymentByCreateDate(formData.created))
            if (isDummyLoggedIn()) {
                set_paymentMethod("demandNote")
            } else if (checkIsOnlyOnlinePayment()){
                set_paymentMethod("online")
            } else if (checkIsNoPaymentByCreateDate(formData.created)){
                set_paymentMethod("demandNote")
            }
        }
    }, [formData]);

    const formik = useFormik({
        enableReinitialize: true,
        initialValues: data,
        validationSchema: yup.object().shape({
            vaild: yup.string().max(255, intl.formatMessage({ id: 'requireLoginPassword' })).required(intl.formatMessage({ id: 'requireLoginPassword' })),
        }),
        onSubmit: values => {
            if (isSubmitting) return;
            if (isOverTime() && !isDummyLoggedIn()) {
                setWarningTitle(intl.formatMessage({ id: "attention" }))
                setWarningText(intl.formatMessage({ id: 'MSG.proofOutOfTime' }));
                setIsWarningPopUp(true);
                return;
            }
            let pm = paymentMethod;
            if (!isDummyLoggedIn()) {
                if (actionValue == true && pm == "demandNote") {
                    pm = isOverDnReviseDeadline() ? "" : pm;
                } else if (actionValue == true && pm == "office") {
                    pm = isOverNpgoReviseDeadline() ? "" : pm;
                }
            }

            if (actionValue == false && isOverReviseDeadline() && !isDummyLoggedIn()) {
                setWarningTitle(intl.formatMessage({ id: "attention" }))
                setWarningText(intl.formatMessage({ id: 'MSG.overReviseDeadline' }));
                setIsWarningPopUp(true);
                return;
            }
            else if (actionValue == true && formData.creditor == false && pm == "") {
                setWarningTitle(intl.formatMessage({ id: "attention" }))
                setWarningText(intl.formatMessage({ id: 'MSG.plzSelectPaymentMethod' }));
                setIsWarningPopUp(true);
                return;
            }

            if (!actionValue) {
                if (!attachments || attachments.length <= 0) {
                    setWarningTitle(intl.formatMessage({ id: "attention" }))
                    setWarningText(intl.formatMessage({ id: 'requireFile' }));
                    setIsWarningPopUp(true);
                    return;
                }
            }
            // console.log(values);
            setIsSubmitting(true);
            HttpUtils.postWithFiles({
                url: UrlUtils.REPLY_PROOF,
                params: {
                    id: data.id,
                    action: actionValue,
                    vaild: values.vaild,
                    paymentMethod: pm
                },
                files: attachments ? attachments : [],
                onSuccess: function (responseData) {
                    setIsSubmitting(false);
                    // console.log(responseData)
                    if (responseData.success === false) {
                        if (responseData.msg) {
                            setWarningTitle(intl.formatMessage({ id: "attention" }))
                            setWarningText(intl.formatMessage({ id: responseData.msg }));
                            setIsWarningPopUp(true);
                            return;
                        }
                        navigate("/publicNotice/" + responseData.id);
                    } else {
                        if (responseData.msg) {
                            setWarningTitle(intl.formatMessage({ id: "attention" }))
                            setWarningText(intl.formatMessage({ id: responseData.msg }));
                            setIsWarningPopUp(true);
                            return;
                        }
                        if (actionValue == true && responseData.id == params.id) {
                            notifyActionSuccess(intl.formatMessage({ id: "submitted" }))
                            navigate("/proof/pay/" + params.id);
                        } else {
                            navigate("/proof/search");
                        }
                    }
                },
                onFail: function (response) {
                    setIsSubmitting(false);
                    setWarningTitle(intl.formatMessage({ id: "attention" }))
                    const msg = response?.data?.msg ? intl.formatMessage({ id: response.data.msg }) : intl.formatMessage({ id: 'actionFail' });
                    setWarningText(msg);
                    setIsWarningPopUp(true);
                    console.log(response);
                },
                onError: function (error) {
                    setIsSubmitting(false);
                    setWarningTitle(intl.formatMessage({ id: "attention" }))
                    const msg = error?.response?.data?.msg ? intl.formatMessage({ id: error.response.data.msg }) : intl.formatMessage({ id: 'actionFail' });
                    setWarningText(msg);
                    setIsWarningPopUp(true);
                    console.log(error);
                }
            });
        }
    });

    const readFile = (event) => {
        let file = event.target.files[0];
        if (file) {
            if (!file.name.toLowerCase().substr(file.name.length - 4).includes(".pdf")) {
                setWarningTitle(intl.formatMessage({ id: "attention" }))
                setWarningText(intl.formatMessage({ id: 'requireValidFileWithPdfFormat' }));
                setIsWarningPopUp(true);
                document.getElementById("uploadFileBtn").value = "";
                return;
            }
            if (file.size >= (10 * 1024 * 1034)) {
                setWarningTitle(intl.formatMessage({ id: "attention" }))
                setWarningText(intl.formatMessage({ id: 'fileSizeWarning' }));
                setIsWarningPopUp(true);
                return;
            }

            file['id'] = attachments.length;
            setAttachments([
                ...attachments,
                file
            ]);
            document.getElementById("uploadFileBtn").value = "";
        }
    }

    const isOverTime = () => {
        let proofPaymentDeadline = DateUtils.convertToDate(formData?.proofPaymentDeadline);
        if (!proofPaymentDeadline) return true;
        let current = new Date();
        return current.getTime() > proofPaymentDeadline;
    }

    const isOverReviseDeadline = () => {
        // if (paymentMethod == "demandNote") return isOverDnReviseDeadline();
        // if (paymentMethod == "office") return isOverNpgoReviseDeadline();
        //online payment
        let reviseDeadline = DateUtils.convertToDate(formData?.reviseDeadline);
        // reviseDeadline?.setTime(reviseDeadline?.getTime() + (14 * 60 * 60 * 1000));// 14:00
        if (!reviseDeadline) return true;
        let current = new Date();
        return current.getTime() > reviseDeadline;
    }

    const isOverDnReviseDeadline = () => {
        let reviseDeadline = DateUtils.convertToDate(formData?.closingDateOff);
        reviseDeadline?.setTime(reviseDeadline?.getTime() + (17 * 60 * 60 * 1000));// 17:00
        if (!reviseDeadline) return true;
        let current = new Date();
        return current.getTime() > reviseDeadline;
    }

    const isOverNpgoReviseDeadline = () => {
        let reviseDeadline = DateUtils.convertToDate(formData?.closingDate);
        reviseDeadline?.setTime(reviseDeadline?.getTime() + (12 * 60 * 60 * 1000));// 12:00
        if (!reviseDeadline) return true;
        let current = new Date();
        return current.getTime() > reviseDeadline;
    }




    return (
        <MainCard xs={12} sm={12} md={12} lg={12}
            border={false}
            content={false}>

            <Typography variant="h4" sx={{ textAlign: "left", mb: 2, borderBottom: "1px solid black" }}>
                <FormattedMessage id="publicNoticePaymentProofComment" />
            </Typography>

            <form onSubmit={formik.handleSubmit}>

                {
                    formik.values.replyDate ?
                        <Grid container direction="column" sx={{ paddingLeft: 0, paddingRight: 0 }}>
                            <Grid item xs={12} sm={12} md={12} lg={8} textAlign="left">
                                <Typography variant="h5">
                                    <FormattedMessage id="proofReplyDate" /> :&nbsp;
                                    {
                                        locale === 'en' ?
                                            DateUtils.datetimeStr(formik.values.replyDate)
                                            :
                                            DateUtils.datetimeStr_Cht(formik.values.replyDate)
                                    }
                                </Typography>
                            </Grid>
                            <Grid item xs={12} md={12} textAlign="left">
                                <Typography variant="h5">
                                    <FormattedMessage id="proofReply" /> : {formik.values.action ?
                                        (<span style={{ color: 'green' }}>
                                            <FormattedMessage id="proofErrorFree" />
                                        </span>)
                                        :
                                        (<span style={{ color: 'red' }}>
                                            <FormattedMessage id="proofWithError" />
                                        </span>)}
                                </Typography>
                            </Grid>
                            {/* <Grid item xs={12} md={12} textAlign="left">
                                <Typography variant="h5">
                                    <FormattedMessage id="proofReply" /> :&nbsp;
                                    <span style={{ color: 'green' }}>
                                        {
                                        locale === 'en' ? 
                                            ProofStatus.getStatusText_Eng(formik.values).text
                                            : 
                                            ProofStatus.getStatusText_Cht(formik.values).text
                                        }
                                    </span>
                                </Typography>
                            </Grid> */}
                            {
                                formik.values.action ?
                                    null
                                    :
                                    <Grid item xs={12} md={12} textAlign="left" sx={{ width: '95%', maxWidth: { xs: '70vw', sm: '72vw', md: '75vw', lg: '80vw' } }}>
                                        <FileList
                                            lang="ch"
                                            refId={params.id}
                                            refType={"proofReply"}
                                            dateHideable={true}
                                            disablePagination
                                            disableSelectionOnClick
                                            disableColumnMenu
                                            disableColumnSelector
                                            hideFooter
                                        />
                                    </Grid>
                            }

                        </Grid>
                        :
                        (
                            isOverTime() ?
                                <Grid container direction="column" sx={{ paddingLeft: 0, paddingRight: 0 }} spacing={1}>
                                    <Grid item xs={12} md={12} textAlign="left">
                                        <Typography variant="h5"><FormattedMessage id="MSG.proofOutOfTime" /></Typography>
                                    </Grid>
                                </Grid>
                                :
                                <Grid container direction="column" sx={{ paddingLeft: 0, paddingRight: 0 }} spacing={1}>

                                    <Grid item xs={12} md={12}>
                                        <RadioGroup
                                            aria-labelledby="demo-radio-buttons-group-label"
                                            id="action"
                                            name="action"
                                            defaultValue={true}
                                            onChange={(event) => {
                                                setActionValue(event.target.value === "true" ? true : false);
                                            }}
                                        >
                                            <FormControlLabel value={true} control={<Radio />} label={intl.formatMessage({ id: 'proofErrorFree' })} />
                                            <FormControlLabel value={false} control={<Radio />} label={intl.formatMessage({ id: 'proofWithError' })} />
                                        </RadioGroup>
                                    </Grid>
                                    {
                                        actionValue && formData.creditor == false ?
                                            isDummyLoggedIn() ?
                                                <Grid item xs={12} sx={{ mb: 1, }}>
                                                    <table style={tabelStyle}>
                                                        <tbody>
                                                            <tr style={tabelStyle}>
                                                                <th style={tabelStyle} width="50" align="left"></th>
                                                                <th style={tabelStyle} width="300" align="left"><FormattedMessage id="paymentMeans" /></th>
                                                                <th style={tabelStyle} width="300" align="left"><FormattedMessage id="commentDeadline" /></th>
                                                                <th style={tabelStyle} width="300" align="left"><FormattedMessage id="confirmingDealine" /></th>
                                                                <th style={tabelStyle} width="400" align="left"><FormattedMessage id="PaymentCoonpletDealine" /></th>
                                                            </tr>
                                                            <tr>
                                                                <td style={tabelStyle}>
                                                                    <Checkbox
                                                                        checked={paymentMethod == "demandNote"}
                                                                        onChange={() => {
                                                                            set_paymentMethod("demandNote")
                                                                        }}
                                                                    />
                                                                </td>
                                                                <td style={tabelStyle}>
                                                                    <FormattedMessage id="paymentMeans" />: <FormattedMessage id="payDn" />
                                                                    <br /><a href="#payOnlineDetails" color='#fff' onClick={() => {
                                                                        setWarningTitle(intl.formatMessage({ id: "paymentMeans" }) + ": " + intl.formatMessage({ id: "payDn" }))
                                                                        setWarningText(
                                                                            <><FormattedMessage id="paymentMethodMeans" />:
                                                                                <ul>
                                                                                    <li><FormattedMessage id="atm" /></li>
                                                                                    <li><FormattedMessage id="pps" /></li>
                                                                                    <li><FormattedMessage id="eBank" /></li>
                                                                                    <li><FormattedMessage id="phoneBank" /></li>
                                                                                    <li><FormattedMessage id="eCheque" /></li>
                                                                                    <li><FormattedMessage id="fps" /></li>
                                                                                    <li><FormattedMessage id="hkpo" /></li>
                                                                                    <li><FormattedMessage id="store" /></li>
                                                                                    <li><FormattedMessage id="post" /></li>
                                                                                </ul>
                                                                                <Typography variant="h6">
                                                                                    <div style={{ padding: 12 }} dangerouslySetInnerHTML={{ __html: intl.formatMessage({ id: "proofNote" }) }} />
                                                                                </Typography>
                                                                            </>
                                                                        );
                                                                        setIsWarningPopUp(true);
                                                                    }}><u><FormattedMessage id="viewDetail" /></u></a>
                                                                </td>
                                                                <td style={tabelStyle}>{DateUtils.dateFormat(formData.closingDateOff, intl.formatMessage({ id: "dateStrFormat" }))} 5:00 p.m.</td>
                                                                <td style={tabelStyle}>{DateUtils.dateFormat(formData.closingDateOff, intl.formatMessage({ id: "dateStrFormat" }))} 5:00 p.m.</td>
                                                                <td style={tabelStyle}>
                                                                    <FormattedMessage id="payDnRemark" values={{
                                                                        date: DateUtils.dateFormat(formData.closingDate, intl.formatMessage({ id: "dateStrFormat" }))
                                                                    }} />
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td style={tabelStyle}>
                                                                    <Checkbox
                                                                        checked={paymentMethod == "office"}
                                                                        onChange={() => {
                                                                            set_paymentMethod("office")
                                                                        }}
                                                                    />
                                                                </td>
                                                                <td style={tabelStyle}>
                                                                    <FormattedMessage id="payNPGO" />
                                                                    <br /><a href="#payOnlineDetails" color='#fff' onClick={() => {
                                                                        setWarningTitle(intl.formatMessage({ id: "paymentMeans" }) + ": " + intl.formatMessage({ id: "payNPGOPopUpTitle" }))
                                                                        setWarningText(
                                                                            <><FormattedMessage id="paymentMethodMeans" />:
                                                                                <ul>
                                                                                    <li><FormattedMessage id="cheque" /></li>
                                                                                    <li><FormattedMessage id="drafts" /></li>
                                                                                    <li><FormattedMessage id="cashierOrders" /></li>
                                                                                    <li><FormattedMessage id="cash" /></li>
                                                                                </ul>
                                                                            </>
                                                                        );
                                                                        setIsWarningPopUp(true);
                                                                    }}><u><FormattedMessage id="viewDetail" /></u></a>
                                                                </td>
                                                                <td style={tabelStyle}>{DateUtils.dateFormat(formData.closingDate, intl.formatMessage({ id: "dateStrFormat" }))} 11:30 a.m.</td>
                                                                <td style={tabelStyle}>{DateUtils.dateFormat(formData.closingDate, intl.formatMessage({ id: "dateStrFormat" }))} 12:00 p.m.</td>
                                                                <td style={tabelStyle}>
                                                                    <FormattedMessage id="payNPGORemark" values={{
                                                                        date: DateUtils.dateFormat(formData.closingDate, intl.formatMessage({ id: "dateStrFormat" }))
                                                                    }} />
                                                                </td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </Grid> :
                                                <>
                                                    {isNoPayment ? 
                                                        null 
                                                    :
                                                        <Grid item xs={12} sx={{ mb: 1, }}>
                                                            <table style={tabelStyle}>
                                                                <tbody>
                                                                    <tr style={tabelStyle}>
                                                                        {!isOnlyOnlinePayment?
                                                                            <th style={tabelStyle} width="50" align="left"></th>
                                                                        :
                                                                            null
                                                                        }
                                                                        <th style={tabelStyle} width="300" align="left"><FormattedMessage id="paymentMeans" /></th>
                                                                        <th style={tabelStyle} width="300" align="left"><FormattedMessage id="commentDeadline" /></th>
                                                                        <th style={tabelStyle} width="300" align="left"><FormattedMessage id="confirmingDealine" /></th>
                                                                        <th style={tabelStyle} width="400" align="left"><FormattedMessage id="PaymentCoonpletDealine" /></th>
                                                                    </tr>
                                                                    <tr>
                                                                        {!isOnlyOnlinePayment?
                                                                            <td style={tabelStyle}>
                                                                                <Checkbox
                                                                                    checked={paymentMethod == "online"}
                                                                                    onChange={() => {
                                                                                        set_paymentMethod("online")
                                                                                    }}
                                                                                />
                                                                            </td>
                                                                            :null
                                                                        }
                                                                        <td style={tabelStyle}>
                                                                            <FormattedMessage id="payOnline" />
                                                                            {checkPaymentSuspension()?
                                                                                <Typography style={{ padding: '16px', color: "red" }}>
                                                                                    <div dangerouslySetInnerHTML={{ __html: intl.formatMessage({ id: "suspensionMessageText" }) }} />
                                                                                </Typography>:null
                                                                            }
                                                                            <br /><a href="#payOnlineDetails" color='#fff' onClick={() => {
                                                                                setWarningTitle(intl.formatMessage({ id: "paymentMeans" }) + ": " + intl.formatMessage({ id: "payOnline" }))
                                                                                setWarningText(
                                                                                    <><FormattedMessage id="paymentMethodMeans" />:
                                                                                        <ul>
                                                                                            <li><FormattedMessage id="fps" /></li>
                                                                                            <li><FormattedMessage id="card" /></li>
                                                                                            <li><FormattedMessage id="pps" /></li>
                                                                                        </ul>
                                                                                    </>
                                                                                );
                                                                                setIsWarningPopUp(true);
                                                                            }}><u><FormattedMessage id="viewDetail" /></u></a>
                                                                        </td>
                                                                        <td style={tabelStyle}>{
                                                                            locale === 'en' ?
                                                                                `${DateUtils.dateFormat(formData.reviseDeadline, intl.formatMessage({ id: "datetimeFormate" }))?.replace("am", "a.m.")?.replace("pm", "p.m.")}`
                                                                                :
                                                                                `${DateUtils.dateFormat(formData.reviseDeadline, intl.formatMessage({ id: "datetimeFormate" }))?.replace("am", "上午")?.replace("pm", "下午").replace("00分", "")}`
                                                                        }</td>
                                                                        <td style={tabelStyle}>{
                                                                            locale === 'en' ?
                                                                                `${DateUtils.dateFormat(formData.proofPaymentDeadline, intl.formatMessage({ id: "datetimeFormate" }))?.replace("am", "a.m.")?.replace("pm", "p.m.")}`
                                                                                :
                                                                                `${DateUtils.dateFormat(formData.proofPaymentDeadline, intl.formatMessage({ id: "datetimeFormate" }))?.replace("am", "上午")?.replace("pm", "下午").replace("00分", "")}`
                                                                        }</td>
                                                                        <td style={tabelStyle}>{
                                                                            locale === 'en' ?
                                                                                `${DateUtils.dateFormat(formData.expiryDate, intl.formatMessage({ id: "datetimeFormate" }))?.replace("am", "a.m.")?.replace("pm", "p.m.")}`
                                                                                :
                                                                                `${DateUtils.dateFormat(formData.expiryDate, intl.formatMessage({ id: "datetimeFormate" }))?.replace("am", "上午")?.replace("pm", "下午").replace("00分", "")}`
                                                                        }</td>
                                                                    </tr>
                                                                    {!isOnlyOnlinePayment?
                                                                        <>
                                                                            <tr>
                                                                                <td style={tabelStyle}>
                                                                                    {isOverDnReviseDeadline() ?
                                                                                        <></> :
                                                                                        <Checkbox
                                                                                            checked={paymentMethod == "demandNote"}
                                                                                            onChange={() => {
                                                                                                set_paymentMethod("demandNote")
                                                                                            }}
                                                                                        />
                                                                                    }
                                                                                </td>
                                                                                <td style={tabelStyle}>
                                                                                    <FormattedMessage id="payDn" />
                                                                                    <br /><a href="#payOnlineDetails" color='#fff' onClick={() => {
                                                                                        setWarningTitle(intl.formatMessage({ id: "paymentMeans" }) + ": " + intl.formatMessage({ id: "payDn" }))
                                                                                        setWarningText(
                                                                                            <><FormattedMessage id="paymentMethodMeans" />:
                                                                                                <ul>
                                                                                                    <li><FormattedMessage id="atm" /></li>
                                                                                                    <li><FormattedMessage id="pps" /></li>
                                                                                                    <li><FormattedMessage id="eBank" /></li>
                                                                                                    <li><FormattedMessage id="phoneBank" /></li>
                                                                                                    <li><FormattedMessage id="eCheque" /></li>
                                                                                                    <li><FormattedMessage id="fps" /></li>
                                                                                                    <li><FormattedMessage id="hkpo" /></li>
                                                                                                    <li><FormattedMessage id="store" /></li>
                                                                                                    <li><FormattedMessage id="post" /></li>
                                                                                                </ul>
                                                                                                <Typography variant="h6">
                                                                                                    <div style={{ padding: 12 }} dangerouslySetInnerHTML={{ __html: intl.formatMessage({ id: "proofNote" }) }} />
                                                                                                </Typography>
                                                                                            </>
                                                                                        );
                                                                                        setIsWarningPopUp(true);
                                                                                    }}><u><FormattedMessage id="viewDetail" /></u></a>
                                                                                </td>
                                                                                <td style={tabelStyle}>{DateUtils.dateFormat(formData.closingDateOff, intl.formatMessage({ id: "dateStrFormat" }))} {locale ==='en'?"5:00 p.m.":"下午5時"}</td>
                                                                                <td style={tabelStyle}>{DateUtils.dateFormat(formData.closingDateOff, intl.formatMessage({ id: "dateStrFormat" }))} {locale ==='en'?"5:00 p.m.":"下午5時"}</td>
                                                                                <td style={tabelStyle}>
                                                                                    <FormattedMessage id="payDnRemark" values={{
                                                                                        date: DateUtils.dateFormat(formData.proofPaymentDeadline, intl.formatMessage({ id: "dateStrFormat" }))
                                                                                    }} />
                                                                                </td>
                                                                            </tr>

                                                                            <tr>
                                                                                <td style={tabelStyle}>
                                                                                    {
                                                                                        isOverNpgoReviseDeadline() ?
                                                                                            <></> :
                                                                                            <Checkbox
                                                                                                checked={paymentMethod == "office"}
                                                                                                onChange={() => {
                                                                                                    set_paymentMethod("office")
                                                                                                }}
                                                                                            />
                                                                                    }
                                                                                </td>
                                                                                <td style={tabelStyle}>
                                                                                    <FormattedMessage id="payNPGO" />
                                                                                    <br /><a href="#payOnlineDetails" color='#fff' onClick={() => {
                                                                                        setWarningTitle(intl.formatMessage({ id: "paymentMeans" }) + ": " + intl.formatMessage({ id: "payNPGOPopUpTitle" }))
                                                                                        setWarningText(
                                                                                            <><FormattedMessage id="paymentMethodMeans" />:
                                                                                                <ul>
                                                                                                    <li><FormattedMessage id="cheque" /></li>
                                                                                                    <li><FormattedMessage id="drafts" /></li>
                                                                                                    <li><FormattedMessage id="cashierOrders" /></li>
                                                                                                    <li><FormattedMessage id="cash" /></li>
                                                                                                </ul>
                                                                                            </>
                                                                                        );
                                                                                        setIsWarningPopUp(true);
                                                                                    }}><u><FormattedMessage id="viewDetail" /></u></a>
                                                                                </td>
                                                                                <td style={tabelStyle}>{DateUtils.dateFormat(formData.closingDate, intl.formatMessage({ id: "dateStrFormat" }))} {locale ==='en'?"11:30 a.m.":"上午11時30分"}</td>
                                                                                <td style={tabelStyle}>{DateUtils.dateFormat(formData.closingDate, intl.formatMessage({ id: "dateStrFormat" }))} {locale ==='en'?"12:00 p.m.":"下午12時"}</td>
                                                                                <td style={tabelStyle}>
                                                                                    <FormattedMessage id="payNPGORemark" values={{
                                                                                        date: DateUtils.dateFormat(formData.closingDate, intl.formatMessage({ id: "dateStrFormat" }))
                                                                                    }} />
                                                                                </td>
                                                                            </tr>
                                                                        </>:null
                                                                    }
                                                                </tbody>

                                                            </table>
                                                        </Grid>
                                                    } 
                                                    {/* <Grid item xs={12}>
                                                        <Typography variant="h6" height="100%" >
                                                            <div style={{ padding: 12 }} dangerouslySetInnerHTML={{ __html: intl.formatMessage({ id: "proofNote" }) }} />
                                                        </Typography>
                                                    </Grid> */}
                                                    {!isOnlyOnlinePayment?
                                                        <Grid item xs={12}>
                                                            <Typography variant="h6" height="100%" >
                                                                <div style={{ padding: 12 }} dangerouslySetInnerHTML={{ __html: intl.formatMessage({ id: "proofImportant" }) }} />
                                                            </Typography>
                                                        </Grid>:null
                                                    }
                                                </>
                                            :
                                            actionValue ?
                                                <></>
                                                :
                                                <>
                                                    {
                                                        isOverReviseDeadline() ?
                                                            <Grid item xs={12} md={12} textAlign="left">
                                                                <Typography variant="h5" style={{ color: "red" }}>
                                                                    <FormattedMessage id="MSG.overReviseDeadline" />
                                                                </Typography>
                                                            </Grid>
                                                            :
                                                            <>
                                                                <Grid item xs={12} md={12} textAlign="left">
                                                                    <Typography variant="h5">
                                                                        <FormattedMessage id="requiredUploadFix" />：
                                                                    </Typography>
                                                                </Grid>

                                                                <Grid item xs={12} md={12} textAlign="left">
                                                                    <ThemeProvider theme={PNSPS_BUTTON_THEME}>
                                                                        <Button
                                                                            color="save"
                                                                            variant="contained"
                                                                            type="button"
                                                                            aria-label={intl.formatMessage({ id: 'upload' })}
                                                                            disabled={attachments.length >= (formik.values.groupType === "Private Bill" ? 2 : 1)}
                                                                            onClick={() => {
                                                                                if (fileInputRef.current) {
                                                                                    fileInputRef.current.click();
                                                                                }
                                                                            }}
                                                                            onKeyDown={(event) => {
                                                                                if (event.key === 'Enter' || event.key === ' ') {
                                                                                    event.preventDefault();
                                                                                    if (fileInputRef.current) {
                                                                                        fileInputRef.current.click();
                                                                                    }
                                                                                }
                                                                            }}
                                                                        >
                                                                            <FormattedMessage id="upload" />
                                                                        </Button>
                                                                    </ThemeProvider>
                                                                    <input
                                                                        id="uploadFileBtn"
                                                                        name="file"
                                                                        type="file"
                                                                        accept=".pdf"
                                                                        style={{ display: 'none' }}
                                                                        disabled={attachments.length >= (formik.values.groupType === "Private Bill" ? 2 : 1)}
                                                                        onChange={(event) => {
                                                                            readFile(event)
                                                                        }}
                                                                        ref={fileInputRef}
                                                                    />
                                                                </Grid>


                                                                <Grid item xs={12} sm={12} md={12} lg={12} textAlign="left" sx={{ width: '95%', maxWidth: { xs: '70vw', sm: '72vw', md: '75vw', lg: '80vw' } }} >
                                                                    <UploadFileTable key="uploadTable" recordList={attachments} setRecordList={setAttachments} />
                                                                </Grid>
                                                            </>
                                                    }
                                                </>
                                    }
                                    {
                                        actionValue == false && isOverReviseDeadline() ?
                                            <></>
                                            :
                                            <Grid item xs={12} sm={12} md={12} lg={12}>
                                                <Stack direction="row" alignItems="center">
                                                    <FormLabel sx={{ paddingRight: 2, paddingBottom: 3, textAlign: "center" }}>
                                                        <Typography variant="h5">
                                                            <FormattedMessage id="sign" />：
                                                        </Typography>
                                                    </FormLabel>
                                                    <TextField
                                                        fullWidth
                                                        type="password"
                                                        onChange={formik.handleChange}
                                                        name="vaild"
                                                        variant="outlined"
                                                        error={Boolean(formik.errors["vaild"])}
                                                        helperText={formik.errors["vaild"] ? formik.errors["vaild"] : ' '}
                                                        placeholder={intl.formatMessage({ id: 'requireLoginPassword' })}
                                                        sx={
                                                            {
                                                                "& .MuiInputBase-input.Mui-disabled": {
                                                                    WebkitTextFillColor: "#000000",
                                                                    background: "#f8f8f8",
                                                                },
                                                                width: '70%'
                                                            }
                                                        }
                                                    />

                                                </Stack>
                                            </Grid>
                                    }
                                    <Grid item xs={12} md={12} textAlign="left">
                                        <ThemeProvider theme={PNSPS_BUTTON_THEME}>
                                            <Button
                                                variant="contained"
                                                type="submit"
                                                disabled={(actionValue == false && isOverReviseDeadline()) || isSubmitting}
                                                aria-label={intl.formatMessage({ id: 'submitReply' })}
                                                sx={{
                                                    backgroundColor: '#0C489E',
                                                    color: '#FFFFFF',
                                                    '&:hover': { backgroundColor: '#093A7A' },
                                                }}
                                            >
                                                {isSubmitting ? <FormattedMessage id="loading" /> : <FormattedMessage id="submitReply" />}
                                            </Button>
                                        </ThemeProvider>
                                    </Grid>
                                </Grid>

                        )


                }



            </form>
            <div>
                <Dialog
                    open={isWarningPopUp}
                    onClose={() => setIsWarningPopUp(false)}
                    PaperProps={{
                        sx: {
                            minWidth: '40vw',
                            maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
                            maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
                        }
                    }}
                >
                    <DialogTitle>
                        {warningTitle}
                    </DialogTitle>
                    <DialogContent style={{ display: 'flex', }}>
                        <Typography variant="h5" style={{ padding: '16px' }}>{warningText}</Typography>
                    </DialogContent>
                    <DialogActions>
                        <Button
                            aria-label={intl.formatMessage({ id: 'close' })}
                            onClick={() => setIsWarningPopUp(false)}
                        >
                            <FormattedMessage id="close" />
                        </Button>
                    </DialogActions>
                </Dialog>
            </div>
        </MainCard>
    );
};

export default FormPanel;
