"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _styles = _interopRequireDefault(require("./styles"));
var _reactNativeCloudCa = require("react-native-cloud-ca");
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; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
const GetDeviceRegistrationSettingsView = props => {
  var _deviceInfo$device_ke;
  const {
    goBack,
    headerProps,
    onDone
  } = props;
  const [isLoading, setIsLoading] = (0, _react.useState)(false);
  const [isShowError, setIsShowError] = (0, _react.useState)(false);
  const [errorResponse, setErrorResponse] = (0, _react.useState)('');
  const [deviceInfo, setDeviceInfo] = (0, _react.useState)();
  const [allResponse, setAllResponse] = (0, _react.useState)();
  (0, _react.useEffect)(() => {
    (async () => {
      setIsLoading(true);
      try {
        await (0, _reactNativeCloudCa.validateToken)();
        const result = await (0, _reactNativeCloudCa.getDeviceRegistrationSettings)();
        setDeviceInfo(result);
        setAllResponse({
          getDeviceRegistrationSettingsResponse: result
        });
        setIsLoading(false);
      } catch (error) {
        setIsShowError(true);
        setErrorResponse(`${error === null || error === void 0 ? void 0 : error.code} - ${error === null || error === void 0 ? void 0 : error.message}`);
        setAllResponse({
          error: error
        });
        setIsLoading(false);
      }
    })();
  }, []);
  (0, _react.useEffect)(() => {
    onDone === null || onDone === void 0 ? void 0 : onDone(allResponse);
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [allResponse]);
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: _styles.default.container
  }, /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.Header, _extends({}, headerProps, {
    label: "Th\xF4ng tin c\u1EA5u h\xECnh c\xE0i \u0111\u1EB7t",
    goBack: goBack
  })), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: _styles.default.contentContainer
  }, /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.InfoField, {
    title: "Ki\u1EC3u m\xE3 ho\xE1",
    info: (deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.device_key_type) || ''
  }), /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.InfoField, {
    title: "K\xEDch th\u01B0\u1EDBc",
    info: (deviceInfo === null || deviceInfo === void 0 ? void 0 : (_deviceInfo$device_ke = deviceInfo.device_key_size) === null || _deviceInfo$device_ke === void 0 ? void 0 : _deviceInfo$device_ke.toString()) || ''
  }), /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.InfoField, {
    title: "Y\xEAu c\u1EA7u x\xE1c th\u1EF1c sinh tr\u1EAFc h\u1ECDc",
    info: deviceInfo !== null && deviceInfo !== void 0 && deviceInfo.biometric_required ? 'Bắt buộc' : 'Không bắt buộc'
  }), /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.InfoField, {
    title: "Gi\u1EDBi h\u1EA1n thi\u1EBFt b\u1ECB \u0111\u0103ng k\xFD",
    info: parseInt(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.allowed_devices, 10) <= 0 ? 'Không giới hạn' : deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.allowed_devices
  })), /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.Dialogue, {
    modalType: "ERROR",
    onClose: () => setIsShowError(false),
    visible: isShowError
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
    style: _styles.default.contentStyle
  }, errorResponse)), isLoading && /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.Loading, null));
};
var _default = GetDeviceRegistrationSettingsView;
exports.default = _default;
//# sourceMappingURL=GetDeviceRegistrationSettingsView.js.map