import CSSettingsSDV3 from "../../../FormTable/CSSettingsV3";

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

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

	public static GetNumberWithComma(num: number, isPadZero: boolean = false): string {
		// 20220719企劃要求不要補0改的地方太多直接寫死
		// isPadZero = false;
		// 20230606企劃又要補.前端規則換成預設都不補零.文件需要補零再帶參數
		// 並把以前設定過的參數都拔掉.下次誰又要改零並且跟上面規則不一樣叫他付一千撫慰金
		return num.ExFormatNumberWithComma(this._numberWithComma, isPadZero);
	}

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