/*
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 { typeCast, fromEnum, markType } from "igniteui-angular-core";
import { NamedCalcReferenceUnconnected } from "./NamedCalcReferenceUnconnected";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
/**
 * @hidden
 */
export class UltraCalcFunctionSheets extends BuiltInFunctionBase {
    evaluate(a, b) {
        let c = null;
        if (b == 1) {
            c = a.pop();
        }
        let d;
        if (b == 0) {
            d = a._r._sheets$i.count;
        }
        else if (c.isReference) {
            let e = c.toReference();
            if (typeCast(NamedCalcReferenceUnconnected.$, e) !== null) {
                d = new ExcelCalcErrorValue(1);
            }
            else {
                let f = e._am();
                if (f.count == 1) {
                    d = 1;
                }
                else {
                    let g = 0x7FFFFFFF;
                    let h = -2147483648;
                    for (let i of fromEnum(f)) {
                        let j = i.worksheet.sheetIndex;
                        if (j < g) {
                            g = j;
                        }
                        if (j > h) {
                            h = j;
                        }
                    }
                    d = (h - g) + 1;
                }
            }
        }
        else if (c.isString || c.isBoolean) {
            d = new ExcelCalcErrorValue(1);
        }
        else if (c.isError) {
            d = c.toErrorValue();
        }
        else {
            d = new ExcelCalcErrorValue(3);
        }
        return new ExcelCalcValue(d);
    }
    get_maxArgs() {
        return 1;
    }
    get maxArgs() {
        return this.get_maxArgs();
    }
    get_minArgs() {
        return 0;
    }
    get minArgs() {
        return this.get_minArgs();
    }
    get_name() {
        return "sheets";
    }
    get name() {
        return this.get_name();
    }
}
UltraCalcFunctionSheets.$t = markType(UltraCalcFunctionSheets, 'UltraCalcFunctionSheets', BuiltInFunctionBase.$);
//# sourceMappingURL=UltraCalcFunctionSheets.js.map