"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var voted_users_modal_exports = {};
__export(voted_users_modal_exports, {
  VotedUsersModal: () => VotedUsersModal
});
module.exports = __toCommonJS(voted_users_modal_exports);
var import_react = __toESM(require("react"));
var import_react_infinite_scroller = __toESM(require("react-infinite-scroller"));
var import_loader_icon = require("../../assets/icons/loader-icon.js");
var import_remove_icon = require("../../assets/icons/remove-icon.js");
var import_rce_helpers_context = require("../rce-helpers-context/index.js");
var import_voted_users_scss = __toESM(require("./voted-users-scss.js"));
var import_voter_avatar = require("./voter-avatar.js");
class VotedUsersModalComponent extends import_react.Component {
  constructor() {
    super(...arguments);
    this.state = {
      members: [],
      moreItems: true,
      cursor: void 0
    };
    this.fetchVoters = async () => {
      const { cursor } = this.state;
      try {
        const { voters, moreItems } = await this.props.fetchVoters({ cursor, limit: 10 });
        const members = await this.props.rce.getSiteMembers(voters.map((v) => v.memberId)) || [];
        this.setState({
          members: this.state.members.concat(members),
          cursor: voters[voters.length - 1].memberId,
          moreItems
        });
      } catch {
      }
    };
  }
  render() {
    const { t, option, onRequestClose } = this.props;
    const { members, moreItems } = this.state;
    return /* @__PURE__ */ import_react.default.createElement("div", { className: import_voted_users_scss.default.voted_users_modal }, /* @__PURE__ */ import_react.default.createElement("div", { className: import_voted_users_scss.default.voted_users_modal_header }, /* @__PURE__ */ import_react.default.createElement("p", { className: import_voted_users_scss.default.title }, t("Poll_Viewer_VoteCount_Modal_Voters_Header", {
      count: option.count,
      number: option.count
    })), /* @__PURE__ */ import_react.default.createElement(import_remove_icon.RemoveIcon, { onClick: onRequestClose, className: import_voted_users_scss.default.close_icon })), /* @__PURE__ */ import_react.default.createElement(
      import_react_infinite_scroller.default,
      {
        className: import_voted_users_scss.default.member_list_container,
        initialLoad: true,
        hasMore: moreItems,
        loadMore: this.fetchVoters,
        loader: /* @__PURE__ */ import_react.default.createElement("div", { className: import_voted_users_scss.default.loader }, /* @__PURE__ */ import_react.default.createElement(import_loader_icon.LoaderIcon, { width: 24, height: 24, className: import_voted_users_scss.default.spinner }))
      },
      /* @__PURE__ */ import_react.default.createElement("ul", { className: import_voted_users_scss.default.member_list }, members.map((member) => {
        return member ? /* @__PURE__ */ import_react.default.createElement("li", { key: member.siteMemberId }, /* @__PURE__ */ import_react.default.createElement("div", { className: import_voted_users_scss.default.user_card }, /* @__PURE__ */ import_react.default.createElement(
          import_voter_avatar.VoterAvatar,
          {
            className: import_voted_users_scss.default.user_avatar,
            member,
            src: member.imageUrl,
            size: {
              width: 36,
              height: 36
            }
          }
        ), /* @__PURE__ */ import_react.default.createElement("span", { className: import_voted_users_scss.default.user_name }, member.name?.nick || t("Poll_Viewer_VoteCount_Modal_Voters_Private_Voter")))) : null;
      }))
    ), option.anonymousCount ? /* @__PURE__ */ import_react.default.createElement("p", { className: import_voted_users_scss.default.anonymous_counter }, t("Poll_Viewer_VoteCount_Modal_Voters_Anonymous", {
      anonNumber: option.anonymousCount
    })) : null);
  }
}
const VotedUsersModal = (0, import_rce_helpers_context.withRCEHelpers)(VotedUsersModalComponent);
//# sourceMappingURL=voted-users-modal.js.map
