"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")
);

var _reactNativeImageMarker = _interopRequireDefault(
  require("react-native-image-marker")
);

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 initial = _reactNativeOrientation.default.getInitialOrientation();

let SCREEN_WIDTH;
let SCREEN_HEIGHT;
let FLASH_INDEX = 0;

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

const leftFlex = 0.85;
const rightFlex = 0.15;

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

const cameraIcon = require("./Image/camera.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");

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

const FLASH_LIGHT = [
  _reactNativeCamera.RNCamera.Constants.FlashMode.off,
  _reactNativeCamera.RNCamera.Constants.FlashMode.auto,
  _reactNativeCamera.RNCamera.Constants.FlashMode.on,
  _reactNativeCamera.RNCamera.Constants.FlashMode.torch,
];

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

    _defineProperty(this, "takePicture", async function (camera) {
      const options = {
        quality: 0.2,
        base64: true,
      };
      const data = await camera.takePictureAsync(options); //  eslint-disable-next-line

      this.setState({
        localPath: data.uri,
        cameraData: data,
        flashState: _reactNativeCamera.RNCamera.Constants.FlashMode.off,
      }); //path of photo
      // console.log(data);//path of photo

      this.watermarkLocation(); //Date calulation for the display on preciew Screen

      const date = new Date().getDate();
      const month = new Date().getMonth() + 1;
      const year = new Date().getFullYear(); //Time calulation for the display on preciew Screen

      const hour = new Date().getHours();
      const minute = new Date().getMinutes();
      const seconds = new Date().getSeconds(); //Alert.alert(date + '-' + month + '-' + year);
      // You can turn it in to your desired format

      this.setState({
        dateAndTime:
          date +
          "-" +
          month +
          "-" +
          year +
          "  " +
          hour +
          ":" +
          minute +
          ":" +
          seconds,
      }); //format: dd-mm-yyyy;
    });

    _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,
      dataSource: "",
      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,
      cameraState: this.props.navigation.state.params.cameraState,
      finalWatermarkResult: "",
    };
  } // componentWillMount() {
  //     // The getOrientation method is async. It happens sometimes that
  //     // you need the orientation at the moment the JS runtime starts running on device.
  //     // `getInitialOrientation` returns directly because its a constant set at the
  //     // beginning of the JS runtime.
  //     if (initial === 'PORTRAIT') {
  //         // do something
  //         Orientation.lockToLandscapeLeft()//make landscape
  //     } else {
  //         // do something else
  //     }
  // }

  /*
                           %%%%%%%%%%%%% For Take Picture %%%%%%%%%%%%%%%%
  */

  watermarkLocation() {
    console.log(
      "\n\n\n\n\n  >>>>>>>>>>>>>>>>>  watermarkLocation  >>>>>>>>\n\n\n\n\n\n"
    );
    return _reactNativeImageMarker.default
      .markText({
        src: this.state.localPath,
        text:
          "lat: " +
          this.state.currentLatitude +
          " " +
          "long: " +
          this.state.currentLongitude,
        position: "topLeft",
        fontName: "Muli-Regular",
        fontSize: 30,
        scale: 1,
        quality: 100,
        color: _Colors.default.digitYellow,
      })
      .then((res) => {
        this.setState({
          markLocationResult: "file://" + res,
        });
        console.log("the path is " + this.state.markLocationResult);
        this.watermarkDigitEdge();
      })
      .catch((err) => {
        console.log(err);
        this.setState({
          err,
        });
      }); // <Image
    //     source={this.state.ress}
    //     style={{ width: 500, height: 500, backgroundColor: 'blue' }}
    // />
  }

  watermarkDigitEdge() {
    console.log(
      "\n\n\n\n\n  >>>>>>>>>>>>>>>>>  watermarkDigitEdge  >>>>>>>>\n\n\n\n\n\n"
    );
    return _reactNativeImageMarker.default
      .markText({
        src: this.state.markLocationResult,
        text: "Digit Edge",
        position: "topRight",
        fontName: "Muli-Regular",
        fontSize: 30,
        scale: 1,
        quality: 100,
        color: _Colors.default.digitYellow,
      })
      .then((res) => {
        this.setState({
          markDigitEdgeResult: "file://" + res,
        });
        console.log("the path is " + this.state.markDigitEdgeResult);
        this.finalWatermark();
      })
      .catch((err) => {
        console.log(err);
        this.setState({
          err,
        });
      });
  }

  finalWatermark() {
    console.log(
      "\n\n\n\n\n  >>>>>>>>>>>>>>>>>  finalWatermark  >>>>>>>>\n\n\n\n\n\n"
    );
    return _reactNativeImageMarker.default
      .markText({
        src: this.state.markDigitEdgeResult,
        text: this.state.dateAndTime,
        position: "bottomLeft",
        fontName: "Muli-Regular",
        fontSize: 30,
        scale: 1,
        quality: 30,
        color: _Colors.default.digitYellow,
      })
      .then((res) => {
        this.setState({
          finalWatermarkResult: "file://" + res, // isLoading: false
        });
        setTimeout(() => {
          this.props.navigation.navigate("PreviewImage", {
            finalWatermarkResult: this.state.finalWatermarkResult,
            count: this.state.count,
            productImage: this.state.productImage,
            stepTitle: this.state.stepTitle,
            extention: this.state.extention,
            instructionData: this.state.instructionData,
          });
        }, 200);
        console.log(
          "the path is finalWatermarkResult " + this.state.finalWatermarkResult
        );
      })
      .catch((err) => {
        console.log(err);
        this.setState({
          err,
        });
      });
  }

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

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

    _reactNativeOrientation.default.addOrientationListener(
      this._orientationDidChange
    );

    if (initial === "PORTRAIT") {
      // do something
      _reactNativeOrientation.default.lockToLandscapeLeft(); //make landscape
    } else {
      // do something else
    }
  }

  componentWillUnmount() {
    _reactNativeOrientation.default.getOrientation((err, orientation) => {
      console.log(`Current Device Orientation: ${orientation}`); //display currrent location state
    }); // Remember to remove listener

    _reactNativeOrientation.default.removeOrientationListener(
      this._orientationDidChange
    );

    _geolocation.default.clearWatch(this.watchID); //For GeoLocation
  }

  render() {
    // Make Landscape
    _reactNativeOrientation.default.lockToLandscapeLeft();

    SCREEN_HEIGHT = Math.round(_reactNative.Dimensions.get("window").height);
    SCREEN_WIDTH = Math.round(_reactNative.Dimensions.get("window").width);
    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",
              },
            },
            /*#__PURE__*/ _react.default.createElement(
              _reactNative.View,
              {
                style: {
                  flex: 0.7,
                },
              },
              /*#__PURE__*/ _react.default.createElement(
                _reactNative.TouchableOpacity,
                {
                  onPress: () => [this.takePicture(this.camera)],
                  style: styles.capture,
                },
                /*#__PURE__*/ _react.default.createElement(_reactNative.Image, {
                  source: cameraIcon,
                  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)
              )
            )
          )
        ),
        /*#__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",
              },
            },
            this.getStencilView()
          ),
          /*#__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;
  }
}

exports.default = Camera;

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=Camera.js.map
