"use strict";

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

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

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

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

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

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

var _reactNativeLoadingSpinnerOverlay = _interopRequireDefault(require("react-native-loading-spinner-overlay"));

var _ApiUrls = require("../Api/ApiUrls");

var _Constants = require("./Constants");

var _SquareRadio = _interopRequireDefault(require("./SquareRadio"));

var _reactNativeGestureHandler = require("react-native-gesture-handler");

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

let SCREEN_WIDTH;
let SCREEN_HEIGHT;

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

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

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

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

const NCB_SLABS = [{
  ncb: 0,
  name: '0%',
  id: 1,
  value: 'ZERO'
}, {
  ncb: 20,
  name: '20%',
  id: 2,
  value: 'TWENTY'
}, {
  ncb: 25,
  name: '25%',
  id: 3,
  value: 'TWENTY_FIVE'
}, {
  ncb: 35,
  name: '35%',
  id: 4,
  value: 'THIRTY_FIVE'
}, {
  ncb: 45,
  name: '45%',
  id: 5,
  value: 'FORTY_FIVE'
}, {
  ncb: 50,
  name: '50%',
  id: 6,
  value: 'FIFTY'
}];

class WithOutQuote extends _react.Component {
  constructor(props) {
    super(props);
    this.state = {
      datasource: [],
      registrationNumber: "",
      showError: false,
      showErrorType: false,
      isSelected: false,
      activityIndicatorVisibility: false
    };
  }

  componentDidMount() {
    //for wite base data
    this.callApiAgentData();
  }

  async callApiAgentData() {
    try {
      this.setState({
        activityIndicatorVisibility: true
      });
      let resp = await fetch(_ApiUrls.AGENT_DATA + "?webUserId=" + this.props.screenProps.webUserId);
      let resJson = await resp.json();
      let fillteredData = [];
      var isPrivateCar = false;
      var isTwoWheeler = false;
      var isCommercialVehicle = false; //Filter Data For The Display Products

      resJson.forEach(element => {
        if (!isPrivateCar && (element.productCode == _Constants.PRIVATE_CAR_20101 || element.productCode == _Constants.PRIVATE_CAR_20102 || element.productCode == _Constants.PRIVATE_CAR_20103)) {
          element = { ...element,
            isPrivateCar: true
          };
          fillteredData.splice(0, 0, element);
          isPrivateCar = true;
        }

        if (!isTwoWheeler && (element.productCode == _Constants.BIKE_20201 || element.productCode == _Constants.BIKE_20202)) {
          element = { ...element,
            isTwoWheeler: true
          };
          fillteredData.splice(1, 0, element);
          isTwoWheeler = true;
        }

        if (!isCommercialVehicle && (element.productCode == _Constants.CUMMERCIAL_20301 || element.productCode == _Constants.CUMMERCIAL_20302)) {
          element = { ...element,
            isCommercialVehicle: true
          };
          fillteredData.splice(2, 0, element);
          isCommercialVehicle = true;
        }
      });
      this.setState({
        datasource: fillteredData
      });
      this.setState({
        activityIndicatorVisibility: false
      });
    } catch (error) {
      _reactNative.Alert.alert("Could not get inspection type");

      this.setState({
        activityIndicatorVisibility: false
      });
    }
  } // Display write base data


