{"version":3,"file":"simulator_controller-DzSJ1z6M.js","names":[],"sources":["../../../app/javascript/entrypoints/site_controllers/simulator_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\"\n\n// Simulator: yearly cost of a manual task, the share an automation recovers and the months the\n// matching offer takes to pay for itself. Same rules as Diagnostics::Simulation (weeks and share\n// come from the server, prices from the catalogue): planning goes to a business application,\n// otherwise an express automation, or a full system from 15 hours a week. On a diagnostic result\n// the offer is the one the diagnostic recommends (offer value).\nconst SYSTEM_MIN_HOURS = 15\n\nexport default class extends Controller {\n static targets = [\"task\", \"people\", \"hours\", \"rate\", \"peopleOut\", \"hoursOut\", \"rateOut\",\n \"yearlyHours\", \"yearlyCost\", \"yearlyGain\", \"payback\", \"solution\", \"link\",\n \"captureTask\", \"capturePeople\", \"captureHours\", \"captureRate\"]\n static values = { weeks: Number, share: Number, offers: Object, offer: String, hourUnit: String, monthUnit: String }\n\n connect() {\n this.update()\n }\n\n update() {\n const people = Number(this.peopleTarget.value)\n const hours = Number(this.hoursTarget.value)\n const rate = Number(this.rateTarget.value)\n const weekly = people * hours\n const cost = Math.round(weekly * this.weeksValue * rate)\n const gain = Math.round(cost * this.shareValue)\n const offer = this.offerFor(weekly)\n\n if (this.hasPeopleOutTarget) this.peopleOutTarget.textContent = people\n this.hoursOutTarget.textContent = `${this.number(hours)} ${this.hourUnitValue}`\n this.rateOutTarget.textContent = this.euros(rate)\n this.yearlyHoursTarget.textContent = `${this.number(Math.round(weekly * this.weeksValue))} ${this.hourUnitValue}`\n this.yearlyCostTarget.textContent = this.euros(cost)\n this.yearlyGainTarget.textContent = this.euros(gain)\n this.paybackTarget.textContent = offer && gain > 0 ? `${Math.max(1, Math.ceil(offer.price / (gain / 12)))} ${this.monthUnitValue}` : \"—\"\n this.solutionTarget.textContent = offer ? `${offer.name} · ${offer.from ? \"≥ \" : \"\"}${this.euros(offer.price)}` : \"—\"\n if (offer) this.linkTarget.href = offer.url\n this.copyToCapture(people, hours, rate)\n }\n\n // The \"receive by e-mail\" form sends the inputs; the server computes the figures again.\n copyToCapture(people, hours, rate) {\n if (!this.hasCaptureTaskTarget) return\n this.captureTaskTarget.value = this.taskTargets.find((input) => input.checked)?.value || \"quotes\"\n this.capturePeopleTarget.value = people\n this.captureHoursTarget.value = hours\n this.captureRateTarget.value = rate\n }\n\n offerFor(weekly) {\n if (this.offerValue && this.offersValue[this.offerValue]) return this.offersValue[this.offerValue]\n const task = this.taskTargets.find((input) => input.checked)?.value\n const key = task === \"planning\" ? \"business-app\" : (weekly >= SYSTEM_MIN_HOURS ? \"automation-system\" : \"automation-express\")\n return this.offersValue[key]\n }\n\n number(value) {\n return new Intl.NumberFormat(document.documentElement.lang, { maximumFractionDigits: 1 }).format(value)\n }\n\n euros(amount) {\n return new Intl.NumberFormat(document.documentElement.lang, { style: \"currency\", currency: \"EUR\", maximumFractionDigits: 0 }).format(amount)\n }\n}\n"],"mappings":"4GAOM,EAAmB,GAEzB,EAAA,cAA6B,CAAW,CACtC,OAAO,QAAU,CAAC,OAAQ,SAAU,QAAS,OAAQ,YAAa,WAAY,UAC5E,cAAe,aAAc,aAAc,UAAW,WAAY,OAClE,cAAe,gBAAiB,eAAgB,cAAc,CAChE,OAAO,OAAS,CAAE,MAAO,OAAQ,MAAO,OAAQ,OAAQ,OAAQ,MAAO,OAAQ,SAAU,OAAQ,UAAW,OAAQ,CAEpH,SAAU,CACR,KAAK,QAAQ,CAGf,QAAS,CACP,IAAM,EAAS,OAAO,KAAK,aAAa,MAAM,CACxC,EAAQ,OAAO,KAAK,YAAY,MAAM,CACtC,EAAO,OAAO,KAAK,WAAW,MAAM,CACpC,EAAS,EAAS,EAClB,EAAO,KAAK,MAAM,EAAS,KAAK,WAAa,EAAK,CAClD,EAAO,KAAK,MAAM,EAAO,KAAK,WAAW,CACzC,EAAQ,KAAK,SAAS,EAAO,CAE/B,KAAK,qBAAoB,KAAK,gBAAgB,YAAc,GAChE,KAAK,eAAe,YAAc,GAAG,KAAK,OAAO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