/*
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 { markType } from "igniteui-angular-core";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { stringIsNullOrWhiteSpace } from "igniteui-angular-core";
/**
 * @hidden
 */
export class UltraCalcFunctionArabic extends BuiltInFunctionBase {
    evaluate(a, b) {
        let c = a.pop();
        let d = c.toString();
        let e = 0;
        if (!stringIsNullOrWhiteSpace(d)) {
            d = d.trim();
            let f = d.charAt(0) == '-';
            if (f && d.length == 1) {
                return new ExcelCalcValue(new ExcelCalcErrorValue(4));
            }
            let g = f ? 1 : 0;
            let h = 0;
            for (let i = d.length - 1; i >= g; i--) {
                let j = d.charAt(i);
                let k = -1;
                switch (j) {
                    case 'm':
                    case 'M':
                        k = 1000;
                        break;
                    case 'D':
                    case 'd':
                        k = 500;
                        break;
                    case 'C':
                    case 'c':
                        k = 100;
                        break;
                    case 'L':
                    case 'l':
                        k = 50;
                        break;
                    case 'X':
                    case 'x':
                        k = 10;
                        break;
                    case 'V':
                    case 'v':
                        k = 5;
                        break;
                    case 'I':
                    case 'i':
                        k = 1;
                        break;
                    default: return new ExcelCalcValue(new ExcelCalcErrorValue(1));
                }
                e += h <= k ? k : -k;
                if (k > h) {
                    h = k;
                }
            }
            if (f) {
                e = -e;
            }
        }
        return new ExcelCalcValue(e);
    }
    get_maxArgs() {
        return 1;
    }
    get maxArgs() {
        return this.get_maxArgs();
    }
    get_minArgs() {
        return 1;
    }
    get minArgs() {
        return this.get_minArgs();
    }
    get_name() {
        return "arabic";
    }
    get name() {
        return this.get_name();
    }
}
UltraCalcFunctionArabic.$t = markType(UltraCalcFunctionArabic, 'UltraCalcFunctionArabic', BuiltInFunctionBase.$);
//# sourceMappingURL=UltraCalcFunctionArabic.js.map