/*
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 { RegionGroupCalcReference } from "./RegionGroupCalcReference";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { markType } from "igniteui-angular-core";
/**
 * @hidden
 */
export class UltraCalcFunctionOffset extends BuiltInFunctionBase {
    evaluate(a, b) {
        let c = null;
        if (b == 5) {
            c = a.pop();
        }
        let d = null;
        if (b >= 4) {
            d = a.pop();
        }
        let e = a.pop();
        let f = a.pop();
        let g = a.pop();
        if (g.isReference == false && g.isError) {
            return g;
        }
        if (f.isError) {
            return f;
        }
        if (e.isError) {
            return e;
        }
        if (d != null && d.isError) {
            return d;
        }
        if (c != null && c.isError) {
            return c;
        }
        if (g.isReference == false) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(1));
        }
        let h = RegionGroupCalcReference._a7(g.toReference());
        if (h._ba.count != 1) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(1));
        }
        let i = h._ba.item(0);
        let j = f._toInt321();
        let k = e._toInt321();
        let l = d == null ? i._aa : d._toInt321();
        let m = c == null ? i._ad : c._toInt321();
        if (l <= 0 || m <= 0) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(0));
        }
        let n = i.firstRow + j;
        let o = i.firstColumn + k;
        if (o < 0 || n < 0) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(0));
        }
        let p = n + l - 1;
        let q = o + m - 1;
        let r = i.worksheet;
        if (r == null) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(0));
        }
        let s = r._rows$i.maxCount - 1;
        let t = r._columns$i.maxCount - 1;
        if (s < p || t < q) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(0));
        }
        return new ExcelCalcValue(r._cx(n, o, p, q)._c);
    }
    get_name() {
        return "offset";
    }
    get name() {
        return this.get_name();
    }
    get_minArgs() {
        return 3;
    }
    get minArgs() {
        return this.get_minArgs();
    }
    get_maxArgs() {
        return 5;
    }
    get maxArgs() {
        return this.get_maxArgs();
    }
    _v(a) {
        if (a == 0) {
            return false;
        }
        return true;
    }
}
UltraCalcFunctionOffset.$t = markType(UltraCalcFunctionOffset, 'UltraCalcFunctionOffset', BuiltInFunctionBase.$);
//# sourceMappingURL=UltraCalcFunctionOffset.js.map