/*
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 { DependencyObject } from "igniteui-react-core/ES2015/DependencyObject";
import { IOverviewPlusDetailControl_$type } from "igniteui-react-core/ES2015/IOverviewPlusDetailControl";
import { INotifyPropertyChanged_$type, PropertyChangedEventArgs, Type, runOn, delegateCombine, typeCast, delegateRemove, enumGetBox, markType } from "igniteui-react-core/ES2015/type";
import { Canvas } from "igniteui-react-core/ES2015/Canvas";
import { Rect } from "igniteui-react-core/ES2015/Rect";
import { DependencyProperty } from "igniteui-react-core/ES2015/DependencyProperty";
import { InteractionState_$type } from "igniteui-react-core/ES2015/InteractionState";
import { ArgumentNullException } from "igniteui-react-core/ES2015/ArgumentNullException";
import { RenderSurface } from "./RenderSurface";
import { RectUtil } from "igniteui-react-core/ES2015/RectUtil";
import { PropertyMetadata } from "igniteui-react-core/ES2015/PropertyMetadata";
import { XamDataChart } from "./XamDataChart";
export class SeriesViewerSurfaceViewer extends DependencyObject {
    constructor(a, b) {
        super();
        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;
        let c = this.l;
        c.windowRectChanged = delegateCombine(c.windowRectChanged, runOn(this, this.u));
        this.m = b;
        this.x = new Canvas();
        this.w();
    }
    u(a, b) {
        let c = this.o;
        this.o = true;
        this.zoomLevel = 1 - Math.min(b.newRect.height, b.newRect.width);
        this.o = c;
    }
    get l() {
        return this.k;
    }
    set l(a) {
        if (this.k != null) {
            let 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) {
            let c = typeCast(INotifyPropertyChanged_$type, this.k);
            if (c != null) {
                c.propertyChanged = delegateCombine(c.propertyChanged, runOn(this, this.t));
            }
        }
    }
    t(a, b) {
        if (b.propertyName == "DefaultInteraction") {
            this.j = this.l.bc;
            this.v(b.propertyName, enumGetBox(InteractionState_$type, this.defaultInteraction), enumGetBox(InteractionState_$type, this.defaultInteraction));
        }
    }
    zoomTo100() {
        this.l.my = XamDataChart.mu;
    }
    scaleToFit() {
        this.l.my = XamDataChart.mu;
    }
    renderPreview() {
        if (!this.isDirty) {
            return;
        }
        let a = new RenderSurface();
        a.a = this.m.l.viewThumbnailContext;
        if (a.a != null && a.a.d) {
            let b = this.m.l.viewThumbnailSize;
            this.m.b4(b.width, b.height, a);
        }
        this.isDirty = false;
    }
    get worldRect() {
        return XamDataChart.mu;
    }
    get viewportRect() {
        return this.l.mx;
    }
    get minimumZoomLevel() {
        return 0;
    }
    get maximumZoomLevel() {
        if (this.l.eu == 0.0001) {
            return 0.9;
        }
        else {
            return 1 - this.l.eu;
        }
    }
    get isDirty() {
        return this.n;
    }
    set isDirty(a) {
        this.n = a;
    }
    get isIsoScaled() {
        if (this.k == null) {
            return false;
        }
        return this.k.ct;
    }
    v(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;
                }
                let d = this.l != null && this.l.bh != null && this.l.bh.updatingSliderRanges;
                if (!this.o && !d) {
                    let e = 1 - this.zoomLevel;
                    let f = RectUtil.l(this.l.mk);
                    let g = new Rect(0, f.x - e / 2, f.y - e / 2, e, e);
                    this.l.my = SeriesViewerSurfaceViewer.z(this.l.my, g, this.l.c0(), this.l.c1(), this.worldRect);
                }
                this.w();
                if (this.l.bh != null) {
                    this.l.bh.pushZoomLevel(this.zoomLevel);
                }
                break;
        }
    }
    w() {
        let a = Math.round(100 * (1 / (1 - this.zoomLevel)));
        if (a <= 1000) {
            this.zoomLevelDisplayText = a.toString();
        }
        else {
            this.zoomLevelDisplayText = "> 1000";
        }
    }
    get zoomLevelDisplayText() {
        return this.q;
    }
    set zoomLevelDisplayText(a) {
        let b = this.zoomLevelDisplayText != a;
        if (b) {
            let c = this.zoomLevelDisplayText;
            this.q = a;
            this.v("ZoomLevelDisplayText", c, a);
        }
    }
    get defaultInteraction() {
        return this.j;
    }
    set defaultInteraction(a) {
        this.j = a;
        this.l.bc = a;
    }
    static z(a, b, c, d, e) {
        let 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;
        }
        let j = f + h;
        let k = g + i;
        let l = Math.max(0, e.left - f);
        let m = Math.max(0, j - e.right);
        let n = Math.max(0, e.top - g);
        let o = Math.max(0, k - e.bottom);
        f += l - m;
        g += n - o;
        let p = new Rect(0, f, g, h, i);
        p.intersect(e);
        return p;
    }
}
SeriesViewerSurfaceViewer.$t = markType(SeriesViewerSurfaceViewer, 'SeriesViewerSurfaceViewer', DependencyObject.$, [IOverviewPlusDetailControl_$type, INotifyPropertyChanged_$type]);
Type.dep(DependencyProperty, PropertyMetadata, SeriesViewerSurfaceViewer, 'v', ['ZoomLevel::y', [1, 0]]);
/*<BeginStatics Name="Infragistics.Controls.Charts.SeriesViewerSurfaceViewer" />*/
/*<EndStatics Name="Infragistics.Controls.Charts.SeriesViewerSurfaceViewer" />*/
