"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.reducer = exports.LoaderState = void 0;
var _react = require("react");
var _LoaderContext = require("./LoaderContext");
var _jsxRuntime = require("react/jsx-runtime");
const reducer = (state, _ref) => {
  let {
    type,
    payload
  } = _ref;
  switch (type) {
    case "status":
    default:
      return {
        visible: payload.visible
      };
  }
};
exports.reducer = reducer;
const LoaderState = props => {
  const [loader, dispatch] = (0, _react.useReducer)(reducer, {
    visible: true
  });
  const updateLoaderStatus = status => {
    const fn = () => {
      dispatch({
        type: "status",
        payload: {
          visible: status
        }
      });
    };
    if (status === false) {
      setTimeout(() => {
        fn();
      }, 1000);
    } else {
      fn();
    }
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_LoaderContext.LoaderContext.Provider, {
    value: {
      loader,
      updateLoaderStatus
    },
    children: props.children
  });
};
exports.LoaderState = LoaderState;