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ASC,KAAO,QACzB,EAMF,C","sources":["webpack://starfish-wp-theme/./themes/starfish/src/js/model/product.js","webpack://starfish-wp-theme/./themes/starfish/src/js/services/product.js","webpack://starfish-wp-theme/./themes/starfish/src/js/services/coupon.js","webpack://starfish-wp-theme/./themes/starfish/src/js/services/storage.js","webpack://starfish-wp-theme/./themes/starfish/src/js/services/glp1-treatment.js"],"sourcesContent":["export default class Product {\n constructor(name, price, extraCharge, treatmentType, slug) {\n this.name = name;\n this.price = price;\n this.extraCharge = extraCharge;\n this.treatmentType = treatmentType;\n this.slug = slug;\n }\n}\n","import couponService from './coupon.js';\nimport storageService from './storage.js';\nimport Product from '../model/product';\nimport glp1TreatmentService from './glp1-treatment';\n\nwindow.onload = function () {\n const glp1_treatment_type = 'glp_1';\n const select_product_btn = document.querySelector('#select_product');\n if (!select_product_btn) {\n return;\n }\n select_product_btn.addEventListener('click', selectProduct);\n\n if (\n storageService().tests.length > 0 &&\n document.querySelector(`[data-qa-id=\"Product - ${storageService().tests[0].name}\"]`)\n ) {\n document\n .querySelector(`[data-qa-id=\"Product - ${storageService().tests[0].name}\"]`)\n .classList.add('jcf-label-active');\n } else {\n document.querySelectorAll('.check-item.product-list-item')[0]?.classList.add('jcf-label-active');\n }\n\n /**\n * Store selected product in localStorage\n */\n function selectProduct() {\n storageService().clearCheckoutData();\n\n const product = getSelectedProductDataset();\n\n if (!product || product.price <= 0) {\n return;\n }\n\n storageService().tests = [{ name: product.name, price: parseInt(product.price), slug: product.slug }];\n storageService().extraCharges =\n product.extraCharge > 0\n ? [{ name: product.name, amount: parseInt(product.extraCharge), type: 'Extra Charge' }]\n : [];\n storageService().treatmentType = product.treatmentType || null;\n\n couponService().applyDefaultCoupon();\n\n if (glp1TreatmentService().isGlp1TreatmentType()) {\n glp1TreatmentService().afterGlp1ProductSelection();\n\n return;\n }\n\n window.location.href = '/select-pharmacy';\n }\n\n /**\n * Retrieve the currently selected product.\n *\n * @returns {Product} the object of the selected product element.\n */\n function getSelectedProductDataset() {\n let product = document.querySelectorAll('.product-list-item.jcf-label-active')[0];\n let values = product ? product.dataset : select_product_btn.dataset;\n\n return new Product(\n values.productName,\n values.productPrice,\n values.productExtraCharge,\n values.productTreatmentType,\n values.productSlug\n );\n }\n};\n","import storageService from './storage.js';\n\n/**\n * Service class for managing coupons.\n */\nexport default function couponService() {\n const couponElement = document.querySelector('#product_coupon');\n\n /**\n * Stores the default coupon in localStorage.\n */\n function applyDefaultCoupon() {\n if (!couponElement) {\n return;\n }\n\n storageService().coupon = getCouponData();\n }\n\n /**\n * Retrieves coupon data from the coupon element.\n */\n function getCouponData() {\n return {\n coupon_code: couponElement?.dataset.couponCode || null,\n coupon_amount: Number(couponElement?.dataset.couponAmount) || null,\n coupon_name: couponElement?.dataset.couponName || null,\n coupon_type: couponElement?.dataset.couponType || null,\n };\n }\n\n return {\n applyDefaultCoupon,\n };\n}\n","/**\n * Service class for accessing localStorage.\n */\nexport default function storageService() {\n /**\n * Keys used to reference data in localStorage\n */\n const SLIDER_ANSWERS = 'sliderAnswers';\n const TESTS_KEY = 'ngStorage-tests';\n const EXTRA_CHARGES_KEY = 'ngStorage-extraCharges';\n const COUPON_KEY = 'ngStorage-coupon';\n const TREATMENT_TYPE_KEY = 'ngStorage-treatmentType';\n const ORDER_UPSELLS = 'ngStorage-orderUpsells';\n const CENTER_KEY = 'ngStorage-center';\n const USER_ID_KEY = 'user_id';\n\n /**\n * Retrieves a value stored as JSON in localStorage\n *\n * @param {string} key the key to retrieve from storage\n *\n * @return {any} The value stored in localStorage, or null if localstorage is not available\n */\n function getLocalStorage(key) {\n try {\n return JSON.parse(window.localStorage?.getItem(key) || null);\n } catch (error) {\n console.error('Error getting value from local storage', error);\n\n return null;\n }\n }\n\n /**\n * Saves a value in localStorage as a JSON string\n *\n * @param {string} key The key to store the value in\n * @param {any} value The value to be stored\n *\n * @return {void}\n */\n function setLocalStorage(key, value) {\n try {\n window.localStorage?.setItem(key, JSON.stringify(value || null));\n } catch (error) {\n console.error('Error setting value in local storage', error);\n }\n }\n\n /**\n * Deletes a value from the storage.\n *\n * @param key {string} The value's key.\n *\n * @return void\n */\n function removeLocalStorage(key) {\n window.localStorage?.removeItem(key);\n }\n\n // Initialize tests in localStorage\n if (!getLocalStorage(TESTS_KEY)) {\n setLocalStorage(TESTS_KEY, []);\n }\n\n return {\n /**\n * Local Storage get, set and remove\n */\n localStorage: {\n get: getLocalStorage,\n set: setLocalStorage,\n remove: removeLocalStorage,\n },\n\n /**\n * Retrieve selected tests data from local storage\n */\n get tests() {\n return this.localStorage.get(TESTS_KEY) ?? [];\n },\n\n /**\n * Store selected tests data in local storage\n *\n * @param {object[]} tests the tests data to store\n */\n set tests(tests) {\n this.localStorage.set(TESTS_KEY, tests);\n },\n\n /**\n * Retrieve slider answers from local storage\n */\n get sliderAnswers() {\n return this.localStorage.get(SLIDER_ANSWERS) ?? {};\n },\n\n /**\n * Store slider answers in local storage\n *\n * @param {object} tests the slider answers to store\n */\n set sliderAnswers(tests) {\n this.localStorage.set(SLIDER_ANSWERS, tests);\n },\n\n /**\n * Retrieve extra charges from local storage\n */\n get extraCharges() {\n return this.localStorage.get(EXTRA_CHARGES_KEY) ?? [];\n },\n\n /**\n * Store selected tests data in local storage\n *\n * @param {object[]} extraCharges the tests data to store\n */\n set extraCharges(extraCharges) {\n this.localStorage.set(EXTRA_CHARGES_KEY, extraCharges);\n },\n\n /**\n * Store coupon data in local storage\n *\n * @param {object} coupon the coupon data to store\n */\n set coupon(coupon) {\n this.localStorage.set(COUPON_KEY, coupon);\n },\n\n /**\n * Store treatment type in local storage\n *\n * @param {string} treatmentType the treatment type to store\n */\n set treatmentType(treatmentType) {\n this.localStorage.set(TREATMENT_TYPE_KEY, treatmentType);\n },\n\n /**\n * Store treatment type in local storage\n */\n get treatmentType() {\n return this.localStorage.get(TREATMENT_TYPE_KEY);\n },\n\n /**\n * Retrieve the order upsells from local storage\n */\n get orderUpsells() {\n return this.localStorage.get(ORDER_UPSELLS) ?? [];\n },\n\n /**\n * Store order upsells in local storage\n *\n * @param {object[]} orderUpsells the order upsells to store\n */\n set orderUpsells(orderUpsells) {\n this.localStorage.set(ORDER_UPSELLS, orderUpsells);\n },\n\n /**\n * Retrieve center from local storage\n */\n get center() {\n return this.localStorage.get(CENTER_KEY) ?? {};\n },\n\n /**\n * Store selected center data in local storage\n *\n * @param {object[]} center the center data to store\n */\n set center(center) {\n this.localStorage.set(CENTER_KEY, center);\n },\n\n /**\n * Retrieve the Manage user ID placing an order from local storage\n */\n get userId() {\n return getLocalStorage(USER_ID_KEY);\n },\n\n /**\n * Store the Manage user ID placing an order in local storage\n */\n set userId(userId) {\n if (typeof userId === 'string' && /^[0-9]+$/.test(userId.trim())) {\n setLocalStorage(USER_ID_KEY, Number(userId));\n } else if (typeof userId === 'number' && Number.isInteger(userId)) {\n setLocalStorage(USER_ID_KEY, userId);\n } else if (userId === null) {\n removeLocalStorage(USER_ID_KEY);\n } else {\n console.error(`Attempt to store invalid user_id in local storage: ${userId} (type: ${typeof userId})`);\n }\n },\n\n /**\n * Clears all checkout data from local storage\n */\n clearCheckoutData() {\n this.localStorage.remove(TREATMENT_TYPE_KEY);\n this.localStorage.remove(TESTS_KEY);\n this.localStorage.remove(ORDER_UPSELLS);\n this.localStorage.remove(EXTRA_CHARGES_KEY);\n this.localStorage.remove(COUPON_KEY);\n },\n };\n}\n","import storageService from './storage.js';\n\n/**\n * Service class for glp1 treatment.\n */\nexport default function glp1TreatmentService() {\n const glp1_treatment_type = 'glp_1';\n\n /**\n * Check if the current treatment type is GLP-1.\n */\n function isGlp1TreatmentType() {\n return storageService().treatmentType === glp1_treatment_type;\n }\n\n /**\n * Set the default pharmacy for GLP-1 treatment\n */\n function setDefaultPharmacyForGlp1() {\n storageService().center = {\n id: '88566',\n title: 'Casa Pharma Rx',\n address: '12855 Capricorn St',\n city: 'Stafford',\n state: 'TX',\n zip: '77477',\n };\n }\n\n /**\n * Set the default pharmacy for GLP-1 treatment and redirect to the order page.\n */\n function afterGlp1ProductSelection() {\n setDefaultPharmacyForGlp1();\n window.location.href = '/order';\n }\n\n return {\n isGlp1TreatmentType,\n afterGlp1ProductSelection,\n };\n}\n"],"names":["Product","constructor","name","price","extraCharge","treatmentType","slug","this","window","onload","select_product_btn","document","querySelector","addEventListener","storage","clearCheckoutData","product","querySelectorAll","values","dataset","productName","productPrice","productExtraCharge","productTreatmentType","productSlug","getSelectedProductDataset","tests","parseInt","extraCharges","amount","type","coupon","applyDefaultCoupon","isGlp1TreatmentType","afterGlp1ProductSelection","location","href","length","classList","add","couponService","couponElement","coupon_code","couponCode","coupon_amount","Number","couponAmount","coupon_name","couponName","coupon_type","couponType","storageService","SLIDER_ANSWERS","TESTS_KEY","EXTRA_CHARGES_KEY","COUPON_KEY","TREATMENT_TYPE_KEY","ORDER_UPSELLS","CENTER_KEY","USER_ID_KEY","getLocalStorage","key","JSON","parse","localStorage","getItem","error","console","setLocalStorage","value","setItem","stringify","removeLocalStorage","removeItem","get","set","remove","sliderAnswers","orderUpsells","center","userId","test","trim","isInteger","glp1TreatmentService","id","title","address","city","state","zip"],"sourceRoot":""}