import * as _ from "lodash";
import React from "react";

export type ModalContext = {
  isCreateJiraIssueModalOpen: boolean;
  setIsCreateJiraIssueModalOpen: (val: boolean) => void;
  dataForCreateJiraModal: any;
  setDataForCreateJiraModal: (val: any) => void;
  // create view modal
  isCreateViewModalOpen: boolean;
  setIsCreateViewModalOpen: (val: boolean) => void;
  dataForCreateViewModal: any;
  setDataForCreateViewModal: (val: any) => void;
};

export const ModalContext = React.createContext<ModalContext>({
  isCreateJiraIssueModalOpen: false,
  dataForCreateJiraModal: {},
  setIsCreateJiraIssueModalOpen: _.noop,
  setDataForCreateJiraModal: _.noop,
  // Create view modal
  isCreateViewModalOpen: false,
  dataForCreateViewModal: {},
  setIsCreateViewModalOpen: _.noop,
  setDataForCreateViewModal: _.noop,
});

function ModalProvider(props: { children: React.ReactChild }) {
  const [
    isCreateJiraIssueModalOpen,
    setIsCreateJiraIssueModalOpen,
  ] = React.useState(false);
  const [dataForCreateJiraModal, setDataForCreateJiraModal] = React.useState<
    any
  >({});
  // create view modal
  const [isCreateViewModalOpen, setIsCreateViewModalOpen] = React.useState(
    false
  );
  const [dataForCreateViewModal, setDataForCreateViewModal] = React.useState<
    any
  >({});
  1;
  return (
    <ModalContext.Provider
      value={{
        isCreateJiraIssueModalOpen,
        setIsCreateJiraIssueModalOpen,
        setDataForCreateJiraModal,
        dataForCreateJiraModal,
        isCreateViewModalOpen,
        setIsCreateViewModalOpen,
        dataForCreateViewModal,
        setDataForCreateViewModal,
      }}
    >
      {props.children}
    </ModalContext.Provider>
  );
}

export const useModalContext = () => React.useContext(ModalContext);

export default ModalProvider;
