import React, { useReducer } from 'react';
import { attachmentReducer, AttachmentReducerDispatchType, IAttachemntState, initialAttachmentState } from './reducer/AttachemntReducer';

export interface IAttachmentStateContext {
    attachmentState: IAttachemntState;
}
const initialStateContext: IAttachmentStateContext = {
    attachmentState: initialAttachmentState
};
const initalDispatchContext: AttachmentReducerDispatchType = null;

export const AttachmentStateContext = React.createContext(initialStateContext);
export const AttachmentDispatchContext = React.createContext(initalDispatchContext);

export function AttachmentContextProvider({ children }) {
  const [attachmentState, dispatch] = useReducer(attachmentReducer, initialAttachmentState);
  return (
    <AttachmentStateContext.Provider value={{attachmentState}}>
      <AttachmentDispatchContext.Provider value={dispatch}>{children}</AttachmentDispatchContext.Provider>
    </AttachmentStateContext.Provider>
  );
}
