"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DocumentsCopyView = DocumentsCopyView;
exports.GetIntructionView2d = GetIntructionView2d;
exports.GetIntructionViewDoc = GetIntructionViewDoc;
exports.Liveness2dView = Liveness2dView;
exports.startDocumentscopy = startDocumentscopy;
exports.startFaceCaptcha = startFaceCaptcha;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _InstructionsView = _interopRequireDefault(require("./screens/Documentscopy/InstructionsView"));
var _InstructionsView2 = _interopRequireDefault(require("./screens/Liveness2D/InstructionsView"));
var _PermissionView = _interopRequireDefault(require("./screens/PermissionView"));
var _reactNativePermissions = require("react-native-permissions");
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 LINKING_ERROR = `The package '@oiti/rn-liveness2d' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
  ios: "- You have run 'pod install'\n",
  default: ''
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
const OitiReactNative = _reactNative.NativeModules.OitiReactNative ? _reactNative.NativeModules.OitiReactNative : new Proxy({}, {
  get() {
    throw new Error(LINKING_ERROR);
  }
});
const SCREEN = Object.freeze({
  INSTRUCTION_VIEW: 1,
  PERMISSION_VIEW: 2
});
function startFaceCaptcha(options) {
  var _options$apparence, _options$apparence2, _options$apparence3, _options$apparence4;
  let args = {
    appkey: (options === null || options === void 0 ? void 0 : options.appkey) === undefined ? '' : options === null || options === void 0 ? void 0 : options.appkey,
    ticket: (options === null || options === void 0 ? void 0 : options.appkey) === undefined ? '' : options === null || options === void 0 ? void 0 : options.ticket,
    environment: (options === null || options === void 0 ? void 0 : options.environment) === undefined ? '.HML' : options === null || options === void 0 ? void 0 : options.environment,
    apparence: {
      backgroundColor: (options === null || options === void 0 ? void 0 : (_options$apparence = options.apparence) === null || _options$apparence === void 0 ? void 0 : _options$apparence.backgroundColor) === '' ? '#1E1E1E' : options === null || options === void 0 ? void 0 : (_options$apparence2 = options.apparence) === null || _options$apparence2 === void 0 ? void 0 : _options$apparence2.backgroundColor,
      loadingColor: (options === null || options === void 0 ? void 0 : (_options$apparence3 = options.apparence) === null || _options$apparence3 === void 0 ? void 0 : _options$apparence3.loadingColor) === '' ? '#05D758' : options === null || options === void 0 ? void 0 : (_options$apparence4 = options.apparence) === null || _options$apparence4 === void 0 ? void 0 : _options$apparence4.loadingColor
    }
  };
  if (_reactNative.Platform.OS === 'android') {
    return OitiReactNative.startfacecaptcha(args.appkey);
  }
  return OitiReactNative.startfacecaptcha(args);
}
function startDocumentscopy(options) {
  var _options$apparence5, _options$apparence6, _options$apparence7, _options$apparence8;
  const args = {
    appkey: (options === null || options === void 0 ? void 0 : options.appkey) === undefined ? '' : options === null || options === void 0 ? void 0 : options.appkey,
    ticket: (options === null || options === void 0 ? void 0 : options.appkey) === undefined ? '' : options === null || options === void 0 ? void 0 : options.ticket,
    environment: (options === null || options === void 0 ? void 0 : options.environment) === undefined ? '.HML' : options === null || options === void 0 ? void 0 : options.environment,
    apparence: {
      backgroundColor: (options === null || options === void 0 ? void 0 : (_options$apparence5 = options.apparence) === null || _options$apparence5 === void 0 ? void 0 : _options$apparence5.backgroundColor) === '' ? '#1E1E1E' : options === null || options === void 0 ? void 0 : (_options$apparence6 = options.apparence) === null || _options$apparence6 === void 0 ? void 0 : _options$apparence6.backgroundColor,
      loadingColor: (options === null || options === void 0 ? void 0 : (_options$apparence7 = options.apparence) === null || _options$apparence7 === void 0 ? void 0 : _options$apparence7.loadingColor) === '' ? '#05D758' : options === null || options === void 0 ? void 0 : (_options$apparence8 = options.apparence) === null || _options$apparence8 === void 0 ? void 0 : _options$apparence8.loadingColor
    },
    custom: (options === null || options === void 0 ? void 0 : options.custom) === undefined ? null : options === null || options === void 0 ? void 0 : options.custom
  };
  if (_reactNative.Platform.OS === 'android') {
    return OitiReactNative.startdocumentscopy(args.appkey, args.ticket);
  }
  return OitiReactNative.startdocumentscopy(args);
}
function GetIntructionView2d(_ref) {
  let {
    CustomInstructionView,
    CustomPermissionView,
    options,
    navigation,
    callBackView
  } = _ref;
  const [screen, setScreen] = (0, _react.useState)(1);
  function onBack() {
    switch (screen) {
      case SCREEN.INSTRUCTION_VIEW:
        navigation.goBack(null);
        break;
      case SCREEN.PERMISSION_VIEW:
        setScreen(1);
        break;
    }
  }
  function verifyPermission() {
    _reactNative.Platform.OS === 'ios' ? (0, _reactNativePermissions.check)(_reactNativePermissions.PERMISSIONS.IOS.CAMERA).then(result => {
      switch (result) {
        case _reactNativePermissions.RESULTS.UNAVAILABLE:
          console.log('This feature is not available (on this device / in this context)');
          break;
        case _reactNativePermissions.RESULTS.DENIED:
          console.log('The permission has not been requested / is denied but requestable');
          if (screen === 1) {
            setScreen(2);
          } else {
            (0, _reactNativePermissions.request)(_reactNativePermissions.PERMISSIONS.IOS.CAMERA).then(() => {
              startFaceCaptcha(options).then(result => {
                console.log(result);
                navigation.navigate(callBackView);
              }, error => {
                console.log(error);
                navigation.navigate(callBackView);
              });
            });
          }
          break;
        case _reactNativePermissions.RESULTS.LIMITED:
          console.log('The permission is limited: some actions are possible');
          break;
        case _reactNativePermissions.RESULTS.GRANTED:
          startFaceCaptcha(options).then(result => {
            console.log(result);
            navigation.navigate(callBackView);
          }, error => {
            console.log(error);
            navigation.navigate(callBackView);
          });
          break;
        case _reactNativePermissions.RESULTS.BLOCKED:
          console.log('The permission is denied and not requestable anymore');
          setScreen(2);
          break;
      }
    }).catch(error => {
      console.log('Error: ' + error);
    }) : (0, _reactNativePermissions.check)(_reactNativePermissions.PERMISSIONS.ANDROID.CAMERA).then(result => {
      switch (result) {
        case _reactNativePermissions.RESULTS.UNAVAILABLE:
          console.log('This feature is not available (on this device / in this context)');
          break;
        case _reactNativePermissions.RESULTS.DENIED:
          console.log('The permission has not been requested / is denied but requestable');
          if (screen === 1) {
            setScreen(2);
          } else {
            (0, _reactNativePermissions.request)(_reactNativePermissions.PERMISSIONS.ANDROID.CAMERA).then(() => {
              startFaceCaptcha(options).then(result => {
                console.log(result);
                navigation.navigate(callBackView);
              }, error => {
                console.log(error);
                navigation.navigate(callBackView);
              });
            });
          }
          /* request(PERMISSIONS.IOS.CAMERA).then(() => {
          'The permission has enabled' + options?.appkey;
          }); */
          break;
        case _reactNativePermissions.RESULTS.LIMITED:
          console.log('The permission is limited: some actions are possible');
          break;
        case _reactNativePermissions.RESULTS.GRANTED:
          startFaceCaptcha(options).then(result => {
            console.log(result);
            navigation.navigate(callBackView);
          }, error => {
            console.log(error);
            navigation.navigate(callBackView);
          });
          break;
        case _reactNativePermissions.RESULTS.BLOCKED:
          console.log('The permission is denied and not requestable anymore');
          setScreen(2);
          break;
      }
    }).catch(error => {
      console.log('Error: ' + error);
    });
  }
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, screen === 1 && (!CustomInstructionView ? /*#__PURE__*/_react.default.createElement(_InstructionsView2.default, {
    onVerify: verifyPermission,
    onBack: onBack
  }) : CustomInstructionView), screen === 2 && (!CustomPermissionView ? /*#__PURE__*/_react.default.createElement(_PermissionView.default, {
    onVerify: verifyPermission,
    onBack: onBack
  }) : CustomPermissionView));
}
function GetIntructionViewDoc(_ref2) {
  let {
    CustomInstructionView,
    CustomPermissionView,
    options,
    navigation,
    callBackView
  } = _ref2;
  const [screen, setScreen] = (0, _react.useState)(1);
  function onBack() {
    switch (screen) {
      case SCREEN.INSTRUCTION_VIEW:
        navigation.goBack(null);
        break;
      case SCREEN.PERMISSION_VIEW:
        setScreen(1);
        break;
    }
  }
  function verifyPermission() {
    _reactNative.Platform.OS === 'ios' ? (0, _reactNativePermissions.check)(_reactNativePermissions.PERMISSIONS.IOS.CAMERA).then(result => {
      switch (result) {
        case _reactNativePermissions.RESULTS.UNAVAILABLE:
          console.log('This 22 feature is not available (on this device / in this context)');
          break;
        case _reactNativePermissions.RESULTS.DENIED:
          console.log('The permission has not been requested / is denied but requestable');
          if (screen === 1) {
            setScreen(2);
          } else {
            (0, _reactNativePermissions.request)(_reactNativePermissions.PERMISSIONS.IOS.CAMERA).then(() => {
              startDocumentscopy(options).then(result => {
                console.log(result);
                navigation.navigate(callBackView);
              }, error => {
                console.log(error);
              });
            });
          }
          break;
        case _reactNativePermissions.RESULTS.LIMITED:
          console.log('The permission is limited: some actions are possible');
          break;
        case _reactNativePermissions.RESULTS.GRANTED:
          startDocumentscopy(options).then(result => {
            console.log(result);
            navigation.navigate(callBackView);
          }, error => {
            console.log(error);
          });
          break;
        case _reactNativePermissions.RESULTS.BLOCKED:
          console.log('The permission is denied and not requestable anymore');
          setScreen(2);
          break;
      }
    }).catch(error => {
      console.log('Error: ' + error);
    }) : (0, _reactNativePermissions.check)(_reactNativePermissions.PERMISSIONS.ANDROID.CAMERA).then(result => {
      switch (result) {
        case _reactNativePermissions.RESULTS.UNAVAILABLE:
          console.log('This is not available (on this device / in this context)');
          break;
        case _reactNativePermissions.RESULTS.DENIED:
          console.log('The permission has not been requested / is denied but requestable');
          if (screen === 1) {
            setScreen(2);
          } else {
            (0, _reactNativePermissions.request)(_reactNativePermissions.PERMISSIONS.ANDROID.CAMERA).then(() => {
              startDocumentscopy(options).then(result => {
                console.log(result);
                navigation.navigate(callBackView);
              }, error => {
                console.log(error);
              });
            });
          }
          break;
        case _reactNativePermissions.RESULTS.LIMITED:
          console.log('The permission is limited: some actions are possible');
          break;
        case _reactNativePermissions.RESULTS.GRANTED:
          startDocumentscopy(options).then(result => {
            console.log(result);
            navigation.navigate(callBackView);
          }, error => {
            console.log(error);
          });
          break;
        case _reactNativePermissions.RESULTS.BLOCKED:
          console.log('The permission is denied and not requestable anymore');
          setScreen(2);
          break;
      }
    }).catch(error => {
      console.log('Error: ' + error);
    });
  }
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, screen === 1 && (!CustomInstructionView ? /*#__PURE__*/_react.default.createElement(_InstructionsView.default, {
    onVerify: verifyPermission,
    onBack: onBack
  }) : CustomInstructionView), screen === 2 && (!CustomPermissionView ? /*#__PURE__*/_react.default.createElement(_PermissionView.default, {
    onVerify: verifyPermission,
    onBack: onBack
  }) : CustomPermissionView));
}
function Liveness2dView(_ref3) {
  let {
    CustomInstructionView,
    CustomPermissionView,
    options,
    navigation,
    callbackView
  } = _ref3;
  return /*#__PURE__*/_react.default.createElement(GetIntructionView2d, {
    CustomInstructionView: CustomInstructionView,
    CustomPermissionView: CustomPermissionView,
    options: options,
    navigation: navigation,
    callBackView: callbackView
  });
}
function DocumentsCopyView(_ref4) {
  let {
    CustomInstructionView,
    CustomPermissionView,
    options,
    navigation,
    callbackView
  } = _ref4;
  return /*#__PURE__*/_react.default.createElement(GetIntructionViewDoc, {
    CustomInstructionView: CustomInstructionView,
    CustomPermissionView: CustomPermissionView,
    options: options,
    navigation: navigation,
    callBackView: callbackView
  });
}
//# sourceMappingURL=index.js.map