"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactHooks = require("@credo-ts/react-hooks");
var _ariesBifoldVerifier = require("@hyperledger/aries-bifold-verifier");
var _react = _interopRequireWildcard(require("react"));
var _reactI18next = require("react-i18next");
var _reactNative = require("react-native");
var _PresentationLoading = _interopRequireDefault(require("../components/animated/PresentationLoading"));
var _Button = _interopRequireWildcard(require("../components/buttons/Button"));
var _theme = require("../contexts/theme");
var _connections = require("../hooks/connections");
var _navigators = require("../types/navigators");
var _testable = require("../utils/testable");
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 MobileVerifierLoading = _ref => {
  var _useOutOfBandByConnec;
  let {
    navigation,
    route
  } = _ref;
  const {
    proofId,
    connectionId
  } = route.params;
  const goalCode = (_useOutOfBandByConnec = (0, _connections.useOutOfBandByConnectionId)(connectionId)) === null || _useOutOfBandByConnec === void 0 ? void 0 : _useOutOfBandByConnec.outOfBandInvitation.goalCode;
  const proofRecord = (0, _reactHooks.useProofById)(proofId);
  const {
    ColorPallet,
    TextTheme
  } = (0, _theme.useTheme)();
  const {
    agent
  } = (0, _reactHooks.useAgent)();
  if (!agent) {
    throw new Error('Unable to fetch agent from Credo');
  }
  const {
    t
  } = (0, _reactI18next.useTranslation)();
  const styles = _reactNative.StyleSheet.create({
    container: {
      height: '100%',
      backgroundColor: ColorPallet.brand.modalPrimaryBackground,
      padding: 20
    },
    image: {
      marginTop: 20
    },
    messageContainer: {
      alignItems: 'center'
    },
    messageText: {
      fontWeight: TextTheme.normal.fontWeight,
      textAlign: 'center',
      marginTop: 30
    },
    controlsContainer: {
      marginTop: 'auto',
      margin: 20
    },
    delayMessageText: {
      textAlign: 'center',
      marginTop: 20
    }
  });
  const onDismissModalTouched = () => {
    navigation.pop();
  };
  (0, _react.useEffect)(() => {
    if (proofRecord && ((0, _ariesBifoldVerifier.isPresentationReceived)(proofRecord) || (0, _ariesBifoldVerifier.isPresentationFailed)(proofRecord))) {
      if (goalCode !== null && goalCode !== void 0 && goalCode.endsWith('verify.once')) {
        agent.connections.deleteById(connectionId);
      }
      navigation.replace(_navigators.Screens.ProofDetails, {
        recordId: proofRecord.id
      });
    }
  }, [proofRecord]);
  return /*#__PURE__*/_react.default.createElement(_reactNative.Modal, {
    transparent: true,
    animationType: 'slide'
  }, /*#__PURE__*/_react.default.createElement(_reactNative.SafeAreaView, {
    style: {
      backgroundColor: ColorPallet.brand.modalPrimaryBackground
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, {
    style: [styles.container]
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: [styles.messageContainer]
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
    style: [TextTheme.modalHeadingThree, styles.messageText],
    testID: (0, _testable.testIdWithKey)('VerifierLoading')
  }, t('Verifier.WaitingForResponse'))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: [styles.image]
  }, /*#__PURE__*/_react.default.createElement(_PresentationLoading.default, null))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: [styles.controlsContainer]
  }, /*#__PURE__*/_react.default.createElement(_Button.default, {
    title: t('Global.GoBack'),
    accessibilityLabel: t('Global.GoBack'),
    testID: (0, _testable.testIdWithKey)('BackToProofList'),
    onPress: onDismissModalTouched,
    buttonType: _Button.ButtonType.ModalSecondary
  }))));
};
var _default = MobileVerifierLoading;
exports.default = _default;
//# sourceMappingURL=MobileVerifierLoading.js.map