/*
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, __read, __spreadArray } from "tslib";
import { Base, runOn, markType, INotifyPropertyChanged_$type, PropertyChangedEventArgs, enumGetBox } from "./type";
import { Size } from "./Size";
import { ElevationHelper } from "./ElevationHelper";
import { CornerRadius } from "./CornerRadius";
import { NativeUI } from "./NativeUI";
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 { PopupPointerPosition_$type } from "./PopupPointerPosition";
import { PopupAnimationType_$type } from "./PopupAnimationType";
import { stringFormat } from "./stringExtended";
import { isNaN_, truncate } from "./number";
import { stringEmpty } from "./string";
import { OnClosedEventArgs } from "./OnClosedEventArgs";
import { MouseEventArgs } from "./MouseEventArgs";
import { FocusEventArgs } from "./FocusEventArgs";
import { List$1 } from "./List$1";
import { AnimationKeyFrameProperty } from "./AnimationKeyFrameProperty";
import { TranslateTransform } from "./TranslateTransform";
import { OnPopupEventArgs } from "./OnPopupEventArgs";
import { PopupAnimation } from "./PopupAnimation";
import { DeviceUtils } from "./DeviceUtils";
import { PopupVisualModelExport } from "./PopupVisualModelExport";
import { AppearanceHelper } from "./AppearanceHelper";
import { BrushUtil } from "./BrushUtil";
/**
 * @hidden
 */
