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iC,GACXT,EACA0C,EACAlE,WAAWF,GAAgC,KAC3CE,WAAWiE,GAAoD,MAC/DO,WAEF,IAAK,IAAI3D,EAAI,EAAGA,EAAIyD,EAAcxD,OAAQD,IACxCyD,EAAczD,GAAGK,YAAc,IAAMrB,EAAgBC,EAAeyE,EAExE,GAAG,IACL,CAqIQE,CAAgBlD,EAAQS,EAAUlC,EAAemC,EAASyC,QAAQ,KAAM,IAAKxC,EAEjF,GAEJ,C","sources":["webpack://healthlabs.com/./public/assets/js/calculate-cart-total.js"],"sourcesContent":["/**\n * Builds the ordering cart with coupons and discounts if they are available.\n *\n * @param {Object} coupon The coupon object to apply to the cart total if it was provided\n * @param {Object} discount The discount to be applied to the cart total\n * @param {float|null} complianceFee The compliance fee if present for the order\n * @param {string} subtotal The total amount before any coupons or discounts applied\n * @param {float|null} inHomeCollectionService The in-home collection fee amount when applicable\n */\nlet buildCouponCart = function (coupon, discount, complianceFee, subtotal, inHomeCollectionService) {\n let couponValue = 0;\n let discountValue = 0;\n var isBaOrder = window.localStorage.getItem('isBaOrder') === 'true';\n\n setTimeout(function () {\n let validCoupon = coupon && coupon.valid && coupon.discount > 0;\n if (validCoupon && !isBaOrder) {\n couponValue = coupon.discount;\n buildCartRows('.coupon-row', coupon.name, '-$' + couponValue);\n }\n\n if (discount && !isBaOrder) {\n discountValue = discount.value;\n buildCartRows('.discount-row', discount.name + ' Discount', '-$' + discountValue);\n }\n\n if ((discount || validCoupon) && !isBaOrder) {\n buildCartRows('.subtotal-row', 'Subtotal', '$' + getParsedAmount(complianceFee, subtotal));\n }\n\n let totalCartRows = document.querySelectorAll('.total-cart');\n let total = (\n parseFloat(subtotal) -\n couponValue -\n discountValue +\n parseFloat(complianceFee ? complianceFee : '0') +\n parseFloat(inHomeCollectionService ? inHomeCollectionService : '0')\n ).toString();\n\n for (let i = 0; i < totalCartRows.length; i++) {\n totalCartRows[i].textContent = '$' + getParsedAmount(complianceFee, total);\n }\n }, 800);\n};\n\n/**\n * Gets the parsed amount with decimals if a compliance fee is present.\n *\n * @param {float|null} complianceFee The compliance fee in the cart\n * @param {string} amount The amount to be parsed\n *\n * @return {string} The parsed amount\n */\nlet getParsedAmount = function (complianceFee, amount) {\n return complianceFee\n ? parseFloat(amount).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })\n : parseInt(amount).toLocaleString();\n};\n\n/**\n * Builds the ordering cart rows with name and value columns.\n *\n * @param {string} rows The name selector to build the rows.\n * @param {string} name The name value to place in the first row column\n * @param {string} value The value to place in the item price row column\n */\nlet buildCartRows = function (rows, name, value) {\n let htmlRows = document.querySelectorAll(rows);\n for (let i = 0; i < htmlRows.length; i++) {\n let nameCell = document.createElement('td');\n nameCell.setAttribute('colspan', '2');\n nameCell.textContent = name;\n\n let valueCell = document.createElement('td');\n valueCell.setAttribute('class', 'cart-item__price');\n valueCell.textContent = value;\n\n htmlRows[i].innerHTML = '';\n htmlRows[i].appendChild(nameCell);\n htmlRows[i].appendChild(valueCell);\n }\n};\n\n/**\n * Creates a strong element with the coupon text.\n *\n * @param {Object} coupon The coupon object to apply to generate the strong\n *\n * @return {HTMLElement} The strong element\n */\nconst createStrongCouponText = (coupon) => {\n const couponValue = coupon.type === 'amount' ? `$${coupon.value}` : `${coupon.value}%`;\n const strongCouponText = document.createElement('strong');\n strongCouponText.appendChild(document.createTextNode(`${couponValue} Off ${coupon.name} Coupon`));\n\n return strongCouponText;\n};\n\n/**\n * Creates an anchor link for the coupon.\n *\n * @param {Object} coupon The coupon object to apply to generate the anchor\n *\n * @return {HTMLAnchorElement} The anchor element\n */\nconst createAnchorLinkForCoupon = (coupon) => {\n let couponTextToAppend = document.createElement('a');\n couponTextToAppend.setAttribute('data-qa-id', 'Coupon Link');\n couponTextToAppend.setAttribute('href', coupon.link);\n couponTextToAppend.setAttribute('target', '_blank');\n couponTextToAppend.appendChild(createStrongCouponText(coupon));\n\n return couponTextToAppend;\n};\n\n/**\n * Creates a coupon alert box with the coupon information.\n *\n * @param {Object} coupon The coupon object to apply to generate the alert box\n *\n * @return {HTMLDivElement} The coupon alert box element\n */\nconst createCouponAlertBox = (coupon) => {\n const couponAlertBox = document.createElement('div');\n couponAlertBox.setAttribute('data-qa-id', 'Coupon Alert Box');\n couponAlertBox.className = `alert-box coupon text-center ${\n coupon && coupon.name && coupon.name.length > 35 && 'coupon-small-screen-large-text'\n }`;\n couponAlertBox.appendChild(document.createTextNode('Your '));\n couponAlertBox.appendChild(coupon.link ? createAnchorLinkForCoupon(coupon) : createStrongCouponText(coupon));\n couponAlertBox.appendChild(document.createTextNode(coupon.valid ? ' will be applied at checkout.' : ' is expired.'));\n\n return couponAlertBox;\n};\n\n/**\n * Loads cart total with coupons and discounts applied.\n *\n * @param {string} couponName The coupon name to apply to the cart total if it was provided\n * @param {string} tz The TZ provided in the url. This is mainly for Testing purposes\n * @param {Object} discount The discount to be applied to the cart total.\n * @param {float|null} complianceFee The total amount before any coupons or discounts applied\n * @param {string} subtotal The total amount before any coupons or discounts applied\n * @param {float|null} inHomeCollectionFee The in-home collection fee amount when applicable\n */\nwindow.loadCouponCartTotal = function (couponName, tz, discount, complianceFee, subtotal, inHomeCollectionFee) {\n let coupon = null;\n\n if (window.localStorage.getItem('isBaOrder') === 'true') {\n $('#coupon-bar').hide();\n $('.alert-box--coupon').addClass('js-hide');\n return;\n }\n\n $.ajax({\n headers: { 'Browser-Timezone': tz || Intl.DateTimeFormat().resolvedOptions().timeZone },\n url: '/coupon/show',\n method: 'GET',\n async: false,\n dataType: 'json',\n data: { name: couponName },\n success: function (response) {\n // If the coupon was not found by the given name.\n if (!(coupon = response)) {\n return;\n }\n\n $('.alert-box--coupon').removeClass('js-hide');\n $('#coupon-bar').html(createCouponAlertBox(coupon));\n $('.steps__container').each(function () {\n $(this).removeClass('without-coupon');\n });\n $('.steps').addClass('with-coupon');\n },\n complete: function () {\n if (typeof subtotal === 'string') {\n buildCouponCart(coupon, discount, complianceFee, subtotal.replace(/,/g, ''), inHomeCollectionFee);\n }\n },\n });\n};\n"],"names":["getParsedAmount","complianceFee","amount","parseFloat","toLocaleString","undefined","minimumFractionDigits","maximumFractionDigits","parseInt","buildCartRows","rows","name","value","htmlRows","document","querySelectorAll","i","length","nameCell","createElement","setAttribute","textContent","valueCell","innerHTML","appendChild","createStrongCouponText","coupon","couponValue","type","strongCouponText","createTextNode","window","loadCouponCartTotal","couponName","tz","discount","subtotal","inHomeCollectionFee","localStorage","getItem","$","hide","addClass","ajax","headers","Intl","DateTimeFormat","resolvedOptions","timeZone","url","method","async","dataType","data","success","response","removeClass","html","couponAlertBox","className","link","couponTextToAppend","createAnchorLinkForCoupon","valid","createCouponAlertBox","each","this","complete","inHomeCollectionService","discountValue","isBaOrder","setTimeout","validCoupon","totalCartRows","total","toString","buildCouponCart","replace"],"sourceRoot":""}