/*
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 { toNullable, Number_$type, typeCast, Boolean_$type, markType } from "igniteui-angular-core";
import { FormatConditionIconSet_$type } from "./FormatConditionIconSet";
import { ExcelUtils } from "./ExcelUtils";
import { IconSetConditionalFormat } from "./IconSetConditionalFormat";
import { ArgumentOutOfRangeException } from "igniteui-angular-core";
import { wrapNullable, nullableEquals, nullableNotEquals, unwrapNullable } from "igniteui-angular-core";
import { intSToU } from "igniteui-angular-core";
/**
 * Represents a sort condition which will sort cells based on a specific conditioanl formmat icon.
 * <p class="body">
 * This sort condition specifies a single icon. Cells with this icon will be moved to the beginning of the data range for the ascending
 * sort direction and moved to the end of the data range for the descending sort direction. All matching cells will be kept in their same
 * relative order to each other. In addition, all non-matching cells will be kept in their same relative order to each other.
 * </p>
 * @see [[SortSettings`1.sortConditions]]
 * @see [[SortCondition.sortDirection]]
 */
var IconSortCondition = /** @class */ (function (_super) {
    tslib_1.__extends(IconSortCondition, _super);
    function IconSortCondition() {
        var _rest = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            _rest[_i] = arguments[_i];
        }
        var _this = this;
        var a;
        if (arguments.length === 2) {
            a = 1;
        }
        else if (arguments.length === 3) {
            if (typeCast(Boolean_$type, arguments[0]) !== null) {
                a = 0;
            }
            else if (typeof arguments[0] === 'number') {
                a = 2;
            }
        }
        switch (a) {
            case 0:
                {
                    var ascending = _rest[0];
                    var iconSetInternal = _rest[1];
                    var iconIndex = _rest[2];
                    _this = _super.call(this, 1, ascending ? 0 : 1) || this;
                    _this._l = toNullable(Number_$type, null);
                    _this._j = 0;
                    _this._l = iconIndex;
                    _this._j = iconSetInternal;
                }
                break;
            case 1:
                {
                    var iconSet = _rest[0];
                    var iconIndex = _rest[1];
                    var b = [iconSet, iconIndex, 0];
                    {
                        var iconSet_1 = b[0];
                        var iconIndex_1 = b[1];
                        var sortDirection = b[2];
                        _this = _super.call(this, 1, sortDirection) || this;
                        _this._l = toNullable(Number_$type, null);
                        _this._j = 0;
                        iconIndex_1 = wrapNullable(Number_$type, iconIndex_1);
                        ExcelUtils.gn(FormatConditionIconSet_$type, iconSet_1);
                        _this._j = ExcelUtils.ai(iconSet_1);
                        if (nullableEquals(iconIndex_1, null)) {
                            _this._l = toNullable(Number_$type, null);
                        }
                        else {
                            var c = IconSetConditionalFormat._b9(iconSet_1);
                            if (iconIndex_1.value < 0 || iconIndex_1.value >= c.length) {
                                throw new ArgumentOutOfRangeException(1, "iconIndex");
                            }
                            _this._l = toNullable(Number_$type, intSToU((iconIndex_1.value)));
                        }
                    }
                    iconIndex = wrapNullable(Number_$type, iconIndex);
                }
                break;
            case 2:
                {
                    var iconSet = _rest[0];
                    var iconIndex = _rest[1];
                    var sortDirection = _rest[2];
                    _this = _super.call(this, 1, sortDirection) || this;
                    _this._l = toNullable(Number_$type, null);
                    _this._j = 0;
                    iconIndex = wrapNullable(Number_$type, iconIndex);
                    ExcelUtils.gn(FormatConditionIconSet_$type, iconSet);
                    _this._j = ExcelUtils.ai(iconSet);
                    if (nullableEquals(iconIndex, null)) {
                        _this._l = toNullable(Number_$type, null);
                    }
                    else {
                        var b = IconSetConditionalFormat._b9(iconSet);
                        if (iconIndex.value < 0 || iconIndex.value >= b.length) {
                            throw new ArgumentOutOfRangeException(1, "iconIndex");
                        }
                        _this._l = toNullable(Number_$type, intSToU((iconIndex.value)));
                    }
                }
                break;
            default: throw new Error('Invalid arguments');
        }
        return _this;
    }
    /**
     * @hidden
     */
    IconSortCondition.prototype._a = function () {
        var a = new IconSortCondition(this.sortDirection == 0, this._j, this._l);
        return a;
    };
    /**
     * @hidden
     */
    IconSortCondition.prototype._g = function ($t, a, b, c, d, e) {
        var f = ExcelUtils.ao(a.a(b, d), this._j, this._l);
        var g = ExcelUtils.ao(a.a(c, e), this._j, this._l);
        if (f == g) {
            return 0;
        }
        else {
            var h = f ? -1 : 1;
            if (this.sortDirection == 1) {
                h *= -1;
            }
            return h;
        }
    };
    /**
     * @hidden
     */
    IconSortCondition.prototype._f = function (a) {
        var b = typeCast(IconSortCondition.$, a);
        return b == null || b._j != this._j || nullableNotEquals(b._l, this._l);
    };
    /**
     * @hidden
     */
    IconSortCondition.prototype.get__d = function () {
        return 3;
    };
    Object.defineProperty(IconSortCondition.prototype, "_d", {
        /**
         * @hidden
         */
        get: function () {
            return this.get__d();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IconSortCondition.prototype, "iconIndex", {
        /**
         * The icon set (read-only).
         */
        get: function () {
            return unwrapNullable(this._iconIndex$i);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IconSortCondition.prototype, "_iconIndex$i", {
        /**
         * @hidden
         */
        get: function () {
            return nullableNotEquals(this._l, null) ? toNullable(Number_$type, this._l.value) : toNullable(Number_$type, null);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IconSortCondition.prototype, "iconSet", {
        /**
         * The icon's index in the associated icon set or null for 'NoCellIcon' (read-only).
         */
        get: function () {
            return ExcelUtils.s(this._j);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IconSortCondition.prototype, "_n", {
        /**
         * @hidden
         */
        get: function () {
            return this._l;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IconSortCondition.prototype, "_k", {
        /**
         * @hidden
         */
        get: function () {
            return this._j;
        },
        enumerable: true,
        configurable: true
    });
    IconSortCondition.$t = markType(IconSortCondition, 'IconSortCondition', SortCondition.$);
    return IconSortCondition;
}(SortCondition));
export { IconSortCondition };
//# sourceMappingURL=IconSortCondition.js.map