import React, { useState } from 'react';
import { Dialogue, DialogueConfirm, Header, InfoField, Loading, PrimaryButton, deleteDevice } from 'react-native-cloud-ca';
import { View, Image, Text } from 'react-native';
import styles from './styles';
import { useParams, useNavigate } from 'react-router-native';
const DeviceInfoView = () => {
  let {
    device_id,
    device_name
  } = useParams();
  let navigate = useNavigate();
  const [isShowRequestDelete, setIsShowRequestDelete] = useState(false);
  const [isShowError, setIsShowError] = useState(false);
  const [isShowSuccess, setIsShowSuccess] = useState(false);
  const [errorResponse, setErrorResponse] = useState('');
  const [isLoading, setIsLoading] = useState(false);
  function onGoBack() {
    navigate(-1);
  }
  const handleShowRequestDelete = state => {
    setIsShowRequestDelete(state);
  };
  const onDeleteDevice = async () => {
    setIsLoading(true);
    try {
      await deleteDevice({
        deviceId: device_id
      });
      setIsLoading(false);
      setIsShowRequestDelete(false);
      setIsShowSuccess(true);
    } catch (error) {
      setErrorResponse(error === null || error === void 0 ? void 0 : error.message);
      setIsLoading(false);
      setIsShowRequestDelete(false);
      setIsShowError(true);
    }
  };
  const handleDone = () => {
    setIsShowSuccess(false);
    onGoBack();
  };
  return /*#__PURE__*/React.createElement(View, {
    style: styles.container
  }, /*#__PURE__*/React.createElement(Header, {
    label: "Chi ti\u1EBFt thi\u1EBFt b\u1ECB",
    goBack: onGoBack
  }), /*#__PURE__*/React.createElement(View, {
    style: styles.contentContainer
  }, /*#__PURE__*/React.createElement(Image, {
    style: styles.smartphoneImage,
    source: require('../../asset/icon/IC_SMARTPHONE.png')
  }), /*#__PURE__*/React.createElement(InfoField, {
    title: "ID",
    info: device_id
  }), /*#__PURE__*/React.createElement(InfoField, {
    title: "T\xEAn",
    info: device_name
  }), /*#__PURE__*/React.createElement(PrimaryButton, {
    label: "Hu\u1EF7 \u0111\u0103ng k\xFD",
    onPress: () => handleShowRequestDelete(true)
  })), /*#__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, {
    title: "Th\xF4ng b\xE1o",
    closeOnPress: () => handleShowRequestDelete(false),
    closeLabel: "\u0110\xF3ng",
    confirmOnPress: onDeleteDevice,
    confirmLabel: "Xo\xE1",
    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.")), isLoading && /*#__PURE__*/React.createElement(Loading, null));
};
export default DeviceInfoView;
//# sourceMappingURL=DeviceInfoView.js.map