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

var _chunkA4KF2LIFjs = require('./chunk-A4KF2LIF.js');


var _chunkA6E7VFHNjs = require('./chunk-A6E7VFHN.js');



var _chunkN4EKRU3Djs = require('./chunk-N4EKRU3D.js');

// tmp-babel/messages/web/__shared__/GroupChatMembersList/index.js
var _react = require('react');
var _inputs = require('@baseapp-frontend/design-system/components/web/inputs');
var _material = require('@mui/material');
var _reacthookform = require('react-hook-form');
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 _toConsumableArray(r) {
  return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
}
function _nonIterableSpread() {
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _iterableToArray(r) {
  if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
}
function _arrayWithoutHoles(r) {
  if (Array.isArray(r)) return _arrayLikeToArray(r);
}
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 GroupChatMembersList = function GroupChatMembersList2(_ref) {
  var FORM_VALUE = _ref.FORM_VALUE, setValue = _ref.setValue, refetch = _ref.refetch, connections = _ref.connections, currentParticipants = _ref.currentParticipants, connectionsLoadNext = _ref.connectionsLoadNext, connectionsHasNext = _ref.connectionsHasNext, connectionsIsLoadingNext = _ref.connectionsIsLoadingNext, membersLoadNext = _ref.membersLoadNext, membersHasNext = _ref.membersHasNext, membersIsLoadingNext = _ref.membersIsLoadingNext, _ref$ProfilesContaine = _ref.ProfilesContainer, ProfilesContainer2 = _ref$ProfilesContaine === void 0 ? _chunkN4EKRU3Djs.ProfilesContainer : _ref$ProfilesContaine, _ref$ProfileCard = _ref.ProfileCard, ProfileCard = _ref$ProfileCard === void 0 ? _chunkA4KF2LIFjs.ProfileCard_default : _ref$ProfileCard, _ref$ProfileCardProps = _ref.ProfileCardProps, ProfileCardProps = _ref$ProfileCardProps === void 0 ? {} : _ref$ProfileCardProps, _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$SearchbarContain = _ref.SearchbarContainer, SearchbarContainer2 = _ref$SearchbarContain === void 0 ? _chunkN4EKRU3Djs.SearchbarContainer : _ref$SearchbarContain, _ref$ConnectionsList = _ref.ConnectionsList, ConnectionsList = _ref$ConnectionsList === void 0 ? _chunkA6E7VFHNjs.ProfilesList_default : _ref$ConnectionsList, _ref$ConnectionsListP = _ref.ConnectionsListProps, ConnectionsListProps = _ref$ConnectionsListP === void 0 ? {} : _ref$ConnectionsListP, _ref$MembersList = _ref.MembersList, MembersList = _ref$MembersList === void 0 ? _chunkA6E7VFHNjs.ProfilesList_default : _ref$MembersList, _ref$MembersListProps = _ref.MembersListProps, MembersListProps = _ref$MembersListProps === void 0 ? {} : _ref$MembersListProps;
  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: ""
    }
  }), searchControl = _useForm.control, searchReset = _useForm.reset, searchWatch = _useForm.watch;
  var handleSearchChange = function handleSearchChange2(e) {
    var value = e.target.value || "";
    startTransition(function() {
      refetch === null || refetch === void 0 || refetch({
        q: value
      });
    });
  };
  var handleSearchClear = function handleSearchClear2() {
    startTransition(function() {
      searchReset();
      refetch === null || refetch === void 0 || refetch({
        q: ""
      });
    });
  };
  var handleAddMember = function handleAddMember2(profile) {
    setValue(FORM_VALUE.participants, [].concat(_toConsumableArray(currentParticipants), [profile]), {
      shouldValidate: true,
      shouldDirty: true,
      shouldTouch: true
    });
  };
  var handleRemoveMember = function handleRemoveMember2(profile) {
    setValue(FORM_VALUE.participants, currentParticipants.filter(function(member) {
      return (member === null || member === void 0 ? void 0 : member.id) !== (profile === null || profile === void 0 ? void 0 : profile.id);
    }), {
      shouldValidate: true,
      shouldDirty: true,
      shouldTouch: true
    });
  };
  var _renderItem = function renderItem(profile) {
    var isMember = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
    if (!profile) return null;
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ProfileCard, _objectSpread({
      profile,
      handleAddMember,
      handleRemoveMember,
      isMember
    }, ProfileCardProps));
  };
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, ProfilesContainer2, {
    children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, SearchbarContainer2, {
      children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Searchbar, _objectSpread({
        name: "search",
        onChange: handleSearchChange,
        onClear: handleSearchClear,
        control: searchControl,
        isPending
      }, SearchbarProps))
    }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
      height: "100%",
      width: "100%",
      children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, MembersList, _objectSpread({
        profiles: currentParticipants,
        renderItem: function renderItem(profile) {
          return _renderItem(profile, true);
        },
        loadNext: membersLoadNext,
        hasNext: membersHasNext,
        isLoadingNext: membersIsLoadingNext,
        label: "Selected group members",
        title: "Members"
      }, MembersListProps)), connections && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ConnectionsList, _objectSpread({
        profiles: connections,
        renderItem: function renderItem(profile) {
          return _renderItem(profile);
        },
        loadNext: connectionsLoadNext,
        hasNext: connectionsHasNext,
        isLoadingNext: connectionsIsLoadingNext,
        isPending,
        searchValue: searchWatch("search")
      }, ConnectionsListProps))]
    })]
  });
};
var GroupChatMembersList_default = GroupChatMembersList;



exports.GroupChatMembersList_default = GroupChatMembersList_default;
//# sourceMappingURL=chunk-NSD4MMXM.js.map