import {
  useEffect,
  useState
  } from "react";

// material-ui
import {
  Button,
  // Link,
  Stack,
  Typography,
  Dialog,
  DialogActions,
  DialogContent,
  DialogContentText,
  DialogTitle,
  FormLabel,
} from '@mui/material';
import { useFormik,FormikProvider } from 'formik';
import * as yup from 'yup';
import {PNSPS_BUTTON_THEME} from "../../../themes/buttonConst";
import {ThemeProvider} from "@emotion/react";
import {FormattedMessage} from "react-intl";
import {useIntl} from "react-intl";

const StatusChangeDialog = (props) => {
  const [status, setStatus] = useState("");
  const intl = useIntl();

  useEffect(() => {
    // console.log(Object.keys(!props.selectedGazetteGroup).length)
    if(props.getStatus === "cancel"){
      setStatus(intl.formatMessage({id: 'cancel'}))
    }
  }, [props.getStatus]);
  
  const acceptedHandle = () => () =>{
    // console.log(selectedGazetteGroup)
    props.setStatusWindowAccepted(true)
  };

  
  const formik = useFormik({
      initialValues:({
          username:'',
      }),
      validationSchema:yup.object().shape({
      }),
  });

  // const handleReset = () => {
  //   setSelectedGazetteGroupInputType("")
  //   selectedGazetteGroup({});
  // };
  
  return (
      <Dialog
        open={props.open}
        onClose={props.handleClose}
        fullWidth={true}
        maxWidth={'xs'}
      >
        <DialogTitle >
          <Typography variant="h4">
            {status} {intl.formatMessage({id: 'publicNotice'})}
          </Typography>
        </DialogTitle>
        <FormikProvider value={formik}>
            <form>
              <DialogContent>
                <DialogContentText>
                  <FormLabel sx={{fontSize: "18px", color:"#000000",textAlign:"center"}}>
                    <Typography variant="h5">
                      {intl.formatMessage({id: 'confirmTo'})}{status} {intl.formatMessage({id: 'publicNoticeApp'})}?</Typography>
                  </FormLabel>
                </DialogContentText>
              </DialogContent>
            </form>
        </FormikProvider>
        <Stack direction="row" justifyContent="space-around" sx={{mb:2}}>
          <ThemeProvider theme={PNSPS_BUTTON_THEME}>
          <DialogActions>
            <Button
                variant="contained"
                onClick={props.handleClose}
                autoFocus
                color="cancel"
            >
              <FormattedMessage id="cancel"/>
            </Button>
          </DialogActions>
          <DialogActions>
            <Button
                variant="contained"
                color="save"
                onClick={acceptedHandle()}
                autoFocus
            >
              <FormattedMessage id="confirm"/>
            </Button>
          </DialogActions>
          </ThemeProvider>
        </Stack>
      </Dialog>
  );
};

export default StatusChangeDialog;
