import type { Reducer } from "react";

import type { IConfirmContextState } from "./ConfirmContext";

export const SHOW_CONFIRM = "SHOW_CONFIRM";
export const HIDE_CONFIRM = "HIDE_CONFIRM";

export const initialState: IConfirmContextState = {
  show: false,
  text: null,
};

export const reducer: Reducer<
  IConfirmContextState,
  { type: "HIDE_CONFIRM" } | { payload: { text: string }; type: "SHOW_CONFIRM" }
> = (_, action) => {
  switch (action.type) {
    case SHOW_CONFIRM:
      return {
        show: true,
        text: action.payload.text,
      };
    case HIDE_CONFIRM:
      return initialState;
    default:
      return initialState;
  }
};
