"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useSystem = exports.defaultConfig = exports.SystemProvider = exports.SystemContext = exports.MainContainer = void 0;
var _ariesBifoldVerifier = require("@hyperledger/aries-bifold-verifier");
var _legacy = require("@hyperledger/aries-oca/build/legacy");
var _react = require("react");
var bundle = _interopRequireWildcard(require("./assets/oca-bundles.json"));
var _Button = _interopRequireDefault(require("./components/buttons/Button"));
var _indy = _interopRequireDefault(require("./configs/ledgers/indy"));
var _constants = require("./constants");
var _containerApi = require("./container-api");
var _store = require("./contexts/reducers/store");
var _store2 = require("./contexts/store");
var _notifications = require("./hooks/notifications");
var _historyManager = _interopRequireDefault(require("./modules/history/context/historyManager"));
var _OnboardingStack = _interopRequireDefault(require("./navigators/OnboardingStack"));
var _defaultStackOptions = require("./navigators/defaultStackOptions");
var _Developer = _interopRequireDefault(require("./screens/Developer"));
var _Onboarding = _interopRequireDefault(require("./screens/Onboarding"));
var _Preface = _interopRequireDefault(require("./screens/Preface"));
var _Splash = _interopRequireDefault(require("./screens/Splash"));
var _Terms = _interopRequireWildcard(require("./screens/Terms"));
var _keychain = require("./services/keychain");
var _logger = require("./services/logger");
var _navigators = require("./types/navigators");
var _OnboardingPages = _interopRequireDefault(require("./screens/OnboardingPages"));
var _UseBiometry = _interopRequireDefault(require("./screens/UseBiometry"));
var _Scan = _interopRequireDefault(require("./screens/Scan"));
var _PINExplainer = _interopRequireDefault(require("./screens/PINExplainer"));
var _HomeHeaderView = _interopRequireDefault(require("./components/views/HomeHeaderView"));
var _HomeFooterView = _interopRequireDefault(require("./components/views/HomeFooterView"));
var _EmptyList = _interopRequireDefault(require("./components/misc/EmptyList"));
var _Record = _interopRequireDefault(require("./components/record/Record"));
var _NotificationListItem = _interopRequireDefault(require("./components/listItems/NotificationListItem"));
var _NoNewUpdates = _interopRequireDefault(require("./components/misc/NoNewUpdates"));
var _PINCreateHeader = _interopRequireDefault(require("./components/misc/PINCreateHeader"));
var _storage = require("./services/storage");
var _localization = require("./localization");
var _ContactListItem = _interopRequireDefault(require("./components/listItems/ContactListItem"));
var _ContactCredentialListItem = _interopRequireDefault(require("./components/listItems/ContactCredentialListItem"));
var _error = require("./types/error");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const defaultConfig = exports.defaultConfig = {
  PINSecurity: {
    rules: _constants.PINRules,
    displayHelper: false
  },
  settings: [],
  enableChat: true,
  enableTours: false,
  supportedLanguages: [_localization.Locales.en, _localization.Locales.fr, _localization.Locales.ptBr],
  showPreface: false,
  disableOnboardingSkip: false,
  whereToUseWalletUrl: 'https://example.com',
  showScanHelp: true,
  showScanButton: true,
  showDetailsInfo: true,
  contactDetailsOptions: {
    showConnectedTime: true,
    enableEditContactName: true,
    enableCredentialList: false
  }
};
class MainContainer {
  static TOKENS = _containerApi.TOKENS;
  constructor(container, log) {
    this._container = container;
    this.log = log;
    this.storage = new _storage.PersistentStorage(log);
  }
  get container() {
    return this._container;
  }
  init() {
    var _this$log;
    (_this$log = this.log) === null || _this$log === void 0 || _this$log.info(`Initializing Bifold container`);
    this._container.registerInstance(_containerApi.TOKENS.SCREEN_PREFACE, _Preface.default);
    this._container.registerInstance(_containerApi.TOKENS.SCREEN_DEVELOPER, _Developer.default);
    this._container.registerInstance(_containerApi.TOKENS.SCREEN_TERMS, {
      screen: _Terms.default,
      version: _Terms.TermsVersion
    });
    this._container.registerInstance(_containerApi.TOKENS.SCREEN_SPLASH, _Splash.default);
    this._container.registerInstance(_containerApi.TOKENS.SCREEN_ONBOARDING_PAGES, _OnboardingPages.default);
    this._container.registerInstance(_containerApi.TOKENS.COMPONENT_PIN_CREATE_HEADER, _PINCreateHeader.default);
    this._container.registerInstance(_containerApi.TOKENS.SCREEN_USE_BIOMETRY, _UseBiometry.default);
    this._container.registerInstance(_containerApi.TOKENS.SCREEN_SCAN, _Scan.default);
    this._container.registerInstance(_containerApi.TOKENS.SCREEN_ONBOARDING_ITEM, _Onboarding.default);
    this._container.registerInstance(_containerApi.TOKENS.SCREEN_ONBOARDING, _Onboarding.default);
    this._container.registerInstance(_containerApi.TOKENS.SCREEN_PIN_EXPLAINER, _PINExplainer.default);
    this._container.registerInstance(_containerApi.TOKENS.STACK_ONBOARDING, _OnboardingStack.default);
    this._container.registerInstance(_containerApi.TOKENS.COMP_BUTTON, _Button.default);
    this._container.registerInstance(_containerApi.TOKENS.GROUP_BY_REFERENT, false);
    this._container.registerInstance(_containerApi.TOKENS.HISTORY_ENABLED, false);
    this._container.registerInstance(_containerApi.TOKENS.CRED_HELP_ACTION_OVERRIDES, []);
    this._container.registerInstance(_containerApi.TOKENS.OBJECT_SCREEN_CONFIG, _defaultStackOptions.DefaultScreenOptionsDictionary);
    this._container.registerInstance(_containerApi.TOKENS.UTIL_LOGGER, new _logger.ConsoleLogger());
    this._container.registerInstance(_containerApi.TOKENS.UTIL_OCA_RESOLVER, new _legacy.DefaultOCABundleResolver(bundle));
    this._container.registerInstance(_containerApi.TOKENS.UTIL_LEDGERS, _indy.default);
    this._container.registerInstance(_containerApi.TOKENS.UTIL_PROOF_TEMPLATE, _ariesBifoldVerifier.getProofRequestTemplates);
    this._container.registerInstance(_containerApi.TOKENS.UTIL_ATTESTATION_MONITOR, {
      useValue: undefined
    });
    this._container.registerInstance(_containerApi.TOKENS.NOTIFICATIONS, {
      useNotifications: _notifications.useNotifications
    });
    this._container.registerInstance(_containerApi.TOKENS.NOTIFICATIONS_LIST_ITEM, _NotificationListItem.default);
    this._container.registerInstance(_containerApi.TOKENS.CONFIG, defaultConfig);
    this._container.registerInstance(_containerApi.TOKENS.COMPONENT_CRED_LIST_HEADER_RIGHT, () => null);
    this._container.registerInstance(_containerApi.TOKENS.COMPONENT_CRED_LIST_OPTIONS, () => null);
    this._container.registerInstance(_containerApi.TOKENS.COMPONENT_CRED_LIST_FOOTER, () => null);
    this._container.registerInstance(_containerApi.TOKENS.COMPONENT_HOME_HEADER, _HomeHeaderView.default);
    this._container.registerInstance(_containerApi.TOKENS.COMPONENT_HOME_NOTIFICATIONS_EMPTY_LIST, _NoNewUpdates.default);
    this._container.registerInstance(_containerApi.TOKENS.COMPONENT_HOME_FOOTER, _HomeFooterView.default);
    this._container.registerInstance(_containerApi.TOKENS.COMPONENT_CRED_EMPTY_LIST, _EmptyList.default);
    this._container.registerInstance(_containerApi.TOKENS.COMPONENT_RECORD, _Record.default);
    this._container.registerInstance(_containerApi.TOKENS.COMPONENT_CONTACT_LIST_ITEM, _ContactListItem.default);
    this._container.registerInstance(_containerApi.TOKENS.COMPONENT_CONTACT_DETAILS_CRED_LIST_ITEM, _ContactCredentialListItem.default);
    this._container.registerInstance(_containerApi.TOKENS.CACHE_CRED_DEFS, []);
    this._container.registerInstance(_containerApi.TOKENS.CACHE_SCHEMAS, []);
    this._container.registerInstance(_containerApi.TOKENS.INLINE_ERRORS, {
      enabled: true,
      position: _error.InlineErrorPosition.Above
    });
    this._container.registerInstance(_containerApi.TOKENS.FN_ONBOARDING_DONE, (dispatch, navigation) => {
      return () => {
        dispatch({
          type: _store.DispatchAction.DID_COMPLETE_TUTORIAL
        });
        navigation.navigate(_navigators.Screens.Terms);
      };
    });
    this._container.registerInstance(_containerApi.TOKENS.FN_LOAD_HISTORY, agent => {
      return new _historyManager.default(agent);
    });
    this._container.registerInstance(_containerApi.TOKENS.CUSTOM_NAV_STACK_1, false);
    this._container.registerInstance(_containerApi.TOKENS.LOAD_STATE, async dispatch => {
      const loadState = async (key, updateVal) => {
        const data = await this.storage.getValueForKey(key);
        if (data) {
          // @ts-expect-error Fix complicated type error
          updateVal(data);
        }
      };
      let loginAttempt = _store2.defaultState.loginAttempt;
      let preferences = _store2.defaultState.preferences;
      let migration = _store2.defaultState.migration;
      let tours = _store2.defaultState.tours;
      let onboarding = _store2.defaultState.onboarding;
      await Promise.all([(0, _keychain.loadLoginAttempt)().then(data => {
        if (data) {
          loginAttempt = data;
        }
      }), loadState(_constants.LocalStorageKeys.Preferences, val => preferences = val), loadState(_constants.LocalStorageKeys.Migration, val => migration = val), loadState(_constants.LocalStorageKeys.Tours, val => tours = val), loadState(_constants.LocalStorageKeys.Onboarding, val => onboarding = val)]);
      const state = {
        loginAttempt: {
          ..._store2.defaultState.loginAttempt,
          ...loginAttempt
        },
        preferences: {
          ..._store2.defaultState.preferences,
          ...preferences
        },
        migration: {
          ..._store2.defaultState.migration,
          ...migration
        },
        tours: {
          ..._store2.defaultState.tours,
          ...tours
        },
        onboarding: {
          ..._store2.defaultState.onboarding,
          ...onboarding
        }
      };
      dispatch({
        type: _store.DispatchAction.STATE_DISPATCH,
        payload: [state]
      });
    });
    return this;
  }
  resolve(token) {
    return this._container.resolve(token);
  }
  resolveAll(tokens) {
    return tokens.map(key => this.resolve(key));
  }
}
exports.MainContainer = MainContainer;
const SystemContext = exports.SystemContext = /*#__PURE__*/(0, _react.createContext)(undefined);
const SystemProvider = exports.SystemProvider = SystemContext.Provider;

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const useSystem = () => (0, _react.useContext)(SystemContext);
exports.useSystem = useSystem;
//# sourceMappingURL=container-impl.js.map