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,oEAACjH,CAAA,CA5c0C,E","sources":["webpack:///./resources/js/components/generic/per-user-pricing-calculator-breakpoint.ts","webpack:///./resources/js/components/generic/per-user-pricing-calculator.ts"],"sourcesContent":["import _ from 'underscore';\n\nexport default class Breakpoint {\n label: string;\n price: any;\n userCount: number;\n isFlatPrice: boolean;\n flatTemplate: any;\n subtotal: any;\n\n constructor(label: string, price: number, userCount: number, isFlatPrice = false, flatTemplate: any) {\n this.label = label;\n this.price = price;\n this.userCount = userCount;\n this.isFlatPrice = isFlatPrice;\n this.flatTemplate = flatTemplate;\n this.subtotal = isNaN(userCount) ? price : price * userCount;\n }\n\n toString() {\n let string;\n\n const i18nUserCount = new Intl.NumberFormat().format(this.userCount);\n const i18nPrice = new Intl.NumberFormat('en-US', {\n style: 'currency',\n currency: 'USD',\n maximumFractionDigits: 0,\n minimumFractionDigits: 0\n }).format(this.price);\n\n const templateSettings = {\n interpolate: /\\{\\{(.+?)\\}\\}/g\n };\n\n if (this.isFlatPrice && !!this.flatTemplate) {\n\n const compiled = _.template(this.flatTemplate, templateSettings);\n string = compiled({\n price: i18nPrice,\n userCount: i18nUserCount\n });\n } else {\n string = `(${i18nUserCount} × ${i18nPrice})`;\n }\n\n return string;\n }\n}\n","import * as $ from \"jquery\";\nimport Breakpoint from \"./per-user-pricing-calculator-breakpoint\";\nimport imkt from '../../imkt';\nimport general from '../../utils/general';\n\nconst DEFAULT_TIER_MODEL = \"pricingTiersMonthly\";\n\nexport default class PerUserPricingCalculator {\n domRoot: JQuery<HTMLElement>;\n params: any;\n userInput: JQuery<HTMLElement>;\n calculateButton: JQuery<HTMLElement>;\n priceLabel: JQuery<HTMLElement>;\n priceUnit: JQuery<HTMLElement>;\n averagePriceLabel: JQuery<HTMLElement>;\n outputHeading: any;\n breakdown: any;\n breakdownContainer: any;\n activeTierModelName: any;\n activeTierModel: any;\n \n constructor(domRoot: HTMLElement, params: any) {\n this.domRoot = $(domRoot);\n this.params = {\n // additional default params\n currencyLabel: '<span class=\"priceCurrency\">$</span>',\n ...params,\n };\n\n // Component HTML elements\n this.userInput = $(\".imkt-pup-calculator__user-input\", this.domRoot);\n this.calculateButton = $(\".imkt-pup-calculator__calculate\", this.domRoot);\n this.priceLabel = $(\".imkt-pup-calculator__price\", this.domRoot);\n this.priceUnit = $(\".imkt-pup-calculator__price-label\", this.domRoot);\n this.averagePriceLabel = $(\".imkt-pup-calculator__average\", this.domRoot);\n this.outputHeading = this.domRoot.find(\".imkt-pup-calculator__sub-heading\");\n this.breakdown = this.domRoot.find(\".imkt-pup-calculator__price-breakdown\");\n this.breakdownContainer = this.breakdown.find(\n \".imkt-pup-calculator__price-breakdown__container\"\n );\n\n this.init();\n\n if (this.userInput.val().trim() !== \"\") {\n this.calculateButton.trigger(\"click\");\n }\n }\n\n init() {\n if (\n !this.params.hasOwnProperty(\"useTiers\") ||\n !$.isEmptyObject(this.params.useTiers)\n ) {\n this.params.useTiers = [DEFAULT_TIER_MODEL];\n }\n\n this.setFormattedMaxUserTierError();\n\n this.setActiveTierModel(this.params.useTiers[0]);\n\n this.setMaxTierPrice();\n this.bindEvents();\n }\n\n bindEvents() {\n this.calculateButton.on(\n \"click\",\n function () {\n this.validateUserInput();\n\n if (this.userInput.val().trim() === \"\") {\n this.resetPrice();\n this.userInput.focus();\n }\n\n return false;\n }.bind(this)\n );\n\n this.userInput.on(\n \"blur\",\n function () {\n if (this.userInput.val().trim() === \"\") {\n this.resetErrors();\n this.resetPrice();\n } else {\n this.validateUserInput();\n }\n }.bind(this)\n );\n\n this.userInput.on(\"keydown\", function (e) {\n // Key is not a number.\n const isNotNumericKey = /[\\d]+/.test(e.key) === false;\n\n // \"Shift\", \"Alt\", \"Ctrl\", etc.; Allow these characters.\n const isHelperKey = /[a-zA-Z]{2,}/.test(e.key);\n const isInvalidKey = isNotNumericKey !== isHelperKey;\n\n if (isInvalidKey) {\n e.preventDefault();\n }\n });\n this.domRoot.on(\"change\", 'input[name=\"tierModel\"]', (e) => {\n const selectedTierModel = e.currentTarget.value;\n this.setActiveTierModel(selectedTierModel);\n\n if (this.userInput.val().trim() === \"\") {\n this.resetErrors();\n this.resetPrice();\n } else {\n this.validateUserInput();\n }\n });\n }\n\n validateUserInput() {\n var userCount = this.userInput.val();\n var numberRegExp = /^[1-9]\\d*$/;\n var isNumber = numberRegExp.test(userCount);\n\n if (isNumber && parseInt(userCount) !== 0) {\n this.priceLookup(parseInt(userCount));\n } else {\n this.errorNaN();\n }\n }\n\n setActiveTierModel(tierModelName) {\n this.activeTierModelName = tierModelName;\n this.activeTierModel = this.params.tierModels[this.activeTierModelName];\n\n const priceLabel = this.activeTierModel.priceLabel;\n\n this.priceUnit.text(priceLabel);\n this.domRoot.attr(\"data-activetier\", this.activeTierModelName);\n }\n\n setMaxTierPrice() {\n $.each(\n this.activeTierModel.tiers,\n function (index, tier) {\n var userRangeCount = tier.maxUserCount + 1 - tier.minUserCount;\n tier.maxTierPrice =\n tier.maxUserCount === -1 ? null : userRangeCount * tier.perUserPrice;\n }.bind(this)\n );\n }\n\n priceLookup(userCount) {\n var price = 0;\n var userCountInRange = 0;\n\n // Sort tiers by minUserCount\n this.activeTierModel.tiers.sort((a, b) => {\n return a.minUserCount - b.minUserCount;\n });\n\n if (this.activeTierModel.pricingStrategy === \"fixedTiers\") {\n this.isNotFlatPrice();\n\n $.each(\n this.activeTierModel.tiers,\n function (index, tier) {\n if (\n userCount >= tier.minUserCount &&\n (userCount <= tier.maxUserCount || tier.maxUserCount === -1)\n ) {\n switch (tier.priceModel) {\n case \"flat\":\n price = tier.flatPrice;\n break;\n\n case \"perUser\":\n price = userCount * tier.perUserPrice;\n break;\n\n case \"perUserGroup\":\n // A + (B * Math.floor((C - D) / E)\n price =\n tier.perUserGroupStartingPrice +\n tier.perUserGroupPriceIncrease *\n Math.floor(\n (userCount - tier.minUserCount) / tier.perUserGroupCount\n );\n break;\n }\n return false;\n }\n }.bind(this)\n );\n } else {\n $.each(\n this.activeTierModel.tiers,\n function (index, tier) {\n // if price is flat\n if (tier.priceModel === \"flat\") {\n // if usercount is within flat rate tier, use flatPrice, else use maxTierPrice which is based on per user price\n if (userCount <= tier.maxUserCount) {\n price = tier.flatPrice;\n this.isFlatPrice();\n } else {\n price = price + tier.maxTierPrice;\n this.isNotFlatPrice();\n }\n // else get lower tier max prices excluding max tier and excluding fixed\n } else if (\n userCount > tier.maxUserCount &&\n tier.maxUserCount !== -1\n ) {\n price = price + tier.maxTierPrice;\n // then if not at max tier, get current/active tier\n } else if (\n userCount >= tier.minUserCount &&\n userCount <= tier.maxUserCount\n ) {\n userCountInRange = userCount + 1 - tier.minUserCount;\n price = price + userCountInRange * tier.perUserPrice;\n // if price is max tier (maxUserCount = -1; used to denote infinity)\n } else if (\n userCount >= tier.minUserCount &&\n tier.maxUserCount === -1\n ) {\n userCountInRange = userCount + 1 - tier.minUserCount;\n price = price + userCountInRange * tier.perUserPrice;\n }\n }.bind(this)\n );\n }\n\n const averagePrice = price / userCount;\n\n const calculationDetails = this.getCalculationDetails(\n userCount,\n this.activeTierModel.tiers\n );\n\n this.updatePrice(\n price.toFixed(2).replace(\".00\", \"\"),\n averagePrice.toFixed(2),\n userCount,\n calculationDetails\n );\n this.overMaxUsers(userCount);\n this.overMinUsers(userCount);\n this.dismissErrorNaN();\n }\n\n // @todo At some point replace parts of \"priceLookup\" with this\n getCalculationDetails(userCount, tiers) {\n const breakdown = [];\n let total = 0;\n let userCountdown = userCount;\n\n for (let i = 0; i < tiers.length; i++) {\n const t = tiers[i];\n t.tierSize =\n t.maxUserCount > 0\n ? t.maxUserCount - t.minUserCount + 1\n : userCount - t.minUserCount + 1;\n\n if (t.priceModel === \"flat\") {\n // Number of users fall outside the \"flat pricing\" range\n // Treat as \"per-user\"\n if (userCountdown > t.maxUserCount) {\n userCountdown -= t.maxUserCount;\n breakdown.push(\n new Breakpoint(\n \"flat-perUser-go\",\n t.perUserPrice,\n t.maxUserCount,\n true\n )\n );\n total += t.perUserPrice * t.maxUserCount;\n\n // Qualifies for flat rate, regardless of number of users\n } else {\n breakdown.push(\n new Breakpoint(\n \"flat-stop\",\n t.flatPrice,\n t.maxUserCount,\n true,\n this.params.breakdownFlatPriceTemplate\n )\n );\n total += t.flatPrice;\n break;\n }\n } else if (t.priceModel === \"perUser\") {\n // Remaining number of users is bigger than the current tier\n // Use up entire tier; keep going\n if (userCountdown > t.tierSize) {\n userCountdown -= t.tierSize;\n breakdown.push(\n new Breakpoint(\"perUser-go\", t.perUserPrice, t.tierSize)\n );\n total += t.perUserPrice * t.tierSize;\n }\n\n // Use as much of this tier as you need; stop\n else {\n breakdown.push(\n new Breakpoint(\"perUser-stop\", t.perUserPrice, userCountdown)\n );\n total += t.perUserPrice * userCountdown;\n userCountdown = 0;\n break;\n }\n }\n }\n\n const avg = Math.round((total / userCount) * 100) / 100;\n\n return {\n userCount,\n total,\n avg,\n breakdown,\n };\n }\n\n getTier(userCount) {\n const tier = this.activeTierModel.tiers.find(\n (tier) =>\n tier.minUserCount &&\n (userCount <= tier.maxUserCount || tier.maxUserCount === -1)\n );\n return (\n tier.minUserCount +\n (tier.maxUserCount === -1 ? \"+\" : ` - ${tier.maxUserCount}`) +\n ` ${this.params.usersString}`\n );\n }\n\n updatePrice(price, averagePrice, userCount, details) {\n // Sort by price (low to high)\n const breakdown = [...details.breakdown].sort(\n (a, b) => parseInt(b.price) - parseInt(a.price)\n );\n let breakdownHtml = [];\n\n if (breakdown.length > 1) {\n const firstBreakpoint = breakdown.shift();\n const secondBreakpoint = breakdown.shift();\n\n if (\n firstBreakpoint.isFlatPrice &&\n firstBreakpoint.price === secondBreakpoint.price\n ) {\n const label = `${firstBreakpoint.label} + ${secondBreakpoint.label}`;\n const userCount =\n firstBreakpoint.userCount + secondBreakpoint.userCount;\n const comboBreakpoint = new Breakpoint(\n label,\n firstBreakpoint.price,\n userCount,\n true\n );\n\n breakdown.unshift(comboBreakpoint);\n } else {\n breakdown.unshift(firstBreakpoint, secondBreakpoint);\n }\n }\n\n this.breakdownContainer.html(\"\");\n breakdown.forEach((breakpoint) => {\n breakdownHtml.push(`<span>${breakpoint}</span>`);\n });\n\n const i18nPrice = new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: \"USD\",\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n }).format(price);\n breakdownHtml = [breakdownHtml.join(\" + \")];\n\n if (breakdown.length > 1) {\n breakdownHtml.push(` = <strong>${i18nPrice}</strong>`);\n }\n\n this.breakdownContainer.html($(breakdownHtml.join(\"\")));\n this.breakdown.show();\n\n this.priceLabel.html(\n this.params.currencyLabel + general.numberWithCommas(price)\n );\n this.averagePriceLabel.html(this.params.currencyLabel + averagePrice);\n\n if (this.params.showUserRange) {\n const tierUserRange = ` (${this.getTier(userCount)})`;\n if (this.outputHeading.find(\"small\").length) {\n this.outputHeading.find(\"small\").text(tierUserRange);\n } else {\n this.outputHeading.append($(`<small>${tierUserRange}</small>`));\n }\n }\n }\n\n resetErrors() {\n $(this.domRoot).removeClass(\"has-input-error is-max-user is-min-user\");\n }\n\n resetPrice() {\n this.priceLabel.text(this.params.priceLabelValue);\n this.averagePriceLabel.text(this.params.priceLabelValue);\n this.outputHeading.find(\"small\").remove();\n this.breakdown.hide();\n }\n\n isFlatPrice() {\n $(this.domRoot).addClass(\"is-flat-price\");\n }\n\n isNotFlatPrice() {\n $(this.domRoot).removeClass(\"is-flat-price\");\n }\n\n overMaxUsers(userCount) {\n if (this.params.maxUserInt > 0 && userCount > this.params.maxUserInt) {\n this.resetPrice();\n $(this.domRoot).addClass(\"is-max-user\");\n } else {\n $(this.domRoot).removeClass(\"is-max-user\");\n }\n }\n\n overMinUsers(userCount) {\n if (userCount < this.params.minUserInt) {\n this.resetPrice();\n $(this.domRoot).addClass(\"is-min-user\");\n } else {\n $(this.domRoot).removeClass(\"is-min-user\");\n }\n }\n\n errorNaN() {\n this.resetPrice();\n $(this.domRoot).addClass(\"has-input-error\");\n }\n\n dismissErrorNaN() {\n $(this.domRoot).removeClass(\"has-input-error\");\n }\n\n setFormattedMaxUserTierError() {\n const errorMessageContainer = $(\".imkt-pup-calculator__error-max-user\");\n const errorMessageMessage = errorMessageContainer.html();\n errorMessageContainer.html(\n errorMessageMessage.replace(\n /[.,\\d]+/,\n this.formatMaxUsers(this.params.maxUserInt)\n )\n );\n }\n\n formatMaxUsers(users) {\n if (\n general &&\n typeof general.numberWithCommas === \"function\"\n ) {\n return general.numberWithCommas(users);\n }\n return users;\n }\n}\n"],"names":["Breakpoint","label","price","userCount","isFlatPrice","arguments","length","undefined","flatTemplate","_classCallCheck","this","subtotal","isNaN","key","value","i18nUserCount","Intl","NumberFormat","format","i18nPrice","style","currency","maximumFractionDigits","minimumFractionDigits","_","interpolate","compiled","concat","PerUserPricingCalculator","domRoot","params","$","_objectSpread","currencyLabel","userInput","calculateButton","priceLabel","priceUnit","averagePriceLabel","outputHeading","find","breakdown","breakdownContainer","init","val","trim","trigger","hasOwnProperty","useTiers","setFormattedMaxUserTierError","setActiveTierModel","setMaxTierPrice","bindEvents","_this","on","validateUserInput","resetPrice","focus","bind","resetErrors","e","test","preventDefault","selectedTierModel","currentTarget","parseInt","priceLookup","errorNaN","tierModelName","activeTierModelName","activeTierModel","tierModels","text","attr","tiers","index","tier","userRangeCount","maxUserCount","minUserCount","maxTierPrice","perUserPrice","userCountInRange","sort","a","b","pricingStrategy","isNotFlatPrice","priceModel","flatPrice","perUserGroupStartingPrice","perUserGroupPriceIncrease","Math","floor","perUserGroupCount","averagePrice","calculationDetails","getCalculationDetails","updatePrice","toFixed","replace","overMaxUsers","overMinUsers","dismissErrorNaN","total","userCountdown","i","t","tierSize","push","breakdownFlatPriceTemplate","avg","round","usersString","details","breakdownHtml","firstBreakpoint","shift","secondBreakpoint","comboBreakpoint","unshift","html","forEach","breakpoint","join","show","general","showUserRange","tierUserRange","getTier","append","removeClass","priceLabelValue","remove","hide","addClass","maxUserInt","minUserInt","errorMessageContainer","errorMessageMessage","formatMaxUsers","users"],"sourceRoot":""}