/*
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 * as tslib_1 from "tslib";
import { BuiltInFunctionBase } from "./BuiltInFunctionBase";
import { ExcelCalcValue } from "./ExcelCalcValue";
import { markType } from "igniteui-angular-core";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
/**
 * @hidden
 */
var UltraCalcFunctionReplace = /** @class */ (function (_super) {
    tslib_1.__extends(UltraCalcFunctionReplace, _super);
    function UltraCalcFunctionReplace() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UltraCalcFunctionReplace.prototype.evaluate = function (a, b) {
        var c = a.pop();
        var d = a.pop();
        var e = a.pop();
        var f = a.pop();
        if (f.isError) {
            return f;
        }
        if (e.isError) {
            return e;
        }
        if (d.isError) {
            return d;
        }
        if (c.isError) {
            return c;
        }
        var g = c.toString();
        var h = d._toInt321();
        var i = e._toInt321() - 1;
        var j = f.toString();
        if (i < 0 || i > j.length) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(1));
        }
        if (h < 0) {
            return new ExcelCalcValue(new ExcelCalcErrorValue(1));
        }
        if (h > j.length - i) {
            h = j.length - i;
        }
        var k = j.substr(0, i) + g + j.substr(i + h);
        return new ExcelCalcValue(k);
    };
    UltraCalcFunctionReplace.prototype.get_name = function () {
        return "replace";
    };
    Object.defineProperty(UltraCalcFunctionReplace.prototype, "name", {
        get: function () {
            return this.get_name();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionReplace.prototype.get_minArgs = function () {
        return 4;
    };
    Object.defineProperty(UltraCalcFunctionReplace.prototype, "minArgs", {
        get: function () {
            return this.get_minArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionReplace.prototype.get_maxArgs = function () {
        return 4;
    };
    Object.defineProperty(UltraCalcFunctionReplace.prototype, "maxArgs", {
        get: function () {
            return this.get_maxArgs();
        },
        enumerable: true,
        configurable: true
    });
    UltraCalcFunctionReplace.prototype.doesParameterAllowIntermediateResultArray = function (a, b) {
        return true;
    };
    UltraCalcFunctionReplace.$t = markType(UltraCalcFunctionReplace, 'UltraCalcFunctionReplace', BuiltInFunctionBase.$);
    return UltraCalcFunctionReplace;
}(BuiltInFunctionBase));
export { UltraCalcFunctionReplace };
//# sourceMappingURL=UltraCalcFunctionReplace.js.map