import React, { useState } from 'react';
import { NativeModules, Platform } from 'react-native';
import InstructionsView from './screens/Documentscopy/InstructionsView';
import InstructionsView2D from './screens/Liveness2D/InstructionsView';
import PermissionView from './screens/PermissionView';
import { check, request, PERMISSIONS, RESULTS } from 'react-native-permissions';
const LINKING_ERROR = `The package '@oiti/rn-liveness2d' doesn't seem to be linked. Make sure: \n\n` + 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 = NativeModules.OitiReactNative ? NativeModules.OitiReactNative : new Proxy({}, {
  get() {
    throw new Error(LINKING_ERROR);
  }
});
const SCREEN = Object.freeze({
  INSTRUCTION_VIEW: 1,
  PERMISSION_VIEW: 2
});
export 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 (Platform.OS === 'android') {
    return OitiReactNative.startfacecaptcha(args.appkey);
  }
  return OitiReactNative.startfacecaptcha(args);
}
export 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 (Platform.OS === 'android') {
    return OitiReactNative.startdocumentscopy(args.appkey, args.ticket);
  }
  return OitiReactNative.startdocumentscopy(args);
}
export function GetIntructionView2d(_ref) {
  let {
    CustomInstructionView,
    CustomPermissionView,
    options,
    navigation,
    callBackView
  } = _ref;
  const [screen, setScreen] = useState(1);
  function onBack() {
    switch (screen) {
      case SCREEN.INSTRUCTION_VIEW:
        navigation.goBack(null);
        break;
      case SCREEN.PERMISSION_VIEW:
        setScreen(1);
        break;
    }
  }
  function verifyPermission() {
    Platform.OS === 'ios' ? check(PERMISSIONS.IOS.CAMERA).then(result => {
      switch (result) {
        case RESULTS.UNAVAILABLE:
          console.log('This feature is not available (on this device / in this context)');
          break;
        case RESULTS.DENIED:
          console.log('The permission has not been requested / is denied but requestable');
          if (screen === 1) {
            setScreen(2);
          } else {
            request(PERMISSIONS.IOS.CAMERA).then(() => {
              startFaceCaptcha(options).then(result => {
                console.log(result);
                navigation.navigate(callBackView);
              }, error => {
                console.log(error);
                navigation.navigate(callBackView);
              });
            });
          }
          break;
        case RESULTS.LIMITED:
          console.log('The permission is limited: some actions are possible');
          break;
        case RESULTS.GRANTED:
          startFaceCaptcha(options).then(result => {
            console.log(result);
            navigation.navigate(callBackView);
          }, error => {
            console.log(error);
            navigation.navigate(callBackView);
          });
          break;
        case RESULTS.BLOCKED:
          console.log('The permission is denied and not requestable anymore');
          setScreen(2);
          break;
      }
    }).catch(error => {
      console.log('Error: ' + error);
    }) : check(PERMISSIONS.ANDROID.CAMERA).then(result => {
      switch (result) {
        case RESULTS.UNAVAILABLE:
          console.log('This feature is not available (on this device / in this context)');
          break;
        case RESULTS.DENIED:
          console.log('The permission has not been requested / is denied but requestable');
          if (screen === 1) {
            setScreen(2);
          } else {
            request(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 RESULTS.LIMITED:
          console.log('The permission is limited: some actions are possible');
          break;
        case RESULTS.GRANTED:
          startFaceCaptcha(options).then(result => {
            console.log(result);
            navigation.navigate(callBackView);
          }, error => {
            console.log(error);
            navigation.navigate(callBackView);
          });
          break;
        case RESULTS.BLOCKED:
          console.log('The permission is denied and not requestable anymore');
          setScreen(2);
          break;
      }
    }).catch(error => {
      console.log('Error: ' + error);
    });
  }
  return /*#__PURE__*/React.createElement(React.Fragment, null, screen === 1 && (!CustomInstructionView ? /*#__PURE__*/React.createElement(InstructionsView2D, {
    onVerify: verifyPermission,
    onBack: onBack
  }) : CustomInstructionView), screen === 2 && (!CustomPermissionView ? /*#__PURE__*/React.createElement(PermissionView, {
    onVerify: verifyPermission,
    onBack: onBack
  }) : CustomPermissionView));
}
export function GetIntructionViewDoc(_ref2) {
  let {
    CustomInstructionView,
    CustomPermissionView,
    options,
    navigation,
    callBackView
  } = _ref2;
  const [screen, setScreen] = useState(1);
  function onBack() {
    switch (screen) {
      case SCREEN.INSTRUCTION_VIEW:
        navigation.goBack(null);
        break;
      case SCREEN.PERMISSION_VIEW:
        setScreen(1);
        break;
    }
  }
  function verifyPermission() {
    Platform.OS === 'ios' ? check(PERMISSIONS.IOS.CAMERA).then(result => {
      switch (result) {
        case RESULTS.UNAVAILABLE:
          console.log('This 22 feature is not available (on this device / in this context)');
          break;
        case RESULTS.DENIED:
          console.log('The permission has not been requested / is denied but requestable');
          if (screen === 1) {
            setScreen(2);
          } else {
            request(PERMISSIONS.IOS.CAMERA).then(() => {
              startDocumentscopy(options).then(result => {
                console.log(result);
                navigation.navigate(callBackView);
              }, error => {
                console.log(error);
              });
            });
          }
          break;
        case RESULTS.LIMITED:
          console.log('The permission is limited: some actions are possible');
          break;
        case RESULTS.GRANTED:
          startDocumentscopy(options).then(result => {
            console.log(result);
            navigation.navigate(callBackView);
          }, error => {
            console.log(error);
          });
          break;
        case RESULTS.BLOCKED:
          console.log('The permission is denied and not requestable anymore');
          setScreen(2);
          break;
      }
    }).catch(error => {
      console.log('Error: ' + error);
    }) : check(PERMISSIONS.ANDROID.CAMERA).then(result => {
      switch (result) {
        case RESULTS.UNAVAILABLE:
          console.log('This is not available (on this device / in this context)');
          break;
        case RESULTS.DENIED:
          console.log('The permission has not been requested / is denied but requestable');
          if (screen === 1) {
            setScreen(2);
          } else {
            request(PERMISSIONS.ANDROID.CAMERA).then(() => {
              startDocumentscopy(options).then(result => {
                console.log(result);
                navigation.navigate(callBackView);
              }, error => {
                console.log(error);
              });
            });
          }
          break;
        case RESULTS.LIMITED:
          console.log('The permission is limited: some actions are possible');
          break;
        case RESULTS.GRANTED:
          startDocumentscopy(options).then(result => {
            console.log(result);
            navigation.navigate(callBackView);
          }, error => {
            console.log(error);
          });
          break;
        case RESULTS.BLOCKED:
          console.log('The permission is denied and not requestable anymore');
          setScreen(2);
          break;
      }
    }).catch(error => {
      console.log('Error: ' + error);
    });
  }
  return /*#__PURE__*/React.createElement(React.Fragment, null, screen === 1 && (!CustomInstructionView ? /*#__PURE__*/React.createElement(InstructionsView, {
    onVerify: verifyPermission,
    onBack: onBack
  }) : CustomInstructionView), screen === 2 && (!CustomPermissionView ? /*#__PURE__*/React.createElement(PermissionView, {
    onVerify: verifyPermission,
    onBack: onBack
  }) : CustomPermissionView));
}
export function Liveness2dView(_ref3) {
  let {
    CustomInstructionView,
    CustomPermissionView,
    options,
    navigation,
    callbackView
  } = _ref3;
  return /*#__PURE__*/React.createElement(GetIntructionView2d, {
    CustomInstructionView: CustomInstructionView,
    CustomPermissionView: CustomPermissionView,
    options: options,
    navigation: navigation,
    callBackView: callbackView
  });
}
export function DocumentsCopyView(_ref4) {
  let {
    CustomInstructionView,
    CustomPermissionView,
    options,
    navigation,
    callbackView
  } = _ref4;
  return /*#__PURE__*/React.createElement(GetIntructionViewDoc, {
    CustomInstructionView: CustomInstructionView,
    CustomPermissionView: CustomPermissionView,
    options: options,
    navigation: navigation,
    callBackView: callbackView
  });
}
//# sourceMappingURL=index.js.map