"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _chunkS2KC5POFjs = require('./chunk-S2KC5POF.js');


var _chunkXMV34ICOjs = require('./chunk-XMV34ICO.js');


var _chunkVYIUO4RDjs = require('./chunk-VYIUO4RD.js');


var _chunkWWBJ47QKjs = require('./chunk-WWBJ47QK.js');


var _chunkLQCR3ZC5js = require('./chunk-LQCR3ZC5.js');



var _chunkPTJJ6CNFjs = require('./chunk-PTJJ6CNF.js');


var _chunkGFUIJZCXjs = require('./chunk-GFUIJZCX.js');


var _chunkRCZ372LZjs = require('./chunk-RCZ372LZ.js');

// tmp-babel/notifications/native/NotificationsList/index.js
var _react = require('react'); var _react2 = _interopRequireDefault(_react);
var _displays = require('@baseapp-frontend/design-system/components/native/displays');
var _typographies = require('@baseapp-frontend/design-system/components/native/typographies');
var _views = require('@baseapp-frontend/design-system/components/native/views');
var _native = require('@baseapp-frontend/design-system/providers/native');
var _reactrelay = require('react-relay');
var _jsxruntime = require('react/jsx-runtime');
function _typeof(o) {
  "@babel/helpers - typeof";
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
    return typeof o2;
  } : function(o2) {
    return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
  }, _typeof(o);
}
function ownKeys(e, r) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var o = Object.getOwnPropertySymbols(e);
    r && (o = o.filter(function(r2) {
      return Object.getOwnPropertyDescriptor(e, r2).enumerable;
    })), t.push.apply(t, o);
  }
  return t;
}
function _objectSpread(e) {
  for (var r = 1; r < arguments.length; r++) {
    var t = null != arguments[r] ? arguments[r] : {};
    r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
      _defineProperty(e, r2, t[r2]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
      Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
    });
  }
  return e;
}
function _defineProperty(e, r, t) {
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey(t) {
  var i = _toPrimitive(t, "string");
  return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
  if ("object" != _typeof(t) || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r || "default");
    if ("object" != _typeof(i)) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}
var NotificationsList = function NotificationsList2(_ref) {
  var _data$notifications2;
  var _ref$EmptyState = _ref.EmptyState, EmptyState = _ref$EmptyState === void 0 ? _chunkWWBJ47QKjs.EmptyState_default : _ref$EmptyState, _ref$NotificationItem = _ref.NotificationItem, NotificationItem = _ref$NotificationItem === void 0 ? _chunkXMV34ICOjs.NotificationItem_default : _ref$NotificationItem, _ref$NotificationItem2 = _ref.NotificationItemProps, NotificationItemProps = _ref$NotificationItem2 === void 0 ? {} : _ref$NotificationItem2;
  var theme = _native.useTheme.call(void 0, );
  var styles = _chunkLQCR3ZC5js.createStyles.call(void 0, theme);
  var options = {
    count: 10
  };
  var _useLazyLoadQuery = _reactrelay.useLazyLoadQuery.call(void 0, _chunkPTJJ6CNFjs.NotificationsListQuery, options, {
    fetchPolicy: "store-and-network"
  }), me = _useLazyLoadQuery.me;
  var _usePaginationFragmen = _reactrelay.usePaginationFragment.call(void 0, _chunkPTJJ6CNFjs.NotificationsListFragment, me), data = _usePaginationFragmen.data, loadNext = _usePaginationFragmen.loadNext, isLoadingNext = _usePaginationFragmen.isLoadingNext, hasNext = _usePaginationFragmen.hasNext, refetch = _usePaginationFragmen.refetch;
  _chunkGFUIJZCXjs.useNotificationsSubscription.call(void 0, me === null || me === void 0 ? void 0 : me.id);
  var notifications = _react.useMemo.call(void 0, function() {
    var _data$notifications;
    return (data === null || data === void 0 || (_data$notifications = data.notifications) === null || _data$notifications === void 0 ? void 0 : _data$notifications.edges.filter(function(edge) {
      return edge === null || edge === void 0 ? void 0 : edge.node;
    }).map(function(edge) {
      return edge === null || edge === void 0 ? void 0 : edge.node;
    })) || [];
  }, [data === null || data === void 0 || (_data$notifications2 = data.notifications) === null || _data$notifications2 === void 0 ? void 0 : _data$notifications2.edges]);
  var refetchNotifications = function refetchNotifications2() {
    refetch(options, {
      fetchPolicy: "store-and-network"
    });
  };
  var renderNotificationItem = function renderNotificationItem2(notification, index) {
    var _notifications;
    if (!notification) return null;
    var divider = null;
    if (!notification.unread && index > 0 && (_notifications = notifications[index - 1]) !== null && _notifications !== void 0 && _notifications.unread) {
      divider = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkVYIUO4RDjs.Divider_default, {});
    }
    return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, {
      children: [divider, /* @__PURE__ */ _jsxruntime.jsx.call(void 0, NotificationItem, _objectSpread({
        notification,
        refetch: refetchNotifications
      }, NotificationItemProps))]
    });
  };
  var renderContent = function renderContent2() {
    if (notifications.length === 0) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, EmptyState, {});
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _views.View, {
      style: styles.listContainer,
      children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _views.InfiniteScrollerView, {
        data: notifications,
        renderItem: function renderItem(_ref2) {
          var item = _ref2.item, index = _ref2.index;
          return renderNotificationItem(item, index);
        },
        estimatedItemSize: 134,
        onEndReached: function onEndReached() {
          if (hasNext) {
            loadNext(_chunkRCZ372LZjs.NUMBER_OF_NOTIFICATIONS_TO_LOAD_NEXT);
          }
        },
        isLoading: isLoadingNext
      })
    });
  };
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _views.View, {
    style: styles.container,
    children: [/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _views.View, {
      style: styles.headerContainer,
      children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _typographies.Text, {
        variant: "h6",
        children: "Notifications"
      }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkS2KC5POFjs.MarkAllAsReadButton_default, {
        refetch: refetchNotifications,
        disabled: !(data !== null && data !== void 0 && data.notificationsUnreadCount)
      })]
    }), renderContent()]
  });
};
var SuspendedNotificationsList = function SuspendedNotificationsList2(props) {
  var theme = _native.useTheme.call(void 0, );
  var styles = _chunkLQCR3ZC5js.createStyles.call(void 0, theme);
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Suspense, {
    fallback: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _views.View, {
      style: styles.container,
      children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _views.View, {
        style: styles.headerContainer,
        children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _typographies.Text, {
          variant: "h6",
          children: "Notifications"
        })
      }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _displays.LoadingScreen, {})]
    }),
    children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, NotificationsList, _objectSpread({}, props))
  });
};
var NotificationsList_default = SuspendedNotificationsList;



exports.NotificationsList_default = NotificationsList_default;
//# sourceMappingURL=chunk-KKK46U7K.js.map