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

var _chunkOMKMJPMZjs = require('./chunk-OMKMJPMZ.js');


var _chunkKYDNTEQOjs = require('./chunk-KYDNTEQO.js');


var _chunkTPEVR5NFjs = require('./chunk-TPEVR5NF.js');


var _chunkADSB4RKLjs = require('./chunk-ADSB4RKL.js');


var _chunkBV6NSNQ2js = require('./chunk-BV6NSNQ2.js');


var _chunk25CJDQG6js = require('./chunk-25CJDQG6.js');

// tmp-babel/messages/web/SingleChatCreate/index.js
var _react = require('react');
var _authentication = require('@baseapp-frontend/authentication');
var _displays = require('@baseapp-frontend/design-system/components/web/displays');
var _inputs = require('@baseapp-frontend/design-system/components/web/inputs');
var _material = require('@mui/material');
var _reacthookform = require('react-hook-form');
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);
}
function _slicedToArray(r, e) {
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _nonIterableRest() {
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray(r, a) {
  if (r) {
    if ("string" == typeof r) return _arrayLikeToArray(r, a);
    var t = {}.toString.call(r).slice(8, -1);
    return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  }
}
function _arrayLikeToArray(r, a) {
  (null == a || a > r.length) && (a = r.length);
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  return n;
}
function _iterableToArrayLimit(r, l) {
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  if (null != t) {
    var e, n, i, u, a = [], f = true, o = false;
    try {
      if (i = (t = t.call(r)).next, 0 === l) {
        if (Object(t) !== t) return;
        f = false;
      } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
    } catch (r2) {
      o = true, n = r2;
    } finally {
      try {
        if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
      } finally {
        if (o) throw n;
      }
    }
    return a;
  }
}
function _arrayWithHoles(r) {
  if (Array.isArray(r)) return r;
}
var SingleChatCreate = function SingleChatCreate2(_ref) {
  var allProfilesRef = _ref.allProfilesRef, _ref$Body = _ref.Body, Body = _ref$Body === void 0 ? _chunkKYDNTEQOjs.Body_default : _ref$Body, _ref$BodyProps = _ref.BodyProps, BodyProps = _ref$BodyProps === void 0 ? {} : _ref$BodyProps, _ref$ChatRoomListItem = _ref.ChatRoomListItem, ChatRoomListItem = _ref$ChatRoomListItem === void 0 ? _chunkTPEVR5NFjs.ChatRoomListItem_default : _ref$ChatRoomListItem, _ref$ChatRoomListItem2 = _ref.ChatRoomListItemProps, ChatRoomListItemProps = _ref$ChatRoomListItem2 === void 0 ? {} : _ref$ChatRoomListItem2, _ref$Header = _ref.Header, Header = _ref$Header === void 0 ? _chunkOMKMJPMZjs.Header_default : _ref$Header, _ref$HeaderProps = _ref.HeaderProps, HeaderProps = _ref$HeaderProps === void 0 ? {} : _ref$HeaderProps, onChatCreation = _ref.onChatCreation, onGroupChatCreationButtonClicked = _ref.onGroupChatCreationButtonClicked, onHeaderClick = _ref.onHeaderClick, _ref$Searchbar = _ref.Searchbar, Searchbar = _ref$Searchbar === void 0 ? _inputs.Searchbar : _ref$Searchbar, _ref$SearchbarProps = _ref.SearchbarProps, SearchbarProps = _ref$SearchbarProps === void 0 ? {} : _ref$SearchbarProps, _ref$VirtuosoProps = _ref.VirtuosoProps, VirtuosoProps = _ref$VirtuosoProps === void 0 ? {} : _ref$VirtuosoProps;
  var _useAllProfilesList = _chunkBV6NSNQ2js.useAllProfilesList.call(void 0, allProfilesRef), allProfiles = _useAllProfilesList.data.allProfiles, loadNext = _useAllProfilesList.loadNext, isLoadingNext = _useAllProfilesList.isLoadingNext, hasNext = _useAllProfilesList.hasNext, refetch = _useAllProfilesList.refetch;
  var _useTransition = _react.useTransition.call(void 0, ), _useTransition2 = _slicedToArray(_useTransition, 2), isPending = _useTransition2[0], startTransition = _useTransition2[1];
  var _useForm = _reacthookform.useForm.call(void 0, {
    defaultValues: {
      search: ""
    }
  }), control = _useForm.control, reset = _useForm.reset, watch = _useForm.watch;
  var _useCurrentProfile = _authentication.useCurrentProfile.call(void 0, ), currentProfile = _useCurrentProfile.currentProfile;
  var handleSearchChange = function handleSearchChange2(e) {
    var value = e.target.value || "";
    startTransition(function() {
      refetch({
        q: value
      });
    });
  };
  var handleSearchClear = function handleSearchClear2() {
    startTransition(function() {
      reset();
      refetch({
        q: ""
      });
    });
  };
  var profiles = _react.useMemo.call(void 0, function() {
    return (allProfiles === null || allProfiles === void 0 ? void 0 : allProfiles.edges.filter(function(edge) {
      return (edge === null || edge === void 0 ? void 0 : edge.node) && edge.node.id !== (currentProfile === null || currentProfile === void 0 ? void 0 : currentProfile.id);
    }).map(function(edge) {
      return edge === null || edge === void 0 ? void 0 : edge.node;
    })) || [];
  }, [allProfiles, currentProfile === null || currentProfile === void 0 ? void 0 : currentProfile.id]);
  var renderLoadingState = function renderLoadingState2() {
    if (!isLoadingNext) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, {
      sx: {
        paddingTop: 3
      }
    });
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _displays.LoadingState, {
      sx: {
        paddingTop: 3,
        paddingBottom: 1
      },
      CircularProgressProps: {
        size: 15
      },
      "aria-label": "loading more profiles"
    });
  };
  var renderItem = function renderItem2(profile) {
    if (!profile) return null;
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ChatRoomListItem, _objectSpread({
      profile,
      onChatCreation
    }, ChatRoomListItemProps));
  };
  var renderListContent = function renderListContent2() {
    var emptyProfilesList = profiles.length === 0;
    var searchValue = watch("search");
    if (!isPending && searchValue && emptyProfilesList) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk25CJDQG6js.SearchNotFoundState_default, {});
    if (!isPending && emptyProfilesList) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkADSB4RKLjs.EmptyProfilesListState_default, {});
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactvirtuoso.Virtuoso, _objectSpread({
      data: profiles,
      itemContent: function itemContent(_index, item) {
        return renderItem(item);
      },
      style: {
        scrollbarWidth: "none",
        maxHeight: "calc(100vh - 72px - 57px - 61px - 72px)"
      },
      components: {
        Footer: renderLoadingState
      },
      endReached: function endReached() {
        if (hasNext) {
          loadNext(5);
        }
      }
    }, VirtuosoProps));
  };
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, {
    children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Header, _objectSpread({
      onHeaderClick
    }, HeaderProps)), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Body, _objectSpread(_objectSpread({
      control,
      isPending,
      handleSearchChange,
      handleSearchClear,
      onGroupChatCreationButtonClicked,
      Searchbar,
      SearchbarProps
    }, BodyProps), {}, {
      children: renderListContent()
    }))]
  });
};
var SingleChatCreate_default = SingleChatCreate;



exports.SingleChatCreate_default = SingleChatCreate_default;
//# sourceMappingURL=chunk-QYYH56EQ.js.map