{"version":3,"sources":["product-page.js"],"names":["document","addEventListener","purchasesContainer","getElementById","addPurchaseFieldButton","trophyPricesContainer","addTrophyFieldButton","totalPriceField","querySelector","huntingPriceField","trophyPriceField","administrationFeesField","extraDaysYes","extraDaysNo","fields","extraHuntingDays","extraStayDays","companionDays","noAdditionalPurchaseCheckbox","optionalPurchasesCheckboxes","querySelectorAll","priceDropdown","toggleOptionalPurchases","isDisabled","checked","forEach","checkbox","disabled","updateHuntPriceField","selectedValue","value","price","parseFloat","isNaN","calculateTotalPrice","totalPrice","reduce","sum","field","parseInt","addField","container","nameFieldName","priceFieldName","index","newField","createElement","classList","add","createInput","type","name","placeholder","width","input","style","nameInputField","priceInputField","removeButton","innerHTML","remove","appendChild","toggleExtraDaysFields","isEnabled","Object","values","childElementCount","radio"],"mappings":"AAAAA,SAAAC,iBAAA,oBAAA,WACA,MAAAC,EAAAF,SAAAG,eAAA,sCACAC,EAAAJ,SAAAG,eAAA,sBACAE,EAAAL,SAAAG,eAAA,2BACAG,EAAAN,SAAAG,eAAA,oBACAI,EAAAP,SAAAQ,cAAA,4BACAC,EAAAT,SAAAQ,cAAA,8BACAE,EAAAV,SAAAQ,cAAA,6BACAG,EAAAX,SAAAQ,cAAA,oCACAI,EAAAZ,SAAAG,eAAA,gBACAU,EAAAb,SAAAG,eAAA,eACAW,EAAA,CACAC,iBAAAf,SAAAQ,cAAA,kCACAQ,cAAAhB,SAAAQ,cAAA,+BACAS,cAAAjB,SAAAQ,cAAA,gCAEAU,EAAAlB,SAAAG,eAAA,0BACAgB,EAAAnB,SAAAoB,iBAAA,sBACAC,EAAArB,SAAAG,eAAA,wBAGA,SAAAmB,IACA,MAAAC,EAAAL,EAAAM,QACAL,EAAAM,SAAAC,IACAA,EAAAC,SAAAJ,EAGAA,IACAG,EAAAF,SAAA,MAMA,SAAAI,IACA,GAAAP,EAAA,CACA,IAAAQ,EAAAR,EAAAS,MACAC,EAAAC,WAAAH,GAGAI,MAAAF,GAGAtB,EAAAqB,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AAgE,sBAGA5D,GAAAL,iBAAA,SAAA,WACAuC,EAAAnC,EAAA,cAAA,eAAAA,EAAA6D,sBAIA,CAAAzD,EAAAC,GAAAe,SAAAa,IACAA,GAAArC,iBAAA,QAAAiC,MAIA,CAAAtB,EAAAC,GAAAY,SAAA0C,IACAA,GAAAlE,iBAAA,SAAA6D,MAIAzC,GACAA,EAAApB,iBAAA,SAAA2B,GAIAV,EAAAjB,iBAAA,SAAAqB,GAGAM,IACAM,IACA4B,IACAxC","file":"productPage.min.js","sourcesContent":["document.addEventListener('DOMContentLoaded', function () {\n const purchasesContainer = document.getElementById('optional-purchase-prices-container');\n const addPurchaseFieldButton = document.getElementById('add-purchase-field');\n const trophyPricesContainer = document.getElementById('trophy-prices-container');\n const addTrophyFieldButton = document.getElementById('add-trophy-field');\n const totalPriceField = document.querySelector('input[name=\"TotalPrice\"]');\n const huntingPriceField = document.querySelector('input[name=\"HuntingPrice\"]');\n const trophyPriceField = document.querySelector('input[name=\"TrophyPrice\"]');\n const administrationFeesField = document.querySelector('input[name=\"AdministrationFees\"]');\n const extraDaysYes = document.getElementById('ExtraDaysYes');\n const extraDaysNo = document.getElementById('ExtraDaysNo');\n const fields = {\n extraHuntingDays: document.querySelector('input[name=\"ExtraHuntingDays\"]'),\n extraStayDays: document.querySelector('input[name=\"ExtraStayDays\"]'),\n companionDays: document.querySelector('input[name=\"CompanionDays\"]')\n };\n const noAdditionalPurchaseCheckbox = document.getElementById('no-additional-purchase');\n const optionalPurchasesCheckboxes = document.querySelectorAll('.optional-purchase');\n const priceDropdown = document.getElementById('pricePackageDropdown');\n\n // Function to enable/disable optional purchases based on the \"No Additional Purchases\" checkbox\n function toggleOptionalPurchases() {\n const isDisabled = noAdditionalPurchaseCheckbox.checked;\n optionalPurchasesCheckboxes.forEach(checkbox => {\n checkbox.disabled = isDisabled;\n\n // Uncheck the optional purchases if \"Ingen ekstra tilk�b\" is checked\n if (isDisabled) {\n checkbox.checked = false;\n }\n });\n }\n\n // Function to update the hunt price field\n function updateHuntPriceField() {\n if (priceDropdown) {\n var selectedValue = priceDropdown.value; // Get the selected option's value (which is the price)\n var price = parseFloat(selectedValue); // Convert it to a float (or integer, depending on your needs)\n\n // Update the price field with the parsed price\n if (!isNaN(price)) {\n huntingPriceField.value = price;\n } else {\n huntingPriceField.value = ''; // Clear the field if no valid price\n }\n calculateTotalPrice();\r\n }\n }\n\n // Function to calculate total price\n function calculateTotalPrice() {\n let totalPrice = [\n huntingPriceField,\n trophyPriceField,\n administrationFeesField\n ].reduce((sum, field) => sum + (parseInt(field?.value) || 0), 0);\n\n // Add up optional purchase prices\n purchasesContainer.querySelectorAll('input[name^=\"OptionalPurchasePrices\"]').forEach(field => {\n totalPrice += parseInt(field.value) || 0;\n });\n\n // Add up trophy prices\n trophyPricesContainer.querySelectorAll('input[name^=\"TrophyPrices\"]').forEach(field => {\n totalPrice += parseInt(field.value) || 0;\n });\n\n totalPriceField.value = totalPrice;\n }\n\n // Function to add a new pair of fields (name and price) with an optional removal button\n function addField(container, nameFieldName, priceFieldName, index) {\n const newField = document.createElement('div');\n newField.classList.add('mb-2', 'd-flex', 'align-items-center');\n\n // Create a helper function to create input fields\n const createInput = (type, name, placeholder, width) => {\n const input = document.createElement('input');\n input.type = type;\n input.name = `${name}[${index}]`;\n input.classList.add('form-control', 'mr-2');\n input.placeholder = placeholder;\n input.style.width = width;\n return input;\n };\n\n // Name and Price fields\n const nameInputField = createInput('text', nameFieldName, 'Indtast navn', '70%');\n const priceInputField = createInput('number', priceFieldName, 'Indtast pris', '30%');\n\n // Recalculate total price on input change\n priceInputField.addEventListener('input', calculateTotalPrice);\n\n // Remove field button\n const removeButton = document.createElement('button');\n removeButton.type = 'button';\n removeButton.classList.add('btn', 'btn-danger');\n removeButton.innerHTML = '-';\n removeButton.addEventListener('click', function () {\n newField.remove();\n calculateTotalPrice();\n });\n\n // Append elements\n newField.appendChild(nameInputField);\n newField.appendChild(priceInputField);\n newField.appendChild(removeButton);\n container.appendChild(newField);\n }\n\n // Function to enable/disable the fields based on whether \"Ja\" or \"Nej\" is selected\n function toggleExtraDaysFields() {\n const isEnabled = extraDaysYes.checked;\n Object.values(fields).forEach(field => {\n field.disabled = !isEnabled;\n if (!isEnabled) field.value = 0;\n });\n }\n\n // Event listeners for button clicks to add new fields\n addPurchaseFieldButton?.addEventListener('click', function () {\n addField(purchasesContainer, 'OptionalPurchaseNames', 'OptionalPurchasePrices', purchasesContainer.childElementCount);\n });\n\n addTrophyFieldButton?.addEventListener('click', function () {\n addField(trophyPricesContainer, 'TrophyNames', 'TrophyPrices', trophyPricesContainer.childElementCount);\n });\n\n // Event listeners for recalculating the total price\n [huntingPriceField, trophyPriceField].forEach(field => {\n field?.addEventListener('input', calculateTotalPrice);\n });\n\n // Event listeners for extra days fields\n [extraDaysYes, extraDaysNo].forEach(radio => {\n radio?.addEventListener('change', toggleExtraDaysFields);\n });\n\n // Add an event listener to update the hunt price when the dropdown value changes\n if (priceDropdown) {\n priceDropdown.addEventListener('change', updateHuntPriceField);\r\n }\n\n // Event listener for when the \"No Additional Purchases\" checkbox changes\n noAdditionalPurchaseCheckbox.addEventListener('change', toggleOptionalPurchases);\n\n // Initialize total price and extra days state on page load\n updateHuntPriceField();\n calculateTotalPrice();\n toggleExtraDaysFields();\n toggleOptionalPurchases();\n});\n"]}