{
  "version": 3,
  "sources": ["/cdn/shop/t/3/assets/cart-otp-single-item-link.js?variant=56712979448190"],
  "sourcesContent": ["/**\n * Current script should be invoked with '?variant=' parameter. Example of usage in liquid template:\n * \n * <script \n *      id=\"cart-otp-single-item-script\" \n *      src=\"{{ 'cart-otp-single-item-link.js' | asset_url | append: '&variant=' | append: product.selected_or_first_available_variant.id }}\"\n * ></script>\n */\nconst getVariantFromScriptSrc = () => {\n    const variant = new URLSearchParams(\n        new URL(\n            document\n                .getElementById('cart-otp-single-item-script')\n                .src\n        ).search\n    )?.get('variant');\n\n    const variantToInteger = parseInt(variant);\n\n    if (isNaN(variantToInteger)) {\n        throw new Error('Current script must be invoked with \"?variant=\" parameter.');\n    }\n\n    return variantToInteger;\n};\n\nfunction addToCart(payload){\n    window.appstleSelectedSellingPlan = null;\n      return fetch('/cart/add.js', {\n        method: 'POST',\n        headers: { 'Content-Type':'application/json', 'Accept':'application/json' , 'Referer': window.location.origin + '/' + window.location.pathname},\n        credentials: 'same-origin',\n        body: JSON.stringify(payload)\n      })\n      .then(async (response) => {\n        const data = await response.json();\n\n        if (!response.ok) {\n          console.error('Cart add error:', data);\n          throw new Error(data?.description || data?.message || 'Add to cart failed');\n        }\n\n        document.dispatchEvent(new CustomEvent('cart:refresh'));\n\n        return data;\n      })\n      .then(async (data) => {\n            if (payload.sections ?? false) {\n                const sectionsConfig = {headers: { 'Content-Type':'application/json', 'Accept':'application/json' }, method: 'GET'};\n\n                const handleResponse = (event) => {\n                    const request = event.target;\n                    if (request.status >= 200 && request.status < 300) {\n                        const sectionsData = {sections: JSON.parse(request.responseText)};\n                        sectionsData.key = data.items?.at(0)?.key;\n\n                        try {\n                            new CartNotification().renderContents(sectionsData);\n                        } catch (error) {\n                            console.error(error);\n                            window.location.href = '/cart';\n                        }\n                    } else {\n                        window.location.href = '/cart'\n                    }\n                };\n\n                const request = new XMLHttpRequest();\n                request.addEventListener('load', handleResponse);\n                request.open('GET', payload.sections_url + '?sections=' + payload.sections, true);\n                request.send();\n            } else {\n                window.location.href = '/cart'\n            }\n      });\n}\n\ndocument.getElementById('otp-single-item-link')?.addEventListener('click', (event) => {\n    let notifier = null;\n    try {\n        notifier = new CartNotification();\n    } catch (error) {\n        notifier = null;\n    }\n\n    const request = { \n        items: [\n            {id: getVariantFromScriptSrc(), quantity: 1, selling_plan: null}\n        ],\n    };\n\n    // Appstle force propagates plan to cart-API request if checked subscription purchase\n    const checkedSellingPlanElement = document.querySelector(\"[name=selling_plan]:checked\") ?? null;\n\n    try {\n        if (notifier !== null) {\n            request.sections = notifier.getSectionsToRender().map((section) => section.id).join(',');\n            request.sections_url = window.location.pathname\n        }\n\n        if (checkedSellingPlanElement !== null) {\n            checkedSellingPlanElement.checked = false;\n        }\n\n        addToCart(request);\n\n        if (checkedSellingPlanElement !== null) {\n            checkedSellingPlanElement.checked = true;\n        }\n    } catch (error) {\n        if (checkedSellingPlanElement !== null) {\n            checkedSellingPlanElement.checked = true;\n        }\n    }\n\n});"],
  "mappings": "AAQA,MAAM,wBAA0B,IAAM,CAClC,MAAM,QAAU,IAAI,gBAChB,IAAI,IACA,SACK,eAAe,6BAA6B,EAC5C,GACT,EAAE,MACN,GAAG,IAAI,SAAS,EAEV,iBAAmB,SAAS,OAAO,EAEzC,GAAI,MAAM,gBAAgB,EACtB,MAAM,IAAI,MAAM,4DAA4D,EAGhF,OAAO,gBACX,EAEA,SAAS,UAAU,QAAQ,CACvB,cAAO,2BAA6B,KAC3B,MAAM,eAAgB,CAC3B,OAAQ,OACR,QAAS,CAAE,eAAe,mBAAoB,OAAS,mBAAqB,QAAW,OAAO,SAAS,OAAS,IAAM,OAAO,SAAS,QAAQ,EAC9I,YAAa,cACb,KAAM,KAAK,UAAU,OAAO,CAC9B,CAAC,EACA,KAAK,MAAO,UAAa,CACxB,MAAM,KAAO,MAAM,SAAS,KAAK,EAEjC,GAAI,CAAC,SAAS,GACZ,cAAQ,MAAM,kBAAmB,IAAI,EAC/B,IAAI,MAAM,MAA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