/*
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, __values } from "tslib";
import { Base, runOn, markType, INotifyPropertyChanged_$type, PropertyChangedEventArgs, enumGetBox, fromEnum } from "./type";
import { Size } from "./Size";
import { ElevationHelper } from "./ElevationHelper";
import { CornerRadius } from "./CornerRadius";
import { NativeUI } from "./NativeUI";
import { PopupPointerPosition_$type } from "./PopupPointerPosition";
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 { PopupAnimationType_$type } from "./PopupAnimationType";
import { stringFormat } from "./stringExtended";
import { isNaN_, truncate } from "./number";
import { stringEmpty } from "./string";
import { NativeUIInputsFactory } from "./NativeUIInputsFactory";
import { OnClosedEventArgs } from "./OnClosedEventArgs";
import { MouseEventArgs } from "./MouseEventArgs";
import { FocusEventArgs } from "./FocusEventArgs";
import { PopupAnimation } from "./PopupAnimation";
import { IKeyFrameAnimation_$type } from "./IKeyFrameAnimation";
import { List$1 } from "./List$1";
import { AnimationKeyFrameProperty } from "./AnimationKeyFrameProperty";
import { TranslateTransform } from "./TranslateTransform";
import { OnPopupEventArgs } from "./OnPopupEventArgs";
import { DeviceUtils } from "./DeviceUtils";
import { PopupVisualModelExport } from "./PopupVisualModelExport";
import { AppearanceHelper } from "./AppearanceHelper";
import { PopupMeasuringContentSizeEventArgs } from "./PopupMeasuringContentSizeEventArgs";
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.ag = null;
        _this.f = null;
        _this.ao = null;
        _this.an = null;
        _this.am = null;
        _this.aj = null;
        _this.al = null;
        _this.ak = null;
        _this.aq = null;
        _this.v = 0;
        _this.w = 0;
        _this.u = 0;
        _this.m = false;
        _this.x = 0;
        _this.s = 0;
        _this.t = 0;
        _this.q = 0;
        _this.r = 0;
        _this.ai = null;
        _this.ap = null;
        _this.br = new Size(1, 0, 0);
        _this.k = true;
        _this.p = false;
        return _this;
    }
    Object.defineProperty(PopupView.prototype, "af", {
        get: function () {
            return this.g.a4;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PopupView.prototype, "ac", {
        get: function () {
            return this.af / 2;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PopupView.prototype, "ab", {
        get: function () {
            return this.af * 1.414;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PopupView.prototype, "aa", {
        get: function () {
            return this.ab / 2;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PopupView.prototype, "ad", {
        get: function () {
            return (this.bs.width / 2 - this.ac);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PopupView.prototype, "ae", {
        get: function () {
            return (this.bs.height / 2 - this.ac);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PopupView.prototype, "g", {
        get: function () {
            return this.f;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PopupView.prototype, "ah", {
        get: function () {
            return this.ag;
        },
        enumerable: false,
        configurable: true
    });
    PopupView.prototype.a6 = function () {
        this.ao.setStyleProperty("height", "0%");
        this.ao.setStyleProperty("width", "0%");
        this.aj = this.ag.createElement("div");
        this.be(this.g.ar);
        this.aj.setStyleProperty("z-index", "10000");
        this.aj.setStyleProperty("inset", "unset");
        this.aj.setStyleProperty("padding", "0px");
        this.aj.setStyleProperty("border-width", "0px");
        this.al = this.ag.createElement("div");
        this.al.setStyleProperty("height", 20 * 1.414 / 2 + "px");
        this.ak = this.ag.createElement("div");
        this.ak.setStyleProperty("position", "relative");
        this.ak.setStyleProperty("width", this.af + "px");
        this.ak.setStyleProperty("height", this.af + "px");
        this.ak.setStyleProperty("z-index", "1");
        this.ak.setStyleProperty("clip-path", stringFormat("path(\"M0,0l{0},{0}l0,-{0}l-{0},0Z\")", this.af));
        this.al.append(this.ak);
        this.an = this.ag.createElement("div");
        this.an.setStyleProperty("position", "relative");
        this.an.setStyleProperty("overflow", "hidden");
        this.an.setAttribute("key", "popupContentAreaOuter");
        this.bf(this.g.as);
        this.aj.listen("mouseenter", runOn(this, this.a7));
        this.aj.listen("mouseleave", runOn(this, this.a8));
        this.aj.listen("focusin", runOn(this, this.a4));
        this.aj.listen("focusout", runOn(this, this.a5));
        this.am = this.ag.createElement("div");
        this.am.setAttribute("key", "popupContentAreaInner");
        this.an.append(this.am);
        this.aj.append(this.an);
    };
    PopupView.prototype.bn = function () {
        var a = this.g;
        var b = ElevationHelper.e(a.a7, a.cz, a.cy, a.cx);
        if (this.l()) {
            this.aj.setStyleProperty("box-shadow", b);
        }
        else {
            this.an.setStyleProperty("box-shadow", b);
        }
    };
    PopupView.prototype.bl = function () {
        if (this.g.c0 != null) {
            this.an.setStyleProperty("background-color", this.g.c0._fill);
            this.ak.setStyleProperty("background-color", this.g.c0._fill);
        }
        if (this.g.c4 != null) {
            this.ak.setStyleProperty("background-color", this.g.c4._fill);
        }
    };
    PopupView.prototype.bm = function () {
        if (!isNaN_(this.g.a1)) {
            NativeUI.o(this.an, new CornerRadius(0, this.g.a1));
        }
    };
    PopupView.prototype.bo = function () {
        if (null == this.ao) {
            return;
        }
        this.be(this.g.ar);
        this.bn();
        this.bl();
        this.bm();
    };
    PopupView.prototype.a7 = function (a) {
        this.g.cf();
    };
    PopupView.prototype.a8 = function (a) {
        this.g.cg();
    };
    PopupView.prototype.a4 = function (a) {
        this.g.cc();
    };
    PopupView.prototype.a5 = function (a) {
        this.g.cd(a.originalEvent.relatedTarget, a.originalEvent.target);
    };
    PopupView.prototype.o = function () {
        return (HTMLElement.prototype.hasOwnProperty("popover"));
    };
    PopupView.prototype.l = function () {
        return this.o() && this.g.ay;
    };
    PopupView.prototype.at = function () {
        if (null != this.aj) {
            this.bo();
            this.an.setStyleProperty("height", "0px");
            var a = this.aj.getNativeElement();
            if (false == this.m) {
                this.al.remove();
                if (this.g.au) {
                    var b = this.g.u();
                    if (b == 1) {
                        this.aj.setStyleProperty("display", "block");
                        var c = this.aj.getNativeElement();
                        var d = this.al.getNativeElement();
                        var e = this.an.getNativeElement();
                        c.insertBefore(d, e);
                    }
                    else if (b == 2) {
                        this.aj.setStyleProperty("display", "block");
                        this.aj.append(this.al);
                    }
                    else if (b == 3) {
                        this.aj.setStyleProperty("display", "flex");
                        var f = this.aj.getNativeElement();
                        var g = this.al.getNativeElement();
                        var h = this.an.getNativeElement();
                        f.insertBefore(g, h);
                        this.al.setStyleProperty("height", "unset");
                        this.al.setStyleProperty("width", 20 * 1.414 / 2 + "px");
                    }
                    else if (b == 4) {
                        this.aj.setStyleProperty("display", "flex");
                        this.aj.append(this.al);
                        this.al.setStyleProperty("height", "unset");
                        this.al.setStyleProperty("width", 20 * 1.414 / 2 + "px");
                    }
                }
                if (this.g.be != null) {
                    this.g.be.appendChild(a);
                }
                else {
                    document.body.appendChild(a);
                }
                this.bh(this.g.ay);
                if (this.l()) {
                    a.showPopover();
                }
                this.m = true;
                if (this.k) {
                    this.a1();
                }
            }
        }
    };
    PopupView.prototype.au = function (a, b) {
        this.aj.setStyleProperty("top", PopupView.ar(a.f));
        this.an.setStyleProperty("height", PopupView.as(a.h));
        this.am.setStyleProperty("top", PopupView.as(b.b));
        this.am.setStyleProperty("opacity", "1");
        this.am.setStyleProperty("transform", stringEmpty());
        this.x = 0;
        if (this.p) {
            this.bk();
        }
        if (this.g.ax) {
            this.ap.observe(this.ai.getNativeElement());
        }
        else {
            this.ap.disconnect();
        }
        if (this.g.ao) {
            this.bg(this.g.at);
        }
        return {
            p0: a,
            p1: b
        };
    };
    PopupView.prototype.av = function (a) {
        this.x = a;
        if (this.g.ao) {
            this.bg(false);
        }
        this.bi(this.bs.width, a);
        this.bj();
    };
    PopupView.prototype.bc = function () {
        if (null != this.aj && this.m) {
            var a = this.aj.getNativeElement();
            if (this.g.be != null) {
                this.g.be.removeChild(a);
            }
            else {
                document.body.removeChild(a);
            }
            this.m = false;
        }
    };
    PopupView.prototype.aw = function (a) {
        this.ai = a;
        this.am.append(this.ai);
        this.ap = new ResizeObserver(runOn(this, this.a3));
    };
    PopupView.prototype.a3 = function (a) {
        if (this.m) {
            if (this.g.ap() && this.g.p == 0) {
                return;
            }
            this.g.b9();
        }
    };
    PopupView.prototype.j = function (a) {
        var b = this.aj.getNativeElement();
        return b.contains(a);
    };
    PopupView.prototype.bb = function (a) {
        this.ai = null;
        this.ap.disconnect();
        this.ap = null;
        a.remove();
    };
    PopupView.prototype.d = function (a) {
        return new AnimationKeyFrameEffect(0, this.am, 0, null, a);
    };
    PopupView.prototype.e = function (a) {
        return new AnimationKeyFrameEffect(0, this.an, 0, null, a);
    };
    PopupView.prototype.ay = function () {
        if (KeyFrameAnimationFactory.h == null) {
            KeyFrameAnimationFactory.h = this.ah;
        }
    };
    PopupView.prototype.c = function (a) {
        return new AnimationKeyFrameEffect(0, this.aj, 0, null, a);
    };
    PopupView.prototype.b = function (a) {
        return new AnimationKeyFrameEffect(0, this.an, 0, null, a);
    };
    PopupView.prototype.a = function (a) {
        return new AnimationKeyFrameEffect(0, this.aj, 0, null, a);
    };
    PopupView.prototype.i = function () {
        return 12;
    };
    PopupView.prototype.h = function () {
        return 11;
    };
    PopupView.prototype.n = function () {
        return this.g.be != null && !this.g.ar && !this.l();
    };
    Object.defineProperty(PopupView.prototype, "bs", {
        get: function () {
            if (this.k) {
                this.a1();
            }
            return this.br;
        },
        enumerable: false,
        configurable: true
    });
    PopupView.prototype.y = function (a, b, c) {
        var d;
        switch (b) {
            case 3:
                d = (!this.n() ? a.left : 0) - (this.bs.width + (this.g.au ? this.aa : 0));
                break;
            case 4:
                d = !this.n() ? a.right : a.width;
                break;
            case 0:
            case 2:
            case 1:
            default:
                switch (c) {
                    case 2:
                        d = (!this.n() ? a.right : a.width) - this.bs.width;
                        break;
                    case 3:
                        d = (!this.n() ? a.right : a.width) - (a.width / 2) - (this.bs.width / 2);
                        break;
                    case 0:
                    case 1:
                    default:
                        d = !this.n() ? a.left : 0;
                        break;
                }
                break;
        }
        return d;
    };
    PopupView.prototype.z = function (a, b, c) {
        var d;
        switch (b) {
            case 3:
            case 4:
                switch (c) {
                    case 2:
                        d = (!this.n() ? a.bottom : 0) - this.bs.height;
                        break;
                    case 3:
                        d = (!this.n() ? a.top : -a.height) - (this.bs.height / 2) + (a.height / 2);
                        break;
                    case 0:
                    case 1:
                    default:
                        d = !this.n() ? a.top : -a.height;
                        break;
                }
                break;
            case 2:
                d = (!this.n() ? a.top : -a.height) - (this.bs.height + (this.g.au ? this.aa : 0));
                break;
            case 0:
            case 1:
            default:
                d = !this.n() ? a.bottom : 0;
                break;
        }
        return d;
    };
    PopupView.as = function (a) {
        return stringFormat("{0}px", a);
    };
    PopupView.ar = function (a) {
        return stringFormat("{0}px", a);
    };
    PopupView.prototype.bj = function () {
        if (this.g.r == 1 || this.g.r == 2) {
            switch (this.g.j) {
                case 3:
                    this.v = this.ad + (this.s - this.q);
                    break;
            }
        }
        else if (this.g.r == 3 || this.g.r == 4) {
            switch (this.g.j) {
                case 3:
                    this.w = this.ae + (this.t - this.r);
                    break;
            }
        }
        this.ak.setStyleProperty("transform", "translate(" + this.v + "px, " + this.w + "px) rotate(" + this.u + "deg)");
    };
    PopupView.prototype.ax = function (a, b, c, d) {
        this.s = a;
        this.t = b;
        if (this.g.r == 1 || this.g.r == 2) {
            var e = (window.innerWidth);
            var f = a;
            var g = f + c;
            if (f < 5) {
                a = 5;
            }
            else if (g > e - 5) {
                a = f - (g - (e - 5));
            }
        }
        else if (this.g.r == 3 || this.g.r == 4) {
            var h = (window.innerHeight);
            var i = b;
            var j = i + d;
            if (i < 5) {
                b = 5;
            }
            else if (j > h - 5) {
                b = i - (j - (h - 5));
            }
        }
        return {
            p0: a,
            p1: b
        };
    };
    PopupView.prototype.bq = function (a, b, c) {
        var d = this.z(a, b, c);
        var e = this.y(a, b, c);
        if (this.g.be == null) {
            var f = this.ax(e, d, this.bs.width, this.bs.height);
            e = f.p0;
            d = f.p1;
        }
        this.bd(e, d);
        if (b == 2 || c == 2) {
            var g = 10;
            while (g > 0) {
                var h = this.z(a, b, c);
                var i = this.y(a, b, c);
                if (this.g.be == null) {
                    var j = this.ax(i, h, this.bs.width, this.bs.height);
                    i = j.p0;
                    h = j.p1;
                }
                if (h == d && i == e) {
                    g = 0;
                    break;
                }
                d = h;
                e = i;
                this.bd(e, d);
                g--;
            }
        }
        this.bj();
        return new Rect(0, e, d, this.bs.width, this.bs.height);
    };
    PopupView.prototype.bp = function (a, b, c) {
        var d = new Rect(4);
        var target_ = a;
        if ((target_.getBoundingClientRect)) {
            var bRect_ = target_.getBoundingClientRect();
            d.left = (bRect_.left);
            d.top = (bRect_.top);
            d.width = (bRect_.width);
            d.height = (bRect_.height);
        }
        var e = this.bq(d, b, c);
        return e;
    };
    PopupView.prototype.a1 = function () {
        if (this.m) {
            this.an.setStyleProperty("width", stringEmpty());
            this.an.setStyleProperty("height", stringEmpty());
            this.aj.setStyleProperty("width", stringEmpty());
            this.aj.setStyleProperty("height", stringEmpty());
            this.aj.setStyleProperty("position", "absolute");
            this.g.ce();
            this.br = new Size(1, this.am.outerWidth(), this.am.outerHeight());
            this.k = false;
            this.bk();
        }
        else {
            this.k = true;
        }
    };
    PopupView.prototype.bd = function (a, b) {
        var c = stringFormat("{0}px", a);
        var d = stringFormat("{0}px", b);
        this.aj.setStyleProperty("left", c);
        this.aj.setStyleProperty("top", d);
        this.q = a;
        this.r = b;
    };
    PopupView.prototype.a9 = function (a) {
        var _this = this;
        if (a == null) {
            this.ag = null;
            if (this.aj != null) {
                this.aj.unlistenAll();
            }
            return;
        }
        this.ag = a;
        var b = a.rootWrapper;
        this.az(b);
        this.ag.getPortal(this.am, "ChildContent", function (c) {
            var comp_ = c.componentRef;
            _this.aq = comp_;
        }, true);
    };
    PopupView.prototype.bk = function () {
        var a = new Size(1, this.bs.width, this.bs.height);
        if (!this.m || (!this.g.ax && !this.g.aq)) {
            a.height = 0;
        }
        var b = a.width;
        var c = a.height;
        var d = stringFormat("{0}px", b);
        var e = stringFormat("{0}px", c);
        this.bi(b, c);
        if (this.g.au) {
            switch (this.g.u()) {
                case 2:
                    d = stringFormat("{0}px", b);
                    e = stringFormat("{0}px", this.aa + c);
                    break;
                case 1:
                    d = stringFormat("{0}px", b);
                    e = stringFormat("{0}px", this.aa + c);
                    break;
                case 3:
                    d = stringFormat("{0}px", this.aa + b);
                    e = stringFormat("{0}px", c);
                    break;
                case 4:
                    d = stringFormat("{0}px", this.aa + b);
                    e = stringFormat("{0}px", c);
                    break;
            }
        }
        if (this.f.ap()) {
            if (this.g.aq || this.x == c) {
                return;
            }
            this.f.b3();
            this.p = true;
            return;
        }
        this.p = false;
        var f = stringFormat("{0}px", b);
        var g = stringFormat("{0}px", c);
        this.an.setStyleProperty("width", f);
        this.an.setStyleProperty("height", g);
        if (!this.l()) {
            if (this.g.be != null) {
                e = "0px";
            }
            this.aj.setStyleProperty("width", d);
            this.aj.setStyleProperty("height", e);
        }
        this.be(this.g.ar);
    };
    PopupView.prototype.bi = function (a, b) {
        if (this.g.au) {
            var c = 0;
            var d = 0;
            switch (this.g.u()) {
                case 2:
                    c = 135;
                    d = -this.ac;
                    this.v = a / 2 - this.ac;
                    this.w = d;
                    break;
                case 1:
                    c = -45;
                    d = this.aa - this.ac;
                    this.v = a / 2 - this.ac;
                    this.w = d;
                    break;
                case 3:
                    c = -135;
                    d = this.aa - this.ac;
                    this.v = d;
                    this.w = b / 2 - this.ac;
                    break;
                case 4:
                    c = 45;
                    d = -this.ac;
                    this.v = d;
                    this.w = b / 2 - this.ac;
                    break;
            }
            this.u = c;
            this.ak.setStyleProperty("transform", "translate(" + this.v + "px, " + this.w + "px) rotate(" + this.u + "deg)");
        }
    };
    PopupView.prototype.az = function (a) {
        this.ao = a;
        this.a6();
    };
    PopupView.prototype.a0 = function (a) {
        this.f = a;
    };
    PopupView.prototype.a2 = function () {
    };
    PopupView.prototype.ba = function () {
        this.at();
        if (this.g.ax) {
            return;
        }
        this.bk();
    };
    PopupView.prototype.bg = function (a) {
        if (this.aj != null) {
            this.aj.setStyleProperty("pointer-events", a ? "auto" : "none");
        }
    };
    PopupView.prototype.bf = function (a) {
        if (this.aj != null) {
            this.aj.setAttribute("tabindex", a ? "-1" : "");
        }
    };
    PopupView.prototype.be = function (a) {
        if (this.aj != null) {
            this.aj.setStyleProperty("position", a ? "fixed" : this.g.be != null ? "relative" : "absolute");
        }
    };
    PopupView.prototype.bh = function (a) {
        if (this.aj != null && this.o()) {
            var b = this.aj.getNativeElement();
            if (a) {
                b.popover = "manual";
            }
            else {
                b.popover = undefined;
            }
        }
    };
    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.q = 0;
        _this.i = 0;
        _this.a2 = 0;
        _this.c7 = null;
        _this.c5 = null;
        _this.bc = null;
        _this.onClosed = null;
        _this.onPopup = null;
        _this.propertyChanged = null;
        _this.popupMouseEnter = null;
        _this.popupMouseLeave = null;
        _this.popupGotFocus = null;
        _this.popupLostFocus = null;
        _this.x = null;
        _this.ag = false;
        _this.a8 = 50;
        _this.al = true;
        _this.o = 0;
        _this.a6 = -1;
        _this.a5 = Popup.ba;
        _this.aw = false;
        _this.cu = Popup.c3;
        _this.ct = Popup.c2;
        _this.cs = Popup.c1;
        _this.cv = null;
        _this.az = 0;
        _this.ah = true;
        _this.ad = false;
        _this.ai = false;
        _this.t = 0;
        _this.cw = null;
        _this.a0 = 20;
        _this.aj = false;
        _this.ae = false;
        _this.af = false;
        _this.ak = false;
        _this.k = null;
        _this.measuringContentSize = null;
        NativeUIInputsFactory.n();
        var a = _this.w();
        _this.x = a;
        a.a0(_this);
        return _this;
    }
    Object.defineProperty(Popup.prototype, "c8", {
        get: function () {
            return this.c7;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "c6", {
        get: function () {
            return this.c5;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "r", {
        get: function () {
            return this.q;
        },
        set: function (a) {
            this.q = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "j", {
        get: function () {
            return this.i;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "a3", {
        get: function () {
            return this.a2;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "be", {
        get: function () {
            return this.bc;
        },
        enumerable: false,
        configurable: true
    });
    Popup.prototype.ch = function (a, b, c) {
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
        this.ck(a, b, c);
    };
    Popup.prototype.cf = function () {
        if (this.popupMouseEnter != null) {
            this.popupMouseEnter(this, new MouseEventArgs());
        }
    };
    Popup.prototype.cg = function () {
        if (this.popupMouseLeave != null) {
            this.popupMouseLeave(this, new MouseEventArgs());
        }
    };
    Popup.prototype.cc = function () {
        if (this.popupGotFocus != null) {
            this.popupGotFocus(this, new FocusEventArgs());
        }
    };
    Popup.prototype.cd = function (a, b) {
        if (this.popupLostFocus != null) {
            this.popupLostFocus(this, ((function () {
                var $ret = new FocusEventArgs();
                $ret.b = a;
                $ret.a = b;
                return $ret;
            })()));
        }
    };
    Object.defineProperty(Popup.prototype, "as", {
        get: function () {
            return this.ag;
        },
        set: function (a) {
            var b = this.ag;
            this.ag = a;
            if (b != this.ag) {
                this.ch("IsFocusable", b, this.ag);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "a9", {
        get: function () {
            return this.a8;
        },
        set: function (a) {
            var b = this.a8;
            this.a8 = a;
            if (b != this.a8) {
                this.ch("AnimationDuration", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "am", {
        get: function () {
            return this.al;
        },
        set: function (a) {
            var b = this.al;
            this.al = a;
            if (b != this.al) {
                this.ch("AnimationEnabled", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "p", {
        get: function () {
            return this.o;
        },
        set: function (a) {
            var b = this.o;
            this.o = a;
            if (b != this.o) {
                this.ch("AnimationType", enumGetBox(PopupAnimationType_$type, b), enumGetBox(PopupAnimationType_$type, this.o));
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "bb", {
        get: function () {
            return this.a6;
        },
        set: function (a) {
            var b = this.a6;
            this.a6 = a;
            if (b != this.a6) {
                this.ch("Elevation", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "a7", {
        get: function () {
            return this.a5;
        },
        set: function (a) {
            var b = this.a5;
            this.a5 = a;
            if (b != this.a5) {
                this.ch("ActualElevation", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "ax", {
        get: function () {
            return this.aw;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "cz", {
        get: function () {
            return this.cu;
        },
        set: function (a) {
            var b = this.cu;
            this.cu = a;
            if (b != this.cu) {
                this.ch("ActualUmbraShadowColor", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "cy", {
        get: function () {
            return this.ct;
        },
        set: function (a) {
            var b = this.ct;
            this.ct = a;
            if (b != this.ct) {
                this.ch("ActualPenumbraShadowColor", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "cx", {
        get: function () {
            return this.cs;
        },
        set: function (a) {
            var b = this.cs;
            this.cs = a;
            if (b != this.cs) {
                this.ch("ActualAmbientShadowColor", b, a);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "c0", {
        get: function () {
            return this.cv;
        },
        set: function (a) {
            var b = this.cv;
            this.cv = a;
            if (b != this.cv) {
                this.ch("Background", b, this.cv);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "a1", {
        get: function () {
            return this.az;
        },
        set: function (a) {
            var b = this.az;
            this.az = a;
            if (b != this.az) {
                this.ch("CornerRadius", b, this.az);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "at", {
        get: function () {
            return this.ah;
        },
        set: function (a) {
            var b = this.ah;
            this.ah = a;
            if (b != this.ah) {
                this.ch("IsHitTestVisible", b, this.ah);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "ao", {
        get: function () {
            return this.ad;
        },
        set: function (a) {
            var b = this.ad;
            this.ad = a;
            if (b != this.ad) {
                this.ch("DisableHitTestDuringAnimation", b, this.ad);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "au", {
        get: function () {
            return this.ai;
        },
        set: function (a) {
            var b = this.ai;
            this.ai = a;
            if (b != this.ai) {
                this.ch("IsPointerEnabled", b, this.ai);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "v", {
        get: function () {
            return this.t;
        },
        set: function (a) {
            var b = this.t;
            this.t = a;
            if (b != this.t) {
                this.ch("PointerPosition", enumGetBox(PopupPointerPosition_$type, b), enumGetBox(PopupPointerPosition_$type, this.t));
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "c4", {
        get: function () {
            return this.cw;
        },
        set: function (a) {
            var b = this.cw;
            this.cw = a;
            if (b != this.cw) {
                this.ch("PointerBackground", b, this.cw);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "a4", {
        get: function () {
            return this.a0;
        },
        set: function (a) {
            var b = this.a0;
            this.a0 = a;
            if (b != this.a0) {
                this.ch("PointerSize", b, this.a0);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "av", {
        get: function () {
            return this.aj;
        },
        set: function (a) {
            this.aj = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "aq", {
        get: function () {
            return this.ae;
        },
        set: function (a) {
            this.ae = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "ar", {
        get: function () {
            return this.af;
        },
        set: function (a) {
            var b = this.af;
            this.af = a;
            if (b != this.af) {
                this.ch("IsFixed", b, this.af);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Popup.prototype, "ay", {
        get: function () {
            return this.ak;
        },
        set: function (a) {
            var b = this.ak;
            this.ak = a;
            if (b != this.ak) {
                this.ch("UseTopLayer", b, this.ak);
            }
        },
        enumerable: false,
        configurable: true
    });
    Popup.prototype.w = function () {
        return new PopupView();
    };
    Popup.prototype.ck = function (a, b, c) {
        switch (a) {
            case "IsShown":
                if (false == this.ax) {
                    this.x.bc();
                    this.bc = null;
                }
                break;
            case "Elevation":
                this.a7 = this.bb == -1 ? Popup.ba : this.bb;
                break;
            case "ActualElevation":
            case "ActualUmbraShadowColor":
            case "ActualPenumbraShadowColor":
            case "ActualAmbientShadowColor":
            case "Background":
            case "CornerRadius":
                this.x.bo();
                break;
            case "AnimationEnabled":
                if (false == this.am) {
                    this.b3();
                }
                break;
            case "IsHitTestVisible":
                this.x.bg(this.at);
                break;
            case "IsFocusable":
                this.x.bf(this.as);
                break;
            case "IsFixed":
                this.x.be(this.ar);
                break;
            case "UseTopLayer":
                this.x.bh(this.ay);
                break;
        }
    };
    Popup.prototype.b3 = function () {
        if (this.ap()) {
            this.k.e();
        }
    };
    Popup.prototype.aa = function (a) {
        var b = this.g(a);
        var c = a ? this.c() : this.b();
        var d = this.x.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.a = function (a) {
        var b = new List$1(IKeyFrameAnimation_$type, 0);
        var c = this.h(a);
        this.x.av(c.h);
        var d = a ? this.c() : this.b();
        var e = this.x.e(d);
        var f = new List$1(AnimationKeyFrameProperty.$, 0);
        var g = new List$1(AnimationKeyFrameProperty.$, 0);
        var h = new AnimationKeyFrameProperty(10, c.g);
        var i = new AnimationKeyFrameProperty(10, c.h);
        f.add(h);
        g.add(i);
        e.m.apply(e, __spreadArray([], __read(f.toArray())));
        e.m.apply(e, __spreadArray([], __read(g.toArray())));
        b.add(KeyFrameAnimationFactory.f.c(e));
        if (this.q == 2) {
            var j = c.c;
            var k = c.f;
            var l = this.x.c(d);
            var m = new List$1(AnimationKeyFrameProperty.$, 0);
            var n = new List$1(AnimationKeyFrameProperty.$, 0);
            var o = new AnimationKeyFrameProperty(12, j);
            var p = new AnimationKeyFrameProperty(12, k);
            m.add(o);
            n.add(p);
            l.m.apply(l, __spreadArray([], __read(m.toArray())));
            l.m.apply(l, __spreadArray([], __read(n.toArray())));
            b.add(KeyFrameAnimationFactory.f.c(l));
        }
        return b.toArray();
    };
    Popup.prototype.b = function () {
        var a = new AnimationKeyFrameEffectTiming();
        a.g = this.a9;
        a.b = 3;
        return a;
    };
    Popup.prototype.c = function () {
        var a = new AnimationKeyFrameEffectTiming();
        a.g = this.a9;
        a.b = 3;
        return a;
    };
    Popup.prototype.b8 = function () {
        this.x.ay();
    };
    Popup.prototype.g = function (a) {
        var b = truncate(this.x.bs.height);
        if (b <= 0) {
            b = 500;
        }
        var c = a ? -b : 0;
        var d = a ? 0 : -b;
        if (this.q == 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.h = function (a) {
        var b = truncate(this.x.bs.height);
        if (b <= 0) {
            b = 500;
        }
        var c = a ? 0 : b;
        var d = a ? b : 0;
        var e = this.c7.top;
        var f = this.c7.top;
        var g = this.c7.left;
        var h = g;
        switch (this.q) {
            case 2:
                e = a ? this.c7.bottom : this.c7.top;
                f = a ? this.c7.top : this.c7.bottom;
                g = this.c7.left;
                h = g;
                break;
            case 1:
                e = this.c7.top;
                f = this.c7.top;
                g = this.c7.left;
                h = g;
                break;
            case 3:
            case 4:
                e = this.c7.top;
                f = e;
                g = this.c7.left;
                h = g;
                break;
        }
        var i = ((function () {
            var $ret = new Popup_OuterAnimationInfo();
            $ret.g = c;
            $ret.h = d;
            $ret.c = e;
            $ret.f = f;
            $ret.a = g;
            $ret.d = h;
            return $ret;
        })());
        return i;
    };
    Popup.prototype.ap = function () {
        if (this.k == null) {
            return false;
        }
        return this.k.b;
    };
    Popup.prototype.b9 = function () {
        this.x.a1();
        if (this.ax) {
            if (this.be != null) {
                this.c7 = this.x.bp(this.be, this.q, this.i);
            }
            else {
                this.c7 = this.x.bq(this.c5, this.q, this.i);
            }
        }
    };
    Popup.prototype.cj = function (a, b, c) {
        this.c5 = a;
        this.q = b;
        this.i = c;
        this.a2 = 0;
        this.x.ba();
        this.c7 = this.x.bq(a, b, c);
    };
    Popup.prototype.ci = function (a, b, c) {
        this.bc = a;
        this.q = b;
        this.i = c;
        this.a2 = 0;
        this.x.ba();
        this.c7 = this.x.bp(a, b, c);
    };
    Popup.prototype.co = function (a, b, c) {
        if (this.aw) {
            this.aw = false;
            this.ch("IsShown", true, this.aw);
        }
        this.cj(a, b, c);
        this.cp(true);
    };
    Popup.prototype.cn = function (a, b, c) {
        if (this.aw) {
            this.aw = false;
            this.ch("IsShown", true, this.aw);
        }
        this.ci(a, b, c);
        this.cp(true);
    };
    Popup.prototype.cp = function (a) {
        var _this = this;
        var b = this.aw;
        this.aw = a;
        this.av = a;
        this.aq = !a;
        if (false == this.am) {
            var c = this.h(a);
            var d = this.g(a);
            var e = this.x.au(c, d);
            c = e.p0;
            d = e.p1;
            return;
        }
        if (this.ap()) {
            this.k.i();
            return;
        }
        this.b8();
        this.k = this.l(this.p, this.aw);
        this.k.h(function (f) {
            _this.k.g();
            if (f) {
                switch (_this.p) {
                    case 0:
                        _this.b5(_this.aw);
                        break;
                    case 1:
                        _this.b4(_this.aw);
                        break;
                }
            }
            _this.ch("IsShown", b, _this.aw);
            if (_this.aw) {
                if (_this.onPopup != null) {
                    _this.onPopup(_this, new OnPopupEventArgs());
                }
            }
            else {
                if (_this.onClosed != null) {
                    _this.onClosed(_this, new OnClosedEventArgs());
                }
            }
            _this.av = false;
            _this.aq = false;
            var g = _this.h(_this.aw);
            var h = _this.g(_this.aw);
            var i = _this.x.au(g, h);
            g = i.p0;
            h = i.p1;
        });
    };
    Popup.prototype.l = function (a, b) {
        switch (a) {
            case 0: return this.n(b);
            case 1: return this.m(b);
            default: return this.n(b);
        }
    };
    Popup.prototype.n = function (a) {
        var b = this.aa(a);
        var c = this.a(a);
        var d = new PopupAnimation();
        d.c.add(b);
        for (var f = 0; f < c.length; f++) {
            var e = c[f];
            d.c.add(e);
        }
        return d;
    };
    Popup.prototype.b5 = function (a) {
        var e_1, _a;
        var b = this.h(a);
        var c = this.g(a);
        try {
            for (var _b = __values(fromEnum(this.k.c)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var d = _c.value;
                for (var e = 0; e < d.effect.f.length; e++) {
                    switch (d.effect.f[e]) {
                        case 14:
                            d.effect.g[e].c(d.effect.a4, ((function () {
                                var $ret = new TranslateTransform();
                                $ret.k = c.b;
                                return $ret;
                            })()));
                            break;
                        case 10:
                            d.effect.g[e].c(d.effect.a4, b.h);
                            break;
                        case 12:
                            d.effect.g[e].c(d.effect.a4, b.f);
                            break;
                    }
                }
            }
        }
        catch (e_1_1) {
            e_1 = { error: e_1_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_1)
                    throw e_1.error;
            }
        }
    };
    Popup.prototype.m = function (a) {
        var b = this.h(a);
        this.x.av(a ? b.h : b.g);
        var c = this.c();
        var d = this.x.c(c);
        var e = DeviceUtils.g(30);
        var f = this.x.i();
        var g = b.f - e;
        var h = b.f;
        switch (this.q) {
            case 2:
                g = a ? b.f + e : b.c + e;
                h = a ? b.f : b.c;
                f = this.x.i();
                break;
            case 1:
                g = b.f - e;
                h = b.f;
                f = this.x.i();
                break;
            case 3:
                g = b.d + e;
                h = b.d;
                f = this.x.h();
                break;
            case 4:
                g = b.d - e;
                h = b.d;
                f = this.x.h();
                break;
        }
        d.m(new AnimationKeyFrameProperty(f, a ? g : h));
        d.m(new AnimationKeyFrameProperty(f, a ? h : g));
        var i = this.x.a(c);
        i.m(new AnimationKeyFrameProperty(1, a ? 0 : 1));
        i.m(new AnimationKeyFrameProperty(1, a ? 1 : 0));
        var j = this.x.b(c);
        j.m(new AnimationKeyFrameProperty(10, (a ? b.h : b.g)));
        j.m(new AnimationKeyFrameProperty(10, (a ? b.h : b.g)));
        var k = new PopupAnimation();
        k.c.add(KeyFrameAnimationFactory.f.c(d));
        k.c.add(KeyFrameAnimationFactory.f.c(i));
        k.c.add(KeyFrameAnimationFactory.f.c(j));
        return k;
    };
    Popup.prototype.b4 = function (a) {
        var e_2, _a;
        var b = this.h(a);
        var c = this.x.i();
        var d = NaN;
        var e = a ? 1 : 0;
        var f = a ? b.h : b.g;
        switch (this.q) {
            case 2:
                c = this.x.i();
                d = a ? b.f : b.c;
                break;
            case 1:
                c = this.x.i();
                d = b.f;
                break;
            case 3:
                c = this.x.h();
                d = b.d;
                break;
            case 4:
                c = this.x.h();
                d = b.d;
                break;
        }
        try {
            for (var _b = __values(fromEnum(this.k.c)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var g = _c.value;
                for (var h = 0; h < g.effect.f.length; h++) {
                    if (g.effect.f[h] == c) {
                        g.effect.g[h].c(g.effect.a4, d);
                    }
                    else if (g.effect.f[h] == 1) {
                        g.effect.g[h].c(g.effect.a4, e);
                    }
                    else if (g.effect.f[h] == 10) {
                        g.effect.g[h].c(g.effect.a4, f);
                    }
                }
            }
        }
        catch (e_2_1) {
            e_2 = { error: e_2_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_2)
                    throw e_2.error;
            }
        }
    };
    Popup.prototype.contains = function (a) {
        return this.x.j(a);
    };
    Popup.prototype.appendPopupContent = function (a) {
        this.x.aw(a);
    };
    Popup.prototype.removePopupContent = function (a) {
        this.x.bb(a);
    };
    Popup.prototype.b6 = function () {
        if (!this.aw) {
            return;
        }
        this.cp(false);
    };
    Popup.prototype.destroy = function () {
        this.provideRenderer(null);
    };
    Popup.prototype.showRelativeToExclusionRect = function (a, b, c) {
        this.co(a, b, c);
    };
    Popup.prototype.cr = function (a, b, c) {
        this.cn(a, b, c);
    };
    Popup.prototype.ca = function (a) {
        this.c5 = a;
        this.c7 = this.x.bq(a, this.q, this.i);
    };
    Popup.prototype.notifySizeChanged = function () {
    };
    Popup.prototype.provideRenderer = function (a) {
        this.x.a9(a);
    };
    Popup.prototype.bd = function () {
        return this.d();
    };
    Popup.prototype.bq = function () {
        var a = this.d();
        return a.f();
    };
    Popup.prototype.d = function () {
        var a = new PopupVisualModelExport();
        a.e = this.a7;
        a.d = this.ax;
        a.c = AppearanceHelper.a(this.cz);
        a.b = AppearanceHelper.a(this.cy);
        a.a = AppearanceHelper.a(this.cx);
        return a;
    };
    Popup.prototype.u = function () {
        var a = this.v;
        if (a == 0) {
            switch (this.r) {
                case 4:
                    a = 3;
                    break;
                case 3:
                    a = 4;
                    break;
                case 2:
                    a = 2;
                    break;
                case 1:
                    a = 1;
                    break;
            }
        }
        return a;
    };
    Popup.prototype.ce = function () {
        if (this.measuringContentSize != null) {
            this.measuringContentSize(this, new PopupMeasuringContentSizeEventArgs());
        }
    };
    Popup.$t = markType(Popup, 'Popup', Base.$, [INotifyPropertyChanged_$type]);
    Popup.ba = 2;
    Popup.c3 = BrushUtil.h(66, 0, 0, 0);
    Popup.c2 = BrushUtil.h(30, 0, 0, 0);
    Popup.c1 = BrushUtil.h(20, 0, 0, 0);
    return Popup;
}(Base));
export { Popup };
