// material-ui
import {
    Typography, Grid, Button
} from '@mui/material';
import MainCard from "../../components/MainCard";
import * as React from "react";
import {ThemeProvider} from "@emotion/react";
import {LIONER_LONG_BUTTON_THEME} from "../../themes/colorConst";
import CampaignIcon from "@mui/icons-material/Campaign";
import axios from "axios";
import {apiPath} from "../../auth/utils";
import ReplayIcon from '@mui/icons-material/Replay';
import {
    POST_RESEND_FAIL_EMAIL,
    POST_TODO_TEST_ANNOUNCEMENT,
    POST_TODO_TEST_REMINDER,
    //XML_TEST
} from "../../utils/ApiPathConst";
import {notifyDeleteError, notifyInfo, notifySuccess} from "../../utils/CommonFunction";
// import {useContext} from "react";
// import UploadContext from "../../components/UploadProvider";
// ==============================|| DASHBOARD - DEFAULT ||============================== //

const SettingPage = () => {
    //zconst { setIsUploading } = useContext(UploadContext);

    function triggerApplicationSchedule(){
        notifyInfo("Schedule have been manually triggered");
        axios.get(`${apiPath}${POST_TODO_TEST_REMINDER}`)
            .then(() => {
                notifySuccess("Schedule job finished!");
            })
            .catch(error => {
                notifyDeleteError("Error occur during schedule job");
                console.log(error);
                return false;
            });
    }

    function triggerAnnouncementSchedule(){
        notifyInfo("Schedule have been manually triggered.");
        axios.get(`${apiPath}${POST_TODO_TEST_ANNOUNCEMENT}`)
            .then(() => {
                notifySuccess("Schedule job finished!");
            })
            .catch(error => {
                notifyDeleteError("Error occur during schedule job");
                console.log(error);
                return false;
            });
    }

    function triggerResendFailEmail(){
        notifyInfo("Resending failed email.");
        axios.get(`${apiPath}${POST_RESEND_FAIL_EMAIL}`)
            .then(() => {
                notifySuccess("Resend email job finished!");
            })
            .catch(error => {
                notifyDeleteError("Error occur when resending email");
                console.log(error);
                return false;
            });
    }

    // function testXML(){
    //     notifyInfo("Download XML");
    //     axios.get(`${apiPath}${XML_TEST}`)
    //         .then((response) => {
    //             if (response.status === 200) {
    //                 setIsUploading(false);
    //                 const url = URL.createObjectURL(new Blob([response.data]));
    //                 const link = document.createElement("a");
    //                 link.href = url;
    //                 link.setAttribute("download", response.headers['filename']);
    //                 link.click();
    //             }
    //         })
    //         .catch(error => {
    //             notifyDeleteError("Downlaod Fail!");
    //             console.log(error);
    //             return false;
    //         });
    // }

    return (
            <Grid container rowSpacing={3} columnSpacing={2.75} justifyContent="center">

                <Grid item xs={12} sx={{mb: -2.25}}>
                    <Typography variant="lionerBold">Generate Reminder</Typography>
                </Grid>
                <Grid item xs={12} md={11} lg={10} >
                    <MainCard xs={12} md={12} lg={12}
                              content={false}>
                        <Grid container xs={12} md={12} lg={12} justifyContent="space-between" sx={{mt:3}}>
                                <Grid item xs={12} md={12} lg={12} >
                                    <Grid container alignItems={"center"}>
                                        <Grid item xs={4} s={4} md={4} lg={4}
                                              sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
                                            <Typography variant="h5">Trigger Reminder (For Test)</Typography>
                                        </Grid>
                                        <ThemeProvider theme={LIONER_LONG_BUTTON_THEME}>
                                        <Grid item xs={3.5} s={3.5} md={3.5} lg={3.5}
                                              sx={{display: 'flex', alignItems: 'center'}}>
                                            <ThemeProvider theme={LIONER_LONG_BUTTON_THEME}>
                                                <Grid item sx={{ml:3, mr:3}}>
                                                    <Button
                                                        variant="contained"
                                                        color="export"
                                                        onClick={triggerApplicationSchedule}
                                                        startIcon={<CampaignIcon />}
                                                    >
                                                        Application
                                                    </Button>
                                                </Grid>
                                            </ThemeProvider>
                                        </Grid>

                                        <Grid item xs={3.5} s={3.5} md={3.5} lg={3.5}
                                              sx={{display: 'flex', alignItems: 'center'}}>
                                                <Grid item sx={{ml:3, mr:3}}>
                                                    <Button
                                                        variant="contained"
                                                        color="export"
                                                        onClick={triggerAnnouncementSchedule}
                                                        startIcon={<CampaignIcon />}
                                                    >
                                                        Announcement
                                                    </Button>
                                                </Grid>
                                        </Grid>
                                        </ThemeProvider>

                                    </Grid>
                                    <Grid item sx={{mb:3, mt:2}}>
                                        <Grid container alignItems={"center"}>
                                            <Grid item xs={4} s={4} md={4} lg={4}
                                                  sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
                                                <Typography variant="h5">Resend Failed Reminder</Typography>
                                            </Grid>
                                            <Grid item xs={7} s={7} md={7} lg={7}>
                                                <ThemeProvider theme={LIONER_LONG_BUTTON_THEME}>
                                                    <Grid item sx={{ml:3, mr:3}}>
                                                        <Button
                                                            variant="contained"
                                                            type="submit"
                                                            color="saveAs"
                                                            onClick={triggerResendFailEmail}
                                                            startIcon={<ReplayIcon />}
                                                        >
                                                            Resend
                                                        </Button>

                                                    </Grid>
                                                </ThemeProvider>
                                            </Grid>
                                        </Grid>
                                    </Grid>

                                    {/*<Grid item sx={{mb:3, mt:2}}>*/}
                                    {/*    <Grid container alignItems={"center"}>*/}
                                    {/*        <Grid item xs={4} s={4} md={4} lg={4}*/}
                                    {/*              sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>*/}
                                    {/*            <Typography variant="h5">XML Test</Typography>*/}
                                    {/*        </Grid>*/}
                                    {/*        <Grid item xs={7} s={7} md={7} lg={7}>*/}
                                    {/*            <ThemeProvider theme={LIONER_LONG_BUTTON_THEME}>*/}
                                    {/*                <Grid item sx={{ml:3, mr:3}}>*/}
                                    {/*                    <Button*/}
                                    {/*                        variant="contained"*/}
                                    {/*                        type="save"*/}
                                    {/*                        color="saveAs"*/}
                                    {/*                        onClick={testXML}*/}
                                    {/*                        //startIcon={<ReplayIcon />}*/}
                                    {/*                    >*/}
                                    {/*                        Download XML*/}
                                    {/*                    </Button>*/}

                                    {/*                </Grid>*/}
                                    {/*            </ThemeProvider>*/}
                                    {/*        </Grid>*/}
                                    {/*    </Grid>*/}
                                    {/*</Grid>*/}

                                </Grid>
                        </Grid>
                    </MainCard>
                </Grid>

            </Grid>

    );
};

export default SettingPage;
