var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ChannelList = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var _ChannelListFooterLoadingIndicator = require("./ChannelListFooterLoadingIndicator");
var _ChannelListHeaderErrorIndicator = require("./ChannelListHeaderErrorIndicator");
var _ChannelListHeaderNetworkDownIndicator = require("./ChannelListHeaderNetworkDownIndicator");
var _ChannelListLoadingIndicator = require("./ChannelListLoadingIndicator");
var _ChannelListMessenger = require("./ChannelListMessenger");
var _useChannelUpdated = require("./hooks/listeners/useChannelUpdated");
var _useCreateChannelsContext = require("./hooks/useCreateChannelsContext");
var _usePaginatedChannels2 = require("./hooks/usePaginatedChannels");
var _Skeleton = require("./Skeleton");
var _ChannelsContext = require("../../contexts/channelsContext/ChannelsContext");
var _ChatContext = require("../../contexts/chatContext/ChatContext");
var _ChannelPreviewMessenger = require("../ChannelPreview/ChannelPreviewMessenger");
var _EmptyStateIndicator = require("../Indicators/EmptyStateIndicator");
var _LoadingErrorIndicator = require("../Indicators/LoadingErrorIndicator");
var _jsxRuntime = require("react/jsx-runtime");
var _this = this,
  _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/components/ChannelList/ChannelList.tsx";
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var DEFAULT_FILTERS = {};
var DEFAULT_OPTIONS = {};
var DEFAULT_SORT = {};
var ChannelList = exports.ChannelList = function ChannelList(props) {
  var _props$additionalFlat = props.additionalFlatListProps,
    additionalFlatListProps = _props$additionalFlat === void 0 ? {} : _props$additionalFlat,
    channelRenderFilterFn = props.channelRenderFilterFn,
    _props$EmptyStateIndi = props.EmptyStateIndicator,
    EmptyStateIndicator = _props$EmptyStateIndi === void 0 ? _EmptyStateIndicator.EmptyStateIndicator : _props$EmptyStateIndi,
    _props$filters = props.filters,
    filters = _props$filters === void 0 ? DEFAULT_FILTERS : _props$filters,
    _props$FooterLoadingI = props.FooterLoadingIndicator,
    FooterLoadingIndicator = _props$FooterLoadingI === void 0 ? _ChannelListFooterLoadingIndicator.ChannelListFooterLoadingIndicator : _props$FooterLoadingI,
    _props$HeaderErrorInd = props.HeaderErrorIndicator,
    HeaderErrorIndicator = _props$HeaderErrorInd === void 0 ? _ChannelListHeaderErrorIndicator.ChannelListHeaderErrorIndicator : _props$HeaderErrorInd,
    _props$HeaderNetworkD = props.HeaderNetworkDownIndicator,
    HeaderNetworkDownIndicator = _props$HeaderNetworkD === void 0 ? _ChannelListHeaderNetworkDownIndicator.ChannelListHeaderNetworkDownIndicator : _props$HeaderNetworkD,
    _props$List = props.List,
    List = _props$List === void 0 ? _ChannelListMessenger.ChannelListMessenger : _props$List,
    ListHeaderComponent = props.ListHeaderComponent,
    _props$LoadingErrorIn = props.LoadingErrorIndicator,
    LoadingErrorIndicator = _props$LoadingErrorIn === void 0 ? _LoadingErrorIndicator.LoadingErrorIndicator : _props$LoadingErrorIn,
    _props$LoadingIndicat = props.LoadingIndicator,
    LoadingIndicator = _props$LoadingIndicat === void 0 ? _ChannelListLoadingIndicator.ChannelListLoadingIndicator : _props$LoadingIndicat,
    _props$loadMoreThresh = props.loadMoreThreshold,
    loadMoreThreshold = _props$loadMoreThresh === void 0 ? 0.1 : _props$loadMoreThresh,
    _props$lockChannelOrd = props.lockChannelOrder,
    lockChannelOrder = _props$lockChannelOrd === void 0 ? false : _props$lockChannelOrd,
    _props$maxUnreadCount = props.maxUnreadCount,
    maxUnreadCount = _props$maxUnreadCount === void 0 ? 255 : _props$maxUnreadCount,
    _props$numberOfSkelet = props.numberOfSkeletons,
    numberOfSkeletons = _props$numberOfSkelet === void 0 ? 6 : _props$numberOfSkelet,
    onAddedToChannel = props.onAddedToChannel,
    onChannelDeleted = props.onChannelDeleted,
    onChannelHidden = props.onChannelHidden,
    onChannelMemberUpdated = props.onChannelMemberUpdated,
    onChannelTruncated = props.onChannelTruncated,
    onChannelUpdated = props.onChannelUpdated,
    onChannelVisible = props.onChannelVisible,
    onNewMessage = props.onNewMessage,
    onNewMessageNotification = props.onNewMessageNotification,
    onRemovedFromChannel = props.onRemovedFromChannel,
    onSelect = props.onSelect,
    _props$options = props.options,
    options = _props$options === void 0 ? DEFAULT_OPTIONS : _props$options,
    _props$Preview = props.Preview,
    Preview = _props$Preview === void 0 ? _ChannelPreviewMessenger.ChannelPreviewMessenger : _props$Preview,
    PreviewAvatar = props.PreviewAvatar,
    PreviewMessage = props.PreviewMessage,
    PreviewMutedStatus = props.PreviewMutedStatus,
    PreviewStatus = props.PreviewStatus,
    PreviewTitle = props.PreviewTitle,
    PreviewUnreadCount = props.PreviewUnreadCount,
    _setFlatListRef = props.setFlatListRef,
    _props$Skeleton = props.Skeleton,
    Skeleton = _props$Skeleton === void 0 ? _Skeleton.Skeleton : _props$Skeleton,
    _props$sort = props.sort,
    sort = _props$sort === void 0 ? DEFAULT_SORT : _props$sort;
  var _useState = (0, _react.useState)(0),
    _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
    forceUpdate = _useState2[0],
    setForceUpdate = _useState2[1];
  var _useChatContext = (0, _ChatContext.useChatContext)(),
    client = _useChatContext.client,
    enableOfflineSupport = _useChatContext.enableOfflineSupport;
  var channelManager = (0, _react.useMemo)(function () {
    return client.createChannelManager({});
  }, [client]);
  (0, _react.useEffect)(function () {
    channelManager.setEventHandlerOverrides({
      channelDeletedHandler: onChannelDeleted,
      channelHiddenHandler: onChannelHidden,
      channelTruncatedHandler: onChannelTruncated,
      channelVisibleHandler: onChannelVisible,
      memberUpdatedHandler: onChannelMemberUpdated ? function (setChannels, event) {
        return onChannelMemberUpdated(lockChannelOrder, setChannels, event, {
          filters: filters,
          sort: sort
        });
      } : undefined,
      newMessageHandler: onNewMessage ? function (setChannels, event) {
        return onNewMessage(lockChannelOrder, setChannels, event, {
          filters: filters,
          sort: sort
        });
      } : undefined,
      notificationAddedToChannelHandler: onAddedToChannel ? function (setChannels, event) {
        return onAddedToChannel(setChannels, event, {
          filters: filters,
          sort: sort
        });
      } : undefined,
      notificationNewMessageHandler: onNewMessageNotification ? function (setChannels, event) {
        return onNewMessageNotification(setChannels, event, {
          filters: filters,
          sort: sort
        });
      } : undefined,
      notificationRemovedFromChannelHandler: onRemovedFromChannel
    });
  }, [channelManager, filters, lockChannelOrder, onAddedToChannel, onChannelDeleted, onChannelHidden, onChannelMemberUpdated, onChannelTruncated, onChannelVisible, onNewMessage, onNewMessageNotification, onRemovedFromChannel, sort]);
  (0, _react.useEffect)(function () {
    channelManager.setOptions({
      abortInFlightQuery: false,
      lockChannelOrder: lockChannelOrder
    });
  }, [channelManager, lockChannelOrder]);
  (0, _react.useEffect)(function () {
    channelManager.registerSubscriptions();
    return function () {
      channelManager.unregisterSubscriptions();
    };
  }, [channelManager]);
  var _usePaginatedChannels = (0, _usePaginatedChannels2.usePaginatedChannels)({
      channelManager: channelManager,
      enableOfflineSupport: enableOfflineSupport,
      filters: filters,
      options: options,
      setForceUpdate: setForceUpdate,
      sort: sort
    }),
    channelListInitialized = _usePaginatedChannels.channelListInitialized,
    channels = _usePaginatedChannels.channels,
    error = _usePaginatedChannels.error,
    hasNextPage = _usePaginatedChannels.hasNextPage,
    loadingChannels = _usePaginatedChannels.loadingChannels,
    loadingNextPage = _usePaginatedChannels.loadingNextPage,
    loadNextPage = _usePaginatedChannels.loadNextPage,
    refreshing = _usePaginatedChannels.refreshing,
    refreshList = _usePaginatedChannels.refreshList,
    reloadList = _usePaginatedChannels.reloadList;
  (0, _useChannelUpdated.useChannelUpdated)({
    onChannelUpdated: onChannelUpdated,
    setChannels: channelManager.setChannels
  });
  var channelsContext = (0, _useCreateChannelsContext.useCreateChannelsContext)({
    additionalFlatListProps: additionalFlatListProps,
    channelListInitialized: channelListInitialized,
    channels: channelRenderFilterFn ? channelRenderFilterFn(channels != null ? channels : []) : channels,
    EmptyStateIndicator: EmptyStateIndicator,
    error: error,
    FooterLoadingIndicator: FooterLoadingIndicator,
    forceUpdate: forceUpdate,
    hasNextPage: hasNextPage,
    HeaderErrorIndicator: HeaderErrorIndicator,
    HeaderNetworkDownIndicator: HeaderNetworkDownIndicator,
    ListHeaderComponent: ListHeaderComponent,
    loadingChannels: loadingChannels,
    LoadingErrorIndicator: LoadingErrorIndicator,
    LoadingIndicator: LoadingIndicator,
    loadingNextPage: loadingNextPage,
    loadMoreThreshold: loadMoreThreshold,
    loadNextPage: loadNextPage,
    maxUnreadCount: maxUnreadCount,
    numberOfSkeletons: numberOfSkeletons,
    onSelect: onSelect,
    Preview: Preview,
    PreviewAvatar: PreviewAvatar,
    PreviewMessage: PreviewMessage,
    PreviewMutedStatus: PreviewMutedStatus,
    PreviewStatus: PreviewStatus,
    PreviewTitle: PreviewTitle,
    PreviewUnreadCount: PreviewUnreadCount,
    refreshing: refreshing,
    refreshList: refreshList,
    reloadList: reloadList,
    setFlatListRef: function setFlatListRef(ref) {
      if (_setFlatListRef) {
        _setFlatListRef(ref);
      }
    },
    Skeleton: Skeleton
  });
  return (0, _jsxRuntime.jsx)(_ChannelsContext.ChannelsProvider, {
    value: channelsContext,
    children: (0, _jsxRuntime.jsx)(List, {})
  });
};
//# sourceMappingURL=ChannelList.js.map