"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _styles = _interopRequireDefault(require("./styles"));
var _reactNativeCloudCa = require("react-native-cloud-ca");
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 ListDocumentView = () => {
  const {
    documents
  } = (0, _reactRouterNative.useParams)();
  const navigate = (0, _reactRouterNative.useNavigate)();
  const [documentsData, setDocumentsData] = (0, _react.useState)(JSON.parse(documents) || []);
  const [searchValue, setSearchValue] = (0, _react.useState)('');
  (0, _react.useEffect)(() => {
    const rootData = JSON.parse(documents);
    if ((searchValue === null || searchValue === void 0 ? void 0 : searchValue.length) === 0) {
      setDocumentsData(rootData);
    }
    const timer = setTimeout(() => {
      const results = rootData.filter(document => {
        return document.Name.includes(searchValue);
      });
      setDocumentsData(results);
      console.log(results);
    }, 500);
    return () => clearTimeout(timer);
  }, [documents, searchValue]);
  function onGoBack() {
    navigate(-1);
  }
  const renderItem = _ref => {
    let {
      item,
      index
    } = _ref;
    return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: _styles.default.documentContainer
    }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
      numberOfLines: 1,
      key: index,
      style: _styles.default.documentItemText
    }, `${index + 1}. ${item === null || item === void 0 ? void 0 : item.Name}`));
  };
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: _styles.default.container
  }, /*#__PURE__*/_react.default.createElement(_reactNativeCloudCa.Header, {
    label: "Danh s\xE1ch t\xE0i li\u1EC7u k\xFD",
    goBack: onGoBack
  }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: _styles.default.contentContainer
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: _styles.default.searchContainer
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: _styles.default.inputContainer
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
    style: _styles.default.iconMagnify,
    source: require('../../asset/icon/IC_MAGNIFY.png')
  }), /*#__PURE__*/_react.default.createElement(_reactNative.TextInput, {
    style: _styles.default.inputField,
    placeholder: " Nh\u1EADp t\xEAn h\u1EE3p \u0111\u1ED3ng c\u1EA7n t\xECm ki\u1EBFm",
    placeholderTextColor: '#6C757D',
    selectionColor: '#121517',
    value: searchValue,
    onChangeText: setSearchValue
  }))), /*#__PURE__*/_react.default.createElement(_reactNative.FlatList, {
    contentContainerStyle: _styles.default.listDocumentContainer,
    data: documentsData,
    renderItem: renderItem,
    keyExtractor: (_item, index) => index.toString()
  })));
};
var _default = ListDocumentView;
exports.default = _default;
//# sourceMappingURL=ListDocumentView.js.map