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 } from 'react';
import { TouchableOpacity, Text } from 'react-native';
import { Dialogue, DialogueConfirm, deleteDevice } from 'react-native-cloud-ca';
import styles from './styles';
const DeleteDeviceView = props => {
  const {
    buttonLabel,
    deviceId,
    onDone,
    ...rest
  } = props;
  const [isShowRequestDelete, setIsShowRequestDelete] = useState(false);
  const [isShowError, setIsShowError] = useState(false);
  const [isShowSuccess, setIsShowSuccess] = useState(false);
  const [errorResponse, setErrorResponse] = useState('');
  const [successResponse, setSuccessResponse] = useState();
  const onDeleteDevice = async () => {
    handleShowRequestDelete(false);
    try {
      const deleteDeviceResult = await deleteDevice({
        deviceId: deviceId || ''
      });
      setSuccessResponse(deleteDeviceResult);
      setIsShowSuccess(true);
    } catch (error) {
      setErrorResponse(error === null || error === void 0 ? void 0 : error.message);
      setIsShowError(true);
    }
  };
  const handleDone = () => {
    setIsShowSuccess(false);
    onDone === null || onDone === void 0 ? void 0 : onDone(successResponse);
  };
  const handleShowRequestDelete = state => {
    setIsShowRequestDelete(state);
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TouchableOpacity, _extends({
    onPress: () => handleShowRequestDelete(true)
  }, rest), /*#__PURE__*/React.createElement(Text, null, buttonLabel)), /*#__PURE__*/React.createElement(Dialogue, {
    visible: isShowSuccess,
    onClose: handleDone
  }, /*#__PURE__*/React.createElement(Text, {
    style: styles.contentStyle
  }, "Hu\u1EF7 thi\u1EBFt b\u1ECB th\xE0nh c\xF4ng")), /*#__PURE__*/React.createElement(Dialogue, {
    modalType: "ERROR",
    onClose: () => setIsShowError(false),
    visible: isShowError
  }, /*#__PURE__*/React.createElement(Text, {
    style: styles.contentStyle
  }, errorResponse)), /*#__PURE__*/React.createElement(DialogueConfirm, {
    modalType: "WARNING",
    title: "Th\xF4ng b\xE1o",
    closeOnPress: () => handleShowRequestDelete(false),
    closeLabel: "Quay l\u1EA1i",
    confirmOnPress: onDeleteDevice,
    confirmLabel: "Hu\u1EF7 \u0111\u0103ng k\xFD",
    visible: isShowRequestDelete
  }, /*#__PURE__*/React.createElement(Text, {
    style: styles.contentStyle
  }, "B\u1EA1n c\xF3 mu\u1ED1n xo\xE1 c\xE1c thi\u1EBFt b\u1ECB n\xE0y kh\xF4ng.")));
};
export default DeleteDeviceView;
//# sourceMappingURL=DeleteDeviceView.js.map