/*
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 { Base, markType, INotifyPropertyChanged_$type, PropertyChangedEventArgs } from "./type";
import { Size } from "./Size";
import { ElevationHelper } from "./ElevationHelper";
import { Popup_OuterAnimationInfo } from "./Popup_OuterAnimationInfo";
import { Popup_InnerAnimationInfo } from "./Popup_InnerAnimationInfo";
import { AnimationKeyFrameEffect } from "./AnimationKeyFrameEffect";
import { AnimationKeyFrameEffectTiming } from "./AnimationKeyFrameEffectTiming";
import { KeyFrameAnimationFactory } from "./KeyFrameAnimationFactory";
import { Rect } from "./Rect";
import { stringEmpty } from "./string";
import { stringFormat } from "./stringExtended";
import { OnClosedEventArgs } from "./OnClosedEventArgs";
import { List$1 } from "./List$1";
import { AnimationKeyFrameProperty } from "./AnimationKeyFrameProperty";
import { TranslateTransform } from "./TranslateTransform";
import { OnPopupEventArgs } from "./OnPopupEventArgs";
import { PopupVisualModelExport } from "./PopupVisualModelExport";
import { AppearanceHelper } from "./AppearanceHelper";
import { BrushUtil } from "./BrushUtil";
import { truncate } from "./number";
/**
 * @hidden
 */
