{"version":3,"file":"package_controller-CXub86kc.js","sources":["../../../app/javascript/controllers/payments/package_controller.js"],"sourcesContent":["import ApplicationController from '../application_controller'\n\nimport { MoneyFormatter } from \"../models/money_formatter\";\nimport { useNumberHelpers } from '../mixins/useNumberHelpers';\n\nexport default class extends ApplicationController {\n static values = {\n info: Object,\n monthlyAmount: Number,\n yearlyAmount: Number,\n active: Boolean,\n selected: Boolean,\n contactUs: Boolean\n }\n\n static targets = ['creditsContainer', 'yearlyAgreementPrice', 'monthlyAgreementPrice', 'creditBundleDropdownContainer']\n\n initialize() {\n super.initialize();\n this.moneyFormatter = new MoneyFormatter();\n this.agreementType = 'yearly'\n\n this.originalAvailableCredits = this.availableCredits\n }\n\n connect() {\n super.connect()\n\n useNumberHelpers(this)\n\n if(this.hasMonthlyAgreementPriceTarget) {\n this.monthlyAgreementPriceTarget.innerText = this.translations.products.packages.package.monthly_price.replace(\n '%{price}',\n this.moneyFormatter.humanizeWithSymbol(this.monthlyAmountValue),\n )\n }\n\n if(this.hasYearlyAgreementPriceTarget) {\n this.yearlyAgreementPriceTarget.innerText = this.translations.products.packages.package.monthly_price.replace(\n '%{price}',\n this.moneyFormatter.humanizeWithSymbol(this.yearlyAmountValue),\n )\n }\n }\n\n onAgreementTypeChange({ detail: agreementType }) {\n if(this.contactUsValue) return\n\n this.agreementType = agreementType\n\n if(agreementType === 'monthly') {\n if(this.hasYearlyAgreementPriceTarget) {\n this.hide(this.yearlyAgreementPriceTarget)\n }\n\n this.show(this.monthlyAgreementPriceTarget)\n } else {\n this.hide(this.monthlyAgreementPriceTarget)\n this.show(this.yearlyAgreementPriceTarget)\n }\n }\n\n onSelectionChange({ target }) {\n this.activeValue = target.checked\n\n if(target.checked) {\n this.dispatch('change', {\n detail: this.infoValue\n })\n }\n\n if(!this.hasCreditBundleDropdownContainerTarget) return\n\n if(target.checked) {\n this.show(this.creditBundleDropdownContainerTarget)\n } else {\n this.hide(this.creditBundleDropdownContainerTarget)\n }\n }\n\n onCreditBundleChange({ target }) {\n const value = parseInt(target.value) || 0\n const total = this.originalAvailableCredits + value\n\n if(this.activeValue) {\n this.infoValue = {\n ...this.infoValue,\n credit_bundle: target.value,\n features: this.infoValue.features.map(feature => {\n if(feature.identifier === 'credit') {\n return {\n ...feature,\n available: total\n }\n } else {\n return feature\n }\n })\n }\n\n this.dispatch('change', {\n detail: this.infoValue\n })\n }\n\n this.creditsContainerTarget.innerText = this.translations.products.packages.package.credits.replace(\n '%{available}',\n this.numberWithDelimiter(total)\n )\n\n if(this.hasMonthlyAgreementPriceTarget) {\n this.monthlyAgreementPriceTarget.innerText = this.translations.products.packages.package.monthly_price.replace(\n '%{price}',\n this.moneyFormatter.humanizeWithSymbol(this.monthlyAmountValue + this.totalPriceForCreditBundle(value))\n )\n }\n\n if(this.hasYearlyAgreementPriceTarget) {\n this.yearlyAgreementPriceTarget.innerText = this.translations.products.packages.package.monthly_price.replace(\n '%{price}',\n this.moneyFormatter.humanizeWithSymbol(this.yearlyAmountValue + this.totalPriceForCreditBundle(value))\n )\n }\n }\n\n totalPriceForCreditBundle(creditBundle) {\n let total;\n\n if(this.agreementType === 'monthly') {\n total = creditBundle * .07 * 1000\n } else {\n total = creditBundle * .05 * 1000\n }\n\n return total\n }\n\n activeValueChanged() {\n if(this.element.querySelector('select')) {\n this.element.querySelector('select').disabled = !this.activeValue\n }\n }\n\n get availableCredits() {\n return parseInt(this.infoValue.features.find(feature => feature.identifier === 'credit').available)\n }\n}\n"],"names":["package_controller","ApplicationController","MoneyFormatter","useNumberHelpers","agreementType","target","value","total","feature","creditBundle","__publicField"],"mappings":"iRAKe,MAAKA,UAASC,CAAsB,CAYjD,YAAa,CACX,MAAM,WAAY,EAClB,KAAK,eAAiB,IAAIC,EAC1B,KAAK,cAAgB,SAErB,KAAK,yBAA2B,KAAK,gBACzC,CAEE,SAAU,CACR,MAAM,QAAO,EAEbC,EAAiB,IAAI,EAElB,KAAK,iCACN,KAAK,4BAA4B,UAAY,KAAK,aAAa,SAA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