"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _reactNativeOrientation = _interopRequireDefault(require("react-native-orientation"));

var _reactNative = require("react-native");

var _react = _interopRequireWildcard(require("react"));

var _Colors = _interopRequireDefault(require("./Colors"));

var _reactNativeCamera = require("react-native-camera");

var _FontAwesome = _interopRequireDefault(require("react-native-vector-icons/FontAwesome"));

var _reactMoment = _interopRequireDefault(require("react-moment"));

var _geolocation = _interopRequireDefault(require("@react-native-community/geolocation"));

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; }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

const leftFlex = 0.85;
const rightFlex = 0.15;

const crossMark = require('./Image/crossMark.png');

const startRecording = require('./Image/startRecording.png');

const stopRecording = require('./Image/stopRecording.png');

const tickMark = require('./Image/tickMark.png');

const topLeft = require('./Image/topLeft.png');

const topRight = require('./Image/topRight.png');

const leftBottom = require('./Image/leftBottom.png');

const rightBottom = require('./Image/rightBottom.png');

const flashIcon = require('./Image/flash.png');

let SCREEN_WIDTH;
let SCREEN_HEIGHT;
const FLASH_LIGHT = [_reactNativeCamera.RNCamera.Constants.FlashMode.off, _reactNativeCamera.RNCamera.Constants.FlashMode.auto, _reactNativeCamera.RNCamera.Constants.FlashMode.on, _reactNativeCamera.RNCamera.Constants.FlashMode.torch];
let FLASH_INDEX = 0;

class VideoRecorder extends _react.Component {
  constructor(props) {
    super(props);

    _defineProperty(this, "_orientationDidChange", orientation => {
      if (orientation === 'LANDSCAPE') {
        // do something with landscape layoutr
        SCREEN_HEIGHT = Math.round(_reactNative.Dimensions.get('window').height);
        SCREEN_WIDTH = Math.round(_reactNative.Dimensions.get('window').width);
      } else {
        // do something with portrait layout   
        SCREEN_HEIGHT = Math.round(_reactNative.Dimensions.get('window').width);
        SCREEN_WIDTH = Math.round(_reactNative.Dimensions.get('window').height);
      }
    });

    this.state = {
      isDisplayQuoteInstruction: true,
      isWithQuote: true,
      isWithOutQuote: false,
      isDisplayInstruction: false,
      torchon: '',
      isDisplayCameraPreview: false,
      isDisplayCamera: false,
      localPath: '',
      flashState: _reactNativeCamera.RNCamera.Constants.FlashMode.off,
      //for flash
      dateAndTime: '',
      //date and time
      currentLongitude: 'unknown',
      //Initial Longitude
      currentLatitude: 'unknown',
      //Initial Latitude
      isDisplayVideoRecorder: false,
      fullDataSource: '',
      assets: '',
      headerShown: false,
      count: 0,
      dataSource: '',
      cameraState: '',
      buttonText: '',
      skipdata: '',
      isBackButtonPressed: false,
      isSkipButtonPressed: false,
      screenShotPath: '',
      isDisplayUploadDocument: false,
      upLoadIamgeDataSource: [],
      documentUploadPercentage: 0,
      odometerReading: '',
      ANDROID_ID: '',
      CurrentDate: '',
      showError: false,
      isLoading: true,
      registrationNumber: '',
      isSelected: false,
      isFocused: false,
      staincil: this.props.navigation.state.params.staincil,
      count: this.props.navigation.state.params.count,
      productImage: this.props.navigation.state.params.productImage,
      extention: this.props.navigation.state.params.extention,
      stepTitle: this.props.navigation.state.params.stepTitle,
      instructionData: this.props.navigation.state.params.instructionData
    };
  }
  /*
                            %%%%%%%%%%%%% For Video Record %%%%%%%%%%%%%%%%
  */


  async startRecording() {
    this.setState({
      recording: true
    }); // default to mp4 for android as codec is not set

    const options = {
      quality: 0.2,
      base64: true
    };
    const {
      uri,
      codec = "mp4"
    } = await this.camera.recordAsync(options);
    this.setState({
      localPath: uri
    });
    setTimeout(() => {
      this.props.navigation.navigate("VideoPreview", {
        localPath: this.state.localPath,
        finalWatermarkResult: this.state.finalWatermarkResult,
        count: this.state.count,
        productImage: this.state.productImage,
        stepTitle: this.state.stepTitle,
        extention: this.state.extention,
        instructionData: this.state.instructionData
      });
    }, 500);
  } //Stop Recording


  stopRecording() {
    this.camera.stopRecording();
    this.setState({
      flashState: _reactNativeCamera.RNCamera.Constants.FlashMode.off
    });
    this.setState({
      recording: false
    });
  }

