{"version":3,"file":"packages_controller-D1R9MXGz.js","sources":["../../../app/javascript/controllers/payments/packages_controller.js"],"sourcesContent":["import ApplicationController from '../application_controller'\n\nimport { useNumberHelpers } from '../mixins/useNumberHelpers'\n\nexport default class extends ApplicationController {\n static values = {\n agreement: String,\n activePackageId: String,\n creditBundle: String,\n swap: Boolean\n }\n\n static targets = ['package', 'agreementCheckbox', 'feature', 'submitButton', 'monthlyAgreementRadio', 'yearlyAgreementRadio']\n\n initialize() {\n super.initialize()\n\n this.initialState = {\n agreement: this.agreementValue,\n activePackage: this.activePackageIdValue,\n credit_bundle: parseInt(this.creditBundleValue)\n }\n\n this.state = { ...this.initialState }\n }\n\n connect() {\n super.connect()\n\n useNumberHelpers(this)\n }\n\n switchToMonthlyAgreement() {\n this.agreementValue = 'monthly'\n this.agreementCheckboxTarget.checked = false\n }\n\n switchToYearlyAgreement() {\n this.agreementValue = 'yearly'\n this.agreementCheckboxTarget.checked = true\n }\n\n toggleAgreement() {\n if(this.agreementCheckboxTarget.checked) {\n this.switchToMonthlyAgreement()\n } else {\n this.switchToYearlyAgreement()\n }\n }\n\n onPackageChange({ detail: info }) {\n this.state.activePackage = info.hashed_id\n this.state.credit_bundle = parseInt(info.credit_bundle) || 0\n\n this.stateChanged()\n\n const seat = {\n element: this.featureTargets.find(element => element.dataset.type === 'seat'),\n feature: info.features.find(feature => feature.identifier === 'seat')\n }\n\n if(parseInt(seat.feature.available) > 1) {\n seat.element.innerText = this.translations.static.pricing.features.seat.available.other.replace(\n '%{count}',\n parseInt(seat.feature.available)\n )\n } else {\n seat.element.innerText = this.translations.static.pricing.features.seat.available.one\n }\n\n const credit = {\n element: this.featureTargets.find(element => element.dataset.type === 'credit'),\n feature: info.features.find(feature => feature.identifier === 'credit')\n }\n\n credit.element.innerText = this.translations.static.pricing.features.credit.available.replace(\n '%{count}',\n this.numberWithDelimiter(parseInt(credit.feature.available))\n )\n\n const phoneNumber = {\n element: this.featureTargets.find(element => element.dataset.type === 'phone_number'),\n feature: info.features.find(feature => feature.identifier === 'phone_number')\n }\n\n if(parseInt(phoneNumber.feature.available) > 1) {\n phoneNumber.element.innerText = this.translations.static.pricing.features.phone_number.available.other.replace(\n '%{count}',\n parseInt(phoneNumber.feature.available)\n )\n } else {\n phoneNumber.element.innerText = this.translations.static.pricing.features.phone_number.available.one\n }\n\n const keyword = {\n element: this.featureTargets.find(element => element.dataset.type === 'keyword'),\n feature: info.features.find(feature => feature.identifier === 'keyword')\n }\n\n if(keyword.feature) {\n keyword.element.querySelector('x-available').innerText = this.translations.static.pricing.features.keyword.allowed_with_owned_shortcode\n } else {\n keyword.element.querySelector('x-available').innerText = this.translations.static.pricing.feature_status.not_included\n }\n\n const audienceTracking = {\n element: this.featureTargets.find(element => element.dataset.type === 'audience_tracking'),\n feature: info.features.find(feature => feature.identifier === 'audience_tracking')\n }\n\n audienceTracking.element.querySelector('x-available').innerText =\n this.translations.static.pricing.features.audience_tracking.available.replace('%{count}', parseInt(audienceTracking.feature.available))\n\n const activityReport = {\n element: this.featureTargets.find(element => element.dataset.type === 'activity_report'),\n feature: info.features.find(feature => feature.identifier === 'activity_report')\n }\n\n\n if('real_time' in activityReport.feature.metadata) {\n activityReport.element.querySelector('x-available').innerText =\n this.translations.static.pricing.features.activity_reports.delay.realtime\n } else {\n activityReport.element.querySelector('x-available').innerText =\n this.translations.static.pricing.features.activity_reports.delay.minute.other.replace('%{count}', activityReport.feature.metadata.delay)\n }\n\n const whiteLabel = {\n element: this.featureTargets.find(element => element.dataset.type === 'white_label'),\n feature: info.features.find(feature => feature.identifier === 'white_label')\n }\n\n if(whiteLabel.feature) {\n whiteLabel.element.querySelector('x-available').innerText = this.translations.static.pricing.feature_status.included\n } else {\n whiteLabel.element.querySelector('x-available').innerText = this.translations.static.pricing.feature_status.not_included\n }\n\n const whiteGlove = {\n element: this.featureTargets.find(element => element.dataset.type === 'white_glove'),\n feature: info.features.find(feature => feature.identifier === 'white_glove')\n }\n\n if(whiteGlove.feature) {\n whiteGlove.element.querySelector('x-available').innerText = this.translations.static.pricing.feature_status.included\n } else {\n whiteGlove.element.querySelector('x-available').innerText = this.translations.static.pricing.feature_status.not_included\n }\n }\n\n // private\n\n agreementValueChanged() {\n this.state.agreement = this.agreementValue\n this.notifyPackages()\n\n this.stateChanged()\n\n if(this.agreementValue === 'monthly') {\n this.monthlyAgreementRadioTarget.checked = true\n } else {\n this.yearlyAgreementRadioTarget.checked = true\n }\n }\n\n stateChanged() {\n if(this.swapValue) {\n this.submitButtonTarget.disabled = Object.keys(this.state).every(key => {\n return this.state[key] === this.initialState[key]\n })\n }\n }\n\n notifyPackages() {\n this.packageTargets.forEach(element => {\n this.dispatch('agreement:change', {\n target: element,\n detail: this.agreementValue\n })\n })\n }\n}\n"],"names":["packages_controller","ApplicationController","useNumberHelpers","info","seat","element","feature","credit","phoneNumber","keyword","audienceTracking","activityReport","whiteLabel","whiteGlove","key","__publicField"],"mappings":"0QAIe,MAAKA,UAASC,CAAsB,CAUjD,YAAa,CACX,MAAM,WAAU,EAEhB,KAAK,aAAe,CAClB,UAAW,KAAK,eAChB,cAAe,KAAK,qBACpB,cAAe,SAAS,KAAK,iBAAiB,CACpD,EAEI,KAAK,MAAQ,CAAE,GAAG,KAAK,YAAY,CACvC,CAEE,SAAU,CACR,MAAM,QAAO,EAEbC,EAAiB,IAAI,CACzB,CAEE,0BAA2B,CACzB,KAAK,eAAiB,UACtB,KAAK,wBAAwB,QAAU,EAC3C,CAEE,yBAA0B,CACxB,KAAK,eAAiB,SACtB,KAAK,wBAAwB,QAAU,EAC3C,CAEE,iBAAkB,CACb,KAAK,wBAAwB,QAC9B,KAAK,yBAAwB,EAE7B,KAAK,wBAAuB,CAElC,CAEE,gBAAgB,CAAE,OAAQC,GAAQ,CAChC,KAAK,MAAM,cAAgBA,EAAK,UAChC,KAAK,MAAM,cAAgB,SAASA,EAAK,aAAa,GAAK,EAE3D,KAAK,aAAY,EAEjB,MAAMC,EAAO,CACX,QAAS,KAAK,eAAe,K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