{
  "version": 3,
  "sources": ["/cdn/shop/t/95/assets/cart-drawer-subtotal.js?cb=20261119"],
  "sourcesContent": ["/**\n * Cart drawer subtotal: \"~~$X~~ $Y\" (styles: assets/cart-drawer-footer.css).\n *\n * The struck total is what the shopper pays plus every saving the drawer\n * already shows on its lines, so the two always agree:\n *   - bundle packs: from bundle-cart.js (window.PocoBeroBundleCart);\n *   - other lines: their regular price \u2014 the pizza upsell's regular price, a\n *     cross-sell product's compare-at price (from the Cart YY rules data) or\n *     Shopify's original price \u2014 minus what Shopify charges.\n * Nothing is struck through when there is nothing saved.\n */\n(() => {\n  const DRAWER_ID = 'cart-drawer';\n  const SUBTOTAL_PRICE_SELECTOR = 'form[action=\"/cart\"] > .flex.justify-between > p:last-child';\n  const CROSS_SELL_RULES_ID = 'pb-cross-sell-rules';\n\n  const formatMoney = (cents) =>\n    new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', currencyDisplay: 'narrowSymbol' }).format(cents / 100);\n\n  /** variantId -> compare-at cents of the cross-sell offers (rules data in the page). */\n  const crossSellCompareAt = () => {\n    const compareAt = new Map();\n    try {\n      const rules = JSON.parse(document.getElementById(CROSS_SELL_RULES_ID)?.textContent || '[]');\n      rules.forEach((rule) => (rule.offers || []).forEach((offer) => {\n        if (offer.compareAtCents > 0) compareAt.set(Number(offer.variantId), offer.compareAtCents);\n      }));\n    } catch (error) {\n      // No rules data: those lines simply count at their own price.\n    }\n    return compareAt;\n  };\n\n  const regularUnitCents = (item, compareAt) => {\n    if (item.properties?._pb_pizza_upsell && window.PocoBeroCartUpsell) {\n      return Math.max(item.original_price, window.PocoBeroCartUpsell.pizzaRegularPrice);\n    }\n    return Math.max(item.original_price, compareAt.get(Number(item.variant_id)) || 0);\n  };\n\n  const savingsCents = (cart) => {\n    const items = cart.items || [];\n    const compareAt = crossSellCompareAt();\n    const bundleSavings = window.PocoBeroBundleCart?.savingsCents(items) || 0;\n    const lineSavings = items\n      .filter((item) => !item.properties?._bundle)\n      .reduce((sum, item) => sum + Math.max(0, regularUnitCents(item, compareAt) * item.quantity - item.final_line_price), 0);\n    return bundleSavings + lineSavings;\n  };\n\n  const patchSubtotal = (cart) => {\n    const priceEl = document.getElementById(DRAWER_ID)?.querySelector(SUBTOTAL_PRICE_SELECTOR);\n    if (!priceEl) return;\n    priceEl.classList.add('pb-cart-subtotal');\n\n    const saved = savingsCents(cart);\n    let was = priceEl.querySelector('.pb-cart-subtotal__was');\n    if (saved <= 0) {\n      was?.remove();\n      return;\n    }\n    if (!was) {\n      was = document.createElement('s');\n      was.className = 'pb-cart-subtotal__was';\n      priceEl.prepend(was);\n    }\n    const text = formatMoney(cart.total_price + saved);\n    if (was.textContent !== text) was.textContent = text;\n  };\n\n  /* ---------- Lifecycle (same pattern as bundle-cart.js) ---------- */\n\n  let observer = null;\n\n  // Shared up-to-date cart (cart-store.js) when loaded; otherwise a fresh read.\n  const readCart = async () => {\n    if (window.PocoBeroCartStore) return window.PocoBeroCartStore.get();\n    const response = await fetch(`/cart.js?t=${Date.now()}`, { headers: { Accept: 'application/json' }, cache: 'no-store' });\n    if (!response.ok) throw new Error(`Cart read failed: ${response.status}`);\n    return response.json();\n  };\n\n  const refresh = async () => {\n    try {\n      const cart = await readCart();\n      const drawer = document.getElementById(DRAWER_ID);\n      observer?.disconnect();\n      patchSubtotal(cart);\n      if (drawer) observer?.observe(drawer, { childList: true, subtree: true });\n    } catch (error) {\n      // Network/parse failure: leave the drawer's own subtotal untouched.\n    }\n  };\n\n  let frame = 0;\n  const scheduleRefresh = () => {\n    window.cancelAnimationFrame(frame);\n    frame = window.requestAnimationFrame(refresh);\n  };\n\n  const init = () => {\n    const drawer = document.getElementById(DRAWER_ID);\n    if (!drawer) return;\n    observer = new MutationObserver(scheduleRefresh);\n    observer.observe(drawer, { childList: true, subtree: true });\n    document.addEventListener('update-cart', scheduleRefresh);\n    document.addEventListener('toggle-cart', scheduleRefresh);\n    scheduleRefresh();\n  };\n\n  if (document.readyState === 'loading') document.addEventListener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