import "core-js/modules/es.symbol.js";
import "core-js/modules/es.array.filter.js";
import "core-js/modules/es.array.for-each.js";
import "core-js/modules/es.array.push.js";
import "core-js/modules/es.object.define-properties.js";
import "core-js/modules/es.object.define-property.js";
import "core-js/modules/es.object.get-own-property-descriptor.js";
import "core-js/modules/es.object.get-own-property-descriptors.js";
import "core-js/modules/es.object.keys.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/esnext.iterator.constructor.js";
import "core-js/modules/esnext.iterator.filter.js";
import "core-js/modules/esnext.iterator.for-each.js";
import "core-js/modules/web.dom-collections.for-each.js";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
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) { _defineProperty(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; }
import { List, AutoSizer, CellMeasurerCache, CellMeasurer } from 'react-virtualized';
import { FcrInput } from '../input';
import './index.css';
import { FcrParticipant } from './attendee';
import { FcrIconType } from '../icon/type';
import { useMemo, useState } from 'react';
import { useI18n } from '../../i18n';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var cache = new CellMeasurerCache({
  fixedWidth: true,
  defaultHeight: 52
});
var userRowRenderer = function userRowRenderer(userList, userRenderer, hasPinnedStream, toggleParticipantAction) {
  return function (renderProps) {
    var key = renderProps.key,
      parent = renderProps.parent,
      index = renderProps.index,
      style = renderProps.style;
    return /*#__PURE__*/_jsx(CellMeasurer, {
      cache: cache,
      parent: parent,
      columnIndex: 0,
      rowIndex: index,
      children: function children(_ref) {
        var measure = _ref.measure;
        return /*#__PURE__*/_jsx("div", {
          style: _objectSpread(_objectSpread({}, style), {}, {
            pointerEvents: 'all'
          }),
          onLoad: measure,
          children: userRenderer ? userRenderer(userList[index]) : /*#__PURE__*/_jsx(FcrParticipant, {
            hasPinnedStream: hasPinnedStream,
            user: userList[index],
            onParticipantsButtonClick: toggleParticipantAction,
            isLocalCameraInSecondaryWindow: false // mobile participants do not have secondary windows
          })
        });
      }
    }, key);
  };
};
export var FcrMobileParticipants = function FcrMobileParticipants(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,
    footer = _props.footer,
    header = _props.header;

  // 使用 useMemo 初始化 value 状态
  var _useState = useState(useMemo(function () {
      return searchText || '';
    }, [searchText])),
    _useState2 = _slicedToArray(_useState, 2),
    value = _useState2[0],
    setValue = _useState2[1];
  var t = useI18n();
  var handleChange = function handleChange(val) {
    setValue(val);
    onSearch(val);
  };
  return /*#__PURE__*/_jsxs("div", {
    className: "fcr-participant",
    children: [header, /*#__PURE__*/_jsx("div", {
      className: "fcr-participant__search-and-invite",
      children: /*#__PURE__*/_jsx(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: FcrIconType.FCR_V2_SEARCH,
          colors: {
            iconPrimary: 'var(--fcr_ui_scene_icontext1)'
          }
        }
      })
    }), /*#__PURE__*/_jsx("div", {
      className: "fcr-participant__list",
      children: /*#__PURE__*/_jsx(AutoSizer, {
        children: function children(_ref2) {
          var height = _ref2.height,
            width = _ref2.width;
          return /*#__PURE__*/_jsx(List, {
            width: width,
            height: height,
            rowCount: userList.length,
            rowHeight: cache.rowHeight,
            rowRenderer: userRowRenderer(userList, userRenderer, hasPinnedStream, toggleParticipantAction)
          });
        }
      })
    }), footer ? footer : null]
  });
};