"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _core = require("@aries-framework/core");
var _reactHooks = require("@aries-framework/react-hooks");
var _react = _interopRequireWildcard(require("react"));
var _reactI18next = require("react-i18next");
var _reactNative = require("react-native");
var _HeaderButton = _interopRequireWildcard(require("../components/buttons/HeaderButton"));
var _ContactListItem = _interopRequireDefault(require("../components/listItems/ContactListItem"));
var _EmptyListContacts = _interopRequireDefault(require("../components/misc/EmptyListContacts"));
var _store = require("../contexts/store");
var _theme = require("../contexts/theme");
var _navigators = require("../types/navigators");
var _testable = require("../utils/testable");
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 ListContacts = _ref => {
  let {
    navigation
  } = _ref;
  const {
    ColorPallet
  } = (0, _theme.useTheme)();
  const {
    t
  } = (0, _reactI18next.useTranslation)();
  const style = _reactNative.StyleSheet.create({
    list: {
      backgroundColor: ColorPallet.brand.secondaryBackground
    },
    itemSeparator: {
      backgroundColor: ColorPallet.brand.primaryBackground,
      height: 1,
      marginHorizontal: 16
    }
  });
  const {
    records
  } = (0, _reactHooks.useConnections)();
  const [store] = (0, _store.useStore)();
  // Filter out mediator agents
  let connections = records;
  if (!store.preferences.developerModeEnabled) {
    connections = records.filter(r => !r.connectionTypes.includes(_core.ConnectionType.Mediator));
  }
  const onPressAddContact = () => {
    var _navigation$getParent;
    (_navigation$getParent = navigation.getParent()) === null || _navigation$getParent === void 0 ? void 0 : _navigation$getParent.navigate(_navigators.Stacks.ConnectStack, {
      screen: _navigators.Screens.Scan,
      params: {
        defaultToConnect: true
      }
    });
  };
  (0, _react.useEffect)(() => {
    if (store.preferences.useConnectionInviterCapability) {
      navigation.setOptions({
        headerRight: () => /*#__PURE__*/_react.default.createElement(_HeaderButton.default, {
          buttonLocation: _HeaderButton.ButtonLocation.Right,
          accessibilityLabel: t('Contacts.AddContact'),
          testID: (0, _testable.testIdWithKey)('AddContact'),
          onPress: onPressAddContact,
          icon: "plus-circle-outline"
        })
      });
    } else {
      navigation.setOptions({
        headerRight: () => false
      });
    }
  }, [store.preferences.useConnectionInviterCapability]);
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, null, /*#__PURE__*/_react.default.createElement(_reactNative.FlatList, {
    style: style.list,
    data: connections,
    ItemSeparatorComponent: () => /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: style.itemSeparator
    }),
    keyExtractor: connection => connection.id,
    renderItem: _ref2 => {
      let {
        item: connection
      } = _ref2;
      return /*#__PURE__*/_react.default.createElement(_ContactListItem.default, {
        contact: connection,
        navigation: navigation
      });
    },
    ListEmptyComponent: () => /*#__PURE__*/_react.default.createElement(_EmptyListContacts.default, {
      navigation: navigation
    })
  }));
};
var _default = ListContacts;
exports.default = _default;
//# sourceMappingURL=ListContacts.js.map