/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { BuiltInFunctionBase } from "./BuiltInFunctionBase";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { MathUtilities } from "./MathUtilities";
import { ValueFormatter } from "./ValueFormatter";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { markType } from "igniteui-angular-core";
import { stringFormat } from "igniteui-angular-core";
import { stringCreateFromChar } from "igniteui-angular-core";
/**
 * @hidden
 */
export let UltraCalcFunctionUSDollar = /*@__PURE__*/ (() => {
    class UltraCalcFunctionUSDollar extends BuiltInFunctionBase {
        evaluate(a, b) {
            let c = null;
            if (b == 2) {
                c = a.pop();
            }
            let d = a.pop();
            if (d.isError) {
                return new ExcelCalcValue(d.toErrorValue());
            }
            if (c != null && c.isError) {
                return new ExcelCalcValue(c.toErrorValue());
            }
            let e = d._toDouble3();
            let f = c == null ? 2 : c._toInt();
            if (f < 0) {
                e = MathUtilities.g(e, f);
            }
            let g = f > 0 ? stringFormat("$#,##0.{0};($#,##0.{0})", stringCreateFromChar('0', f)) : "$#,##0;($#,##0)";
            let h = new ValueFormatter(0, d._r, g, a._w);
            let i;
            if (((() => { let j = h.v(e, null, i); i = j.p2; return j.ret; })()) == false) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(1));
            }
            return new ExcelCalcValue(i);
        }
        get_name() {
            return "usdollar";
        }
        get name() {
            return this.get_name();
        }
        get_minArgs() {
            return 1;
        }
        get minArgs() {
            return this.get_minArgs();
        }
        get_maxArgs() {
            return 2;
        }
        get maxArgs() {
            return this.get_maxArgs();
        }
    }
    UltraCalcFunctionUSDollar.$t = markType(UltraCalcFunctionUSDollar, 'UltraCalcFunctionUSDollar', BuiltInFunctionBase.$);
    return UltraCalcFunctionUSDollar;
})();
