"use strict";Object.defineProperty(exports, "__esModule", {value: true});

var _chunk4LRRYTKUjs = require('./chunk-4LRRYTKU.js');


var _chunkLOUC6I6Ajs = require('./chunk-LOUC6I6A.js');


var _chunkO5KBQ5MEjs = require('./chunk-O5KBQ5ME.js');


var _chunk7VI6GWMGjs = require('./chunk-7VI6GWMG.js');



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


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


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

// tmp-babel/notifications/web/NotificationsList/index.js
var _react = require('react');
var _buttons = require('@baseapp-frontend/design-system/components/web/buttons');
var _displays = require('@baseapp-frontend/design-system/components/web/displays');
var _icons = require('@baseapp-frontend/design-system/components/web/icons');
var _web = require('@baseapp-frontend/design-system/hooks/web');
var _material = require('@mui/material');
var _reactrelay = require('react-relay');
var _reactvirtuoso = require('react-virtuoso');
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 setIsDrawerOpened = _ref.setIsDrawerOpened, _ref$EmptyState = _ref.EmptyState, EmptyState = _ref$EmptyState === void 0 ? _chunkO5KBQ5MEjs.EmptyState_default : _ref$EmptyState, _ref$LoadingState = _ref.LoadingState, LoadingState = _ref$LoadingState === void 0 ? _displays.LoadingState : _ref$LoadingState, _ref$LoadingStateProp = _ref.LoadingStateProps, LoadingStateProps = _ref$LoadingStateProp === void 0 ? {} : _ref$LoadingStateProp, _ref$NotificationItem = _ref.NotificationItem, NotificationItem = _ref$NotificationItem === void 0 ? _chunkLOUC6I6Ajs.NotificationItem_default : _ref$NotificationItem, _ref$NotificationItem2 = _ref.NotificationItemProps, NotificationItemProps = _ref$NotificationItem2 === void 0 ? {} : _ref$NotificationItem2;
  var smDown = _web.useResponsive.call(void 0, "down", "sm");
  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 renderNotificationItem = function renderNotificationItem2(notification, index) {
    var _notifications;
    if (!notification) return null;
    if (!notification.unread && (_notifications = notifications[index - 1]) !== null && _notifications !== void 0 && _notifications.unread) {
      return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, {
        children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Divider, {
          children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
            variant: "body2",
            children: "Older"
          })
        }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, NotificationItem, _objectSpread({
          notification
        }, NotificationItemProps), "notification-".concat(notification.id))]
      });
    }
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, NotificationItem, _objectSpread({
      notification
    }, NotificationItemProps), "notification-".concat(notification.id));
  };
  var renderVirtuosoHeader = function renderVirtuosoHeader2() {
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {
      className: "h-2"
    });
  };
  var renderVirtuosoLoadingState = function renderVirtuosoLoadingState2() {
    if (!isLoadingNext) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, {
      sx: {
        paddingTop: 3
      }
    });
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LoadingState, _objectSpread({
      sx: {
        paddingTop: 3
      },
      CircularProgressProps: {
        size: 15
      }
    }, LoadingStateProps));
  };
  var renderContent = function renderContent2() {
    if (notifications.length === 0) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, EmptyState, {});
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, {
      sx: {
        backgroundColor: "common.white"
      },
      children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactvirtuoso.Virtuoso, {
        data: notifications,
        style: {
          height: "calc(100vh - 68px)"
        },
        itemContent: function itemContent(index, notification) {
          return renderNotificationItem(notification, index);
        },
        components: {
          Header: renderVirtuosoHeader,
          Footer: renderVirtuosoLoadingState
        },
        endReached: function endReached() {
          if (hasNext) {
            loadNext(_chunkRCZ372LZjs.NUMBER_OF_NOTIFICATIONS_TO_LOAD_NEXT);
          }
        }
      })
    });
  };
  var refetchNotifications = function refetchNotifications2() {
    refetch(options, {
      fetchPolicy: "network-only"
    });
  };
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
    display: "grid",
    gridTemplateRows: "min-content 1fr",
    height: "100%",
    children: [/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunk7VI6GWMGjs.HeaderContainer, {
      children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
        variant: "h6",
        children: "Notifications"
      }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
        display: "grid",
        gridTemplateColumns: "max-content min-content",
        children: [!!(data !== null && data !== void 0 && data.notificationsUnreadCount) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk4LRRYTKUjs.MarkAllAsReadButton_default, {
          refetch: refetchNotifications
        }), smDown && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _buttons.IconButton, {
          onClick: function onClick() {
            return setIsDrawerOpened(false);
          },
          "aria-label": "close notifications",
          children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _icons.CloseIcon, {})
        })]
      })]
    }), renderContent()]
  });
};
var NotificationsListSuspended = function NotificationsListSuspended2(props) {
  var _props$LoadingState = props.LoadingState, LoadingState = _props$LoadingState === void 0 ? _displays.LoadingState : _props$LoadingState, _props$LoadingStatePr = props.LoadingStateProps, LoadingStateProps = _props$LoadingStatePr === void 0 ? {} : _props$LoadingStatePr;
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Suspense, {
    fallback: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LoadingState, _objectSpread({}, LoadingStateProps)),
    children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, NotificationsList, _objectSpread({}, props))
  });
};
var NotificationsList_default = NotificationsListSuspended;



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