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); }
import React, { useState, useEffect } from 'react';
import { View, Text } from 'react-native';
import styles from './styles';
import { Dialogue, Header, InfoField, Loading, getDeviceRegistrationSettings, validateToken } from 'react-native-cloud-ca';
const GetDeviceRegistrationSettingsView = props => {
  var _deviceInfo$device_ke;
  const {
    goBack,
    headerProps,
    onDone
  } = props;
  const [isLoading, setIsLoading] = useState(false);
  const [isShowError, setIsShowError] = useState(false);
  const [errorResponse, setErrorResponse] = useState('');
  const [deviceInfo, setDeviceInfo] = useState();
  const [allResponse, setAllResponse] = useState();
  useEffect(() => {
    (async () => {
      setIsLoading(true);
      try {
        await validateToken();
        const result = await 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);
      }
    })();
  }, []);
  useEffect(() => {
    onDone === null || onDone === void 0 ? void 0 : onDone(allResponse);
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [allResponse]);
  return /*#__PURE__*/React.createElement(View, {
    style: styles.container
  }, /*#__PURE__*/React.createElement(Header, _extends({}, headerProps, {
    label: "Th\xF4ng tin c\u1EA5u h\xECnh c\xE0i \u0111\u1EB7t",
    goBack: goBack
  })), /*#__PURE__*/React.createElement(View, {
    style: styles.contentContainer
  }, /*#__PURE__*/React.createElement(InfoField, {
    title: "Ki\u1EC3u m\xE3 ho\xE1",
    info: (deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.device_key_type) || ''
  }), /*#__PURE__*/React.createElement(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.createElement(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.createElement(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.createElement(Dialogue, {
    modalType: "ERROR",
    onClose: () => setIsShowError(false),
    visible: isShowError
  }, /*#__PURE__*/React.createElement(Text, {
    style: styles.contentStyle
  }, errorResponse)), isLoading && /*#__PURE__*/React.createElement(Loading, null));
};
export default GetDeviceRegistrationSettingsView;
//# sourceMappingURL=GetDeviceRegistrationSettingsView.js.map