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, FlatList } from 'react-native';
import styles from './styles';
import { DeviceInfoView, Header, Loading, listRegisteredDevices } from 'react-native-cloud-ca';
import { NativeRouter, Routes, Route, Link } from 'react-router-native';
import { DeviceItem } from './components';
const ListRegisteredDevicesView = props => {
  const {
    headerProps
  } = props;
  const [listDevices, setListDevices] = useState([]);
  const [isLoading, setIsLoading] = useState(false);
  useEffect(() => {
    (async () => {
      setIsLoading(true);
      try {
        const result = await listRegisteredDevices();
        setListDevices(result);
        setIsLoading(false);
      } catch (error) {
        setIsLoading(false);
      }
    })();
  }, []);
  const renderItem = _ref => {
    let {
      item,
      index
    } = _ref;
    return /*#__PURE__*/React.createElement(Link, {
      to: `/deviceInfo/${item.device_id}/${item.device_name}/${item.secure_element}/${item.biometric}`,
      underlayColor: "rgba(0,0,0,.01)"
    }, /*#__PURE__*/React.createElement(DeviceItem, {
      key: index,
      deviceInfo: item
    }));
  };
  const rootViewContainer = () => {
    return /*#__PURE__*/React.createElement(View, {
      style: styles.container
    }, /*#__PURE__*/React.createElement(Header, _extends({}, headerProps, {
      goBack: () => console.log('asd')
    })), /*#__PURE__*/React.createElement(Text, {
      style: styles.numberOfDevices
    }, "Thi\u1EBFt b\u1ECB \u0111\xE3 \u0111\u0103ng k\xFD (", listDevices === null || listDevices === void 0 ? void 0 : listDevices.length, ")"), /*#__PURE__*/React.createElement(FlatList, {
      data: listDevices,
      keyExtractor: (_item, index) => index.toString(),
      renderItem: renderItem,
      style: styles.listConatiner,
      contentContainerStyle: styles.contentContainerStyle
    }), isLoading && /*#__PURE__*/React.createElement(Loading, null));
  };
  return /*#__PURE__*/React.createElement(NativeRouter, null, /*#__PURE__*/React.createElement(Routes, null, /*#__PURE__*/React.createElement(Route, {
    path: "/",
    Component: rootViewContainer
  }), /*#__PURE__*/React.createElement(Route, {
    path: "/deviceInfo/:device_id/:device_name/:secure_element/:biometric",
    Component: DeviceInfoView
  })));
};
export default ListRegisteredDevicesView;
//# sourceMappingURL=ListRegisteredDevicesView.js.map