  componentDidMount() {
    // this locks the view to Portrait Mode
    const initial = _reactNativeOrientation.default.getInitialOrientation();

    _reactNativeOrientation.default.addOrientationListener(this._orientationDidChange);

    _reactNativeOrientation.default.lockToLandscapeLeft();

    if (initial === 'PORTRAIT') {
      // do something
      SCREEN_HEIGHT = Math.round(_reactNative.Dimensions.get('window').height);
      SCREEN_WIDTH = Math.round(_reactNative.Dimensions.get('window').width);
    } else {
      // do something else
      SCREEN_HEIGHT = Math.round(_reactNative.Dimensions.get('window').height);
      SCREEN_WIDTH = Math.round(_reactNative.Dimensions.get('window').width);
    }
  }

  componentWillUnmount() {
    _reactNativeOrientation.default.removeOrientationListener(this._orientationDidChange);
  }

  render() {
    _reactNativeOrientation.default.lockToLandscapeLeft();

    SCREEN_HEIGHT = Math.round(_reactNative.Dimensions.get('window').height);
    SCREEN_WIDTH = Math.round(_reactNative.Dimensions.get('window').width);
    const {
      recording,
      processing
    } = this.state;

    let button = /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 1,
        flexDirection: 'column'
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 0.7
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
      onPress: () => [this.startRecording()],
      style: styles.capture
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
      source: startRecording,
      style: {
        width: 70,
        height: 70
      }
    }))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 0.3
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
      onPress: () => this.toggleTorch(),
      style: styles.capture
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
      source: flashIcon,
      style: {
        width: 70,
        height: 70
      }
    })), /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
      style: styles.torchTitle
    }, this.getFlashTorch(this.state.flashState))));

    if (recording) {
      button = /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          flex: 1,
          flexDirection: 'column'
        }
      }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          flex: 0.7
        }
      }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
        onPress: () => [this.stopRecording()],
        style: styles.capture
      }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
        source: stopRecording,
        style: {
          width: 70,
          height: 70
        }
      }))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          flex: 0.3
        }
      }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
        onPress: () => this.toggleTorch(),
        style: styles.capture
      }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
        source: flashIcon,
        style: {
          width: 70,
          height: 70
        }
      })), /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
        style: styles.torchTitle
      }, this.getFlashTorch(this.state.flashState))));
    }

    return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: styles.container
    }, /*#__PURE__*/_react.default.createElement(_reactNative.StatusBar, {
      hidden: true
    }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 1,
        flexDirection: 'row'
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNativeCamera.RNCamera, {
      ref: ref => {
        this.camera = ref;
      },
      style: [styles.preview, {
        flex: leftFlex
      }],
      type: this.state.cameraState,
      flashMode: this.state.flashState,
      androidCameraPermissionOptions: {
        title: 'Permission to use camera',
        message: 'We need your permission to use your camera',
        buttonPositive: 'Ok',
        buttonNegative: 'Cancel'
      },
      androidRecordAudioPermissionOptions: {
        title: 'Permission to use audio recording',
        message: 'We need your permission to use your audio',
        buttonPositive: 'Ok',
        buttonNegative: 'Cancel'
      } // pausePreview={true}
      // pauseAfterCapture={true}
      ,
      autoFocus: true
    }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        backgroundColor: _Colors.default.greyBlack,
        flex: rightFlex
      }
    }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 1,
        flexDirection: 'row',
        position: 'absolute',
        width: SCREEN_WIDTH,
        height: SCREEN_HEIGHT
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: leftFlex,
        flexDirection: 'column'
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 1,
        flexDirection: 'row',
        justifyContent: 'space-between'
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
      source: topLeft,
      style: {
        width: 70,
        height: 70,
        left: 1,
        resizeMode: 'contain'
      }
    }), /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
      source: topRight,
      style: {
        width: 70,
        height: 70,
        right: 1,
        resizeMode: 'contain'
      }
    })), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 1,
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'flex-end'
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
      source: leftBottom,
      style: {
        width: 70,
        height: 70,
        left: 1,
        bottom: 1,
        resizeMode: 'contain'
      }
    }), /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
      source: rightBottom,
      style: {
        width: 70,
        height: 70,
        right: 1,
        bottom: 1,
        resizeMode: 'contain'
      }
    }))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: rightFlex,
        flexDirection: 'column'
      }
    }, button)), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 1,
        flexDirection: 'row',
        position: 'absolute',
        width: SCREEN_WIDTH,
        height: SCREEN_HEIGHT
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: leftFlex,
        justifyContent: 'center',
        alignItems: 'center'
      }
    }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: rightFlex
      }
    }))));
  }

  getStencilView() {
    if (this.state.staincil) return /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
      source: {
        uri: this.state.staincil
      },
      style: {
        width: SCREEN_WIDTH - 50,
        height: SCREEN_HEIGHT,
        position: 'absolute',
        marginRight: 15,
        marginLeft: 15,
        resizeMode: 'contain'
      }
    });else return null;
  }

  toggleTorch() {
    FLASH_INDEX = FLASH_INDEX + 1;
    if (FLASH_INDEX == FLASH_LIGHT.length) FLASH_INDEX = 0;
    this.setState({
      flashState: FLASH_LIGHT[FLASH_INDEX]
    });
  }

  getFlashTorch(activeFlashType) {
    switch (activeFlashType) {
      case _reactNativeCamera.RNCamera.Constants.FlashMode.off:
        return "off";

      case _reactNativeCamera.RNCamera.Constants.FlashMode.auto:
        return "auto";

      case _reactNativeCamera.RNCamera.Constants.FlashMode.on:
        return "on";

      case _reactNativeCamera.RNCamera.Constants.FlashMode.torch:
        return "torch";

      default:
        return "off";
    }
  }

}

