"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useStore = exports.mergeReducers = exports.defaultState = exports.defaultReducer = exports.StoreProvider = exports.StoreContext = void 0;
var _react = _interopRequireWildcard(require("react"));
var _helpers = require("../utils/helpers");
var _store = _interopRequireDefault(require("./reducers/store"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const defaultState = {
  onboarding: {
    didSeePreface: false,
    didAgreeToTerms: false,
    didCompleteTutorial: false,
    didCreatePIN: false,
    didConsiderPushNotifications: false,
    didConsiderBiometry: false,
    didNameWallet: false,
    onboardingVersion: 0,
    didCompleteOnboarding: false,
    postAuthScreens: []
  },
  authentication: {
    didAuthenticate: false
  },
  // NOTE: from Credo 0.4.0 on we use Aries Askar. New wallets will be created with Askar from the start
  // which we will know when we create the pin while using askar as a dependency.
  migration: {
    didMigrateToAskar: false
  },
  loginAttempt: {
    loginAttempts: 0,
    servedPenalty: true
  },
  lockout: {
    displayNotification: false
  },
  preferences: {
    developerModeEnabled: false,
    biometryPreferencesUpdated: false,
    useBiometry: false,
    usePushNotifications: false,
    useVerifierCapability: false,
    useConnectionInviterCapability: false,
    useDevVerifierTemplates: false,
    acceptDevCredentials: false,
    useDataRetention: true,
    enableWalletNaming: false,
    walletName: (0, _helpers.generateRandomWalletName)(),
    preventAutoLock: false,
    alternateContactNames: {}
  },
  tours: {
    seenToursPrompt: false,
    enableTours: true,
    seenHomeTour: false,
    seenCredentialsTour: false,
    seenCredentialOfferTour: false,
    seenProofRequestTour: false
  },
  deepLink: {
    activeDeepLink: ''
  },
  loading: false,
  stateLoaded: false
};
exports.defaultState = defaultState;
const StoreContext = /*#__PURE__*/(0, _react.createContext)([defaultState, () => {
  return;
}]);
exports.StoreContext = StoreContext;
const mergeReducers = (a, b) => {
  return (state, action) => {
    return a(b(state, action), action);
  };
};
exports.mergeReducers = mergeReducers;
const defaultReducer = _store.default;
exports.defaultReducer = defaultReducer;
const StoreProvider = _ref => {
  let {
    children,
    initialState,
    reducer
  } = _ref;
  const _reducer = reducer ?? defaultReducer;
  const _state = initialState ?? defaultState;
  const [state, dispatch] = (0, _react.useReducer)(_reducer, _state);
  return /*#__PURE__*/_react.default.createElement(StoreContext.Provider, {
    value: [state, dispatch]
  }, children);
};
exports.StoreProvider = StoreProvider;
const useStore = () => {
  const context = (0, _react.useContext)(StoreContext);
  return context;
};
exports.useStore = useStore;
//# sourceMappingURL=store.js.map