var PopupView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(PopupView, _super);
    function PopupView() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.k = null;
        _this.c = null;
        _this.o = null;
        _this.n = null;
        _this.m = null;
        _this.p = null;
        _this.f = false;
        _this.h = 0;
        _this.al = new Size(1, 0, 0);
        _this.e = true;
        _this.g = false;
        return _this;
    }
    Object.defineProperty(PopupView.prototype, "d", {
        get: function () {
            return this.c;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PopupView.prototype, "l", {
        get: function () {
            return this.k;
        },
        enumerable: true,
        configurable: true
    });
    PopupView.prototype.ab = function () {
        this.o.setStyleProperty("height", "0%");
        this.o.setStyleProperty("width", "0%");
        this.n = this.k.createElement("div");
        this.n.setStyleProperty("position", "absolute");
        this.n.setStyleProperty("overflow", "hidden");
        this.n.setStyleProperty("z-index", "10000");
        this.n.setAttribute("key", "popupContentAreaOuter");
        this.m = this.k.createElement("div");
        this.m.setAttribute("key", "popupContentAreaInner");
        this.n.append(this.m);
    };
    PopupView.prototype.ai = function () {
        var a = this.d;
        var b = ElevationHelper.e(a.w, a.a7, a.a6, a.a5);
        this.n.setStyleProperty("box-shadow", b);
    };
    PopupView.prototype.ah = function () {
        if (this.d.a8 != null) {
            this.n.setStyleProperty("background-color", this.d.a8._fill);
        }
    };
    PopupView.prototype.aj = function () {
        if (null == this.o) {
            return;
        }
        this.ai();
        this.ah();
    };
    PopupView.prototype.s = function () {
        if (null != this.n) {
            this.aj();
            this.n.setStyleProperty("height", "0px");
            var a = this.n.getNativeElement();
            if (false == this.f) {
                document.body.appendChild(a);
                this.f = true;
                if (this.e) {
                    this.z();
                }
            }
        }
    };
    PopupView.prototype.t = function (a, b) {
        this.n.setStyleProperty("top", PopupView.q(a.b));
        this.n.setStyleProperty("height", PopupView.r(a.d));
        this.m.setStyleProperty("top", PopupView.r(b.b));
        this.m.setStyleProperty("opacity", "1");
        this.m.setStyleProperty("transform", stringEmpty());
        this.h = 0;
        if (this.g) {
            this.ag();
        }
        return {
            p0: a,
            p1: b
        };
    };
    PopupView.prototype.u = function (a) {
        this.h = a;
    };
    PopupView.prototype.ae = function () {
        if (null != this.n && this.f) {
            var a = this.n.getNativeElement();
            document.body.removeChild(a);
            this.f = false;
        }
    };
    PopupView.prototype.v = function (a) {
        this.m.append(a);
    };
    PopupView.prototype.a = function (a) {
        return new AnimationKeyFrameEffect(0, this.m, 0, null, a);
    };
    PopupView.prototype.b = function (a) {
        return new AnimationKeyFrameEffect(0, this.n, 0, null, a);
    };
    PopupView.prototype.w = function () {
        if (KeyFrameAnimationFactory.h == null) {
            KeyFrameAnimationFactory.h = this.l;
        }
    };
    Object.defineProperty(PopupView.prototype, "am", {
        get: function () {
            if (this.e) {
                this.z();
            }
            return this.al;
        },
        enumerable: true,
        configurable: true
    });
    PopupView.prototype.i = function (a, b) {
        var c;
        var t1 = b;
        L0: while (true) {
            switch (t1) {
                case 0:
                case 1:
                    c = a.left;
                    break;
                case 2:
                    c = a.right - this.am.width;
                    break;
                default:
                    t1 = 0;
                    continue L0;
            }
            break;
        }
        return c;
    };
    PopupView.prototype.j = function (a, b) {
        var c;
        var t1 = b;
        L0: while (true) {
            switch (t1) {
                case 0:
                case 1:
                    c = a.bottom;
                    break;
                case 2:
                    c = a.top - this.am.height;
                    break;
                default:
                    t1 = 0;
                    continue L0;
            }
            break;
        }
        return c;
    };
    PopupView.r = function (a) {
        return stringFormat("{0}px", a);
    };
    PopupView.q = function (a) {
        return stringFormat("{0}px", a);
    };
    PopupView.prototype.ak = function (a, b, c) {
        var d = this.j(a, b);
        var e = this.i(a, c);
        this.af(e, d);
        if (b == 2 || c == 2) {
            var f = 10;
            while (f > 0) {
                var g = this.j(a, b);
                var h = this.i(a, c);
                if (g == d && h == e) {
                    f = 0;
                    break;
                }
                d = g;
                e = h;
                this.af(e, d);
                f--;
            }
        }
        return new Rect(0, e, d, this.am.width, this.am.height);
    };
    PopupView.prototype.z = function () {
        if (this.f) {
            this.n.setStyleProperty("width", stringEmpty());
            this.n.setStyleProperty("height", stringEmpty());
            this.al = new Size(1, this.m.outerWidth(), this.m.outerHeight());
            this.e = false;
            this.ag();
        }
        else {
            this.e = true;
        }
    };
    PopupView.prototype.af = function (a, b) {
        var c = stringFormat("{0}px", a);
        var d = stringFormat("{0}px", b);
        this.n.setStyleProperty("left", c);
        this.n.setStyleProperty("top", d);
    };
    PopupView.prototype.ac = function (a) {
        var _this = this;
        if (a == null) {
            this.k = null;
            return;
        }
        this.k = a;
        var b = a.rootWrapper;
        this.x(b);
        this.k.getPortal(this.m, "ChildContent", function (c) {
            var comp_ = c.componentRef;
            _this.p = comp_;
        }, true);
    };
    PopupView.prototype.ag = function () {
        var a = new Size(1, this.am.width, this.am.height);
        if (!this.f || !this.d.t) {
            a.height = 0;
        }
        var b = a.width;
        var c = a.height;
        if (this.c.r()) {
            if (this.h == c) {
                return;
            }
            this.c.an();
            this.g = true;
            return;
        }
        this.g = false;
        var d = stringFormat("{0}px", b);
        var e = stringFormat("{0}px", c);
        this.n.setStyleProperty("width", d);
        this.n.setStyleProperty("height", e);
    };
    PopupView.prototype.x = function (a) {
        this.o = a;
        this.ab();
    };
    PopupView.prototype.y = function (a) {
        this.c = a;
    };
    PopupView.prototype.aa = function () {
    };
    PopupView.prototype.ad = function () {
        this.s();
        if (this.d.t) {
            return;
        }
        this.ag();
    };
    PopupView.$t = markType(PopupView, 'PopupView');
    return PopupView;
}(Base));
export { PopupView };
/**
 * @hidden
 */