exports.default = VideoRecorder;

const styles = _reactNative.StyleSheet.create({
  main: {
    flex: 1,
    flexDirection: 'row'
  },
  productImageView: {
    flex: 0.475
  },
  blankView: {
    flex: 0.05
  },
  productInfoView: {
    flex: 0.475,
    marginRight: 16,
    width: SCREEN_WIDTH,
    height: SCREEN_HEIGHT
  },
  headerView: {
    backgroundColor: '#C6AFFF',
    height: 40,
    justifyContent: 'center'
  },
  headerText: {
    marginLeft: 16,
    fontSize: 20,
    fontFamily: 'Muli-Black'
  },
  productImageStyle: {
    marginTop: 8,
    marginLeft: 16,
    marginBottom: 40,
    height: SCREEN_HEIGHT - 70
  },
  backButtonImageStyle: {
    marginLeft: 32,
    height: 24,
    width: 24,
    backgroundColor: 'red'
  },
  subHeaderText: {
    fontFamily: 'Mulli-Regular',
    fontSize: 16,
    marginLeft: 16
  },
  instructionText: {
    fontFamily: 'Mulli-Regular',
    fontSize: 16,
    marginLeft: 16,
    marginBottom: 20
  },
  captureImageButtonView: {
    height: 48,
    borderRadius: 4,
    backgroundColor: _Colors.default.digitYellow,
    marginTop: 2,
    flexDirection: 'row',
    justifyContent: 'center'
  },
  captureImageButtonText: {
    fontSize: 16,
    fontFamily: 'Muli-Black',
    alignSelf: 'center'
  },
  container: {
    flex: 1 // flexDirection: 'row',
    // backgroundColor: 'black',

  },
  preview: {
    flex: 1,
    justifyContent: 'flex-end',
    alignItems: 'center'
  },
  capture: {
    flex: leftFlex,
    alignItems: 'center',
    justifyContent: 'flex-end'
  },
  torchTitle: {
    alignSelf: 'center',
    justifyContent: 'center',
    fontFamily: 'Muli-Bold',
    color: _Colors.default.white
  },
  flash: {
    flex: rightFlex,
    alignItems: 'center'
  },
  previewImageStyle: {
    width: SCREEN_WIDTH,
    height: SCREEN_HEIGHT
  },
  dateAndTimeText: {
    position: 'absolute',
    fontSize: 20,
    color: _Colors.default.digitYellow,
    left: 1,
    bottom: 1
  },
  previewImageIconMainView: {
    flex: 0.05,
    backgroundColor: 'black'
  },
  tickMarkImageView: {
    flex: 0.6,
    justifyContent: 'flex-end'
  },
  tickMarkImageStyle: {
    width: 30,
    height: 30,
    backgroundColor: 'white',
    alignContent: 'flex-end',
    marginBottom: 20
  },
  crossImageView: {
    flex: 0.4,
    justifyContent: 'flex-end',
    marginBottom: 20
  },
  crossImageStyle: {
    width: 30,
    height: 30,
    backgroundColor: 'white',
    alignContent: 'flex-end'
  },
  cameraIconView: {
    flexDirection: 'row',
    justifyContent: 'center',
    width: SCREEN_WIDTH,
    position: 'absolute'
  },
  infoScrollView: {
    marginTop: 40,
    height: SCREEN_HEIGHT - 200
  },
  subHeaderTextView: {
    height: 40,
    marginTop: 8
  },
  backButtonImageView: {
    backgroundColor: '#C6AFFF',
    height: 40,
    justifyContent: 'center',
    marginLeft: 16
  },
  latLongText: {
    position: 'absolute',
    fontSize: 20,
    color: _Colors.default.digitYellow,
    left: 1
  },
  digitEdgeText: {
    position: 'absolute',
    fontSize: 20,
    color: _Colors.default.digitYellow,
    right: 1
  }
});
//# sourceMappingURL=VideoRecorder.js.map