import { createContext, useState } from "react";
import { PropTypes } from "prop-types";
import moment from "moment/moment";

export const AppContext = createContext();

export const AppContextProvider = (props) => {
  const [notifState, setNotifState] = useState({
    open: false,
    vertical: "top",
    horizontal: "center",
    severity: "success",
    msg: "",
  });

  const [selectedDate1, setSelectedDate1] = useState(
    moment(new Date()).format("YYYY-MM-DD")
  );
  const [selectedDate2, setSelectedDate2] = useState(
    moment(new Date()).format("YYYY-MM-DD")
  );

  const openNotif = (newState) => {
    setNotifState({ open: true, ...newState });
  };

  return (
    <AppContext.Provider
      value={[
        openNotif,
        notifState,
        selectedDate1,
        setSelectedDate1,
        selectedDate2,
        setSelectedDate2,
      ]}
    >
      {props.children}
    </AppContext.Provider>
  );
};

AppContextProvider.propTypes = {
  children: PropTypes.any,
};
