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, getUserProfile, validateToken } from 'react-native-cloud-ca';
const GetUsersProfileView = props => {
  const {
    goBack,
    headerProps,
    onDone
  } = props;
  const [isLoading, setIsLoading] = useState(false);
  const [isShowError, setIsShowError] = useState(false);
  const [errorResponse, setErrorResponse] = useState('');
  const [userInfo, setUserInfo] = useState();
  const [allResult, setAllResult] = useState();
  useEffect(() => {
    (async () => {
      setIsLoading(true);
      try {
        await validateToken();
        const result = await getUserProfile();
        setUserInfo(result);
        setIsLoading(false);
        setAllResult({
          getUserProfileResponse: result
        });
      } catch (error) {
        setIsShowError(true);
        setErrorResponse(`${error === null || error === void 0 ? void 0 : error.code} - ${error === null || error === void 0 ? void 0 : error.message}`);
        setIsLoading(false);
        setAllResult({
          error: error
        });
      }
    })();
  }, []);
  useEffect(() => {
    onDone === null || onDone === void 0 ? void 0 : onDone(allResult);
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [allResult]);
  return /*#__PURE__*/React.createElement(View, {
    style: styles.container
  }, /*#__PURE__*/React.createElement(Header, _extends({}, headerProps, {
    label: "Th\xF4ng tin t\xE0i kho\u1EA3n",
    goBack: goBack
  })), /*#__PURE__*/React.createElement(View, {
    style: styles.contentContainer
  }, /*#__PURE__*/React.createElement(InfoField, {
    title: "Lo\u1EA1i t\xE0i kho\u1EA3n",
    info: 'Doanh nghiệp'
  }), /*#__PURE__*/React.createElement(InfoField, {
    title: "H\u1ECD v\xE0 t\xEAn",
    info: (userInfo === null || userInfo === void 0 ? void 0 : userInfo.user_name) || ''
  }), /*#__PURE__*/React.createElement(InfoField, {
    title: "S\u1ED1 \u0111i\u1EC7n tho\u1EA1i",
    info: (userInfo === null || userInfo === void 0 ? void 0 : userInfo.user_mobile) || ''
  }), /*#__PURE__*/React.createElement(InfoField, {
    title: "Email",
    info: (userInfo === null || userInfo === void 0 ? void 0 : userInfo.user_email) || ''
  })), /*#__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 GetUsersProfileView;
//# sourceMappingURL=GetUsersProfileView.js.map