/*
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 { DependencyObject } from "igniteui-angular-core";
import { IOverviewPlusDetailControl_$type } from "igniteui-angular-core";
import { INotifyPropertyChanged_$type, PropertyChangedEventArgs, runOn, delegateCombine, typeCast, delegateRemove, enumGetBox, markType, markDep } from "igniteui-angular-core";
import { Canvas } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { DependencyProperty } from "igniteui-angular-core";
import { InteractionState_$type } from "igniteui-angular-core";
import { ArgumentNullException } from "igniteui-angular-core";
import { RenderSurface } from "./RenderSurface";
import { RectUtil } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { XamDataChart } from "./XamDataChart";
/**
 * @hidden
 */
var SeriesViewerSurfaceViewer = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(SeriesViewerSurfaceViewer, _super);
    function SeriesViewerSurfaceViewer(a, b) {
        var _this = _super.call(this) || this;
        _this.m = null;
        _this.o = false;
        _this.k = null;
        _this.x = null;
        _this.n = true;
        _this.q = null;
        _this.j = 0;
        _this.propertyChanged = null;
        if (a == null || b == null) {
            throw new ArgumentNullException(0, "model");
        }
        _this.l = a;
        var c = _this.l;
        c.windowRectChanged = delegateCombine(c.windowRectChanged, runOn(_this, _this.u));
        _this.m = b;
        _this.x = new Canvas();
        _this.w();
        return _this;
    }
    SeriesViewerSurfaceViewer.prototype.u = function (a, b) {
        var c = this.o;
        this.o = true;
        this.zoomLevel = 1 - Math.min(b.newRect.height, b.newRect.width);
        this.o = c;
    };
    Object.defineProperty(SeriesViewerSurfaceViewer.prototype, "l", {
        get: function () {
            return this.k;
        },
        set: function (a) {
            if (this.k != null) {
                var b = typeCast(INotifyPropertyChanged_$type, this.k);
                if (b != null) {
                    b.propertyChanged = delegateRemove(b.propertyChanged, runOn(this, this.t));
                }
            }
            this.k = a;
            if (this.k != null) {
                var c = typeCast(INotifyPropertyChanged_$type, this.k);
                if (c != null) {
                    c.propertyChanged = delegateCombine(c.propertyChanged, runOn(this, this.t));
                }
            }
        },
        enumerable: false,
        configurable: true
    });
    SeriesViewerSurfaceViewer.prototype.t = function (a, b) {
        if (b.propertyName == "DefaultInteraction") {
            this.j = this.l.ce;
            this.v(b.propertyName, enumGetBox(InteractionState_$type, this.defaultInteraction), enumGetBox(InteractionState_$type, this.defaultInteraction));
        }
    };
    SeriesViewerSurfaceViewer.prototype.zoomTo100 = function () {
        this.l.sv = XamDataChart.sr;
    };
    SeriesViewerSurfaceViewer.prototype.scaleToFit = function () {
        this.l.sv = XamDataChart.sr;
    };
    SeriesViewerSurfaceViewer.prototype.renderPreview = function () {
        if (!this.isDirty) {
            return;
        }
        var a = new RenderSurface();
        a.a = this.m.n.viewThumbnailContext;
        if (a.a != null && a.a.d) {
            var b = this.m.n.viewThumbnailSize;
            this.m.cb(b.width, b.height, a);
        }
        this.isDirty = false;
    };
    Object.defineProperty(SeriesViewerSurfaceViewer.prototype, "worldRect", {
        get: function () {
            return XamDataChart.sr;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerSurfaceViewer.prototype, "viewportRect", {
        get: function () {
            return this.l.su;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerSurfaceViewer.prototype, "minimumZoomLevel", {
        get: function () {
            return 0;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerSurfaceViewer.prototype, "maximumZoomLevel", {
        get: function () {
            if (this.l.g6 == 0.0001) {
                return 0.9;
            }
            else {
                return 1 - this.l.g6;
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerSurfaceViewer.prototype, "isDirty", {
        get: function () {
            return this.n;
        },
        set: function (a) {
            this.n = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerSurfaceViewer.prototype, "isIsoScaled", {
        get: function () {
            if (this.k == null) {
                return false;
            }
            return this.k.ee;
        },
        enumerable: false,
        configurable: true
    });
    SeriesViewerSurfaceViewer.prototype.v = function (a, b, c) {
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
        switch (a) {
            case SeriesViewerSurfaceViewer.$$p[0]:
                if (c - this.minimumZoomLevel < -1E-05) {
                    this.zoomLevel = this.minimumZoomLevel;
                    return;
                }
                if (c - this.maximumZoomLevel > 0.0001) {
                    this.zoomLevel = this.maximumZoomLevel;
                    return;
                }
                var d = this.l != null && this.l.cj != null && this.l.cj.updatingSliderRanges;
                if (!this.o && !d) {
                    var e = 1 - this.zoomLevel;
                    var f = RectUtil.l(this.l.sf);
                    var g = new Rect(0, f.x - e / 2, f.y - e / 2, e, e);
                    this.l.sv = SeriesViewerSurfaceViewer.z(this.l.sv, g, this.l.em(), this.l.en(), this.worldRect);
                }
                this.w();
                if (this.l.cj != null) {
                    this.l.cj.pushZoomLevel(this.zoomLevel);
                }
                break;
        }
    };
    SeriesViewerSurfaceViewer.prototype.w = function () {
        var a = Math.round(100 * (1 / (1 - this.zoomLevel)));
        if (a <= 1000) {
            this.zoomLevelDisplayText = a.toString();
        }
        else {
            this.zoomLevelDisplayText = "> 1000";
        }
    };
    Object.defineProperty(SeriesViewerSurfaceViewer.prototype, "zoomLevelDisplayText", {
        get: function () {
            return this.q;
        },
        set: function (a) {
            var b = this.zoomLevelDisplayText != a;
            if (b) {
                var c = this.zoomLevelDisplayText;
                this.q = a;
                this.v("ZoomLevelDisplayText", c, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SeriesViewerSurfaceViewer.prototype, "defaultInteraction", {
        get: function () {
            return this.j;
        },
        set: function (a) {
            this.j = a;
            this.l.ce = a;
        },
        enumerable: false,
        configurable: true
    });
    SeriesViewerSurfaceViewer.z = function (a, b, c, d, e) {
        var f, g, h, i;
        if (c) {
            f = b.left;
            h = b.width;
        }
        else {
            f = a.left;
            h = a.width;
        }
        if (d) {
            g = b.top;
            i = b.height;
        }
        else {
            g = a.top;
            i = a.height;
        }
        var j = f + h;
        var k = g + i;
        var l = Math.max(0, e.left - f);
        var m = Math.max(0, j - e.right);
        var n = Math.max(0, e.top - g);
        var o = Math.max(0, k - e.bottom);
        f += l - m;
        g += n - o;
        var p = new Rect(0, f, g, h, i);
        p.intersect(e);
        return p;
    };
    SeriesViewerSurfaceViewer.$t = markType(SeriesViewerSurfaceViewer, 'SeriesViewerSurfaceViewer', DependencyObject.$, [IOverviewPlusDetailControl_$type, INotifyPropertyChanged_$type]);
    SeriesViewerSurfaceViewer.$$p = markDep(DependencyProperty, PropertyMetadata, SeriesViewerSurfaceViewer, 'v', ['ZoomLevel::y', [1, 0]]);
    return SeriesViewerSurfaceViewer;
}(DependencyObject));
export { SeriesViewerSurfaceViewer };
