{
  "version": 3,
  "sources": ["/cdn/shop/t/95/assets/cart-upsell-events.js?cb=20261119"],
  "sourcesContent": ["/**\n * Intelligems custom events for the cart drawer upsells.\n *\n * Sent with `window.igEvents.push({ event })` (Intelligems \"events sent directly\n * from your theme code\"). Each new event name shows up in Intelligems > Events\n * Manager, where it must be registered once before it can be used in a test.\n * Every action sends a general event plus one with the product / flavor, so\n * results can be read in total or broken down:\n *\n *   cart_crosssell_add            cart_crosssell_add_<product handle>\n *   cart_pizza_upsell_add         cart_pizza_upsell_add_<flavor>\n *   cart_crosssell_remove         cart_crosssell_remove_<product handle>\n *   cart_pizza_upsell_remove      cart_pizza_upsell_remove_<flavor>\n *\n * Adds are reported by the code that adds (cart-cross-sell-yy.js and\n * cart-subscription-upsell.js), once Shopify accepts them. Removals are found by\n * comparing carts: an upsell line that was in the previous cart and is gone\n * now. Only removals by the shopper count; lines the theme removes itself (the\n * discounted pizza when the dough is removed) are announced with\n * `expectRemoval()` and skipped.\n *\n * Loaded before cart-subscription-upsell.js and the cross-sell scripts.\n */\n(() => {\n  if (window.PocoBeroCartEvents) return;\n\n  const MAX_EVENT_LENGTH = 100; // Intelligems limit for custom event identifiers.\n\n  // Line properties set when an upsell is added (cart-cross-sell-yy.js and\n  // cart-subscription-upsell.js); hidden from the shopper (leading underscore).\n  const CROSS_SELL_SOURCE = 'cart-crosssell';\n  const isCrossSellLine = (item) => item.properties?._pb_upsell_source === CROSS_SELL_SOURCE;\n  const isPizzaUpsellLine = (item) => Boolean(item.properties?._pb_pizza_upsell);\n\n  /** \"Garlic Pesto\" -> \"garlic-pesto\"; keeps names short and safe for Intelligems. */\n  const slug = (text) => String(text || '')\n    .toLowerCase()\n    .normalize('NFD')\n    .replace(/[\u0300-\u036F]/g, '')\n    .replace(/[^a-z0-9]+/g, '-')\n    .replace(/^-+|-+$/g, '');\n\n  const push = (name) => {\n    const event = name.slice(0, MAX_EVENT_LENGTH);\n    window.igEvents = window.igEvents || [];\n    window.igEvents.push({ event });\n  };\n\n  /** Sends the general event and, when there is one, the detailed one. */\n  const track = (action, detail) => {\n    push(action);\n    const suffix = slug(detail);\n    if (suffix) push(`${action}_${suffix}`);\n  };\n\n  const pizzaFlavor = (item) => {\n    const title = item.properties?._pb_display_title || item.product_title || '';\n    return title.replace(/\\s+pizza$/i, '');\n  };\n\n  /* ---------------------------------------------------------------- Adds */\n\n  const crossSellAdded = (handle) => track('cart_crosssell_add', handle);\n  const pizzaUpsellAdded = (flavor) => track('cart_pizza_upsell_add', flavor);\n\n  /* ------------------------------------------------------------- Removals */\n\n  let previousLines = null; // Map<line key, item> of upsell lines in the last cart seen.\n  const expectedRemovals = new Set(); // Line keys the theme is removing on its own.\n\n  const upsellLines = (cart) => new Map(\n    (cart.items || []).filter((item) => isCrossSellLine(item) || isPizzaUpsellLine(item)).map((item) => [item.key, item])\n  );\n\n  /** Called with every fresh cart; the first one only sets the starting point. */\n  const observeCart = (cart) => {\n    if (!cart?.items) return;\n    const currentLines = upsellLines(cart);\n    if (previousLines) {\n      previousLines.forEach((item, key) => {\n        if (currentLines.has(key)) return;\n        if (expectedRemovals.delete(key)) return; // Removed by the theme, not the shopper.\n        if (isPizzaUpsellLine(item)) track('cart_pizza_upsell_remove', pizzaFlavor(item));\n        else track('cart_crosssell_remove', item.handle);\n      });\n    }\n    previousLines = currentLines;\n  };\n\n  /** Marks lines the theme is about to remove itself, so they are not reported. */\n  const expectRemoval = (keys) => keys.forEach((key) => expectedRemovals.add(key));\n\n  window.PocoBeroCartEvents = Object.freeze({\n    CROSS_SELL_SOURCE,\n    crossSellAdded,\n    pizzaUpsellAdded,\n    observeCart,\n    expectRemoval\n  });\n})();\n"],
  "mappings": "CAuBC,IAAM,CACL,GAAI,OAAO,mBAAoB,OAE/B,MAAM,iBAAmB,IAInB,kBAAoB,iBACpB,gBAAmB,MAAS,KAAK,YAAY,oBAAsB,kBACnE,kBAAqB,MAAS,EAAQ,KAAK,YAAY,iBAGvD,KAAQ,MAAS,OAAO,MAAQ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