/*
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 { __extends } from "tslib";
import { ColorScale } from "./ColorScale";
import { DependencyProperty } from "igniteui-angular-core";
import { ObservableColorCollection } from "igniteui-angular-core";
import { runOn, delegateCombine, delegateRemove, enumGetBox, markType, markDep } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
import { ColorScaleInterpolationMode_$type } from "./ColorScaleInterpolationMode";
import { ColorUtil } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, isNaN_ } from "igniteui-angular-core";
/**
 * @hidden
 */
var CustomPaletteColorScale = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CustomPaletteColorScale, _super);
    function CustomPaletteColorScale() {
        var _this = _super.call(this) || this;
        _this.p = null;
        _this.ag = new Color();
        _this.u = NaN;
        _this.t = NaN;
        _this.s = true;
        _this.r = true;
        _this.n = 0;
        _this.ag = Color.u(0, 0, 0, 0);
        _this.p = new ObservableColorCollection();
        var a = _this.p;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.ab));
        _this.propertyUpdated = delegateCombine(_this.propertyUpdated, function (b, c) { return _this.k(b, c.propertyName, c.oldValue, c.newValue); });
        return _this;
    }
    Object.defineProperty(CustomPaletteColorScale.prototype, "palette", {
        get: function () {
            return this.p;
        },
        set: function (a) {
            var b = this.p;
            if (this.p != null) {
                var c = this.p;
                c.collectionChanged = delegateRemove(c.collectionChanged, runOn(this, this.ab));
            }
            this.p = a;
            if (this.p != null) {
                var d = this.p;
                d.collectionChanged = delegateCombine(d.collectionChanged, runOn(this, this.ab));
            }
            this.l("Palette", b, this.palette);
        },
        enumerable: false,
        configurable: true
    });
    CustomPaletteColorScale.prototype.ab = function (a, b) {
        this.l("Palette", this.palette, this.palette);
    };
    CustomPaletteColorScale.prototype.k = function (a, b, c, d) {
        _super.prototype.k.call(this, a, b, c, d);
        switch (b) {
            case CustomPaletteColorScale.$$p[2]:
                this.u = this.minimumValue;
                this.s = isNaN_(this.u);
                break;
            case CustomPaletteColorScale.$$p[1]:
                this.t = this.maximumValue;
                this.r = isNaN_(this.t);
                break;
            case CustomPaletteColorScale.$$p[0]:
                this.n = this.interpolationMode;
                break;
        }
    };
    CustomPaletteColorScale.prototype.getColor = function (a, b, c, d) {
        if (((this.p == null) || (this.p.count == 0)) || d == null) {
            return this.ag;
        }
        var e = this.s ? b : this.u;
        var f = this.r ? c : this.t;
        var g = (a - e) / (f - e);
        if (isNaN_(g) || g < 0 || g > 1) {
            return this.ag;
        }
        var h = g * (this.p.count - 1);
        if (this.n == 2 || this.n == 1) {
            var i = Math.floor(h);
            var j = Math.ceil(h);
            var k = this.p._inner[truncate(i)];
            var l = this.p._inner[truncate(j)];
            var m = h - i;
            var n = this.n == 2 ? 1 : 0;
            return ColorUtil.u(k, m, l, n);
        }
        else {
            var o = truncate(Math.round(h));
            return this.p._inner[o];
        }
    };
    CustomPaletteColorScale.prototype.providePalette = function (a) {
        var b = new ObservableColorCollection();
        var _loop_1 = function (d) {
            var c = a[d];
            var e = ((function () {
                var $ret = new Color();
                $ret.colorString = c;
                return $ret;
            })());
            b.add(e);
        };
        for (var d = 0; d < a.length; d++) {
            _loop_1(d);
        }
        this.palette = b;
    };
    CustomPaletteColorScale.$t = markType(CustomPaletteColorScale, 'CustomPaletteColorScale', ColorScale.$);
    CustomPaletteColorScale.$$p = markDep(DependencyProperty, PropertyMetadata, CustomPaletteColorScale, 'l', ['InterpolationMode', [ColorScaleInterpolationMode_$type, enumGetBox(ColorScaleInterpolationMode_$type, 0)], 'MaximumValue', [1, NaN], 'MinimumValue', [1, NaN]]);
    return CustomPaletteColorScale;
}(ColorScale));
export { CustomPaletteColorScale };
