{
  "version": 3,
  "sources": ["/cdn/shop/t/3/assets/tb-m-cartpill.js?x=1794560344112"],
  "sourcesContent": ["/* Toybox phone floating cart pill and the wishlist count in the bottom bar (snippets/tb-mobile-nav).\n   The pill shows only when the cart has toys: first toy's photo, \"View cart\", item count and total, and a tag\n   with the amount left for free delivery (window.TbFreeAt). It opens the quick cart sheet (window.TbCart from\n   assets/tb-m-cart.js). It keeps the header cart badge in step.\n   Speed: the card \"Add +\" stepper (assets/tb-m-shop.js) sends tb:cart-optimistic the moment a shopper taps\n   (variant, change in quantity, and the card for its photo and price), so the pill appears, updates and goes\n   away straight away. When the cart has been saved the stepper sends tb:cart-data with the saved cart, which\n   the pill then shows as is. Horizon's cart:update and shopify:cart:lines-update events still re-read the cart.\n   Styles: assets/tb-m-cartpill.css. */\n(() => {\n  const pill = document.querySelector('[data-tb-cpill]');\n  const FREE = window.TbFreeAt || 79900;\n  const BAG = '<svg width=\"22\" height=\"22\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M5 8h14l-1 12H6L5 8z\"/><path d=\"M9 8V6a3 3 0 016 0v2\"/></svg>';\n  const inr = (c) => '\u20B9' + (c / 100).toLocaleString('en-IN', { maximumFractionDigits: 2 });\n  const pic = (u) => (u ? (u.indexOf('//') === 0 ? 'https:' + u : u) + (u.indexOf('?') > -1 ? '&' : '?') + 'width=120' : '');\n  let last = -1;\n  let shown = null; // the cart the pill is showing (saved, or with taps not yet saved)\n  let optAt = 0; // time of the last tap not yet confirmed by a saved cart\n  let timer;\n\n  const badge = (n) => {\n    document.querySelectorAll('header-actions .cart-bubble__text-count').forEach((el) => { el.textContent = n; });\n    document.querySelectorAll('header-actions cart-icon').forEach((el) => el.classList.toggle('header-actions__cart-icon--has-cart', n > 0));\n  };\n  const render = (c) => {\n    if (!pill || !c || !Array.isArray(c.items)) return;\n    shown = c;\n    const toys = c.items.filter((it) => it.handle !== 'gift-wrap' && it.quantity > 0);\n    const n = toys.reduce((a, it) => a + it.quantity, 0);\n    badge(n); // the badge counts toys only, not gift wrap\n    const show = n > 0;\n    pill.hidden = !show;\n    document.body.classList.toggle('tb-has-cpill', show);\n    if (!show) { last = 0; return; }\n    const first = toys[0] || {};\n    const img = first.image || (first.featured_image && first.featured_image.url) || '';\n    const imgBox = pill.querySelector('[data-img]');\n    if (imgBox.dataset.src !== img) { imgBox.dataset.src = img; imgBox.innerHTML = img ? '<img src=\"' + pic(img) + '\" alt=\"\" width=\"44\" height=\"44\">' : BAG; }\n    const sum = n + (n === 1 ? ' item' : ' items') + ' \u00B7 ' + inr(c.total_price || 0);\n    pill.querySelector('[data-sum]').textContent = sum;\n    // Free delivery counts toys only: gift wrap lines are left out of the total.\n    const toySub = toys.reduce((a, it) => a + (it.final_price != null ? it.final_price : it.price || 0) * it.quantity, 0);\n    const left = FREE - toySub;\n    const f = pill.querySelector('[data-free]');\n    f.textContent = left > 0 ? inr(left) + ' more in toys for free delivery' : 'Free delivery unlocked';\n    f.classList.toggle('is-done', left <= 0);\n    pill.setAttribute('aria-label', 'View cart, ' + sum + '. ' + f.textContent);\n    if (last >= 0 && n > last) {\n      pill.classList.remove('is-pop');\n      void pill.offsetWidth;\n      pill.classList.add('is-pop');\n    }\n    last = n;\n  };\n  const real = (c) => { optAt = 0; render(c); };\n  const refresh = () => {\n    const asked = Date.now();\n    return fetch('/cart.js', { credentials: 'same-origin' }).then((r) => r.json()).then((c) => {\n      // A tap after this request started is newer than its answer: keep showing the tap.\n      if (optAt && optAt > asked) return;\n      real(c);\n    }).catch(() => {});\n  };\n  const soon = () => { clearTimeout(timer); timer = setTimeout(refresh, 150); };\n\n  /* A tap on a card stepper: change the shown cart at once. */\n  const cardInfo = (el) => {\n    const card = el && el.closest ? el.closest('.tb-card, article, li') : null;\n    let price = 0, image = '';\n    if (card) {\n      const p = card.querySelector('[data-price]');\n      price = p ? parseInt(p.dataset.price, 10) || 0 : 0;\n      if (!price) { const s = card.querySelector('.tb-card__price strong, [class*=\"price\"] strong'); price = s ? Math.round(parseFloat(s.textContent.replace(/[^0-9.]/g, '')) * 100) || 0 : 0; }\n      const im = card.querySelector('.tb-card__slide img, img');\n      image = im ? (im.currentSrc || im.src || '') : '';\n    }\n    return { price, image };\n  };\n  const optimistic = (d) => {\n    if (!pill || !d || !d.id || !d.delta) return;\n    const base = shown || { items: [], item_count: 0, total_price: 0, items_subtotal_price: 0 };\n    const items = base.items.map((it) => Object.assign({}, it));\n    const id = Number(d.id);\n    let line = items.find((it) => Number(it.variant_id) === id);\n    let price = line ? (line.final_price != null ? line.final_price : line.price) : 0;\n    if (!line) {\n      const info = cardInfo(d.el);\n      price = info.price;\n      line = { variant_id: id, handle: '', quantity: 0, price, image: info.image };\n      items.push(line);\n    }\n    const before = line.quantity;\n    line.quantity = Math.max(0, before + d.delta);\n    const moved = (line.quantity - before) * (price || 0);\n    optAt = Date.now();\n    render({\n      items,\n      item_count: Math.max(0, (base.item_count || 0) + (line.quantity - before)),\n      total_price: Math.max(0, (base.total_price || 0) + moved),\n      items_subtotal_price: Math.max(0, (base.items_subtotal_price || 0) + moved)\n    });\n  };\n\n  if (pill) {\n    document.addEventListener('tb:cart-optimistic', (e) => optimistic(e.detail));\n    document.addEventListener('tb:cart-data', (e) => { if (e.detail && Array.isArray(e.detail.items)) real(e.detail); });\n    document.addEventListener('cart:update', (e) => {\n      const c = e.detail && (e.detail.resource || e.detail.cart);\n      if (c && Array.isArray(c.items) && typeof c.items_subtotal_price === 'number') real(c); else soon();\n    });\n    document.addEventListener('shopify:cart:lines-update', (e) => {\n      const p = e && e.promise;\n      if (p && typeof p.then === 'function') p.then(soon, soon); else setTimeout(soon, 800);\n    });\n    window.addEventListener('pageshow', (e) => { if (e.persisted) refresh(); });\n    pill.addEventListener('click', (e) => {\n      if (window.TbCart && window.matchMedia('(max-width: 749px)').matches) {\n        e.preventDefault();\n        window.TbCart.open();\n      }\n    });\n    refresh();\n  }\n\n  /* Wishlist count on the bottom bar tab */\n  const wish = () => {\n    let n = 0;\n    try { n = (JSON.parse(localStorage.getItem('tb-wishlist')) || []).length; } catch (e) {}\n    document.querySelectorAll('[data-tb-wish-count]').forEach((b) => { b.textContent = n > 99 ? '99+' : String(n); b.hidden = !n; });\n  };\n  document.addEventListener('tb:wish-change', wish);\n  window.addEventListener('storage', (e) => { if (e.key === 'tb-wishlist') wish(); });\n  wish();\n})();\n"],
  "mappings": "CASC,IAAM,CACL,MAAM,KAAO,SAAS,cAAc,iBAAiB,EAC/C,KAAO,OAAO,UAAY,MAC1B,IAAM,8OACN,IAAO,GAAM,UAAO,EAAI,KAAK,eAAe,QAAS,CAAE,sBAAuB,CAAE,CAAC,EACjF,IAAO,GAAO,GAAK,EAAE,QAAQ,IAAI,IAAM,EAAI,SAAW,EAAI,IAAM,EAAE,QAAQ,GAAG,EAAI,GAAK,IAAM,KAAO,YAAc,GACvH,IAAI,KAAO,GACP,MAAQ,KACR,MAAQ,EACR,MAEJ,MAAM,MAAS,GAAM,CACnB,SAAS,iBAAiB,yCAAyC,EAAE,QAAS,IAAO,CAAE,GAAG,YAAc,CAAG,CAAC,EAC5G,SAAS,iBAAiB,0BAA0B,EAAE,QAAS,IAAO,GAAG,UAAU,OAAO,sCAAuC,EAAI,CAAC,CAAC,CACzI,EACM,OAAU,GAAM,CACpB,GAAI,CAAC,MAAQ,CAAC,GAAK,CAAC,MAAM,QAAQ,EAAE,KAAK,EAAG,OAC5C,MAAQ,EACR,MAAM,KAAO,EAAE,MAAM,OAAQ,IAAO,GAAG,SAAW,aAAe,GAAG,SAAW,CAAC,EAC1E,EAAI,KAAK,OAAO,CAAC,EAAG,KAAO,EAAI,GAAG,SAAU,CAAC,EACnD,MAAM,CAAC,EACP,MAAM,KAAO,EAAI,EAGjB,GAFA,KAAK,OAAS,CAAC,KACf,SAAS,KAAK,UAAU,OAAO,eAAgB,IAAI,EAC/C,CAAC,KAAM,CAAE,KAAO,EAAG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