/*
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 { SortCondition } from "./SortCondition";
import { WorksheetRow } from "./WorksheetRow";
import { Base, typeCast, Boolean_$type, markType } from "igniteui-angular-core";
import { ExcelUtils } from "./ExcelUtils";
import { ErrorValue } from "./ErrorValue";
import { StringUtilities } from "./StringUtilities";
import { boolCompare } from "igniteui-angular-core";
/**
 * Represents an ordered sort condition, which can sort data in either an ascending or descending manner.
 * @see [[SortSettings`1.sortConditions]]
 */
var OrderedSortCondition = /** @class */ (function (_super) {
    tslib_1.__extends(OrderedSortCondition, _super);
    function OrderedSortCondition() {
        var _rest = [];
        for (var _b = 0; _b < arguments.length; _b++) {
            _rest[_b] = arguments[_b];
        }
        var _this = this;
        var a;
        if (arguments.length === 0) {
            a = 0;
        }
        else if (arguments.length === 1) {
            a = 1;
        }
        switch (a) {
            case 0:
                {
                    _this = _super.call(this, 0) || this;
                }
                break;
            case 1:
                {
                    var sortDirection = _rest[0];
                    _this = _super.call(this, 1, sortDirection) || this;
                }
                break;
            default: throw new Error('Invalid arguments');
        }
        return _this;
    }
    /**
     * @hidden
     */
    OrderedSortCondition.prototype._a = function () {
        var a = new OrderedSortCondition(this.sortDirection);
        return a;
    };
    /**
     * @hidden
     */
    OrderedSortCondition.prototype._g = function ($t, a, b, c, d, e) {
        var f = a.c;
        var g = f._rows$i._aj(b);
        var h = b == c ? g : f._rows$i._aj(c);
        var i = WorksheetRow._c2(g, d);
        var j = WorksheetRow._c2(h, e);
        if (i == null) {
            if (j == null) {
                return 0;
            }
            return 1;
        }
        else if (j == null) {
            return -1;
        }
        var k = OrderedSortCondition._i($t, a.b, f, i, j);
        if (this.sortDirection == 1) {
            return -k;
        }
        return k;
    };
    /**
     * @hidden
     */
    OrderedSortCondition.prototype._f = function (a) {
        return a == null || a._d != 0;
    };
    /**
     * @hidden
     */
    OrderedSortCondition.prototype.get__d = function () {
        return 0;
    };
    Object.defineProperty(OrderedSortCondition.prototype, "_d", {
        /**
         * @hidden
         */
        get: function () {
            return this.get__d();
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @hidden
     */
    OrderedSortCondition._i = function ($t, a, b, c, d) {
        var e;
        var f = ((function () { var g = ExcelUtils.bz(b.workbook, c, e); e = g.p2; return g.ret; })());
        var g;
        var h = ((function () { var i = ExcelUtils.bz(b.workbook, d, g); g = i.p2; return i.ret; })());
        if (f) {
            if (h) {
                return Base.compareSimple(e, g);
            }
            return -1;
        }
        else if (h) {
            return 1;
        }
        var i = typeCast(Boolean_$type, c) !== null;
        var j = typeCast(Boolean_$type, d) !== null;
        var k = null;
        if (typeCast(ErrorValue.$, c) !== null == false && i == false) {
            k = c.toString();
        }
        var l = null;
        if (typeCast(ErrorValue.$, d) !== null == false && j == false) {
            l = d.toString();
        }
        if (k != null) {
            if (l != null) {
                return StringUtilities.d(k, l, a._q, a.caseSensitive ? 0 : 1);
            }
            return -1;
        }
        else if (l != null) {
            return 1;
        }
        if (i) {
            if (j) {
                return boolCompare(c, d);
            }
            return -1;
        }
        else if (j) {
            return 1;
        }
        return 0;
    };
    OrderedSortCondition.$t = markType(OrderedSortCondition, 'OrderedSortCondition', SortCondition.$);
    return OrderedSortCondition;
}(SortCondition));
export { OrderedSortCondition };
//# sourceMappingURL=OrderedSortCondition.js.map