"use strict";

require("core-js/modules/es.symbol.js");
require("core-js/modules/es.array.filter.js");
require("core-js/modules/es.array.for-each.js");
require("core-js/modules/es.array.push.js");
require("core-js/modules/es.object.define-properties.js");
require("core-js/modules/es.object.define-property.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
require("core-js/modules/es.object.get-own-property-descriptors.js");
require("core-js/modules/es.object.keys.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/esnext.iterator.constructor.js");
require("core-js/modules/esnext.iterator.filter.js");
require("core-js/modules/esnext.iterator.for-each.js");
require("core-js/modules/web.dom-collections.for-each.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FcrParticipants = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _button = require("../button");
var _reactVirtualized = require("react-virtualized");
var _input = require("../input");
var _attendee = require("./attendee");
var _type = require("../icon/type");
var _react = require("react");
var _i18n = require("../../i18n");
require("./index.css");
var _jsxRuntime = require("react/jsx-runtime");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).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), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var cache = new _reactVirtualized.CellMeasurerCache({
  fixedWidth: true,
  defaultHeight: 52
});
var userRowRenderer = function userRowRenderer(userList, userRenderer, hasPinnedStream, toggleParticipantAction, isLocalCameraInSecondaryWindow) {
  return function (renderProps) {
    var key = renderProps.key,
      parent = renderProps.parent,
      index = renderProps.index,
      style = renderProps.style;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactVirtualized.CellMeasurer, {
      cache: cache,
      parent: parent,
      columnIndex: 0,
      rowIndex: index,
      children: function children(_ref) {
        var measure = _ref.measure;
        return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          style: _objectSpread(_objectSpread({}, style), {}, {
            pointerEvents: 'all'
          }),
          onLoad: measure,
          children: userRenderer ? userRenderer(userList[index]) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_attendee.FcrParticipant, {
            hasPinnedStream: hasPinnedStream,
            user: userList[index],
            onParticipantsButtonClick: toggleParticipantAction,
            isLocalCameraInSecondaryWindow: isLocalCameraInSecondaryWindow
          })
        });
      }
    }, key);
  };
};
var FcrParticipants = exports.FcrParticipants = function FcrParticipants(props) {
  var _props = _objectSpread({}, props),
    searchText = _props.searchText,
    onSearch = _props.onSearch,
    userList = _props.userList,
    userRenderer = _props.userRenderer,
    onInvite = _props.onInvite,
    hasPinnedStream = _props.hasPinnedStream,
    toggleParticipantAction = _props.toggleParticipantAction,
    toggleRoomControlAction = _props.toggleRoomControlAction,
    isLocalCameraInSecondaryWindow = _props.isLocalCameraInSecondaryWindow,
    _props$hasInvite = _props.hasInvite,
    hasInvite = _props$hasInvite === void 0 ? true : _props$hasInvite,
    footer = _props.footer,
    header = _props.header,
    emptyContent = _props.emptyContent;

  // 使用 useMemo 初始化 value 状态
  var _useState = (0, _react.useState)((0, _react.useMemo)(function () {
      return searchText || '';
    }, [searchText])),
    _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
    value = _useState2[0],
    setValue = _useState2[1];
  var t = (0, _i18n.useI18n)();
  var handleChange = function handleChange(val) {
    setValue(val);
    onSearch(val);
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: "fcr-participant",
    children: [header, /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "fcr-participant__search-and-invite",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_input.FcrInput, {
        size: "small",
        placeholder: t('fmt_attendies_button_serach'),
        value: value,
        shape: "rounded",
        onChange: handleChange,
        maxLength: 21,
        style: {
          background: 'var(--fcr_ui_scene_input2)'
        }
        // autoFocus
        ,
        iconPrefix: {
          type: _type.FcrIconType.FCR_V2_SEARCH,
          colors: {
            iconPrimary: 'var(--fcr_ui_scene_icontext1)'
          }
        }
      }), hasInvite && onInvite ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.FcrButton, {
        className: "fcr_participants_button_invite",
        type: "secondary-bordered",
        shape: "rounded",
        size: "XS",
        onClick: onInvite,
        children: t('fmt_participants_button_invite')
      }) : null]
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "fcr-participant__list",
      children: [userList.length === 0 && emptyContent, /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactVirtualized.AutoSizer, {
        children: function children(_ref2) {
          var height = _ref2.height,
            width = _ref2.width;
          return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactVirtualized.List, {
            width: width,
            height: height,
            rowCount: userList.length,
            rowHeight: cache.rowHeight,
            rowRenderer: userRowRenderer(userList, userRenderer, hasPinnedStream, toggleParticipantAction, isLocalCameraInSecondaryWindow)
          });
        }
      })]
    }), footer ? footer : null]
  });
};