"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNativeCloudCa = require("react-native-cloud-ca");
var _reactNative = require("react-native");
var _styles = _interopRequireDefault(require("./styles"));
var _reactRouterNative = require("react-router-native");
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 DeviceInfoView = () => {
  let {
    device_id,
    device_name
  } = (0, _reactRouterNative.useParams)();
  let navigate = (0, _reactRouterNative.useNavigate)();
  const [isShowRequestDelete, setIsShowRequestDelete] = (0, _react.useState)(false);
  const [isShowError, setIsShowError] = (0, _react.useState)(false);
  const [isShowSuccess, setIsShowSuccess] = (0, _react.useState)(false);
  const [errorResponse, setErrorResponse] = (0, _react.useState)('');
  const [isLoading, setIsLoading] = (0, _react.useState)(false);
  function onGoBack() {
    navigate(-1);
  }
  const handleShowRequestDelete = state => {
    setIsShowRequestDelete(state);
  };
  const onDeleteDevice = async () => {
    setIsLoading(true);
    try {
      await (0, _reactNativeCloudCa.deleteDevice)({
        deviceId: device_id
      });
      setIsLoading(false);
      setIsShowSuccess(true);
    } catch (error) {
      setErrorResponse(error === null || error === void 0 ? void 0 : error.message);
      setIsLoading(false);
      setIsShowError(true);
    }
  };
  const handleDone = () => {
    setIsShowSuccess(false);
  };
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: _styles.default.container
  }, /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.Header, {
    label: "Chi ti\u1EBFt thi\u1EBFt b\u1ECB",
    goBack: onGoBack
  }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: _styles.default.contentContainer
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
    style: _styles.default.smartphoneImage,
    source: require('../../asset/icon/IC_SMARTPHONE.png')
  }), /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.InfoField, {
    title: "ID",
    info: device_id
  }), /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.InfoField, {
    title: "T\xEAn",
    info: device_name
  }), /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.PrimaryButton, {
    label: "Hu\u1EF7 \u0111\u0103ng k\xFD",
    onPress: () => handleShowRequestDelete(true)
  })), /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.Dialogue, {
    visible: isShowSuccess,
    onClose: handleDone
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
    style: _styles.default.contentStyle
  }, "Hu\u1EF7 thi\u1EBFt b\u1ECB th\xE0nh c\xF4ng")), /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.Dialogue, {
    modalType: "ERROR",
    onClose: () => setIsShowError(false),
    visible: isShowError
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
    style: _styles.default.contentStyle
  }, errorResponse)), /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.DialogueConfirm, {
    title: "Th\xF4ng b\xE1o",
    closeOnPress: () => handleShowRequestDelete(false),
    closeLabel: "\u0110\xF3ng",
    confirmOnPress: onDeleteDevice,
    confirmLabel: "Xo\xE1",
    visible: isShowRequestDelete
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
    style: _styles.default.contentStyle
  }, "B\u1EA1n c\xF3 mu\u1ED1n xo\xE1 c\xE1c thi\u1EBFt b\u1ECB n\xE0y kh\xF4ng.")), isLoading && /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.Loading, null));
};
var _default = DeviceInfoView;
exports.default = _default;
//# sourceMappingURL=DeviceInfoView.js.map