import CSSettingsV3 from "../../CSSettingsV3";

const { ccclass } = cc._decorator;

@ccclass
export class CurrencyManager {
	public static get DefaultCurrencyId(): number { return 3; }
	public static get Currency(): number { return this._useFormId; }
	private static _currencyStr: string = null;
	private static _useFormId: number = null;
	private static _numberWithComma: number = null;
	public static get NumberWithComma(): number { return this._numberWithComma };

	public static SetCurrency(data: JSON) {
		if (!data) {
			this._numberWithComma = 2;
			this._currencyStr = "TWD"
		}
		this._numberWithComma = data["pr"];
		this._currencyStr = data["cu"];
		for (let i: number = 1; i < CSSettingsV3.Currency.Count; i++) {
			let check: string = CSSettingsV3.Currency[i].Type;
			if (check == this._currencyStr) {
				this._useFormId = i;
				return;
			}
		}
		this._useFormId = this.DefaultCurrencyId;
	}

	public static GetNumberWithComma(num: number, isPadZero: boolean = true): string {
		return num.ExFormatNumberWithComma(this._numberWithComma, isPadZero);
	}

	public static GetNumberTransferToBMK(num: number, offset: number = 0): string {
		return num.ExTransferToBMK(this._numberWithComma, offset);
	}
}