var Popup = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(Popup, _super);
    function Popup() {
        var _this = _super.call(this) || this;
        _this.i = 0;
        _this.h = 0;
        _this.bc = null;
        _this.n = null;
        _this.o = null;
        _this.onClosed = null;
        _this.onPopup = null;
        _this.propertyChanged = null;
        _this.k = null;
        _this.x = 50;
        _this.p = true;
        _this.v = -1;
        _this.u = Popup.z;
        _this.s = false;
        _this.a3 = Popup.bb;
        _this.a2 = Popup.ba;
        _this.a1 = Popup.a9;
        _this.a4 = null;
        var a = _this.j();
        _this.k = a;
        a.y(_this);
        return _this;
    }
    Popup.prototype.au = function (a, b, c) {
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
        this.aw(a, b, c);
    };
    Object.defineProperty(Popup.prototype, "y", {
        get: function () {
            return this.x;
        },
        set: function (a) {
            var b = this.x;
            this.x = a;
            if (b != this.x) {
                this.au("AnimationDuration", b, a);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "q", {
        get: function () {
            return this.p;
        },
        set: function (a) {
            var b = this.p;
            this.p = a;
            if (b != this.p) {
                this.au("AnimationEnabled", b, a);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "aa", {
        get: function () {
            return this.v;
        },
        set: function (a) {
            var b = this.v;
            this.v = a;
            if (b != this.v) {
                this.au("Elevation", b, a);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "w", {
        get: function () {
            return this.u;
        },
        set: function (a) {
            var b = this.u;
            this.u = a;
            if (b != this.u) {
                this.au("ActualElevation", b, a);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "t", {
        get: function () {
            return this.s;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "a7", {
        get: function () {
            return this.a3;
        },
        set: function (a) {
            var b = this.a3;
            this.a3 = a;
            if (b != this.a3) {
                this.au("ActualUmbraShadowColor", b, a);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "a6", {
        get: function () {
            return this.a2;
        },
        set: function (a) {
            var b = this.a2;
            this.a2 = a;
            if (b != this.a2) {
                this.au("ActualPenumbraShadowColor", b, a);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "a5", {
        get: function () {
            return this.a1;
        },
        set: function (a) {
            var b = this.a1;
            this.a1 = a;
            if (b != this.a1) {
                this.au("ActualAmbientShadowColor", b, a);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "a8", {
        get: function () {
            return this.a4;
        },
        set: function (a) {
            var b = this.a4;
            this.a4 = a;
            if (b != this.a4) {
                this.au("Background", b, this.a4);
            }
        },
        enumerable: true,
        configurable: true
    });
    Popup.prototype.j = function () {
        return new PopupView();
    };
    Popup.prototype.aw = function (a, b, c) {
        switch (a) {
            case "IsShown":
                if (false == this.t) {
                    this.k.ae();
                }
                break;
            case "Elevation":
                this.w = this.aa == -1 ? Popup.z : this.aa;
                break;
            case "ActualElevation":
            case "ActualUmbraShadowColor":
            case "ActualPenumbraShadowColor":
            case "ActualAmbientShadowColor":
            case "Background":
                this.k.aj();
                break;
            case "AnimationEnabled":
                if (false == this.q) {
                    this.an();
                }
                break;
        }
    };
    Popup.prototype.an = function () {
        if (this.r()) {
            if (null != this.o && this.o.playState == 1) {
                this.o.cancel();
            }
            if (null != this.n && this.n.playState == 1) {
                this.n.cancel();
            }
        }
    };
    Popup.prototype.l = function (a) {
        var b = this.f(a);
        var c = a ? this.b() : this.a();
        var d = this.k.a(c);
        var e = new List$1(AnimationKeyFrameProperty.$, 0);
        var f = new List$1(AnimationKeyFrameProperty.$, 0);
        var g = new TranslateTransform();
        g.k = b.a;
        var h = new TranslateTransform();
        h.k = b.b;
        var i = new AnimationKeyFrameProperty(14, g);
        var j = new AnimationKeyFrameProperty(14, h);
        e.add(i);
        f.add(j);
        d.m.apply(d, tslib_1.__spread(e.toArray()));
        d.m.apply(d, tslib_1.__spread(f.toArray()));
        return KeyFrameAnimationFactory.f.c(d);
    };
    Popup.prototype.m = function (a) {
        var b = this.g(a);
        this.k.u(b.d);
        var c = a ? this.b() : this.a();
        var d = this.k.b(c);
        var e = new List$1(AnimationKeyFrameProperty.$, 0);
        var f = new List$1(AnimationKeyFrameProperty.$, 0);
        var g = new AnimationKeyFrameProperty(10, b.c);
        var h = new AnimationKeyFrameProperty(10, b.d);
        e.add(g);
        f.add(h);
        if (this.i == 2) {
            var i = b.a;
            var j = b.b;
            var k = new AnimationKeyFrameProperty(12, i);
            var l = new AnimationKeyFrameProperty(12, j);
            e.add(k);
            f.add(l);
        }
        d.m.apply(d, tslib_1.__spread(e.toArray()));
        d.m.apply(d, tslib_1.__spread(f.toArray()));
        return KeyFrameAnimationFactory.f.c(d);
    };
    Popup.prototype.a = function () {
        var a = new AnimationKeyFrameEffectTiming();
        a.g = this.y;
        a.b = 3;
        return a;
    };
    Popup.prototype.b = function () {
        var a = new AnimationKeyFrameEffectTiming();
        a.g = this.y;
        a.b = 3;
        return a;
    };
    Popup.prototype.aq = function () {
        this.k.w();
    };
    Popup.prototype.f = function (a) {
        var b = truncate(this.k.am.height);
        if (b <= 0) {
            b = 500;
        }
        var c = a ? -b : 0;
        var d = a ? 0 : -b;
        if (this.i == 2) {
            c = 0;
            d = 0;
        }
        var e = ((function () {
            var $ret = new Popup_InnerAnimationInfo();
            $ret.a = c;
            $ret.b = d;
            return $ret;
        })());
        return e;
    };
    Popup.prototype.g = function (a) {
        var b = truncate(this.k.am.height);
        if (b <= 0) {
            b = 500;
        }
        var c = a ? 0 : b;
        var d = a ? b : 0;
        var e;
        var f;
        if (this.i == 2) {
            e = a ? this.bc.bottom : this.bc.top;
            f = a ? this.bc.top : this.bc.bottom;
        }
        else {
            e = this.bc.top;
            f = this.bc.top;
        }
        var g = ((function () {
            var $ret = new Popup_OuterAnimationInfo();
            $ret.c = c;
            $ret.d = d;
            $ret.a = e;
            $ret.b = f;
            return $ret;
        })());
        return g;
    };
    Popup.prototype.r = function () {
        if (null == this.o && null == this.n) {
            return false;
        }
        if (null != this.o && this.o.playState == 1) {
            return true;
        }
        if (null != this.n && this.n.playState == 1) {
            return true;
        }
        return false;
    };
    Popup.prototype.ar = function () {
        this.k.z();
    };
    Popup.prototype.av = function (a, b, c) {
        this.k.ad();
        this.bc = this.k.ak(a, b, c);
        this.i = b;
        this.h = c;
    };
    Popup.prototype.ay = function (a, b, c) {
        if (this.s) {
            this.s = false;
            this.au("IsShown", true, this.s);
        }
        this.av(a, b, c);
        this.az(true);
    };
    Popup.prototype.az = function (a) {
        var _this = this;
        this.an();
        var b = this.s;
        this.s = a;
        var c = this.g(a);
        var d = this.f(a);
        if (false == this.q) {
            var e = this.k.t(c, d);
            c = e.p0;
            d = e.p1;
            return;
        }
        this.aq();
        this.n = this.l(this.s);
        this.o = this.m(this.s);
        this.n.play();
        this.o.play();
        this.n.finished.f(function (f) { return _this.n.commitStyles(); });
        this.o.finished.f(function (f) {
            _this.o.commitStyles();
            _this.au("IsShown", b, _this.s);
            if (_this.s) {
                if (_this.onPopup != null) {
                    _this.onPopup(_this, new OnPopupEventArgs());
                }
            }
            else {
                if (_this.onClosed != null) {
                    _this.onClosed(_this, new OnClosedEventArgs());
                }
            }
            var g = _this.k.t(c, d);
            c = g.p0;
            d = g.p1;
        });
    };
    Popup.prototype.appendPopupContent = function (a) {
        this.k.v(a);
    };
    Popup.prototype.ao = function () {
        if (!this.s) {
            return;
        }
        this.az(false);
    };
    Popup.prototype.destroy = function () {
        this.provideRenderer(null);
    };
    Popup.prototype.showRelativeToExclusionRect = function (a, b, c) {
        this.ay(a, b, c);
    };
    Popup.prototype.as = function (a) {
        this.bc = this.k.ak(a, this.i, this.h);
    };
    Popup.prototype.notifySizeChanged = function () {
    };
    Popup.prototype.provideRenderer = function (a) {
        this.k.ac(a);
    };
    Popup.prototype.ab = function () {
        return this.c();
    };
    Popup.prototype.ak = function () {
        var a = this.c();
        return a.f();
    };
    Popup.prototype.c = function () {
        var a = new PopupVisualModelExport();
        a.e = this.w;
        a.d = this.t;
        a.c = AppearanceHelper.a(this.a7);
        a.b = AppearanceHelper.a(this.a6);
        a.a = AppearanceHelper.a(this.a5);
        return a;
    };
    Popup.$t = markType(Popup, 'Popup', Base.$, [INotifyPropertyChanged_$type]);
    Popup.z = 2;
    Popup.bb = BrushUtil.g(66, 0, 0, 0);
    Popup.ba = BrushUtil.g(30, 0, 0, 0);
    Popup.a9 = BrushUtil.g(20, 0, 0, 0);
    return Popup;
}(Base));
export { Popup };
