"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
exports.getAnalyticsContentFromRefs = getAnalyticsContentFromRefs;
/**
 * Gets text content from an element and even follows `slot` elements across Shadow DOM
 * barriers to get the full text that the user sees.
 */
function getTextContent(nodes) {
  return nodes.map(node => {
    if (node.nodeType === Node.TEXT_NODE) {
      return node.textContent;
    } else if (node.nodeType === Node.ELEMENT_NODE) {
      if (node.tagName === 'SLOT') {
        // If it's a slot, it won't actually have any content in itself, so we have to
        // follow the trail to its "assigned nodes" and look there.
        const assignedNodes = node.assignedNodes({
          flatten: true
        });
        return getTextContent(assignedNodes);
      } else {
        return getTextContent(Array.from(node.childNodes));
      }
    } else {
      return '';
    }
  }).join('');
}
function getAnalyticsContentFromRefs(refs) {
  return refs.map(ref => ref.current ? getTextContent(Array.from(ref.current.childNodes)) : undefined).find(textContent => textContent);
}
var _default = exports.default = getAnalyticsContentFromRefs;