var PopupView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(PopupView, _super);
    function PopupView() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.t = null;
        _this.f = null;
        _this.ab = null;
        _this.aa = null;
        _this.z = null;
        _this.w = null;
        _this.y = null;
        _this.x = null;
        _this.ad = null;
        _this.k = false;
        _this.m = 0;
        _this.v = null;
        _this.ac = null;
        _this.a8 = new Size(1, 0, 0);
        _this.j = true;
        _this.l = false;
        return _this;
    }
    Object.defineProperty(PopupView.prototype, "g", {
        get: function () {
            return this.f;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PopupView.prototype, "u", {
        get: function () {
            return this.t;
        },
        enumerable: false,
        configurable: true
    });
    PopupView.prototype.as = function () {
        this.ab.setStyleProperty("height", "0%");
        this.ab.setStyleProperty("width", "0%");
        this.w = this.t.createElement("div");
        this.w.setStyleProperty("position", "absolute");
        this.w.setStyleProperty("z-index", "10000");
        this.y = this.t.createElement("div");
        this.y.setStyleProperty("height", 20 * 1.414 / 2 + "px");
        this.x = this.t.createElement("div");
        this.x.setStyleProperty("position", "relative");
        this.x.setStyleProperty("width", 20 + "px");
        this.x.setStyleProperty("height", 20 + "px");
        this.x.setStyleProperty("z-index", "1");
        this.x.setStyleProperty("clip-path", stringFormat("path(\"M0,0l{0},{0}l0,-{0}l-{0},0Z\")", 20));
        this.y.append(this.x);
        this.aa = this.t.createElement("div");
        this.aa.setStyleProperty("position", "relative");
        this.aa.setStyleProperty("overflow", "hidden");
        this.aa.setAttribute("key", "popupContentAreaOuter");
        this.a0(this.g.ak);
        this.w.listen("mouseenter", runOn(this, this.at));
        this.w.listen("mouseleave", runOn(this, this.au));
        this.w.listen("focusin", runOn(this, this.aq));
        this.w.listen("focusout", runOn(this, this.ar));
        this.z = this.t.createElement("div");
        this.z.setAttribute("key", "popupContentAreaInner");
        this.aa.append(this.z);
        this.w.append(this.aa);
    };
    PopupView.prototype.a5 = function () {
        var a = this.g;
        var b = ElevationHelper.e(a.at, a.b8, a.b7, a.b6);
        this.aa.setStyleProperty("box-shadow", b);
    };
    PopupView.prototype.a3 = function () {
        if (this.g.b9 != null) {
            this.aa.setStyleProperty("background-color", this.g.b9._fill);
            this.x.setStyleProperty("background-color", this.g.b9._fill);
        }
        if (this.g.cd != null) {
            this.x.setStyleProperty("background-color", this.g.cd._fill);
        }
    };
    PopupView.prototype.a4 = function () {
        if (!isNaN_(this.g.aq)) {
            NativeUI.n(this.aa, new CornerRadius(0, this.g.aq));
        }
    };
    PopupView.prototype.a6 = function () {
        if (null == this.ab) {
            return;
        }
        this.a5();
        this.a3();
        this.a4();
    };
    PopupView.prototype.at = function (a) {
        this.g.br();
    };
    PopupView.prototype.au = function (a) {
        this.g.bs();
    };
    PopupView.prototype.aq = function (a) {
        this.g.bp();
    };
    PopupView.prototype.ar = function (a) {
        this.g.bq(a.originalEvent.relatedTarget);
    };
    PopupView.prototype.ag = function () {
        if (null != this.w) {
            this.a6();
            this.aa.setStyleProperty("height", "0px");
            var a = this.w.getNativeElement();
            if (false == this.k) {
                this.y.remove();
                if (this.g.am) {
                    if (this.g.q == 0) {
                        var b = this.w.getNativeElement();
                        var c = this.y.getNativeElement();
                        var d = this.aa.getNativeElement();
                        b.insertBefore(c, d);
                    }
                    else {
                        this.w.append(this.y);
                    }
                }
                document.body.appendChild(a);
                this.k = true;
                if (this.j) {
                    this.an();
                }
            }
        }
    };
    PopupView.prototype.ah = function (a, b) {
        this.w.setStyleProperty("top", PopupView.ae(a.d));
        this.aa.setStyleProperty("height", PopupView.af(a.f));
        this.w.setStyleProperty("top", PopupView.af(b.b));
        this.z.setStyleProperty("opacity", "1");
        this.z.setStyleProperty("transform", stringEmpty());
        this.m = 0;
        if (this.l) {
            this.a2();
        }
        if (this.g.ao) {
            this.ac.observe(this.v.getNativeElement());
        }
        else {
            this.ac.disconnect();
        }
        if (this.g.ai) {
            this.a1(this.g.al);
        }
        return {
            p0: a,
            p1: b
        };
    };
    PopupView.prototype.ai = function (a) {
        this.m = a;
        if (this.g.ai) {
            this.a1(false);
        }
    };
    PopupView.prototype.ay = function () {
        if (null != this.w && this.k) {
            var a = this.w.getNativeElement();
            document.body.removeChild(a);
            this.k = false;
        }
    };
    PopupView.prototype.aj = function (a) {
        this.v = a;
        this.z.append(this.v);
        this.ac = new ResizeObserver(runOn(this, this.ap));
    };
    PopupView.prototype.ap = function (a) {
        if (this.k) {
            if (this.g.aj() && this.g.n == 0) {
                return;
            }
            this.g.bm();
        }
    };
    PopupView.prototype.i = function (a) {
        var b = this.w.getNativeElement();
        return b.contains(a);
    };
    PopupView.prototype.ax = function (a) {
        this.v = null;
        this.ac.disconnect();
        this.ac = null;
        a.remove();
    };
    PopupView.prototype.d = function (a) {
        return new AnimationKeyFrameEffect(0, this.z, 0, null, a);
    };
    PopupView.prototype.e = function (a) {
        return new AnimationKeyFrameEffect(0, this.aa, 0, null, a);
    };
    PopupView.prototype.ak = function () {
        if (KeyFrameAnimationFactory.h == null) {
            KeyFrameAnimationFactory.h = this.u;
        }
    };
    PopupView.prototype.c = function (a) {
        return new AnimationKeyFrameEffect(0, this.w, 0, null, a);
    };
    PopupView.prototype.b = function (a) {
        return new AnimationKeyFrameEffect(0, this.aa, 0, null, a);
    };
    PopupView.prototype.a = function (a) {
        return new AnimationKeyFrameEffect(0, this.w, 0, null, a);
    };
    PopupView.prototype.h = function () {
        return 12;
    };
    Object.defineProperty(PopupView.prototype, "a9", {
        get: function () {
            if (this.j) {
                this.an();
            }
            return this.a8;
        },
        enumerable: false,
        configurable: true
    });
    PopupView.prototype.n = 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.a9.width;
                    break;
                case 3:
                    c = a.right - (a.width / 2) - (this.a8.width / 2);
                    break;
                default:
                    t1 = 0;
                    continue L0;
            }
            break;
        }
        return c;
    };
    PopupView.prototype.o = 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.a9.height;
                    break;
                default:
                    t1 = 0;
                    continue L0;
            }
            break;
        }
        return c;
    };
    PopupView.af = function (a) {
        return stringFormat("{0}px", a);
    };
    PopupView.ae = function (a) {
        return stringFormat("{0}px", a);
    };
    PopupView.prototype.a7 = function (a, b, c) {
        var d = this.o(a, b);
        var e = this.n(a, c);
        this.az(e, d);
        if (b == 2 || c == 2) {
            var f = 10;
            while (f > 0) {
                var g = this.o(a, b);
                var h = this.n(a, c);
                if (g == d && h == e) {
                    f = 0;
                    break;
                }
                d = g;
                e = h;
                this.az(e, d);
                f--;
            }
        }
        return new Rect(0, e, d, this.a9.width, this.a9.height);
    };
    PopupView.prototype.an = function () {
        if (this.k) {
            this.aa.setStyleProperty("width", stringEmpty());
            this.aa.setStyleProperty("height", stringEmpty());
            this.w.setStyleProperty("width", stringEmpty());
            this.w.setStyleProperty("height", stringEmpty());
            this.a8 = new Size(1, this.z.outerWidth(), this.z.outerHeight());
            this.j = false;
            this.a2();
        }
        else {
            this.j = true;
        }
    };
    PopupView.prototype.az = function (a, b) {
        var c = stringFormat("{0}px", a);
        var d = stringFormat("{0}px", b);
        this.w.setStyleProperty("left", c);
        this.w.setStyleProperty("top", d);
    };
    PopupView.prototype.av = function (a) {
        var _this = this;
        if (a == null) {
            this.t = null;
            if (this.w != null) {
                this.w.unlistenAll();
            }
            return;
        }
        this.t = a;
        var b = a.rootWrapper;
        this.al(b);
        this.t.getPortal(this.z, "ChildContent", function (c) {
            var comp_ = c.componentRef;
            _this.ad = comp_;
        }, true);
    };
    PopupView.prototype.a2 = function () {
        var a = new Size(1, this.a9.width, this.a9.height);
        if (!this.k || !this.g.ao) {
            a.height = 0;
        }
        var b = a.width;
        var c = a.height;
        if (this.f.aj()) {
            if (this.m == c) {
                return;
            }
            this.f.bi();
            this.l = true;
            return;
        }
        this.l = false;
        var d = stringFormat("{0}px", b);
        var e = stringFormat("{0}px", c);
        this.aa.setStyleProperty("width", d);
        this.aa.setStyleProperty("height", e);
        this.w.setStyleProperty("width", d);
        this.w.setStyleProperty("height", e);
        if (this.g.am) {
            var f = this.g.q == 1 ? 135 : -45;
            var g = this.g.q == 1 ? -10 : 14.139999999999999 - 10;
            this.x.setStyleProperty("transform", "translate(" + (b / 2 - 10) + "px, " + g + "px) rotate(" + f + "deg)");
            e = stringFormat("{0}px", 14.139999999999999 + c);
            this.w.setStyleProperty("height", e);
        }
    };
    PopupView.prototype.al = function (a) {
        this.ab = a;
        this.as();
    };
    PopupView.prototype.am = function (a) {
        this.f = a;
    };
    PopupView.prototype.ao = function () {
    };
    PopupView.prototype.aw = function () {
        this.ag();
        if (this.g.ao) {
            return;
        }
        this.a2();
    };
    PopupView.prototype.a1 = function (a) {
        if (this.w != null) {
            this.w.setStyleProperty("pointer-events", a ? "auto" : "none");
        }
    };
    PopupView.prototype.a0 = function (a) {
        if (this.w != null) {
            this.w.setAttribute("tabindex", a ? "-1" : "");
        }
    };
    PopupView.$t = markType(PopupView, 'PopupView');
    return PopupView;
}(Base));
export { PopupView };
/**
 * @hidden
 */
