"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/editor/src/components/collab-sidebar/note-indicator-toolbar.js
var note_indicator_toolbar_exports = {};
__export(note_indicator_toolbar_exports, {
  NoteAvatarIndicator: () => NoteAvatarIndicator
});
module.exports = __toCommonJS(note_indicator_toolbar_exports);
var import_components = require("@wordpress/components");
var import_ui = require("@wordpress/ui");
var import_i18n = require("@wordpress/i18n");
var import_element = require("@wordpress/element");
var import_block_editor = require("@wordpress/block-editor");
var import_lock_unlock = require("../../lock-unlock.cjs");
var import_utils = require("./utils.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
var { NoteIconToolbarSlotFill } = (0, import_lock_unlock.unlock)(import_block_editor.privateApis);
function NoteAvatarIndicator({ onClick, note }) {
  const threadParticipants = (0, import_element.useMemo)(() => {
    if (!note) {
      return [];
    }
    const participantsMap = /* @__PURE__ */ new Map();
    const allNotes = [note, ...note.reply];
    allNotes.sort((a, b) => new Date(a.date) - new Date(b.date));
    allNotes.forEach((entry) => {
      if (entry.author_name && entry.author_avatar_urls) {
        if (!participantsMap.has(entry.author)) {
          participantsMap.set(entry.author, {
            name: entry.author_name,
            avatar: entry.author_avatar_urls?.["48"] || entry.author_avatar_urls?.["96"],
            id: entry.author,
            date: entry.date
          });
        }
      }
    });
    return Array.from(participantsMap.values());
  }, [note]);
  if (!threadParticipants.length) {
    return null;
  }
  const maxAvatars = 3;
  const isOverflow = threadParticipants.length > maxAvatars;
  const visibleParticipants = isOverflow ? threadParticipants.slice(0, maxAvatars - 1) : threadParticipants;
  const overflowCount = Math.max(
    0,
    threadParticipants.length - visibleParticipants.length
  );
  const threadHasMoreParticipants = threadParticipants.length > 100;
  const overflowText = threadHasMoreParticipants && overflowCount > 0 ? (0, import_i18n.__)("100+") : (0, import_i18n.sprintf)(
    // translators: %s: Number of participants.
    (0, import_i18n.__)("+%s"),
    overflowCount
  );
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NoteIconToolbarSlotFill.Fill, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_components.ToolbarButton,
    {
      className: "editor-note-indicator",
      label: (0, import_i18n.__)("View notes"),
      onClick: () => onClick(),
      showTooltip: true,
      children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Stack, { direction: "row", align: "center", gap: "xs", children: [
        visibleParticipants.map((participant) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          "img",
          {
            src: participant.avatar,
            alt: participant.name,
            className: "editor-note-indicator__avatar",
            style: {
              borderColor: (0, import_utils.getAvatarBorderColor)(
                participant.id
              )
            }
          },
          participant.id
        )),
        overflowCount > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "editor-note-indicator__overflow", children: overflowText })
      ] })
    }
  ) });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  NoteAvatarIndicator
});
//# sourceMappingURL=note-indicator-toolbar.cjs.map
