import { createAnalyticsLookupKey as k } from "./analyticsAnalysisUtils.js";
const f = (n, r, p) => {
  const l = n.get(r) ?? /* @__PURE__ */ new Set();
  l.add(p), n.set(r, l);
}, g = (n, r = 3) => !n || n.size === 0 ? "" : Array.from(n).slice(0, r).join(", "), w = (n) => n.toLowerCase().replace(/[\s,]+/g, " ").trim(), S = (n) => {
  const { analyticsLookup: r, trackedElements: p, previousFingerprint: l } = n, b = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
  p.forEach((t) => {
    const e = t.getAttribute("data-track-ga-event-action"), i = t.getAttribute("data-track-ga-event-label");
    if (!e || !i)
      return;
    const c = t.getAttribute("data-track-ga-event-trigger"), a = k(e, i), o = b.get(a) ?? {
      hasSupportedTrigger: !1,
      triggers: /* @__PURE__ */ new Set()
    };
    c && o.triggers.add(c), (c === "click" || c === "visibility") && (o.hasSupportedTrigger = !0), b.set(a, o), f(m, e, i), f(v, i, e);
    const s = w(e);
    f(A, s, i), f(h, s, e);
  });
  const $ = Array.from(r.values()).flat(), L = /* @__PURE__ */ new Set(), d = $.reduce((t, e) => {
    const i = `${e.eventAction}::${e.eventLabel}`;
    if (L.has(i))
      return t;
    L.add(i);
    const c = k(e.eventAction, e.eventLabel), a = b.get(c);
    if (a?.hasSupportedTrigger)
      return t;
    let o = "No frontend element with matching action and label was found.";
    if (a && !a.hasSupportedTrigger) {
      const s = g(a.triggers);
      o = s.length > 0 ? `Element found, but trigger "${s}" is not supported. Use "click" or "visibility".` : 'Element found, but trigger is missing. Use "click" or "visibility".';
    } else if (m.has(e.eventAction))
      o = `Action exists in frontend, but label differs. Example labels: ${g(
        m.get(e.eventAction)
      )}`;
    else if (v.has(e.eventLabel))
      o = `Label exists in frontend, but action differs. Example actions: ${g(
        v.get(e.eventLabel)
      )}`;
    else {
      const s = w(e.eventAction), u = h.get(s), y = A.get(s);
      u && u.size > 0 && (y?.has(e.eventLabel) ? o = `Action differs by formatting (e.g. commas/spaces). Example frontend actions: ${g(
        u
      )}` : o = `Possible action formatting mismatch. Example frontend actions: ${g(
        u
      )}`);
    }
    return t.push({
      eventAction: e.eventAction,
      eventLabel: e.eventLabel,
      reason: o
    }), t;
  }, []), E = d.map((t) => `${t.eventAction}|${t.eventLabel}|${t.reason}`).sort().join(`
`);
  return E === l ? l : (d.length > 0 && (console.groupCollapsed(
    `[Analytics Overlay] ${d.length} CSV row(s) could not be matched to frontend elements`
  ), console.table(d), console.groupEnd()), E);
};
export {
  S as logAnalyticsOverlayUnmatchedEntries
};
//# sourceMappingURL=logAnalyticsOverlayUnmatchedEntries.js.map