var Popup = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(Popup, _super);
    function Popup() {
        var _this = _super.call(this) || this;
        _this.o = 0;
        _this.h = 0;
        _this.cg = null;
        _this.ce = null;
        _this.x = null;
        _this.y = null;
        _this.onClosed = null;
        _this.onPopup = null;
        _this.propertyChanged = null;
        _this.popupMouseEnter = null;
        _this.popupMouseLeave = null;
        _this.popupGotFocus = null;
        _this.popupLostFocus = null;
        _this.s = null;
        _this.ac = false;
        _this.au = 50;
        _this.af = true;
        _this.m = 0;
        _this.as = -1;
        _this.ar = Popup.aw;
        _this.an = false;
        _this.b3 = Popup.cc;
        _this.b2 = Popup.cb;
        _this.b1 = Popup.ca;
        _this.b4 = null;
        _this.ap = 0;
        _this.ad = true;
        _this.ab = false;
        _this.ae = false;
        _this.p = 0;
        _this.b5 = null;
        _this.i = null;
        var a = _this.r();
        _this.s = a;
        a.am(_this);
        return _this;
    }
    Object.defineProperty(Popup.prototype, "ch", {
        get: function () {
            return this.cg;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "cf", {
        get: function () {
            return this.ce;
        },
        enumerable: false,
        configurable: true
    });
    Popup.prototype.bt = function (a, b, c) {
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
        this.bv(a, b, c);
    };
    Popup.prototype.br = function () {
        if (this.popupMouseEnter != null) {
            this.popupMouseEnter(this, new MouseEventArgs());
        }
    };
    Popup.prototype.bs = function () {
        if (this.popupMouseLeave != null) {
            this.popupMouseLeave(this, new MouseEventArgs());
        }
    };
    Popup.prototype.bp = function () {
        if (this.popupGotFocus != null) {
            this.popupGotFocus(this, new FocusEventArgs());
        }
    };
    Popup.prototype.bq = function (a) {
        if (this.popupLostFocus != null) {
            this.popupLostFocus(this, ((function () {
                var $ret = new FocusEventArgs();
                $ret.a = a;
                return $ret;
            })()));
        }
    };
    Object.defineProperty(Popup.prototype, "ak", {
        get: function () {
            return this.ac;
        },
        set: function (a) {
            var b = this.ac;
            this.ac = a;
            if (b != this.ac) {
                this.bt("IsFocusable", b, this.ac);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "av", {
        get: function () {
            return this.au;
        },
        set: function (a) {
            var b = this.au;
            this.au = a;
            if (b != this.au) {
                this.bt("AnimationDuration", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "ag", {
        get: function () {
            return this.af;
        },
        set: function (a) {
            var b = this.af;
            this.af = a;
            if (b != this.af) {
                this.bt("AnimationEnabled", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "n", {
        get: function () {
            return this.m;
        },
        set: function (a) {
            var b = this.m;
            this.m = a;
            if (b != this.m) {
                this.bt("AnimationType", enumGetBox(PopupAnimationType_$type, b), enumGetBox(PopupAnimationType_$type, this.m));
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "ax", {
        get: function () {
            return this.as;
        },
        set: function (a) {
            var b = this.as;
            this.as = a;
            if (b != this.as) {
                this.bt("Elevation", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "at", {
        get: function () {
            return this.ar;
        },
        set: function (a) {
            var b = this.ar;
            this.ar = a;
            if (b != this.ar) {
                this.bt("ActualElevation", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "ao", {
        get: function () {
            return this.an;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "b8", {
        get: function () {
            return this.b3;
        },
        set: function (a) {
            var b = this.b3;
            this.b3 = a;
            if (b != this.b3) {
                this.bt("ActualUmbraShadowColor", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "b7", {
        get: function () {
            return this.b2;
        },
        set: function (a) {
            var b = this.b2;
            this.b2 = a;
            if (b != this.b2) {
                this.bt("ActualPenumbraShadowColor", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "b6", {
        get: function () {
            return this.b1;
        },
        set: function (a) {
            var b = this.b1;
            this.b1 = a;
            if (b != this.b1) {
                this.bt("ActualAmbientShadowColor", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "b9", {
        get: function () {
            return this.b4;
        },
        set: function (a) {
            var b = this.b4;
            this.b4 = a;
            if (b != this.b4) {
                this.bt("Background", b, this.b4);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "aq", {
        get: function () {
            return this.ap;
        },
        set: function (a) {
            var b = this.ap;
            this.ap = a;
            if (b != this.ap) {
                this.bt("CornerRadius", b, this.ap);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "al", {
        get: function () {
            return this.ad;
        },
        set: function (a) {
            var b = this.ad;
            this.ad = a;
            if (b != this.ad) {
                this.bt("IsHitTestVisible", b, this.ad);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "ai", {
        get: function () {
            return this.ab;
        },
        set: function (a) {
            var b = this.ab;
            this.ab = a;
            if (b != this.ab) {
                this.bt("DisableHitTestDuringAnimation", b, this.ab);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "am", {
        get: function () {
            return this.ae;
        },
        set: function (a) {
            var b = this.ae;
            this.ae = a;
            if (b != this.ae) {
                this.bt("IsPointerEnabled", b, this.ae);
            }
        },
        enumerable: false,
        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.bt("PointerPosition", enumGetBox(PopupPointerPosition_$type, b), enumGetBox(PopupPointerPosition_$type, this.p));
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "cd", {
        get: function () {
            return this.b5;
        },
        set: function (a) {
            var b = this.b5;
            this.b5 = a;
            if (b != this.b5) {
                this.bt("PointerBackground", b, this.b5);
            }
        },
        enumerable: false,
        configurable: true
    });
    Popup.prototype.r = function () {
        return new PopupView();
    };
    Popup.prototype.bv = function (a, b, c) {
        switch (a) {
            case "IsShown":
                if (false == this.ao) {
                    this.s.ay();
                }
                break;
            case "Elevation":
                this.at = this.ax == -1 ? Popup.aw : this.ax;
                break;
            case "ActualElevation":
            case "ActualUmbraShadowColor":
            case "ActualPenumbraShadowColor":
            case "ActualAmbientShadowColor":
            case "Background":
            case "CornerRadius":
                this.s.a6();
                break;
            case "AnimationEnabled":
                if (false == this.ag) {
                    this.bi();
                }
                break;
            case "IsHitTestVisible":
                this.s.a1(this.al);
                break;
            case "IsFocusable":
                this.s.a0(this.ak);
                break;
        }
    };
    Popup.prototype.bi = function () {
        if (this.aj()) {
            if (null != this.y && this.y.playState == 1) {
                this.y.cancel();
            }
            if (null != this.x && this.x.playState == 1) {
                this.x.cancel();
            }
        }
    };
    Popup.prototype.v = function (a) {
        var b = this.f(a);
        var c = a ? this.b() : this.a();
        var d = this.s.d(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, __spreadArray([], __read(e.toArray())));
        d.m.apply(d, __spreadArray([], __read(f.toArray())));
        return KeyFrameAnimationFactory.f.c(d);
    };
    Popup.prototype.w = function (a) {
        var b = this.g(a);
        this.s.ai(b.f);
        var c = a ? this.b() : this.a();
        var d = this.s.e(c);
        var e = new List$1(AnimationKeyFrameProperty.$, 0);
        var f = new List$1(AnimationKeyFrameProperty.$, 0);
        var g = new AnimationKeyFrameProperty(10, b.e);
        var h = new AnimationKeyFrameProperty(10, b.f);
        e.add(g);
        f.add(h);
        if (this.o == 2) {
            var i = b.b;
            var j = b.d;
            var k = new AnimationKeyFrameProperty(12, i);
            var l = new AnimationKeyFrameProperty(12, j);
            e.add(k);
            f.add(l);
        }
        d.m.apply(d, __spreadArray([], __read(e.toArray())));
        d.m.apply(d, __spreadArray([], __read(f.toArray())));
        return KeyFrameAnimationFactory.f.c(d);
    };
    Popup.prototype.a = function () {
        var a = new AnimationKeyFrameEffectTiming();
        a.g = this.av;
        a.b = 3;
        return a;
    };
    Popup.prototype.b = function () {
        var a = new AnimationKeyFrameEffectTiming();
        a.g = this.av;
        a.b = 3;
        return a;
    };
    Popup.prototype.bl = function () {
        this.s.ak();
    };
    Popup.prototype.f = function (a) {
        var b = truncate(this.s.a9.height);
        if (b <= 0) {
            b = 500;
        }
        var c = a ? -b : 0;
        var d = a ? 0 : -b;
        if (this.o == 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.s.a9.height);
        if (b <= 0) {
            b = 500;
        }
        var c = a ? 0 : b;
        var d = a ? b : 0;
        var e;
        var f;
        if (this.o == 2) {
            e = a ? this.cg.bottom : this.cg.top;
            f = a ? this.cg.top : this.cg.bottom;
        }
        else {
            e = this.cg.top;
            f = this.cg.top;
        }
        var g = ((function () {
            var $ret = new Popup_OuterAnimationInfo();
            $ret.e = c;
            $ret.f = d;
            $ret.b = e;
            $ret.d = f;
            return $ret;
        })());
        return g;
    };
    Popup.prototype.aj = function () {
        if (null == this.y && null == this.x) {
            return false;
        }
        if (null != this.y && this.y.playState == 1) {
            return true;
        }
        if (null != this.x && this.x.playState == 1) {
            return true;
        }
        return false;
    };
    Popup.prototype.bm = function () {
        this.s.an();
        if (this.ao) {
            this.cg = this.s.a7(this.ce, this.o, this.h);
        }
    };
    Popup.prototype.bu = function (a, b, c) {
        this.ce = a;
        this.s.aw();
        this.cg = this.s.a7(a, b, c);
        this.o = b;
        this.h = c;
    };
    Popup.prototype.by = function (a, b, c) {
        if (this.an) {
            this.an = false;
            this.bt("IsShown", true, this.an);
        }
        this.bu(a, b, c);
        this.bz(true);
    };
    Popup.prototype.bz = function (a) {
        var _this = this;
        this.bi();
        var b = this.an;
        this.an = a;
        var c = this.g(a);
        var d = this.f(a);
        if (false == this.ag) {
            var e = this.s.ah(c, d);
            c = e.p0;
            d = e.p1;
            return;
        }
        this.bl();
        this.i = this.j(this.n, this.an);
        this.i.d(function () {
            _this.i.c();
            _this.bt("IsShown", b, _this.an);
            if (_this.an) {
                if (_this.onPopup != null) {
                    _this.onPopup(_this, new OnPopupEventArgs());
                }
            }
            else {
                if (_this.onClosed != null) {
                    _this.onClosed(_this, new OnClosedEventArgs());
                }
            }
            var f = _this.s.ah(c, d);
            c = f.p0;
            d = f.p1;
        });
    };
    Popup.prototype.j = function (a, b) {
        switch (a) {
            case 0: return this.l(b);
            case 1: return this.k(b);
            default: return this.l(b);
        }
    };
    Popup.prototype.l = function (a) {
        var b = this.v(a);
        var c = this.w(a);
        var d = new PopupAnimation();
        d.a.add(b);
        d.a.add(c);
        return d;
    };
    Popup.prototype.k = function (a) {
        var b = this.g(a);
        this.s.ai(a ? b.f : b.e);
        var c = this.b();
        var d = this.s.c(c);
        var e = DeviceUtils.g(30);
        var f = this.o == 1 ? b.d - e : b.d + e;
        d.m(new AnimationKeyFrameProperty(this.s.h(), a ? f : b.d));
        d.m(new AnimationKeyFrameProperty(this.s.h(), a ? b.d : f));
        var g = this.s.a(c);
        g.m(new AnimationKeyFrameProperty(1, a ? 0 : 1));
        g.m(new AnimationKeyFrameProperty(1, a ? 1 : 0));
        var h = this.s.b(c);
        h.m(new AnimationKeyFrameProperty(10, (a ? b.f : b.e)));
        h.m(new AnimationKeyFrameProperty(10, (a ? b.f : b.e)));
        var i = new PopupAnimation();
        i.a.add(KeyFrameAnimationFactory.f.c(d));
        i.a.add(KeyFrameAnimationFactory.f.c(g));
        i.a.add(KeyFrameAnimationFactory.f.c(h));
        return i;
    };
    Popup.prototype.contains = function (a) {
        return this.s.i(a);
    };
    Popup.prototype.appendPopupContent = function (a) {
        this.s.aj(a);
    };
    Popup.prototype.removePopupContent = function (a) {
        this.s.ax(a);
    };
    Popup.prototype.bj = function () {
        if (!this.an) {
            return;
        }
        this.bz(false);
    };
    Popup.prototype.destroy = function () {
        this.provideRenderer(null);
    };
    Popup.prototype.showRelativeToExclusionRect = function (a, b, c) {
        this.by(a, b, c);
    };
    Popup.prototype.bn = function (a) {
        this.ce = a;
        this.cg = this.s.a7(a, this.o, this.h);
    };
    Popup.prototype.notifySizeChanged = function () {
    };
    Popup.prototype.provideRenderer = function (a) {
        this.s.av(a);
    };
    Popup.prototype.ay = function () {
        return this.c();
    };
    Popup.prototype.ba = function () {
        var a = this.c();
        return a.f();
    };
    Popup.prototype.c = function () {
        var a = new PopupVisualModelExport();
        a.e = this.at;
        a.d = this.ao;
        a.c = AppearanceHelper.a(this.b8);
        a.b = AppearanceHelper.a(this.b7);
        a.a = AppearanceHelper.a(this.b6);
        return a;
    };
    Popup.$t = markType(Popup, 'Popup', Base.$, [INotifyPropertyChanged_$type]);
    Popup.aw = 2;
    Popup.cc = BrushUtil.g(66, 0, 0, 0);
    Popup.cb = BrushUtil.g(30, 0, 0, 0);
    Popup.ca = BrushUtil.g(20, 0, 0, 0);
    return Popup;
}(Base));
export { Popup };
