var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "../../core/Bind", "../../core/BindableProperty", "../../core/XNode", "../styles/AtomNotificationStyle", "./AtomControl"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const Bind_1 = require("../../core/Bind");
    const BindableProperty_1 = require("../../core/BindableProperty");
    const XNode_1 = require("../../core/XNode");
    const AtomNotificationStyle_1 = require("../styles/AtomNotificationStyle");
    const AtomControl_1 = require("./AtomControl");
    class AtomNotification extends AtomControl_1.AtomControl {
        constructor() {
            super(...arguments);
            this.timeout = 5000;
            this.timeoutKey = null;
        }
        onPropertyChanged(name) {
            switch (name) {
                case "timeout":
                    this.setupTimeout();
                    break;
            }
        }
        create() {
            this.defaultControlStyle = AtomNotificationStyle_1.default;
            this.render(XNode_1.default.create("div", { formattedText: Bind_1.default.oneWay(() => this.viewModel.message), timeout: Bind_1.default.oneWay(() => this.viewModel.timeout || 5000), styleClass: Bind_1.default.oneWay(() => ({
                    [this.controlStyle.name]: 1,
                    error: this.viewModel.type && /error/i.test(this.viewModel.type),
                    warning: this.viewModel.type && /warn/i.test(this.viewModel.type),
                })) }));
        }
        setupTimeout() {
            if (this.timeoutKey) {
                clearTimeout(this.timeoutKey);
            }
            this.timeoutKey = setTimeout(() => {
                if (this.element) {
                    this.app.broadcast(`atom-window-close:${this.id}`, "");
                }
            }, this.timeout);
        }
    }
    __decorate([
        BindableProperty_1.BindableProperty,
        __metadata("design:type", Number)
    ], AtomNotification.prototype, "timeout", void 0);
    exports.default = AtomNotification;
});
//# sourceMappingURL=AtomNotification.js.map