import initCtx from "@/utils/ctx.js";

export default function () {
	const {} = initCtx(this)

	this.formattedAmount = ""
	this.hasRegionPrice = false

	this.$delay(function () {
		this.changePriceType(this.config.priceType)

		this.$watch(() => this.config.priceType, function (priceType) {
			this.formattedAmount = ""
			this.changePriceType(priceType)
		})
	})

	this.success = function (resp) {
		this.formattedAmount = resp.data.amountFormatted
		this.hasRegionPrice = resp.data.hasRegionPrice
	}

	this.changePriceType = function (priceType) {
		switch (priceType) {
			case "traffic":
				this.$refs.trafficInput.focus()
				break
			case "bandwidth":
				this.$refs.bandwidthInput.focus()
				break
		}
	}

	this.requestId = ""
	this.change = function () {
		this.formattedAmount = ""
		this.hasRegionPrice = false

		this.$refs.calculatorForm.submit()
	}
}