  renderItems(datasource) {
    const renderMap = [];
    datasource !== undefined && datasource.forEach(item => {
      if (item.isPrivateCar) renderMap.push( /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
        key: item.productCode,
        onPress: () => this.setState({
          isCarFocused: true,
          isBikeFocused: false,
          isCummercialFocused: false,
          isSelected: true
        })
      }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          width: (SCREEN_WIDTH - 64) / 3,
          height: SCREEN_HEIGHT / 8,
          borderWidth: 1,
          borderRadius: 4,
          marginLeft: 16,
          marginBottom: 16,
          borderColor: this.state.isCarFocused ? _Colors.default.digitYellow : _Colors.default.lightGray,
          justifyContent: 'center'
        }
      }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: styles.productImageView
      }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
        source: car,
        style: styles.productImage,
        resizeMethod: "auto",
        resizeMode: "contain"
      })), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: styles.productImageView
      }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
        style: styles.productNameStyle
      }, "Car")))));
      if (item.isTwoWheeler) renderMap.push( /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
        key: item.productCode,
        onPress: () => this.setState({
          isBikeFocused: true,
          isCarFocused: false,
          isCummercialFocused: false,
          isSelected: true
        })
      }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          width: (SCREEN_WIDTH - 64) / 3,
          height: SCREEN_HEIGHT / 8,
          borderWidth: 1,
          borderRadius: 4,
          marginLeft: 16,
          marginBottom: 16,
          borderColor: this.state.isBikeFocused ? _Colors.default.digitYellow : _Colors.default.lightGray,
          justifyContent: 'center'
        }
      }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: styles.productImageView
      }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
        source: Bike,
        style: styles.productImage,
        resizeMethod: "auto",
        resizeMode: "contain"
      })), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: styles.productImageView
      }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
        style: styles.productNameStyle
      }, "Bike")))));
      if (item.isCommercialVehicle) renderMap.push( /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
        key: item.productCode,
        onPress: () => this.setState({
          isBikeFocused: false,
          isCarFocused: false,
          isCummercialFocused: true,
          isSelected: true
        })
      }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: {
          width: (SCREEN_WIDTH - 64) / 3,
          height: SCREEN_HEIGHT / 8,
          borderWidth: 1,
          borderRadius: 4,
          marginLeft: 16,
          marginBottom: 16,
          borderColor: this.state.isCummercialFocused ? _Colors.default.digitYellow : _Colors.default.lightGray,
          justifyContent: 'center'
        }
      }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: styles.productImageView
      }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
        source: Auto,
        style: styles.productImage,
        resizeMethod: "auto",
        resizeMode: "contain"
      })), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: styles.productImageView
      }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
        style: styles.productNameStyle
      }, "Commercial")))));
    });
    return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 1,
        flexDirection: 'row'
      }
    }, renderMap);
  } //validate


  validate() {
    if (this.state.skipdata == _Constants.ODOMETER) {
      if (this.state.odometerReading != '') {
        this.setState({
          isDisplayInstruction: false,
          showError: false,
          odometerReading: ''
        });
      } else {
        this.setState({
          isDisplayInstruction: true,
          showError: true
        });
      }
    } else {
      this.setState({
        isDisplayInstruction: false
      });
    }

    if (this.state.isSelected === true) {
      this.setState({
        showErrorType: false
      });
    } else {
      this.setState({
        showErrorType: true
      });
      return;
    }

    if (this.state.registrationNumber.trim().length == 0) {
      this.setState({
        showError: true
      });
      return;
    } else {
      this.setState({
        showError: false
      });
    }

    this.props.navigation.navigate("DocumentCollection");
  } //Error Text


  showErrorText() {
    if (this.state.showError) {
      return /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
        style: {
          color: 'red',
          marginLeft: 4,
          fontFamily: 'Muli-Regular',
          marginLeft: 16
        }
      }, "Enter Vehicle Registration Number");
    }
  } //Error Text


  showErrorTextVechicleType() {
    if (this.state.showErrorType) {
      return /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
        style: {
          color: 'red',
          marginLeft: 4,
          fontFamily: 'Muli-Regular',
          marginLeft: 16
        }
      }, "Enter Vehicle Type");
    }
  }

  render() {
    SCREEN_HEIGHT = Math.round(_reactNative.Dimensions.get('window').height);
    SCREEN_WIDTH = Math.round(_reactNative.Dimensions.get('window').width);
    const dataSource = this.state.datasource;
    return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 1,
        backgroundColor: '#FFFFFF'
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.StatusBar, {
      hidden: true
    }), /*#__PURE__*/_react.default.createElement(_reactNativeGestureHandler.ScrollView, null, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        width: SCREEN_WIDTH,
        height: 70,
        backgroundColor: '#F5F5F5',
        marginBottom: 16,
        flexDirection: 'row'
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        alignSelf: "center"
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
      onPress: () => this.props.navigation.navigate("PI")
    }, /*#__PURE__*/_react.default.createElement(_FontAwesome.default, {
      name: "arrow-left",
      size: 25,
      style: {
        marginLeft: 16,
        marginRight: 16
      }
    }))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        alignSelf: "center"
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
      style: {
        fontFamily: 'Muli-Bold',
        fontSize: 22,
        marginLeft: 16
      }
    }, "Pre Inspection"))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 0.9
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
      style: {
        marginLeft: 16,
        fontSize: 16,
        fontFamily: 'Muli-Bold',
        marginBottom: 4
      }
    }, "Choose Vechicle Type "), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        marginTop: 16,
        flexDirection: 'column'
      }
    }, this.renderItems(this.state.datasource), this.showErrorTextVechicleType()), /*#__PURE__*/_react.default.createElement(_reactNative.View, null, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
      style: {
        marginLeft: 16,
        fontSize: 16,
        fontFamily: 'Muli-Bold',
        marginBottom: 4
      }
    }, "Vechicle Registration Number "), /*#__PURE__*/_react.default.createElement(_reactNative.TextInput, {
      style: {
        width: SCREEN_WIDTH - 32,
        height: 50,
        borderColor: this.state.isFocused ? _Colors.default.digitYellow : _Colors.default.lightGray,
        borderWidth: 1,
        marginLeft: 16,
        borderRadius: 4,
        fontFamily: 'Muli-Regular',
        fontSize: 16
      },
      onChangeText: registrationNumber => this.setState({
        registrationNumber
      }),
      placeholder: "Type Registration Number",
      autoCapitalize: "characters" // onFocus={this.setState({ isFocused: true })}
      // onBlur={this.setState({ isFocused: false })}

    }), this.showErrorText()), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        marginTop: 22
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
      onPress: () => this.props.navigation.navigate("PI")
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
      style: {
        marginLeft: 16,
        fontSize: 16,
        fontFamily: 'Muli-Bold',
        color: _Colors.default.digitYellow
      }
    }, "Search with Quote Number"))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        marginTop: 44,
        marginLeft: 16,
        marginRight: 16
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
      style: {
        fontSize: 16,
        fontFamily: "Muli-Bold",
        marginBottom: 8
      }
    }, "Select NCB percentage"), /*#__PURE__*/_react.default.createElement(_SquareRadio.default, {
      gap: 16,
      data: NCB_SLABS,
      numberOfRecord: 3,
      isFullValue: true,
      selected: value => {
        this.setState({
          ncbSelected: value.id
        });
      },
      selectedvalue: this.state.ncbSelected,
      labelStyle: styles.squareRadioStyle
    }))), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 0.1,
        marginTop: 40,
        marginBottom: 8
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        marginLeft: 16
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
      onPress: () => this.validate()
    }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: styles.captureImageButtonView
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
      style: styles.captureImageButtonText
    }, "Continue"))))), this.displaySpinner()));
  } //Display Spinner


  displaySpinner() {
    if (this.state.activityIndicatorVisibility) {
      return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        style: styles.splashView
      }, /*#__PURE__*/_react.default.createElement(_reactNativeLoadingSpinnerOverlay.default, {
        visible: true,
        textContent: 'Loading...',
        color: _Colors.default.digitYellow
      }));
    } else {
      return null;
    }
  }

}

exports.default = WithOutQuote;

const styles = _reactNative.StyleSheet.create({
  main: {
    flex: 1 // backgroundColor: Colors.white,

  },
  captureImageButtonView: {
    height: 48,
    borderRadius: 4,
    backgroundColor: _Colors.default.digitYellow,
    marginTop: 2,
    flexDirection: 'row',
    justifyContent: 'center',
    marginRight: 16
  },
  captureImageButtonText: {
    fontSize: 16,
    fontFamily: 'Muli-Black',
    alignSelf: 'center'
  },
  productImageView: {
    flexDirection: 'row',
    justifyContent: 'center'
  },
  productImage: {
    width: 50,
    height: 50,
    marginTop: 16,
    flexDirection: 'row',
    justifyContent: 'space-around',
    marginLeft: 16,
    marginRight: 16
  },
  squareRadioStyle: {
    fontSize: 14,
    color: _Colors.default.darkBlack
  }
});
//# sourceMappingURL=WithOutQuote.js.map