"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _react = _interopRequireWildcard(require("react"));
var _reactNativeActionsSheet = _interopRequireDefault(require("react-native-actions-sheet"));
var _Matrics = _interopRequireDefault(require("./helpers/Matrics"));
var _bluetoothPermissionHelper = require("./helpers/bluetoothPermissionHelper");
var _reactNativePermissions = require("react-native-permissions");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const DeviceList = [{
  // image: Images.GoodFlipBcaDevice,
  device_type: 'GoodFlip',
  title: 'GoodFlip device'
}];
const colors = {
  gun_powder: '#49454F',
  mountain_meadow: '#12B76A',
  solitude: '#E4E7EC',
  royal_blue_goodflip: '#444CE7',
  alice_blue: '#EEF4FF',
  auro_metal_saurus: '#667085',
  anti_flash_white: '#F2F4F7',
  illuminating_emerald: '#299D6B',
  aero_blue: '#CBF0E0',
  honeydew: '#E6FAF1',
  sea_green: '#2A805A',
  dark_jungle_green: '#101828',
  cosmic_cobalt: '#2D3282',
  brunswick_green: '#1D4D38'
};
const BcaDeviceListSheet = ({
  sheetId,
  payload
}) => {
  const {
    onPressConnectSmartScaleBtn
  } = payload;
  const [devices, setDevices] = (0, _react.useState)([]);
  const [closeOnTouchBackdrop, setCloseOnTouchBackdrop] = (0, _react.useState)(false);
  const [bluetoothIsEnable, setBluetoothIsEnable] = (0, _react.useState)(false);
  const [selectedDevice, setSelectedDevice] = (0, _react.useState)(null);
  const actionSheetRef = (0, _react.useRef)(null);
  (0, _react.useEffect)(() => {
    checkBleEnable();
    //   handlePageViewEvent(Constants.SCREEN_NAME.BCABluetoothToggle);
  }, []);
  (0, _react.useEffect)(() => {
    checkDeviceIsAvailable();
  }, []);
  const onChange = position => {
    if (position == 0) {
      setCloseOnTouchBackdrop(true);
    }
  };
  const checkDeviceIsAvailable = () => {
    const tempDevideList = [];
    tempDevideList.push(DeviceList[0]);
    setDevices(tempDevideList);
  };
  const checkBleEnable = async () => {
    const permission = await (0, _bluetoothPermissionHelper.checkBluetoothPermission)();
    if (permission.status !== _reactNativePermissions.RESULTS.GRANTED) {
      setBluetoothIsEnable(false);
    }
  };
  const onPressSwitch = async value => {
    if (value) {
      const permission = await (0, _bluetoothPermissionHelper.checkBluetoothPermission)();
      await (0, _bluetoothPermissionHelper.managePermission)(permission, value, () => {
        setBluetoothIsEnable(true);
      });
    } else {
      setBluetoothIsEnable(false);
    }
  };
  const renderHeader = (0, _react.useCallback)(() => {
    return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: styles.headerContainer
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
      style: styles.syncSmartScaleTxt
    }, "Sync Smart Scale"), /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
      activeOpacity: 0.8,
      onPress: () => {
        var _actionSheetRef$curre;
        return (_actionSheetRef$curre = actionSheetRef.current) === null || _actionSheetRef$curre === void 0 ? void 0 : _actionSheetRef$curre.hide();
      }
    }));
  }, []);
  const renderRightContainer = (0, _react.useCallback)(() => {
    return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: [styles.rightContainer, {
        paddingLeft: _Matrics.default.s((devices !== null && devices !== void 0 ? devices : []).length ? 15 : 0)
      }]
    }, renderStep2Container());
  }, [selectedDevice, bluetoothIsEnable, devices]);
  const renderStep2Container = (0, _react.useCallback)(() => {
    return /*#__PURE__*/_react.default.createElement(_reactNative.View, null, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
      style: styles.inOrderToConnectTxt
    }, "In order to connect with the GoodFlip smart scale, you need to turn on the Bluetooth on your device"), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: styles.switchButtonContainer
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
      style: styles.turnOnBluetoothTxt
    }, "Turn on Bluetooth"), /*#__PURE__*/_react.default.createElement(_reactNative.Switch, {
      trackColor: {
        false: '#F2F4F7',
        true: '#299D6B'
      },
      thumbColor: 'white',
      ios_backgroundColor: '#F2F4F7',
      onValueChange: onPressSwitch,
      value: bluetoothIsEnable
    })));
  }, [bluetoothIsEnable, devices]);
  const renderBottomBtn = (0, _react.useCallback)(() => {
    return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
      onPress: () => {
        if (selectedDevice) {
          onPressConnectSmartScaleBtn(selectedDevice);
        }
      },
      activeOpacity: 0.8,
      disabled: !bluetoothIsEnable || !selectedDevice,
      style: [styles.connectWithSmartSmartScaleButtonContainer, {
        backgroundColor: !bluetoothIsEnable || !selectedDevice ? colors.aero_blue : colors.illuminating_emerald,
        shadowColor: !bluetoothIsEnable || !selectedDevice ? colors.honeydew : colors.sea_green
      }]
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
      style: styles.connectWithSmartScaleTxt
    }, "Connect With Smart Scale"));
  }, [selectedDevice, bluetoothIsEnable]);
  return /*#__PURE__*/_react.default.createElement(_reactNativeActionsSheet.default, {
    id: sheetId,
    ref: actionSheetRef,
    containerStyle: styles.sheet,
    onChange: onChange,
    isModal: true,
    snapPoints: [100],
    initialSnapIndex: 0,
    useBottomSafeAreaPadding: _reactNative.Platform.OS === 'ios' ? !closeOnTouchBackdrop : true,
    gestureEnabled: false,
    drawUnderStatusBar: false,
    defaultOverlayOpacity: 0.3,
    closeOnTouchBackdrop: closeOnTouchBackdrop
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: styles.smallHeight
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: styles.mainContainer
  }, renderHeader(), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: {
      flexDirection: 'row'
    }
  }, renderRightContainer())), renderBottomBtn()));
};
var _default = exports.default = BcaDeviceListSheet;
const styles = _reactNative.StyleSheet.create({
  sheet: {
    borderTopRightRadius: 20,
    borderTopLeftRadius: 20,
    paddingBottom: _Matrics.default.vs(_reactNative.Platform.OS === 'android' ? 20 : 5)
  },
  smallHeight: {
    paddingHorizontal: _Matrics.default.s(15),
    paddingVertical: _Matrics.default.s(15)
  },
  mainContainer: {
    marginBottom: _Matrics.default.vs(40)
  },
  headerContainer: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    marginBottom: _Matrics.default.vs(20)
  },
  syncSmartScaleTxt: {
    // fontFamily: Fonts.ROBOTO_SEMI_BOLD,
    fontSize: _Matrics.default.mvs(18),
    color: '#101828'
  },
  mainStepContainer: {
    backgroundColor: 'E4E7EC',
    borderRadius: _Matrics.default.mvs(100),
    alignItems: 'center',
    justifyContent: 'space-between',
    marginBottom: _Matrics.default.vs(15),
    overflow: 'hidden'
  },
  gradientContainer: {
    height: _Matrics.default.vs(30),
    alignItems: 'center'
  },
  stepContainer: {
    height: _Matrics.default.mvs(14),
    width: _Matrics.default.mvs(14),
    backgroundColor: 'white',
    borderRadius: _Matrics.default.mvs(100),
    marginHorizontal: _Matrics.default.s(1)
  },
  rightContainer: {
    flex: 1,
    paddingLeft: _Matrics.default.s(15)
  },
  step1Container: {
    gap: 15,
    paddingBottom: _Matrics.default.vs(30)
  },
  stepHeaderTxt: {
    // fontFamily: Fonts.ROBOTO_REGULAR,
    fontSize: _Matrics.default.mvs(12),
    color: '#101828'
  },
  selectYourSmartScaleTxt: {
    // fontFamily: Fonts.ROBOTO_SEMI_BOLD,
    fontSize: _Matrics.default.mvs(16),
    color: '#101828'
  },
  deviceItemContainer: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    borderWidth: 1,
    borderRadius: _Matrics.default.mvs(8),
    paddingVertical: _Matrics.default.vs(10),
    paddingHorizontal: _Matrics.default.s(13)
  },
  deviceItemDetailsContainer: {
    flexDirection: 'row',
    alignItems: 'center',
    gap: 15
  },
  deviceImageContainer: {
    height: _Matrics.default.mvs(50),
    width: _Matrics.default.mvs(50),
    resizeMode: 'contain'
  },
  deviceNameTxt: {
    // fontFamily: Fonts.ROBOTO_BOLD,
    fontSize: _Matrics.default.mvs(16),
    color: '#101828'
  },
  switchButtonContainer: {
    borderWidth: 1,
    borderRadius: _Matrics.default.mvs(16),
    paddingVertical: _Matrics.default.vs(10),
    paddingHorizontal: _Matrics.default.s(13),
    borderColor: '#E4E7EC',
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between'
  },
  turnOnBluetoothTxt: {
    // fontFamily: Fonts.ROBOTO_SEMI_BOLD,
    fontSize: _Matrics.default.mvs(16),
    color: '#2D3282'
  },
  connectWithSmartSmartScaleButtonContainer: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    borderRadius: _Matrics.default.mvs(8),
    paddingVertical: _Matrics.default.vs(15),
    shadowOffset: {
      height: 12,
      width: 0
    },
    shadowOpacity: 1,
    shadowRadius: 1,
    gap: 15,
    elevation: 8
  },
  connectWithSmartScaleTxt: {
    fontSize: _Matrics.default.mvs(16),
    // fontFamily: Fonts.ROBOTO_BOLD,
    color: 'white'
  },
  inOrderToConnectTxt: {
    // fontFamily: Fonts.ROBOTO_REGULAR,
    fontSize: _Matrics.default.mvs(14),
    color: '#667085',
    marginBottom: _Matrics.default.vs(25)
  }
});
//# sourceMappingURL=BcaDeviceListSheet.js.map